Skip to content

Commit

Permalink
corretto errore dati ISTAT file comuni_italiani 17/01/2024
Browse files Browse the repository at this point in the history
  • Loading branch information
MocioF committed Jan 18, 2024
1 parent 54465e6 commit 62ac392
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</rule>
<rule ref="WordPress.NamingConventions.ValidVariableName">
<properties>
<property name="customPropertiesWhitelist" type="array">
<property name="allowed_custom_properties" type="array">
<element value="nodeName"/>
<element value="nodeValue"/>
<element value="statIndex"/>
Expand Down
59 changes: 42 additions & 17 deletions admin/class-gcmi-activator.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,9 +777,12 @@ public static function create_db_table( $name, $table ) {
i_cod_comune_num_2006_2009 int(6) NOT NULL,
i_cod_comune_num_1995_2005 int(6) NOT NULL,
i_cod_catastale char(4) NOT NULL,
i_nuts1 char(3) NOT NULL,
i_nuts23 char(4) NOT NULL,
i_nuts3 char(5) NOT NULL,
i_nuts1_2010 char(3) NOT NULL,
i_nuts2_2010 char(4) NOT NULL,
i_nuts3_2010 char(5) NOT NULL,
i_nuts1_2021 char(3) NOT NULL,
i_nuts2_2021 char(4) NOT NULL,
i_nuts3_2021 char(5) NOT NULL,
PRIMARY KEY (id)
) $charset_collate";
break;
Expand Down Expand Up @@ -967,6 +970,22 @@ public static function convert_file_charset( $filepath, $orig_enc = 'UTF-8' ) {
return true;
}

/**
*
* @param string $string Una stringa numerica
* @param int $len il numero di caratteri della stringa restituita
* @return string
*/
private static function add_trailing_zeroes( $string, $len ) {
if ( ! is_numeric( $string ) ) {
return $string;
}
if ( $len === strlen( $string ) ) {
return $string;
}
return sprintf( '%0' . strval( $len ) . 's', $string );
}

/**
* Populates a db table.
*
Expand Down Expand Up @@ -1033,29 +1052,32 @@ public static function populate_db_table( $name, $csv_file_path, $table ) {
if ( ! ( $wpdb->insert(
$table,
array(
'i_cod_regione' => $gcmi_dati_line[0],
'i_cod_unita_territoriale' => $gcmi_dati_line[1],
'i_cod_provincia_storico' => $gcmi_dati_line[2],
'i_prog_comune' => $gcmi_dati_line[3],
'i_cod_comune' => $gcmi_dati_line[4],
'i_denominazione_full' => $gcmi_dati_line[5],
'i_denominazione_ita' => $gcmi_dati_line[6],
'i_cod_regione' => self::add_trailing_zeroes( trim( $gcmi_dati_line[0] ), 2 ),
'i_cod_unita_territoriale' => self::add_trailing_zeroes( trim( $gcmi_dati_line[1] ), 3 ),
'i_cod_provincia_storico' => self::add_trailing_zeroes( trim( $gcmi_dati_line[2] ), 3 ),
'i_prog_comune' => self::add_trailing_zeroes( trim( $gcmi_dati_line[3] ), 3 ),
'i_cod_comune' => self::add_trailing_zeroes( trim( $gcmi_dati_line[4] ), 6 ),
'i_denominazione_full' => trim( $gcmi_dati_line[5] ),
'i_denominazione_ita' => trim( $gcmi_dati_line[6] ),
'i_denominazione_altralingua' => $gcmi_dati_line[7],
'i_cod_ripartizione_geo' => $gcmi_dati_line[8],
'i_ripartizione_geo' => $gcmi_dati_line[9],
'i_den_regione' => $gcmi_dati_line[10],
'i_den_unita_territoriale' => $gcmi_dati_line[11],
'i_ripartizione_geo' => trim( $gcmi_dati_line[9] ),
'i_den_regione' => trim( $gcmi_dati_line[10] ),
'i_den_unita_territoriale' => trim( $gcmi_dati_line[11] ),
'i_cod_tipo_unita_territoriale' => $gcmi_dati_line[12],
'i_flag_capoluogo' => $gcmi_dati_line[13],
'i_sigla_automobilistica' => $gcmi_dati_line[14],
'i_sigla_automobilistica' => trim( $gcmi_dati_line[14] ),
'i_cod_comune_num' => $gcmi_dati_line[15],
'i_cod_comune_num_2010_2016' => $gcmi_dati_line[16],
'i_cod_comune_num_2006_2009' => $gcmi_dati_line[17],
'i_cod_comune_num_1995_2005' => $gcmi_dati_line[18],
'i_cod_catastale' => $gcmi_dati_line[19],
'i_nuts1' => $gcmi_dati_line[20],
'i_nuts23' => $gcmi_dati_line[21],
'i_nuts3' => $gcmi_dati_line[22],
'i_nuts1_2010' => $gcmi_dati_line[20],
'i_nuts2_2010' => $gcmi_dati_line[21],
'i_nuts3_2010' => $gcmi_dati_line[22],
'i_nuts1_2021' => $gcmi_dati_line[23],
'i_nuts2_2021' => $gcmi_dati_line[24],
'i_nuts3_2021' => $gcmi_dati_line[25],
),
array(
'%s',
Expand All @@ -1081,6 +1103,9 @@ public static function populate_db_table( $name, $csv_file_path, $table ) {
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
)
) )
) {
Expand Down
4 changes: 2 additions & 2 deletions campi-moduli-italiani.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
* Domain Path: /languages
* Plugin URI: https://wordpress.org/plugins/campi-moduli-italiani/
* Description: (Generator of) Fields for Italian CF7 and wpforms modules. The plugin generates specific fields for Italian forms created with Contact Form 7 and wpforms. This version makes available 4 form-tags for CF7 and 2 fields for wpforms: a cascade selection for an Italian municipality (CF7 + wpforms), a select for a state (CF7 + wpforms), an Italian tax code field with validation (CF7 only), a hidden field that allows you to digitally sign e-mails to ensure that they have been sent via the form (CF7 only). The databases are taken from the Istat and Agenzia delle entrate websites. The digital signature on the form data uses the RSA algorithm with a 4096 bit private key. <strong> Activation can take a few minutes to download the updated data and to import them into the database </strong>.
* Version: 2.1.4
* Version: 2.1.5
* Author: Giuseppe Foti
* Author URI: https://bertocchi28.ddns.net/
* License: GPLv2 or later
**/

