source: trunk/admin/modules/Elezioni/aggiornadb.php@ 401

Last change on this file since 401 was 401, checked in by roby, 3 months ago

Sostituisce la rev 400

File size: 24.3 KB
Line 
1<?php
2
3#imposta il charset su utf8, qualsiasi altro valore per cambiarlo in latin1;
4$newcs='utf8';
5global $ctrlerr;
6
7/*
8@require_once("../../config.php");
9 try{
10 $dbi = new PDO("mysql:host=$dbhost", $dbuname, $dbpass, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
11 $sql = "use $dbname";
12 $dbi->exec($sql);
13 }
14 catch(PDOException $e)
15 {
16 die( $sql . "<br>" . $e->getMessage());
17 }
18*/
19
20###############
21function aggiorna($sql,$dbi,$sql2,$num){
22 $ret=0;
23 try{
24 $res = $dbi->prepare("$sql");
25 $res->execute();
26 $ret= 1;
27 }
28 catch(PDOException $e)
29 {
30 $ret=0;
31 $ctrlerr=1;
32 echo "<br><span style=\"color: red;\">- Aggiornamento Fallito: $sql</span>";
33 return $ret;
34 }
35
36 if("$sql2"!=""){
37 try{
38 $res = $dbi->prepare("$sql2");
39 $res->execute();
40 $ret=2;
41 }
42 catch(PDOException $e)
43 {
44 $ret=0;
45 $ctrlerr=1;
46 echo "<br><span style=\"color: red;\">- Aggiornamento Fallito: $sql2</span>";
47 return $ret;
48 }
49 }
50 echo "<br><span style=\"color: green;\">- Aggiornamento eseguito correttamente</span>";
51 return $ret;
52}
53
54function aggiorna_index($tab,$ind,$dbi,$sql2,$num){
55 $ret=0;
56# $conn->getAttribute( constant( "PDO::ATTR_$val" ) )
57 $sqltest="SHOW INDEX FROM `$tab` WHERE KEY_NAME = '$ind'";
58 $res = $dbi->prepare("$sqltest");
59 $res->execute();
60
61 if($res->rowCount()) {
62 if($ind=='PRIMARY')
63 $sql="ALTER TABLE `$tab` DROP PRIMARY KEY , $sql2 ";
64 else
65 $sql="ALTER TABLE `$tab` DROP INDEX `$ind`";
66 try{
67 $res = $dbi->prepare("$sql");
68 $res->execute();
69 $ret= 1;
70 }
71 catch(PDOException $e)
72 {
73 $ret=0;
74 $ctrlerr=1;
75 echo "<br><span style=\"color: red;\">- Tabella: $tab - Indice: $ind - Aggiornamento Fallito: $sql</span>";
76 return $ret;
77 }
78 }
79 if("$sql2"!="" and $ind!='PRIMARY'){
80 try{
81 $res = $dbi->prepare("$sql2");
82 $res->execute();
83 $ret=2;
84 }
85 catch(PDOException $e)
86 {
87 $ret=0;
88 $ctrlerr=1;
89 echo "<br><span style=\"color: red;\">- Tabella: $tab - Indice: $ind - Aggiornamento Fallito: $sql2</span>";
90 return $ret;
91 }
92 }
93 echo "<br><span style=\"color: green;\">- Tabella: $tab - Indice: $ind - Index aggiornato</span>";
94 return $ret;
95}
96
97
98
99
100function controllo($tabella,$campo,$num)
101{
102 global $dbi, $dbname;
103 $sql="SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '$dbname' AND TABLE_NAME = '$tabella'";
104 $res = $dbi->prepare("$sql");
105 $res->execute();
106 if($res->rowCount() and $campo=='') return 1;
107 while(list($nome)=$res->fetch(PDO::FETCH_NUM)) {if($nome==$campo) { echo "<br>".$num.") Il campo: $campo Ú presente nella tabella: $tabella"; return 1;}}
108 if($campo) echo "<br>$num) Il campo: $campo non Ú presente nella tabella: $tabella";
109 return 0;
110}
111
112$num=0;
113
114if(controllo($prefix.'_authors','admincomune',++$num))
115{
116 $sql="UPDATE `".$prefix."_authors` SET `adminop` = '1', `adminsuper` = '0',`admincomune` = '0' WHERE `".$prefix."_authors`.`aid` != 'admin' AND `".$prefix."_authors`.`adminsuper` != '1'";
117 $ret=aggiorna($sql,$dbi,'',$num);
118 $sql="UPDATE `".$prefix."_authors` SET `adminop` = '0', `adminsuper` = '0',`admincomune` = '1' WHERE `".$prefix."_authors`.`aid` = 'admin'";
119 $ret=aggiorna($sql,$dbi,'',$num);
120 $sql="UPDATE `".$prefix."_authors` SET `adminop` = '0', `adminsuper` = '1',`admincomune` = '0' WHERE `".$prefix."_authors`.`aid` = 'suser' or `".$prefix."_authors`.`adminsuper` = '1'";
121 $ret=aggiorna($sql,$dbi,'',$num);
122 echo "<br> La tabella dei permessi Ú stata aggiornata<br>";
123}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_authors non richiede questo aggiornamento</span><br>";
124
125$sql="SELECT * from `".$prefix."_ele_widget` WHERE `soraldo_ele_widget`.`id` = 29";
126$res = $dbi->prepare("$sql");
127$res->execute();
128if($res->rowCount()) {
129 $sql="DELETE FROM soraldo_ele_widget WHERE `soraldo_ele_widget`.`id` = 29";
130 $res = $dbi->prepare("$sql");
131 $res->execute();
132 echo "<br> Il record cookie_law.php Ú stato eliminato dalla tabella dei widget, usare privacy.php<br>";
133} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_widget non richiede questo aggiornamento</span><br>";
134if(!controllo($prefix.'_config','versione',++$num))
135{
136 $sql="alter table `".$prefix."_config` change column `Versione` `versione` int(3)";
137 $ret=aggiorna($sql,$dbi,'',$num);
138} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_config non richiede questo aggiornamento</span><br>";
139if(!controllo($prefix.'_config','versione',++$num))
140{
141 $sql="alter table `".$prefix."_config` change column `Versione` `versione` int(3)";
142 $ret=aggiorna($sql,$dbi,'',$num);
143} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_config non richiede questo aggiornamento</span><br>";
144if(controllo($prefix.'_config','secret',++$num))
145{
146 $sql="alter table `".$prefix."_config` DROP `secret`";
147 $ret=aggiorna($sql,$dbi,'',$num);
148} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_config non richiede questo aggiornamento</span><br>";
149if(controllo($prefix.'_config','aggiornamento',++$num))
150{
151 $sql="alter table `".$prefix."_config` DROP `aggiornamento`";
152 $ret=aggiorna($sql,$dbi,'',$num);
153} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_config non richiede questo aggiornamento</span><br>";
154if(!controllo($prefix.'_ele_conf','votolista',++$num))
155{
156 $sql="ALTER TABLE `".$prefix."_ele_conf` ADD `votolista` enum('0', '1') NOT NULL DEFAULT '0' AFTER `supdisgiunto`";
157 $ret=aggiorna($sql,$dbi,'',$num);
158} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_conf non richiede questo aggiornamento</span><br>";
159if(!controllo($prefix.'_ele_conf','inffisso',++$num))
160{
161 $sql="ALTER TABLE `".$prefix."_ele_conf` ADD `inffisso` enum('0', '1') NOT NULL DEFAULT '0' AFTER `votolista`";
162 $ret=aggiorna($sql,$dbi,'',$num);
163} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_conf non richiede questo aggiornamento</span><br>";
164if(!controllo($prefix.'_ele_conf','supfisso',++$num))
165{
166 $sql="ALTER TABLE `".$prefix."_ele_conf` ADD `supfisso` enum('0', '1') NOT NULL DEFAULT '0' AFTER `inffisso`";
167 $ret=aggiorna($sql,$dbi,'',$num);
168} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_conf non richiede questo aggiornamento</span><br>";
169if(!controllo($prefix.'_ele_conf','fascia_capoluogo',++$num))
170{
171 $sql="ALTER TABLE `".$prefix."_ele_conf` ADD `fascia_capoluogo` int(2) NOT NULL DEFAULT '0' AFTER `supfisso`";
172 $ret=aggiorna($sql,$dbi,'',$num);
173} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_conf non richiede questo aggiornamento</span><br>";
174if(controllo($prefix.'_ele_sezioni','bianchi_lista',++$num))
175{
176 $sql="alter table `".$prefix."_ele_sezioni` DROP `bianchi_lista`";
177 $ret=aggiorna($sql,$dbi,'',$num);
178} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_sezioni non richiede questo aggiornamento</span><br>";
179if(controllo($prefix.'_ele_sezioni','nulli_lista',++$num))
180{
181 $sql="alter table `".$prefix."_ele_sezioni` DROP `nulli_lista`";
182 $ret=aggiorna($sql,$dbi,'',$num);
183} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_sezioni non richiede questo aggiornamento</span><br>";
184if(controllo($prefix.'_ele_voti_parziale','data',++$num))
185{
186 $sql="ALTER TABLE `".$prefix."_ele_voti_parziale` CHANGE `data` `data` DATE NOT NULL DEFAULT '1900-01-01'";
187 $ret=aggiorna($sql,$dbi,'',$num);
188 echo "<br>";
189}
190++$num;
191$sql="ALTER TABLE `".$prefix."_ele_come` CHANGE `title` `title` VARCHAR(150) NOT NULL DEFAULT ' ', CHANGE `preamble` `preamble` TEXT, CHANGE `content` `content` TEXT, CHANGE `editimage` `editimage` VARCHAR(100) NOT NULL DEFAULT ' '";
192$ret=aggiorna($sql,$dbi,'',$num);
193echo "<br>";
194if(!$ret) echo "Il tuo sistema non necessita di questo aggiornamento, questo avviso di errore va ignorato<br>";
195++$num;
196$sql="ALTER TABLE `".$prefix."_ele_link` CHANGE `title` `title` VARCHAR(150) NOT NULL DEFAULT ' ', CHANGE `preamble` `preamble` TEXT, CHANGE `content` `content` TEXT, CHANGE `editimage` `editimage` VARCHAR(100) NOT NULL DEFAULT ' '";
197$ret=aggiorna($sql,$dbi,'',$num);
198echo "<br>";
199if(!$ret) echo "Il tuo sistema non necessita di questo aggiornamento, questo avviso di errore va ignorato<br>";
200++$num;
201$sql="ALTER TABLE `".$prefix."_ele_servizi` CHANGE `title` `title` VARCHAR(150) NOT NULL DEFAULT ' ', CHANGE `preamble` `preamble` TEXT, CHANGE `content` `content` TEXT, CHANGE `editimage` `editimage` VARCHAR(100) NOT NULL DEFAULT ' '";
202$ret=aggiorna($sql,$dbi,'',$num);
203echo "<br>";
204if(!$ret) echo "Il tuo sistema non necessita di questo aggiornamento, questo avviso di errore va ignorato<br>";
205
206if(controllo($prefix.'_ele_rilaff','data',++$num))
207{
208 $sql="ALTER TABLE `".$prefix."_ele_rilaff` CHANGE `data` `data` DATE NOT NULL DEFAULT '1900-01-01'";
209 $ret=aggiorna($sql,$dbi,'',$num);
210 echo "<br>";
211}
212
213if(!controllo($prefix.'_ele_gruppo','num_circ',++$num))
214{
215 $sql="ALTER TABLE `".$prefix."_ele_gruppo` ADD `num_circ` INT(2) UNSIGNED NOT NULL AFTER `id_circ`";
216 $ret=aggiorna($sql,$dbi,'',$num);
217} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_gruppo non richiede questo aggiornamento</span><br>";
218
219if(!controllo($prefix.'_ele_voti_gruppo','num_gruppo',++$num))
220{
221 $sql="ALTER TABLE `".$prefix."_ele_voti_gruppo` ADD `num_gruppo` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
222 $ret=aggiorna($sql,$dbi,'',$num);
223} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_gruppo non richiede questo aggiornamento</span><br>";
224
225if(!controllo($prefix.'_ele_lista','num_gruppo',++$num))
226{
227 $sql="ALTER TABLE `".$prefix."_ele_lista` ADD `num_gruppo` INT(2) UNSIGNED NOT NULL AFTER `id_gruppo`";
228 $sql2="update `".$prefix."_ele_lista` as t1 set t1.num_gruppo=(select t2.num_gruppo from `".$prefix."_ele_gruppo` as t2 where t2.id_gruppo=t1.id_gruppo) where t1.num_gruppo=0 and (select t2.num_gruppo from `".$prefix."_ele_gruppo` as t2 where t2.id_gruppo=t1.id_gruppo) is not null";
229 $ret=aggiorna($sql,$dbi,$sql2,$num);
230}else{
231 $sql="update `".$prefix."_ele_lista` as t1 set t1.num_gruppo=(select t2.num_gruppo from `".$prefix."_ele_gruppo` as t2 where t2.id_gruppo=t1.id_gruppo) where t1.num_gruppo=0 and (select t2.num_gruppo from `".$prefix."_ele_gruppo` as t2 where t2.id_gruppo=t1.id_gruppo) is not null";
232 $ret=aggiorna($sql,$dbi,'',$num);
233echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_lista non richiede questo aggiornamento</span><br>";
234}
235if(!controllo($prefix.'_ele_lista','num_circ',++$num))
236{
237 $sql="ALTER TABLE `".$prefix."_ele_lista` ADD `num_circ` INT(2) UNSIGNED NOT NULL AFTER `id_circ`";
238 $ret=aggiorna($sql,$dbi,'',$num);
239}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_lista non richiede questo aggiornamento</span><br>";
240
241if(!controllo($prefix.'_ele_operatori','id_circ',++$num))
242{
243 $sql="ALTER TABLE `".$prefix."_ele_operatori` ADD `id_circ` INT(11) NOT NULL DEFAULT 0 AFTER `aid`";
244 $ret=aggiorna($sql,$dbi,'',$num);
245}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_operatori non richiede questo aggiornamento</span><br>";
246
247if(!controllo($prefix.'_ele_operatori','id_sez',++$num))
248{
249 $sql="ALTER TABLE `".$prefix."_ele_operatori` ADD `id_sez` INT(11) NOT NULL DEFAULT 0 AFTER `id_circ`";
250 $ret=aggiorna($sql,$dbi,'',$num);
251}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_operatori non richiede questo aggiornamento</span><br>";
252
253if(!controllo($prefix.'_ele_temi','id',++$num))
254{
255 $sql="ALTER TABLE `".$prefix."_ele_temi` ADD `id` INT(11) NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`)";
256 $ret=aggiorna($sql,$dbi,'',$num);
257}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_operatori non richiede questo aggiornamento</span><br>";
258
259if(!controllo($prefix.'_ele_voti_lista','num_lista',++$num))
260{
261 $sql="ALTER TABLE `".$prefix."_ele_voti_lista` ADD `num_lista` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
262 $ret=aggiorna($sql,$dbi,'',$num);
263}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_voti_lista non richiede questo aggiornamento</span><br>";
264
265if(!controllo($prefix.'_ele_voti_ref','num_gruppo',++$num))
266{
267 $sql="ALTER TABLE `".$prefix."_ele_voti_ref` ADD `num_gruppo` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
268 $ret=aggiorna($sql,$dbi,'',$num);
269}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_voti_ref non richiede questo aggiornamento</span><br>";
270
271if(controllo($prefix.'_ele_candidati','Sesso',++$num))
272{
273 $sql="ALTER TABLE `".$prefix."_ele_candidati` DROP `Sesso`";
274 $ret=aggiorna($sql,$dbi,'',$num);
275} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_candidati non richiede questo aggiornamento</span><br>";
276if(!controllo($prefix.'_ele_voti_candidati','num_cand',++$num))
277{
278 $sql="ALTER TABLE `".$prefix."_ele_voti_candidati` ADD `num_cand` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
279 $ret=aggiorna($sql,$dbi,'',$num);
280}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_voti_candidati non richiede questo aggiornamento</span><br>";
281
282if(!controllo($prefix.'_ele_candidati','num_lista',++$num))
283{
284 $sql="ALTER TABLE `".$prefix."_ele_candidati` ADD `num_lista` INT(2) UNSIGNED NOT NULL AFTER `id_lista`";
285 $ret=aggiorna($sql,$dbi,'',$num);
286}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_candidati non richiede questo aggiornamento</span><br>";
287
288if(!controllo($prefix.'_ele_sezioni','colore',++$num))
289{
290 $sql="ALTER TABLE `".$prefix."_ele_sezioni` ADD `colore` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '#FAFAD2' AFTER `solo_lista`";
291 $ret=aggiorna($sql,$dbi,'',$num);
292}else{
293 $sql="ALTER TABLE `".$prefix."_ele_sezioni` CHANGE `colore` `colore` VARCHAR(50) DEFAULT '#FAFAD2'";
294 $ret=aggiorna($sql,$dbi,'',$num);
295} echo "<br>";
296
297echo "<br>Aggiornamento per nuovo sistema dei controlli di congruità";
298
299if(!controllo($prefix.'_ele_controlli','id_cons',++$num))
300{
301 $sql="CREATE TABLE if not exists`".$prefix."_ele_controlli` ( `id_cons` INT(11) NOT NULL , `id_sez` INT(11) NOT NULL , `tipo` VARCHAR(10) NOT NULL , `id` INT(11) NOT NULL , INDEX `sezione` (`id_sez`)) ENGINE = MyISAM";
302 echo "<br>".$num.") Creazione tabella dei controlli: ";
303 $ret=aggiorna($sql,$dbi,'',$num);
304}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_controlli non richiede questo aggiornamento</span><br>";
305
306echo "<br>".++$num.") Eliminazione della vecchia tabella dei controlli: ";
307if(controllo($prefix.'_ele_controllisez','',$num))
308{
309$sql="DROP TABLE if exists `".$prefix."_ele_controllisez`";
310$ret=aggiorna($sql,$dbi,'',$num);
311} else echo "<br><span style=\"color: green;\">- Tabella non presente</span><br>";
312
313echo "<br>".++$num.") Aggiornamento tabella ".$prefix."_ele_voti_gruppo";
314$sql="update `".$prefix."_ele_voti_gruppo` as t1 left join `".$prefix."_ele_gruppo` as t2 on t1.id_gruppo=t2.id_gruppo set t1.num_gruppo=t2.num_gruppo;";
315$ret=aggiorna($sql,$dbi,'',$num);
316
317echo "<br><br>".++$num.") Aggiornamento dei valori di default: ".$prefix."_ele_voti_lista";
318$sql="ALTER TABLE `".$prefix."_ele_voti_lista` CHANGE `num_lista` `num_lista` INT(2) UNSIGNED NULL DEFAULT '0';";
319$ret=aggiorna($sql,$dbi,'',$num);
320
321echo "<br><br>".++$num.") Aggiornamento tabella ".$prefix."_ele_voti_lista";
322$sql="update `".$prefix."_ele_voti_lista` as t1 left join `".$prefix."_ele_lista` as t2 on t1.id_lista=t2.id_lista set t1.num_lista=t2.num_lista;";
323$ret=aggiorna($sql,$dbi,'',$num);
324##############################################
325
326echo "<br><br>".++$num.") Aggiornamento dei valori di default: ".$prefix."_ele_gruppo";
327$sql="ALTER TABLE `".$prefix."_ele_gruppo` CHANGE `num_circ` `num_circ` INT(2) UNSIGNED NOT NULL DEFAULT '1';";
328$ret=aggiorna($sql,$dbi,'',$num);
329
330$sql="ALTER TABLE `".$prefix."_authors` CHANGE `adminsuper` `adminsuper` TINYINT(2) NOT NULL DEFAULT '0';";
331$ret=aggiorna($sql,$dbi,'',$num);
332
333$sql="ALTER TABLE `".$prefix."_ele_lista` CHANGE `num_gruppo` `num_gruppo` INT(2) UNSIGNED NOT NULL DEFAULT '0';";
334$ret=aggiorna($sql,$dbi,'',$num);
335
336$sql="ALTER TABLE `".$prefix."_ele_lista` CHANGE `num_circ` `num_circ` INT(2) UNSIGNED NOT NULL DEFAULT '1';";
337$ret=aggiorna($sql,$dbi,'',$num);
338
339echo "<br><br>".++$num.") Aggiornamento della tabella _ele_conf per la nuova gestione della L.R. Sicilia";
340$sql="UPDATE `".$prefix."_ele_conf` SET `inffisso` = '1' WHERE `id_conf` = 4;";
341$ret=aggiorna($sql,$dbi,'',$num);
342
343echo "<br><br>".++$num.") Ricostruzione della tabella ".$prefix."_ele_fasce`";
344$sql="DROP TABLE `".$prefix."_ele_fasce`";
345$ret=aggiorna($sql,$dbi,'',$num);
346
347$sql="CREATE TABLE `".$prefix."_ele_fasce` (
348 `id_fascia` int(2) NOT NULL,
349 `abitanti` int(11) NOT NULL,
350 `seggi` int(4) NOT NULL,
351 `id_conf` int(11) DEFAULT 1
352) ENGINE=MyISAM DEFAULT CHARSET 'utf8';";
353
354
355$sql2="INSERT INTO `".$prefix."_ele_fasce` (`id_fascia`, `abitanti`, `seggi`, `id_conf`) VALUES
356(1, 3000, 12, 1),
357(2, 10000, 16, 1),
358(3, 15000, 20, 1),
359(4, 30000, 20, 1),
360(5, 100000, 30, 1),
361(6, 250000, 40, 1),
362(7, 500000, 46, 1),
363(8, 1000000, 50, 1),
364(9, 100000000, 60, 1),
365(1, 3000, 12, 2),
366(2, 10000, 16, 2),
367(3, 15000, 20, 2),
368(4, 30000, 20, 2),
369(5, 100000, 30, 2),
370(6, 250000, 40, 2),
371(7, 500000, 46, 2),
372(8, 1000000, 50, 2),
373(9, 100000000, 60, 2),
374(1, 3000, 9, 3),
375(2, 5000, 9, 3),
376(4, 15000, 16, 3),
377(3, 10000, 12, 3),
378(5, 30000, 16, 3),
379(6, 100000, 24, 3),
380(7, 250000, 32, 3),
381(8, 500000, 36, 3),
382(9, 1000000, 40, 3),
383(10, 100000000, 48, 3),
384(1, 3000, 6, 4),
385(2, 5000, 7, 4),
386(3, 10000, 12, 4),
387(4, 15000, 16, 4),
388(5, 30000, 16, 4),
389(6, 100000, 24, 4),
390(7, 250000, 32, 4),
391(8, 500000, 36, 4),
392(9, 1000000, 40, 4),
393(10, 100000000, 48, 4),
394(1, 3000, 9, 5),
395(2, 5000, 9, 5),
396(3, 10000, 12, 5),
397(4, 15000, 16, 5),
398(5, 30000, 16, 5),
399(6, 100000, 24, 5),
400(7, 250000, 32, 5),
401(8, 500000, 36, 5),
402(9, 1000000, 40, 5),
403(10, 100000000, 48, 5),
404(1, 3000, 6, 6),
405(2, 5000, 7, 6),
406(3, 10000, 10, 6),
407(4, 15000, 16, 6),
408(5, 30000, 16, 6),
409(6, 100000, 24, 6),
410(7, 250000, 32, 6),
411(8, 500000, 36, 6),
412(9, 1000000, 40, 6),
413(10, 100000000, 48, 6),
414(1, 3000, 10, 7),
415(2, 10000, 12, 7),
416(3, 15000, 16, 7),
417(4, 30000, 16, 7),
418(5, 100000, 24, 7),
419(6, 250000, 32, 7),
420(7, 500000, 36, 7),
421(8, 1000000, 40, 7),
422(9, 100000000, 48, 7);";
423$ret=aggiorna($sql,$dbi,$sql2,$num);
424#if(!$ret) echo "<br>".$num++.") Fallito: $sql"; else echo "<br>".$num++.") Aggiornato<br>";
425
426$sql="ALTER TABLE `".$prefix."_ele_fasce`
427 ADD KEY `id_fascia` (`id_fascia`);";
428$ret=aggiorna($sql,$dbi,'',$num);
429#if(!$ret) echo "<br>".$num++.") Fallito: $sql"; else echo "<br>".$num++.") Aggiornato<br>";
430
431
432
433#if(!$ret)
434# echo "<br>".$num++.") Fallito: $sql";
435#elseif ($ret==1)
436# echo "<br>".$num++.") Index eliminato";
437#else
438# echo "<br>".$num++.") Index aggiunto";
439#$sql="ALTER TABLE `".$prefix."_ele_voti_lista` DROP INDEX if exists `id_cons`";
440echo "<br><br>".++$num.") Ricostruzione e aggioramento indici";
441$tab=$prefix."_ele_voti_ref";
442$ind="id_cons";
443# $sql="ALTER TABLE `".$prefix."_ele_voti_ref` DROP INDEX `id_cons`; ";
444$sql2="ALTER TABLE `".$prefix."_ele_voti_ref` ADD INDEX `id_cons` (`id_cons`, `id_gruppo`) USING BTREE";
445$ret=aggiorna_index($tab, $ind,$dbi,$sql2,$num);
446
447$tab=$prefix."_ele_sezioni";
448$ind="id_cons";
449$sql2="ALTER TABLE `".$prefix."_ele_sezioni` ADD UNIQUE `id_cons` (`id_cons`, `num_sez`) USING BTREE";
450$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
451
452$tab=$prefix."_ele_voti_lista";
453$ind="id_cons";
454$sql2="ALTER TABLE `".$prefix."_ele_voti_lista` ADD INDEX `id_cons` (`id_cons`, `id_sez`, `id_lista`) USING BTREE";
455$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
456
457$tab=$prefix."_ele_voti_gruppo";
458$ind="id_cons";
459#$sql="ALTER TABLE `".$prefix."_ele_voti_gruppo` DROP INDEX if exists `id_cons`";
460$sql2="ALTER TABLE `".$prefix."_ele_voti_gruppo` ADD INDEX `id_cons` (`id_cons`, `id_sez`, `id_gruppo`) USING BTREE";
461$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
462
463$tab=$prefix."_ele_voti_candidati";
464$ind="id_cons";
465#$sql="ALTER TABLE `".$prefix."_ele_voti_candidati` DROP INDEX if exists `id_cons`";
466$sql2="ALTER TABLE `".$prefix."_ele_voti_candidati` ADD INDEX `id_cons` (`id_cons`, `id_sez`, `id_cand`) USING BTREE";
467$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
468
469$tab=$prefix."_ele_lista";
470$ind="id_cons";
471#$sql="ALTER TABLE `".$prefix."_ele_lista` DROP INDEX if exists `id_cons`";
472$sql2="ALTER TABLE `".$prefix."_ele_lista` ADD INDEX `id_cons` (`id_cons`, `id_gruppo`) USING BTREE";
473$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
474
475$tab=$prefix."_ele_lista";
476$ind="PRIMARY";
477#$sql="ALTER TABLE `".$prefix."_ele_lista` DROP INDEX if exists `PRIMARY`";
478$sql2="ADD PRIMARY KEY (`id_lista`) USING BTREE";
479$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
480
481$tab=$prefix."_ele_gruppo";
482$ind="id_cons";
483#$sql="ALTER TABLE `".$prefix."_ele_gruppo` DROP INDEX if exists `id_cons`";
484$sql2="ALTER TABLE `".$prefix."_ele_gruppo` ADD INDEX `id_cons` (`id_cons`, `id_circ`) USING BTREE";
485$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
486
487$tab=$prefix."_ele_gruppo";
488$ind="PRIMARY";
489#$sql="ALTER TABLE `".$prefix."_ele_gruppo` DROP INDEX if exists `PRIMARY`";
490$sql2="ADD PRIMARY KEY (`id_gruppo`) USING BTREE";
491$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
492
493$tab=$prefix."_ele_candidati";
494$ind="id_cons";
495#$sql="ALTER TABLE `".$prefix."_ele_candidati` DROP INDEX if exists `id_cons`";
496$sql2="ALTER TABLE `".$prefix."_ele_candidati` ADD INDEX `id_cons` (`id_cons`, `id_lista`) USING BTREE";
497$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
498
499$tab=$prefix."_ele_candidati";
500$ind="PRIMARY";
501#$sql="ALTER TABLE `".$prefix."_ele_candidati` DROP INDEX if exists `PRIMARY`";
502$sql2="ADD PRIMARY KEY (`id_cand`) USING BTREE";
503$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
504
505$tab=$prefix."_ele_consultazione";
506$ind="descrizione";
507#$sql="ALTER TABLE `".$prefix."_ele_consultazione` DROP INDEX if exists `descrizione`";
508$sql2="ALTER TABLE `".$prefix."_ele_consultazione` ADD UNIQUE `descrizione` (`descrizione`(100))";
509$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
510
511echo "<br><br>".++$num.") Modifica Charset del database";
512if($newcs=='utf8') {
513 $cset='utf8';
514 $ccollate='utf8_general_ci';
515 $preset='latin1';
516}else{
517 $cset='latin1';
518 $ccollate='latin1_swedish_ci';
519 $preset='utf8';
520}
521#$sql="ALTER DATABASE $dbname CHARACTER SET '$cset' COLLATE '$ccollate'";
522#$res = $dbi->prepare("$sql");
523#$res->execute();
524
525$sql="SELECT table_name,column_name,column_default,column_type,is_nullable FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '$dbname' and (character_set_name='$preset' or collation_name like '$preset%')";
526$res = $dbi->prepare("$sql");
527$res->execute();
528$tab='';
529$agg=$res->rowCount();
530
531while(list($nometab,$campo,$def,$tipo,$nul)=$res->fetch(PDO::FETCH_NUM)) {
532 if($tab!=$nometab){
533 $sql="alter table $nometab DEFAULT CHARSET=$cset COLLATE $ccollate";
534 try{
535 $res2 = $dbi->prepare("$sql");
536 $res2->execute();
537 }
538 catch(PDOException $e)
539 {
540 die( $sql . "<br>" . $e->getMessage());
541 }
542 $tab=$nometab; echo "<br><span style=\"color: green;\">- Tabella: $nometab</span>";
543 }
544 if($def!='') $default="DEFAULT '$def'"; else $default='';
545 if($nul=='NO') $nullable='NOT NULL'; else $nullable='NULL';
546 $sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET '$cset' COLLATE '$ccollate' $nullable $default;";
547 try{
548 $res2 = $dbi->prepare("$sql");
549 $res2->execute();
550 }
551 catch(PDOException $e)
552 {
553 $default="DEFAULT $def";
554 $sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET '$cset' COLLATE '$ccollate' $nullable $default;";
555 try{
556 $res2 = $dbi->prepare("$sql");
557 $res2->execute();
558 }
559 catch(PDOException $e)
560 {
561 die( $sql . "<br>" . $e->getMessage());
562 }
563 }
564 echo "<br><span style=\"color: green;\">-- $campo</span>";
565}
566 $sql="SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE TABLE_SCHEMA = '$dbname' and table_collation like '$preset%'";
567 $res = $dbi->prepare("$sql");
568 $res->execute();
569$tab='';
570if(!$agg) $agg=$res->rowCount();
571while(list($nometab)=$res->fetch(PDO::FETCH_NUM)) {
572 $sql="alter table $nometab DEFAULT CHARSET=$cset COLLATE $ccollate";
573 try{
574 $res2 = $dbi->prepare("$sql");
575 $res2->execute();
576 }
577 catch(PDOException $e)
578 {
579 die( $sql . "<br>" . $e->getMessage());
580 }
581 echo "<br><span style=\"color: green;\">- Tabella: $nometab</span>";
582}
583if(!$agg) echo "<br><span style=\"color: green;\">- Nessuna tabella da aggiornare</span>";
584echo "<br><br>";
585?>
Note: See TracBrowser for help on using the repository browser.