openstamanager/update/2_4_2.php

668 lines
17 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*
* Aggiornamento nazioni con codice ISO 3166-1 alpha-2 e nome in inglese.
* @source umpirsky/country-list
*/
$it = [
'AF' => 'Afghanistan',
'AL' => 'Albania',
'DZ' => 'Algeria',
'UM' => 'Altre isole americane del Pacifico',
'AD' => 'Andorra',
'AO' => 'Angola',
'AI' => 'Anguilla',
'AQ' => 'Antartide',
'AG' => 'Antigua e Barbuda',
'SA' => 'Arabia Saudita',
'AR' => 'Argentina',
'AM' => 'Armenia',
'AW' => 'Aruba',
'AU' => 'Australia',
'AT' => 'Austria',
'AZ' => 'Azerbaigian',
'BS' => 'Bahamas',
'BH' => 'Bahrein',
'BD' => 'Bangladesh',
'BB' => 'Barbados',
'BE' => 'Belgio',
'BZ' => 'Belize',
'BJ' => 'Benin',
'BM' => 'Bermuda',
'BT' => 'Bhutan',
'BY' => 'Bielorussia',
'BO' => 'Bolivia',
'BA' => 'Bosnia ed Erzegovina',
'BW' => 'Botswana',
'BR' => 'Brasile',
'BN' => 'Brunei',
'BG' => 'Bulgaria',
'BF' => 'Burkina Faso',
'BI' => 'Burundi',
'KH' => 'Cambogia',
'CM' => 'Camerun',
'CA' => 'Canada',
'CV' => 'Capo Verde',
'BQ' => 'Caraibi olandesi',
'CZ' => 'Repubblica ceca',
'EA' => 'Ceuta e Melilla',
'TD' => 'Ciad',
'CL' => 'Cile',
'CN' => 'Cina',
'CY' => 'Cipro',
'VA' => 'Città del Vaticano',
'CO' => 'Colombia',
'KM' => 'Comore',
'CD' => 'Congo - Kinshasa',
'CG' => 'Congo-Brazzaville',
'KP' => 'Corea del Nord',
'KR' => 'Corea del Sud',
'CI' => 'Costa dAvorio',
'CR' => 'Costa Rica',
'HR' => 'Croazia',
'CU' => 'Cuba',
'CW' => 'Curaçao',
'DK' => 'Danimarca',
'DG' => 'Diego Garcia',
'DM' => 'Dominica',
'EC' => 'Ecuador',
'EG' => 'Egitto',
'SV' => 'El Salvador',
'AE' => 'Emirati Arabi Uniti',
'ER' => 'Eritrea',
'EE' => 'Estonia',
'ET' => 'Etiopia',
'EZ' => 'Eurozone',
'FJ' => 'Figi',
'PH' => 'Filippine',
'FI' => 'Finlandia',
'FR' => 'Francia',
'GA' => 'Gabon',
'GM' => 'Gambia',
'GE' => 'Georgia',
'GS' => 'Georgia del Sud e Sandwich australi',
'DE' => 'Germania',
'GH' => 'Ghana',
'JM' => 'Giamaica',
'JP' => 'Giappone',
'GI' => 'Gibilterra',
'DJ' => 'Gibuti',
'JO' => 'Giordania',
'GR' => 'Grecia',
'GD' => 'Grenada',
'GL' => 'Groenlandia',
'GP' => 'Guadalupa',
'GU' => 'Guam',
'GT' => 'Guatemala',
'GG' => 'Guernsey',
'GN' => 'Guinea',
'GQ' => 'Guinea Equatoriale',
'GW' => 'Guinea-Bissau',
'GY' => 'Guyana',
'GF' => 'Guyana francese',
'HT' => 'Haiti',
'HN' => 'Honduras',
'IN' => 'India',
'ID' => 'Indonesia',
'IR' => 'Iran',
'IQ' => 'Iraq',
'IE' => 'Irlanda',
'IS' => 'Islanda',
'AC' => 'Isola Ascensione',
'CX' => 'Isola Christmas',
'IM' => 'Isola di Man',
'NF' => 'Isola Norfolk',
'AX' => 'Isole Åland',
'IC' => 'Isole Canarie',
'KY' => 'Isole Cayman',
'CC' => 'Isole Cocos (Keeling)',
'CK' => 'Isole Cook',
'FO' => 'Isole Fær Øer',
'FK' => 'Isole Falkland',
'MP' => 'Isole Marianne settentrionali',
'MH' => 'Isole Marshall',
'PN' => 'Isole Pitcairn',
'SB' => 'Isole Salomone',
'TC' => 'Isole Turks e Caicos',
'VI' => 'Isole Vergini Americane',
'VG' => 'Isole Vergini Britanniche',
'IL' => 'Israele',
'IT' => 'Italia',
'JE' => 'Jersey',
'KZ' => 'Kazakistan',
'KE' => 'Kenya',
'KG' => 'Kirghizistan',
'KI' => 'Kiribati',
'XK' => 'Kosovo',
'KW' => 'Kuwait',
'LA' => 'Laos',
'LS' => 'Lesotho',
'LV' => 'Lettonia',
'LB' => 'Libano',
'LR' => 'Liberia',
'LY' => 'Libia',
'LI' => 'Liechtenstein',
'LT' => 'Lituania',
'LU' => 'Lussemburgo',
'MG' => 'Madagascar',
'MW' => 'Malawi',
'MY' => 'Malesia',
'MV' => 'Maldive',
'ML' => 'Mali',
'MT' => 'Malta',
'MA' => 'Marocco',
'MQ' => 'Martinica',
'MR' => 'Mauritania',
'MU' => 'Mauritius',
'YT' => 'Mayotte',
'MX' => 'Messico',
'FM' => 'Micronesia',
'MD' => 'Moldavia',
'MC' => 'Monaco',
'MN' => 'Mongolia',
'ME' => 'Montenegro',
'MS' => 'Montserrat',
'MZ' => 'Mozambico',
'MM' => 'Myanmar (Birmania)',
'NA' => 'Namibia',
'NR' => 'Nauru',
'UN' => 'nazioni unite',
'NP' => 'Nepal',
'NI' => 'Nicaragua',
'NE' => 'Niger',
'NG' => 'Nigeria',
'NU' => 'Niue',
'NO' => 'Norvegia',
'NC' => 'Nuova Caledonia',
'NZ' => 'Nuova Zelanda',
'OM' => 'Oman',
'NL' => 'Paesi Bassi',
'PK' => 'Pakistan',
'PW' => 'Palau',
'PA' => 'Panamá',
'PG' => 'Papua Nuova Guinea',
'PY' => 'Paraguay',
'PE' => 'Perù',
'PF' => 'Polinesia francese',
'PL' => 'Polonia',
'PT' => 'Portogallo',
'PR' => 'Portorico',
'QA' => 'Qatar',
'HK' => 'RAS di Hong Kong',
'MO' => 'RAS di Macao',
'GB' => 'Regno Unito',
'CF' => 'Repubblica Centrafricana',
'MK' => 'Repubblica di Macedonia',
'DO' => 'Repubblica Dominicana',
'RE' => 'Riunione',
'RO' => 'Romania',
'RW' => 'Ruanda',
'RU' => 'Russia',
'EH' => 'Sahara occidentale',
'KN' => 'Saint Kitts e Nevis',
'LC' => 'Saint Lucia',
'MF' => 'Saint Martin',
'PM' => 'Saint Pierre e Miquelon',
'VC' => 'Saint Vincent e Grenadines',
'BL' => 'Saint-Barthélemy',
'WS' => 'Samoa',
'AS' => 'Samoa americane',
'SM' => 'San Marino',
'SH' => 'SantElena',
'ST' => 'São Tomé e Príncipe',
'SN' => 'Senegal',
'RS' => 'Serbia',
'SC' => 'Seychelles',
'SL' => 'Sierra Leone',
'SG' => 'Singapore',
'SX' => 'Sint Maarten',
'SY' => 'Siria',
'SK' => 'Slovacchia',
'SI' => 'Slovenia',
'SO' => 'Somalia',
'ES' => 'Spagna',
'LK' => 'Sri Lanka',
'US' => 'Stati Uniti',
'SS' => 'Sud Sudan',
'ZA' => 'Sudafrica',
'SD' => 'Sudan',
'SR' => 'Suriname',
'SJ' => 'Svalbard e Jan Mayen',
'SE' => 'Svezia',
'CH' => 'Svizzera',
'SZ' => 'Swaziland',
'TJ' => 'Tagikistan',
'TW' => 'Taiwan',
'TZ' => 'Tanzania',
'TF' => 'Terre australi francesi',
'PS' => 'Territori palestinesi',
'IO' => 'Territorio britannico dellOceano Indiano',
'TH' => 'Thailandia',
'TL' => 'Timor Est',
'TG' => 'Togo',
'TK' => 'Tokelau',
'TO' => 'Tonga',
'TT' => 'Trinidad e Tobago',
'TA' => 'Tristan da Cunha',
'TN' => 'Tunisia',
'TR' => 'Turchia',
'TM' => 'Turkmenistan',
'TV' => 'Tuvalu',
'UA' => 'Ucraina',
'UG' => 'Uganda',
'HU' => 'Ungheria',
'UY' => 'Uruguay',
'UZ' => 'Uzbekistan',
'VU' => 'Vanuatu',
'VE' => 'Venezuela',
'VN' => 'Vietnam',
'WF' => 'Wallis e Futuna',
'YE' => 'Yemen',
'ZM' => 'Zambia',
'ZW' => 'Zimbabwe',
'AN' => 'Antille olandesi',
];
$en = [
'AF' => 'Afghanistan',
'AX' => 'Åland Islands',
'AL' => 'Albania',
'DZ' => 'Algeria',
'AS' => 'American Samoa',
'AD' => 'Andorra',
'AO' => 'Angola',
'AI' => 'Anguilla',
'AQ' => 'Antarctica',
'AG' => 'Antigua & Barbuda',
'AR' => 'Argentina',
'AM' => 'Armenia',
'AW' => 'Aruba',
'AC' => 'Ascension Island',
'AU' => 'Australia',
'AT' => 'Austria',
'AZ' => 'Azerbaijan',
'BS' => 'Bahamas',
'BH' => 'Bahrain',
'BD' => 'Bangladesh',
'BB' => 'Barbados',
'BY' => 'Belarus',
'BE' => 'Belgium',
'BZ' => 'Belize',
'BJ' => 'Benin',
'BM' => 'Bermuda',
'BT' => 'Bhutan',
'BO' => 'Bolivia',
'BA' => 'Bosnia & Herzegovina',
'BW' => 'Botswana',
'BR' => 'Brazil',
'IO' => 'British Indian Ocean Territory',
'VG' => 'British Virgin Islands',
'BN' => 'Brunei',
'BG' => 'Bulgaria',
'BF' => 'Burkina Faso',
'BI' => 'Burundi',
'KH' => 'Cambodia',
'CM' => 'Cameroon',
'CA' => 'Canada',
'IC' => 'Canary Islands',
'CV' => 'Cape Verde',
'BQ' => 'Caribbean Netherlands',
'KY' => 'Cayman Islands',
'CF' => 'Central African Republic',
'EA' => 'Ceuta & Melilla',
'TD' => 'Chad',
'CL' => 'Chile',
'CN' => 'China',
'CX' => 'Christmas Island',
'CC' => 'Cocos (Keeling) Islands',
'CO' => 'Colombia',
'KM' => 'Comoros',
'CG' => 'Repubblica del Congo',
'CD' => 'Repubblica Democratica del Congo',
'CK' => 'Cook Islands',
'CR' => 'Costa Rica',
'CI' => 'Côte dIvoire',
'HR' => 'Croatia',
'CU' => 'Cuba',
'CW' => 'Curaçao',
'CY' => 'Cyprus',
'CZ' => 'Czechia',
'DK' => 'Denmark',
'DG' => 'Diego Garcia',
'DJ' => 'Djibouti',
'DM' => 'Dominica',
'DO' => 'Dominican Republic',
'EC' => 'Ecuador',
'EG' => 'Egypt',
'SV' => 'El Salvador',
'GQ' => 'Equatorial Guinea',
'ER' => 'Eritrea',
'EE' => 'Estonia',
'ET' => 'Ethiopia',
'EZ' => 'Eurozone',
'FK' => 'Falkland Islands',
'FO' => 'Faroe Islands',
'FJ' => 'Fiji',
'FI' => 'Finland',
'FR' => 'France',
'GF' => 'French Guiana',
'PF' => 'French Polynesia',
'TF' => 'French Southern Territories',
'GA' => 'Gabon',
'GM' => 'Gambia',
'GE' => 'Georgia',
'DE' => 'Germany',
'GH' => 'Ghana',
'GI' => 'Gibraltar',
'GR' => 'Greece',
'GL' => 'Greenland',
'GD' => 'Grenada',
'GP' => 'Guadeloupe',
'GU' => 'Guam',
'GT' => 'Guatemala',
'GG' => 'Guernsey',
'GN' => 'Guinea',
'GW' => 'Guinea-Bissau',
'GY' => 'Guyana',
'HT' => 'Haiti',
'HN' => 'Honduras',
'HK' => 'Hong Kong SAR China',
'HU' => 'Hungary',
'IS' => 'Iceland',
'IN' => 'India',
'ID' => 'Indonesia',
'IR' => 'Iran',
'IQ' => 'Iraq',
'IE' => 'Ireland',
'IM' => 'Isle of Man',
'IL' => 'Israel',
'IT' => 'Italy',
'JM' => 'Jamaica',
'JP' => 'Japan',
'JE' => 'Jersey',
'JO' => 'Jordan',
'KZ' => 'Kazakhstan',
'KE' => 'Kenya',
'KI' => 'Kiribati',
'XK' => 'Kosovo',
'KW' => 'Kuwait',
'KG' => 'Kyrgyzstan',
'LA' => 'Laos',
'LV' => 'Latvia',
'LB' => 'Lebanon',
'LS' => 'Lesotho',
'LR' => 'Liberia',
'LY' => 'Libya',
'LI' => 'Liechtenstein',
'LT' => 'Lithuania',
'LU' => 'Luxembourg',
'MO' => 'Macau SAR China',
'MK' => 'Macedonia',
'MG' => 'Madagascar',
'MW' => 'Malawi',
'MY' => 'Malaysia',
'MV' => 'Maldives',
'ML' => 'Mali',
'MT' => 'Malta',
'MH' => 'Marshall Islands',
'MQ' => 'Martinique',
'MR' => 'Mauritania',
'MU' => 'Mauritius',
'YT' => 'Mayotte',
'MX' => 'Mexico',
'FM' => 'Micronesia',
'MD' => 'Moldova',
'MC' => 'Monaco',
'MN' => 'Mongolia',
'ME' => 'Montenegro',
'MS' => 'Montserrat',
'MA' => 'Morocco',
'MZ' => 'Mozambique',
'MM' => 'Myanmar (Burma)',
'NA' => 'Namibia',
'NR' => 'Nauru',
'NP' => 'Nepal',
'NL' => 'Netherlands',
'NC' => 'New Caledonia',
'NZ' => 'New Zealand',
'NI' => 'Nicaragua',
'NE' => 'Niger',
'NG' => 'Nigeria',
'NU' => 'Niue',
'NF' => 'Norfolk Island',
'KP' => 'North Korea',
'MP' => 'Northern Mariana Islands',
'NO' => 'Norway',
'OM' => 'Oman',
'PK' => 'Pakistan',
'PW' => 'Palau',
'PS' => 'Palestinian Territories',
'PA' => 'Panama',
'PG' => 'Papua New Guinea',
'PY' => 'Paraguay',
'PE' => 'Peru',
'PH' => 'Philippines',
'PN' => 'Pitcairn Islands',
'PL' => 'Poland',
'PT' => 'Portugal',
'PR' => 'Puerto Rico',
'QA' => 'Qatar',
'RE' => 'Réunion',
'RO' => 'Romania',
'RU' => 'Russia',
'RW' => 'Rwanda',
'WS' => 'Samoa',
'SM' => 'San Marino',
'ST' => 'São Tomé & Príncipe',
'SA' => 'Saudi Arabia',
'SN' => 'Senegal',
'RS' => 'Serbia',
'SC' => 'Seychelles',
'SL' => 'Sierra Leone',
'SG' => 'Singapore',
'SX' => 'Sint Maarten',
'SK' => 'Slovakia',
'SI' => 'Slovenia',
'SB' => 'Solomon Islands',
'SO' => 'Somalia',
'ZA' => 'South Africa',
'GS' => 'South Georgia & South Sandwich Islands',
'KR' => 'South Korea',
'SS' => 'South Sudan',
'ES' => 'Spain',
'LK' => 'Sri Lanka',
'BL' => 'St. Barthélemy',
'SH' => 'St. Helena',
'KN' => 'St. Kitts & Nevis',
'LC' => 'St. Lucia',
'MF' => 'St. Martin',
'PM' => 'St. Pierre & Miquelon',
'VC' => 'St. Vincent & Grenadines',
'SD' => 'Sudan',
'SR' => 'Suriname',
'SJ' => 'Svalbard & Jan Mayen',
'SZ' => 'Swaziland',
'SE' => 'Sweden',
'CH' => 'Switzerland',
'SY' => 'Syria',
'TW' => 'Taiwan',
'TJ' => 'Tajikistan',
'TZ' => 'Tanzania',
'TH' => 'Thailand',
'TL' => 'Timor-Leste',
'TG' => 'Togo',
'TK' => 'Tokelau',
'TO' => 'Tonga',
'TT' => 'Trinidad & Tobago',
'TA' => 'Tristan da Cunha',
'TN' => 'Tunisia',
'TR' => 'Turkey',
'TM' => 'Turkmenistan',
'TC' => 'Turks & Caicos Islands',
'TV' => 'Tuvalu',
'UM' => 'U.S. Outlying Islands',
'VI' => 'U.S. Virgin Islands',
'UG' => 'Uganda',
'UA' => 'Ukraine',
'AE' => 'United Arab Emirates',
'GB' => 'United Kingdom',
'UN' => 'United Nations',
'US' => 'United States',
'UY' => 'Uruguay',
'UZ' => 'Uzbekistan',
'VU' => 'Vanuatu',
'VA' => 'Vatican City',
'VE' => 'Venezuela',
'VN' => 'Vietnam',
'WF' => 'Wallis & Futuna',
'EH' => 'Western Sahara',
'YE' => 'Yemen',
'ZM' => 'Zambia',
'ZW' => 'Zimbabwe',
'AN' => 'Netherlands Antilles',
];
// Fix dei valori preimpostati
$database->update('an_nazioni', [
'nome' => 'Antigua e Barbuda',
], ['nome' => 'ANTIGUA AND BARBUDA']);
$database->update('an_nazioni', [
'nome' => 'Azerbaijan',
], ['nome' => 'AZERBAIJAN REPUBLIC']);
$database->update('an_nazioni', [
'nome' => 'Bosnia & Herzegovina',
], ['nome' => 'BOSNIA AND HERZEGOVINA']);
$database->update('an_nazioni', [
'nome' => 'China',
], ['nome' => 'CHINA WORLDWIDE']);
$database->update('an_nazioni', [
'nome' => 'Repubblica Democratica del Congo',
], ['nome' => 'DEMOCRATIC REPUBLIC OF THE CONGO']);
$database->update('an_nazioni', [
'nome' => 'Micronesia',
], ['nome' => 'FEDERATED STATES OF MICRONESIA']);
$database->update('an_nazioni', [
'nome' => 'Gabon',
], ['nome' => 'GABON REPUBLIC']);
$database->update('an_nazioni', [
'nome' => 'Guinea-Bissau',
], ['nome' => 'GUINEA BISSAU']);
$database->update('an_nazioni', [
'nome' => 'RAS di Hong Kong',
], ['nome' => 'HONG KONG']);
$database->update('an_nazioni', [
'nome' => 'Paesi Bassi',
], ['nome' => 'OLANDA']);
$database->update('an_nazioni', [
'nome' => 'Norway',
], ['nome' => 'NORWEGIA']);
$database->update('an_nazioni', [
'nome' => 'Saint Vincent e Grenadines',
], ['nome' => 'SAINT VINCENT AND THE GRENADINES']);
$database->update('an_nazioni', [
'nome' => 'South Africa',
], ['nome' => 'SUD AFRICA']);
$database->update('an_nazioni', [
'nome' => 'Corea del Sud',
], ['nome' => 'SUD KOREA']);
$database->update('an_nazioni', [
'nome' => 'Saint Kitts e Nevis',
], ['nome' => 'ST. KITTS AND NEVIS']);
$database->update('an_nazioni', [
'nome' => 'St. Pierre & Miquelon',
], ['nome' => 'ST. PIERRE AND MIQUELON']);
$database->update('an_nazioni', [
'nome' => 'Svalbard e Jan Mayen',
], ['nome' => 'SVALBARD AND JAN MAYEN ISLANDS']);
$database->update('an_nazioni', [
'nome' => 'Isole Turks e Caicos',
], ['nome' => 'TURKS AND CAICOS ISLANDS']);
$database->update('an_nazioni', [
'nome' => 'Wallis & Futuna',
], ['nome' => 'WALLIS AND FUTUNA ISLANDS']);
// Aggiornamenti e inserimenti
foreach ($it as $key => $value) {
$italian = $value;
$english = $en[$key];
if ($database->fetchNum('SELECT id FROM an_nazioni WHERE nome IN('.prepare($italian).', '.prepare($english).')') != 0) {
$database->update('an_nazioni', [
'iso2' => $key,
'nome' => $italian,
'name' => $english,
], [
'nome' => [$italian, $english],
]);
} else {
$database->insert('an_nazioni', [
'iso2' => $key,
'nome' => $italian,
'name' => $english,
]);
}
}
// Script per aggiornare le date dei movimenti con le date dei documenti
$movimenti = $dbo->fetchArray('SELECT * FROM mg_movimenti');
foreach ($movimenti as $movimento) {
$documento = null;
if (!empty($movimento['idintervento'])) {
$documento = $dbo->fetchOne('SELECT IFNULL(MAX(orario_fine), data_richiesta) AS data FROM in_interventi LEFT JOIN in_interventi_tecnici ON in_interventi.id=in_interventi_tecnici.idintervento WHERE in_interventi.id='.prepare($movimento['idintervento']));
} elseif (!empty($movimento['idddt'])) {
$documento = $dbo->fetchOne('SELECT data FROM dt_ddt WHERE id='.prepare($movimento['idddt']));
} elseif (!empty($movimento['iddocumento'])) {
$documento = $dbo->fetchOne('SELECT data FROM co_documenti WHERE id='.prepare($movimento['iddocumento']));
}
if (!empty($documento['data'])) {
$dbo->update('mg_movimenti', [
'data' => $documento['data'],
], [
'id' => $movimento['id'],
]);
}
}
$dbo->query("UPDATE mg_movimenti SET data = created_at WHERE data = '0000-00-00'");
// Fix Partite IVA
foreach ($it as $key => $value) {
$dbo->query("UPDATE `an_anagrafiche` SET `piva` = SUBSTRING(`piva`, 2) WHERE `piva` LIKE '".$key."%'");
}
// File e cartelle deprecate
$files = [
'docs',
'couscous.yml',
];
foreach ($files as $key => $value) {
$files[$key] = realpath(DOCROOT.'/'.$value);
}
delete($files);