defined( 'ABSPATH' ) || die( 'you do not have access to this page!' );

define( 'GCMI_VERSION', '2.1.4' );
define( 'GCMI_VERSION', '2.1.5' );
define( 'GCMI_MINIMUM_WP_VERSION', '5.9' );
define( 'GCMI_MINIMUM_PHP_VERSION', '7.2' );
define( 'GCMI_MINIMUM_CF7_VERSION', '5.1.7' );
Expand Down
2 changes: 1 addition & 1 deletion integrations/contact-form-7/contact-form-7-legacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function gcmi_wpcf7_select_validation_filter( $result, $tag ) {
if ( $has_value and $tag->has_option( 'multiple' ) ) {
$vals = array_filter(
(array) $_POST[ $name ],
function( $val ) {
function ( $val ) {
return '' !== $val;
}
);
Expand Down
5 changes: 2 additions & 3 deletions integrations/wpforms/wpforms-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function gcmi_wpforms_builder_fields_buttons( $fields ) {
if ( GCMI_USE_STATO === true ) {
add_action(
'init',
function() {
function () {
require_once plugin_dir_path( GCMI_PLUGIN ) . 'modules/stato/class-wpforms-field-stato.php';
},
99
Expand All @@ -45,10 +45,9 @@ function() {
if ( GCMI_USE_COMUNE === true ) {
add_action(
'init',
function() {
function () {
require_once plugin_dir_path( GCMI_PLUGIN ) . 'modules/comune/class-wpforms-field-comune.php';
},
99
);
}

53 changes: 26 additions & 27 deletions modules/cf/class-gcmi-cf-wpcf7-formtag.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function gcmi_cf_WPCF7_addfilter() {
// mail tag filter: converte in maiuscolo.
add_filter(
'wpcf7_mail_tag_replaced_cf*',
function( $replaced, $submitted, $html, $mail_tag ) {
function ( $replaced, $submitted, $html, $mail_tag ) {
$replaced = strtoupper( $submitted );
return $replaced;
},
Expand All @@ -40,7 +40,7 @@ function( $replaced, $submitted, $html, $mail_tag ) {

add_filter(
'wpcf7_mail_tag_replaced_cf',
function( $replaced, $submitted, $html, $mail_tag ) {
function ( $replaced, $submitted, $html, $mail_tag ) {
$replaced = strtoupper( $submitted );
return $replaced;
},
Expand Down Expand Up @@ -116,13 +116,13 @@ public static function cf_validation_filter( $result, $tag ) {
$parte_cognome = $matches2[0][0] . $matches2[0][1] . $matches2[0][2];
} else {
for ( $i = 0; $i < $nconsonanti; $i++ ) {
$parte_cognome = $parte_cognome . $matches2[0][ $i ];
$parte_cognome = $parte_cognome . $matches2[0][ $i ];
}
$n = 3 - strlen( $parte_cognome );
$n = 3 - strlen( $parte_cognome );
for ( $i = 0; $i < $n; $i++ ) {
$parte_cognome = $parte_cognome . $matches1[0][ $i ];
$parte_cognome = $parte_cognome . $matches1[0][ $i ];
}
$n = 3 - strlen( $parte_cognome );
$n = 3 - strlen( $parte_cognome );
for ( $i = 0; $i < $n;
$i++ ) {
$parte_cognome = $parte_cognome . 'X';
Expand Down Expand Up @@ -158,13 +158,13 @@ public static function cf_validation_filter( $result, $tag ) {
$parte_nome = $matches2[0][0] . $matches2[0][1] . $matches2[0][2];
} else {
for ( $i = 0; $i < $nconsonanti; $i++ ) {
$parte_nome = $parte_nome . $matches2[0][ $i ];
$parte_nome = $parte_nome . $matches2[0][ $i ];
}
$n = 3 - strlen( $parte_nome );
$n = 3 - strlen( $parte_nome );
for ( $i = 0; $i < $n; $i++ ) {
$parte_nome = $parte_nome . $matches1[0][ $i ];
$parte_nome = $parte_nome . $matches1[0][ $i ];
}
$n = 3 - strlen( $parte_nome );
$n = 3 - strlen( $parte_nome );
for ( $i = 0; $i < $n;
$i++ ) {
$parte_nome = $parte_nome . 'X';
Expand Down Expand Up @@ -321,27 +321,26 @@ public static function cf_validation_filter( $result, $tag ) {
$err_msg = esc_html( __( 'Unexpected value in birth country field', 'campi-moduli-italiani' ) );
$err_tit = esc_html( __( 'Error in submitted birth country value', 'campi-moduli-italiani' ) );
wp_die( $err_msg, $err_tit );
} else {
if ( '100' !== $codice_stato ) { // 100 è il codice ISTAT per l'ITALIA
} elseif ( '100' !== $codice_stato ) {
// 100 è il codice ISTAT per l'ITALIA
$cache_key = 'gcmi_codice_stato_cf_' . strval( $codice_stato );
$cod_at = wp_cache_get( $cache_key, GCMI_CACHE_GROUP );
if ( false === $cod_at ) {
$sql = 'SELECT `i_cod_AT` FROM ';
$sql .= '( ';
$sql .= 'SELECT `i_cod_AT` FROM `' . GCMI_TABLE_PREFIX . 'stati` ';
$sql .= "WHERE `i_cod_istat` = '" . esc_sql( $codice_stato ) . "'";
$sql .= 'UNION ';
$sql .= 'SELECT `i_cod_AT` FROM `' . GCMI_TABLE_PREFIX . 'stati_cessati` ';
$sql .= "WHERE `i_cod_istat` = '" . esc_sql( $codice_stato ) . "'";
$sql .= ') as subQuery ';
if ( false === $cod_at ) {
$sql = 'SELECT `i_cod_AT` FROM ';
$sql .= '( ';
$sql .= 'SELECT `i_cod_AT` FROM `' . GCMI_TABLE_PREFIX . 'stati` ';
$sql .= "WHERE `i_cod_istat` = '" . esc_sql( $codice_stato ) . "'";
$sql .= 'UNION ';
$sql .= 'SELECT `i_cod_AT` FROM `' . GCMI_TABLE_PREFIX . 'stati_cessati` ';
$sql .= "WHERE `i_cod_istat` = '" . esc_sql( $codice_stato ) . "'";
$sql .= ') as subQuery ';

$cod_at = $wpdb->get_var( $sql );
wp_cache_set( $cache_key, $cod_at, GCMI_CACHE_GROUP, GCMI_CACHE_EXPIRE_SECS );
}
$cod_at = $wpdb->get_var( $sql );
wp_cache_set( $cache_key, $cod_at, GCMI_CACHE_GROUP, GCMI_CACHE_EXPIRE_SECS );
}

if ( $comune !== $cod_at ) {
$result->invalidate( $tag, esc_html( __( 'Tax code does not match the Country of birth', 'campi-moduli-italiani' ) ) );
}
if ( $comune !== $cod_at ) {
$result->invalidate( $tag, esc_html( __( 'Tax code does not match the Country of birth', 'campi-moduli-italiani' ) ) );
}
}
}
Expand Down
74 changes: 36 additions & 38 deletions modules/comune/class-gcmi-comune.php
Original file line number Diff line number Diff line change
Expand Up @@ -916,58 +916,56 @@ public static function gcmi_get_data_from_comune( $i_cod_comune, $kind ) {
if ( $results ) {
wp_cache_set( $cache_key, $results, GCMI_CACHE_GROUP, GCMI_CACHE_EXPIRE_SECS );
$output_string = $results['i_cod_regione'] . $results['i_cod_unita_territoriale'] . $i_cod_comune;
} else { // non ha trovato nulla nei comuni attuali.
if ( 'attuali' !== $kind ) {
} elseif ( 'attuali' !== $kind ) { // non ha trovato nulla nei comuni attuali.
$cache_key = 'gcmi_data_from_comune_cessato_' . sanitize_key( $i_cod_comune );
$results = wp_cache_get( $cache_key, GCMI_CACHE_GROUP );
if ( false === $results ) {
$results = $wpdb->get_row(
$wpdb->prepare(
'SELECT `i_cod_unita_territoriale`, `i_sigla_automobilistica` ' .
'FROM `' . GCMI_TABLE_PREFIX . 'comuni_soppressi` ' .
'WHERE `i_cod_comune` = %s LIMIT 1',
$i_cod_comune
),
ARRAY_A
);
wp_cache_set( $cache_key, $results, GCMI_CACHE_GROUP, GCMI_CACHE_EXPIRE_SECS );
}
$targa = $results['i_sigla_automobilistica'];
$old_provincia = $results['i_cod_unita_territoriale'];

if ( '7' === substr( $old_provincia, 0, 1 ) ) { // Istria e Dalmazia.
$cod_provincia = $old_provincia;
$cod_regione = self::$def_strings['COD_REG_ISDA'];
} else {
$cache_key = 'gcmi_data_from_targa_' . strval( $targa );
$results = wp_cache_get( $cache_key, GCMI_CACHE_GROUP );
if ( false === $results ) {
$results = $wpdb->get_row(
$wpdb->prepare(
'SELECT `i_cod_unita_territoriale`, `i_sigla_automobilistica` ' .
'FROM `' . GCMI_TABLE_PREFIX . 'comuni_soppressi` ' .
'WHERE `i_cod_comune` = %s LIMIT 1',
$i_cod_comune
'SELECT `i_cod_regione`, `i_cod_unita_territoriale`, `i_sigla_automobilistica` ' .
'FROM `' . GCMI_TABLE_PREFIX . 'comuni_attuali` ' .
'WHERE `' . GCMI_TABLE_PREFIX . 'comuni_attuali`.`i_sigla_automobilistica` = %s LIMIT 1',
$targa
),
ARRAY_A
);
wp_cache_set( $cache_key, $results, GCMI_CACHE_GROUP, GCMI_CACHE_EXPIRE_SECS );
}
$targa = $results['i_sigla_automobilistica'];
$old_provincia = $results['i_cod_unita_territoriale'];

if ( '7' === substr( $old_provincia, 0, 1 ) ) { // Istria e Dalmazia.
$cod_provincia = $old_provincia;
$cod_regione = self::$def_strings['COD_REG_ISDA'];
} else {
$cache_key = 'gcmi_data_from_targa_' . strval( $targa );
$results = wp_cache_get( $cache_key, GCMI_CACHE_GROUP );
if ( false === $results ) {
$results = $wpdb->get_row(
$wpdb->prepare(
'SELECT `i_cod_regione`, `i_cod_unita_territoriale`, `i_sigla_automobilistica` ' .
'FROM `' . GCMI_TABLE_PREFIX . 'comuni_attuali` ' .
'WHERE `' . GCMI_TABLE_PREFIX . 'comuni_attuali`.`i_sigla_automobilistica` = %s LIMIT 1',
$targa
),
ARRAY_A
);
wp_cache_set( $cache_key, $results, GCMI_CACHE_GROUP, GCMI_CACHE_EXPIRE_SECS );
}

$cod_provincia = $results['i_cod_unita_territoriale'];
$cod_regione = $results['i_cod_regione'];
}
$cod_provincia = $results['i_cod_unita_territoriale'];
$cod_regione = $results['i_cod_regione'];
}

if ( 'evidenza_cessati' === $kind ) {
$output_string = $cod_regione . $cod_provincia . $i_cod_comune;
}
if ( 'evidenza_cessati' === $kind ) {
$output_string = $cod_regione . $cod_provincia . $i_cod_comune;
}

if ( 'tutti' === $kind ) {
$output_string = self::$def_strings['COD_REG_SOPP'] . $cod_provincia . $i_cod_comune;
}
} else {
$output_string = '00000000000';
if ( 'tutti' === $kind ) {
$output_string = self::$def_strings['COD_REG_SOPP'] . $cod_provincia . $i_cod_comune;
}
} else {
$output_string = '00000000000';
}
return $output_string;
}
Expand Down
Loading

0 comments on commit 62ac392

Please sign in to comment.