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

Last change on this file was 411, checked in by roby, 5 weeks ago
  • ADMIN

-- aggiornamento del campo num_cand nella tabella _ele_voti_candidati

  • CLIENT

-- modifica alla stampa del pdf per il riepilogo affluenze

File size: 25.2 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>";
134
135
136if(!controllo($prefix.'_ele_cons_comune','proiezione',++$num))
137{
138 $sql="ALTER TABLE `".$prefix."_ele_cons_comune` ADD `proiezione` ENUM('0','1') NOT NULL DEFAULT '0' AFTER `disgiunto`";
139 $ret=aggiorna($sql,$dbi,'',$num);
140 $sql="update `".$prefix."_ele_cons_comune` set proiezione='1' where chiusa='1' and id_conf>0";
141 $ret=aggiorna($sql,$dbi,'',$num);
142} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_cons_comune non richiede questo aggiornamento</span><br>";
143
144if(!controllo($prefix.'_config','versione',++$num))
145{
146 $sql="alter table `".$prefix."_config` change column `Versione` `versione` int(3)";
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','versione',++$num))
150{
151 $sql="alter table `".$prefix."_config` change column `Versione` `versione` int(3)";
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.'_config','secret',++$num))
155{
156 $sql="alter table `".$prefix."_config` DROP `secret`";
157 $ret=aggiorna($sql,$dbi,'',$num);
158} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_config non richiede questo aggiornamento</span><br>";
159if(controllo($prefix.'_config','aggiornamento',++$num))
160{
161 $sql="alter table `".$prefix."_config` DROP `aggiornamento`";
162 $ret=aggiorna($sql,$dbi,'',$num);
163} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_config non richiede questo aggiornamento</span><br>";
164if(!controllo($prefix.'_ele_conf','votolista',++$num))
165{
166 $sql="ALTER TABLE `".$prefix."_ele_conf` ADD `votolista` enum('0', '1') NOT NULL DEFAULT '0' AFTER `supdisgiunto`";
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','inffisso',++$num))
170{
171 $sql="ALTER TABLE `".$prefix."_ele_conf` ADD `inffisso` enum('0', '1') NOT NULL DEFAULT '0' AFTER `votolista`";
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_conf','supfisso',++$num))
175{
176 $sql="ALTER TABLE `".$prefix."_ele_conf` ADD `supfisso` enum('0', '1') NOT NULL DEFAULT '0' AFTER `inffisso`";
177 $ret=aggiorna($sql,$dbi,'',$num);
178} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_conf non richiede questo aggiornamento</span><br>";
179if(!controllo($prefix.'_ele_conf','fascia_capoluogo',++$num))
180{
181 $sql="ALTER TABLE `".$prefix."_ele_conf` ADD `fascia_capoluogo` int(2) NOT NULL DEFAULT '0' AFTER `supfisso`";
182 $ret=aggiorna($sql,$dbi,'',$num);
183} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_conf non richiede questo aggiornamento</span><br>";
184if(controllo($prefix.'_ele_sezioni','bianchi_lista',++$num))
185{
186 $sql="alter table `".$prefix."_ele_sezioni` DROP `bianchi_lista`";
187 $ret=aggiorna($sql,$dbi,'',$num);
188} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_sezioni non richiede questo aggiornamento</span><br>";
189if(controllo($prefix.'_ele_sezioni','nulli_lista',++$num))
190{
191 $sql="alter table `".$prefix."_ele_sezioni` DROP `nulli_lista`";
192 $ret=aggiorna($sql,$dbi,'',$num);
193} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_sezioni non richiede questo aggiornamento</span><br>";
194if(controllo($prefix.'_ele_voti_parziale','data',++$num))
195{
196 $sql="ALTER TABLE `".$prefix."_ele_voti_parziale` CHANGE `data` `data` DATE NOT NULL DEFAULT '1900-01-01'";
197 $ret=aggiorna($sql,$dbi,'',$num);
198 echo "<br>";
199}
200++$num;
201$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 ' '";
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++$num;
206$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 ' '";
207$ret=aggiorna($sql,$dbi,'',$num);
208echo "<br>";
209if(!$ret) echo "Il tuo sistema non necessita di questo aggiornamento, questo avviso di errore va ignorato<br>";
210++$num;
211$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 ' '";
212$ret=aggiorna($sql,$dbi,'',$num);
213echo "<br>";
214if(!$ret) echo "Il tuo sistema non necessita di questo aggiornamento, questo avviso di errore va ignorato<br>";
215
216if(controllo($prefix.'_ele_rilaff','data',++$num))
217{
218 $sql="ALTER TABLE `".$prefix."_ele_rilaff` CHANGE `data` `data` DATE NOT NULL DEFAULT '1900-01-01'";
219 $ret=aggiorna($sql,$dbi,'',$num);
220 echo "<br>";
221}
222
223if(!controllo($prefix.'_ele_gruppo','num_circ',++$num))
224{
225 $sql="ALTER TABLE `".$prefix."_ele_gruppo` ADD `num_circ` INT(2) UNSIGNED NOT NULL AFTER `id_circ`";
226 $ret=aggiorna($sql,$dbi,'',$num);
227} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_gruppo non richiede questo aggiornamento</span><br>";
228
229if(!controllo($prefix.'_ele_voti_gruppo','num_gruppo',++$num))
230{
231 $sql="ALTER TABLE `".$prefix."_ele_voti_gruppo` ADD `num_gruppo` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
232 $ret=aggiorna($sql,$dbi,'',$num);
233} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_gruppo non richiede questo aggiornamento</span><br>";
234
235if(!controllo($prefix.'_ele_lista','num_gruppo',++$num))
236{
237 $sql="ALTER TABLE `".$prefix."_ele_lista` ADD `num_gruppo` INT(2) UNSIGNED NOT NULL AFTER `id_gruppo`";
238 $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";
239 $ret=aggiorna($sql,$dbi,$sql2,$num);
240}else{
241 $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";
242 $ret=aggiorna($sql,$dbi,'',$num);
243echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_lista non richiede questo aggiornamento</span><br>";
244}
245if(!controllo($prefix.'_ele_lista','num_circ',++$num))
246{
247 $sql="ALTER TABLE `".$prefix."_ele_lista` ADD `num_circ` INT(2) UNSIGNED NOT NULL AFTER `id_circ`";
248 $ret=aggiorna($sql,$dbi,'',$num);
249}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_lista non richiede questo aggiornamento</span><br>";
250
251if(!controllo($prefix.'_ele_operatori','id_circ',++$num))
252{
253 $sql="ALTER TABLE `".$prefix."_ele_operatori` ADD `id_circ` INT(11) NOT NULL DEFAULT 0 AFTER `aid`";
254 $ret=aggiorna($sql,$dbi,'',$num);
255}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_operatori non richiede questo aggiornamento</span><br>";
256
257if(!controllo($prefix.'_ele_operatori','id_sez',++$num))
258{
259 $sql="ALTER TABLE `".$prefix."_ele_operatori` ADD `id_sez` INT(11) NOT NULL DEFAULT 0 AFTER `id_circ`";
260 $ret=aggiorna($sql,$dbi,'',$num);
261}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_operatori non richiede questo aggiornamento</span><br>";
262
263if(!controllo($prefix.'_ele_temi','id',++$num))
264{
265 $sql="ALTER TABLE `".$prefix."_ele_temi` ADD `id` INT(11) NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`)";
266 $ret=aggiorna($sql,$dbi,'',$num);
267}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_operatori non richiede questo aggiornamento</span><br>";
268
269if(!controllo($prefix.'_ele_voti_lista','num_lista',++$num))
270{
271 $sql="ALTER TABLE `".$prefix."_ele_voti_lista` ADD `num_lista` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
272 $ret=aggiorna($sql,$dbi,'',$num);
273}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_voti_lista non richiede questo aggiornamento</span><br>";
274
275if(!controllo($prefix.'_ele_voti_ref','num_gruppo',++$num))
276{
277 $sql="ALTER TABLE `".$prefix."_ele_voti_ref` ADD `num_gruppo` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
278 $ret=aggiorna($sql,$dbi,'',$num);
279}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_voti_ref non richiede questo aggiornamento</span><br>";
280
281if(controllo($prefix.'_ele_candidati','Sesso',++$num))
282{
283 $sql="ALTER TABLE `".$prefix."_ele_candidati` DROP `Sesso`";
284 $ret=aggiorna($sql,$dbi,'',$num);
285} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_candidati non richiede questo aggiornamento</span><br>";
286if(!controllo($prefix.'_ele_voti_candidati','num_cand',++$num))
287{
288 $sql="ALTER TABLE `".$prefix."_ele_voti_candidati` ADD `num_cand` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
289 $ret=aggiorna($sql,$dbi,'',$num);
290}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_voti_candidati non richiede questo aggiornamento</span><br>";
291
292if(!controllo($prefix.'_ele_candidati','num_lista',++$num))
293{
294 $sql="ALTER TABLE `".$prefix."_ele_candidati` ADD `num_lista` INT(2) UNSIGNED NOT NULL AFTER `id_lista`";
295 $ret=aggiorna($sql,$dbi,'',$num);
296}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_candidati non richiede questo aggiornamento</span><br>";
297
298if(!controllo($prefix.'_ele_sezioni','colore',++$num))
299{
300 $sql="ALTER TABLE `".$prefix."_ele_sezioni` ADD `colore` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '#FAFAD2' AFTER `solo_lista`";
301 $ret=aggiorna($sql,$dbi,'',$num);
302}else{
303 $sql="ALTER TABLE `".$prefix."_ele_sezioni` CHANGE `colore` `colore` VARCHAR(50) DEFAULT '#FAFAD2'";
304 $ret=aggiorna($sql,$dbi,'',$num);
305} echo "<br>";
306
307echo "<br>Aggiornamento per nuovo sistema dei controlli di congruità";
308
309if(!controllo($prefix.'_ele_controlli','id_cons',++$num))
310{
311 $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";
312 echo "<br>".$num.") Creazione tabella dei controlli: ";
313 $ret=aggiorna($sql,$dbi,'',$num);
314}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_controlli non richiede questo aggiornamento</span><br>";
315
316echo "<br>".++$num.") Eliminazione della vecchia tabella dei controlli: ";
317if(controllo($prefix.'_ele_controllisez','',$num))
318{
319$sql="DROP TABLE if exists `".$prefix."_ele_controllisez`";
320$ret=aggiorna($sql,$dbi,'',$num);
321} else echo "<br><span style=\"color: green;\">- Tabella non presente</span><br>";
322
323echo "<br>".++$num.") Aggiornamento tabella ".$prefix."_ele_voti_gruppo";
324$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;";
325$ret=aggiorna($sql,$dbi,'',$num);
326
327echo "<br><br>".++$num.") Aggiornamento dei valori di default: ".$prefix."_ele_voti_lista";
328$sql="ALTER TABLE `".$prefix."_ele_voti_lista` CHANGE `num_lista` `num_lista` INT(2) UNSIGNED NULL DEFAULT '0';";
329$ret=aggiorna($sql,$dbi,'',$num);
330
331echo "<br><br>".++$num.") Aggiornamento tabella ".$prefix."_ele_voti_lista";
332$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;";
333$ret=aggiorna($sql,$dbi,'',$num);
334##############################################
335
336echo "<br><br>".++$num.") Aggiornamento dei valori di default: ".$prefix."_ele_gruppo";
337$sql="ALTER TABLE `".$prefix."_ele_gruppo` CHANGE `num_circ` `num_circ` INT(2) UNSIGNED NOT NULL DEFAULT '1';";
338$ret=aggiorna($sql,$dbi,'',$num);
339
340$sql="ALTER TABLE `".$prefix."_authors` CHANGE `adminsuper` `adminsuper` TINYINT(2) NOT NULL DEFAULT '0';";
341$ret=aggiorna($sql,$dbi,'',$num);
342
343$sql="ALTER TABLE `".$prefix."_ele_lista` CHANGE `num_gruppo` `num_gruppo` INT(2) UNSIGNED NOT NULL DEFAULT '0';";
344$ret=aggiorna($sql,$dbi,'',$num);
345
346$sql="ALTER TABLE `".$prefix."_ele_lista` CHANGE `num_circ` `num_circ` INT(2) UNSIGNED NOT NULL DEFAULT '1';";
347$ret=aggiorna($sql,$dbi,'',$num);
348
349echo "<br><br>".++$num.") Aggiornamento della tabella _ele_conf per la nuova gestione della L.R. Sicilia";
350$sql="UPDATE `".$prefix."_ele_conf` SET `inffisso` = '1' WHERE `id_conf` = 4;";
351$ret=aggiorna($sql,$dbi,'',$num);
352
353echo "<br><br>".++$num.") Aggiornamento del campo numero candidato della tabella _ele_voti_candidati per le consultazioni precedenti all'aggiunta del campo stesso";
354$sql="update `".$prefix."_ele_voti_candidati` as t1 left join `".$prefix."_ele_candidati` as t2 on t1.id_cand=t2.id_cand set t1.num_cand=t2.num_cand where t1.num_cand=0 and t2.num_cand>0;";
355$ret=aggiorna($sql,$dbi,'',$num);
356
357echo "<br><br>".++$num.") Ricostruzione della tabella ".$prefix."_ele_fasce`";
358$sql="DROP TABLE `".$prefix."_ele_fasce`";
359$ret=aggiorna($sql,$dbi,'',$num);
360
361$sql="CREATE TABLE `".$prefix."_ele_fasce` (
362 `id_fascia` int(2) NOT NULL,
363 `abitanti` int(11) NOT NULL,
364 `seggi` int(4) NOT NULL,
365 `id_conf` int(11) DEFAULT 1
366) ENGINE=MyISAM DEFAULT CHARSET 'utf8';";
367
368
369$sql2="INSERT INTO `".$prefix."_ele_fasce` (`id_fascia`, `abitanti`, `seggi`, `id_conf`) VALUES
370(1, 3000, 12, 1),
371(2, 10000, 16, 1),
372(3, 15000, 20, 1),
373(4, 30000, 20, 1),
374(5, 100000, 30, 1),
375(6, 250000, 40, 1),
376(7, 500000, 46, 1),
377(8, 1000000, 50, 1),
378(9, 100000000, 60, 1),
379(1, 3000, 12, 2),
380(2, 10000, 16, 2),
381(3, 15000, 20, 2),
382(4, 30000, 20, 2),
383(5, 100000, 30, 2),
384(6, 250000, 40, 2),
385(7, 500000, 46, 2),
386(8, 1000000, 50, 2),
387(9, 100000000, 60, 2),
388(1, 3000, 9, 3),
389(2, 5000, 9, 3),
390(4, 15000, 16, 3),
391(3, 10000, 12, 3),
392(5, 30000, 16, 3),
393(6, 100000, 24, 3),
394(7, 250000, 32, 3),
395(8, 500000, 36, 3),
396(9, 1000000, 40, 3),
397(10, 100000000, 48, 3),
398(1, 3000, 6, 4),
399(2, 5000, 7, 4),
400(3, 10000, 12, 4),
401(4, 15000, 16, 4),
402(5, 30000, 16, 4),
403(6, 100000, 24, 4),
404(7, 250000, 32, 4),
405(8, 500000, 36, 4),
406(9, 1000000, 40, 4),
407(10, 100000000, 48, 4),
408(1, 3000, 9, 5),
409(2, 5000, 9, 5),
410(3, 10000, 12, 5),
411(4, 15000, 16, 5),
412(5, 30000, 16, 5),
413(6, 100000, 24, 5),
414(7, 250000, 32, 5),
415(8, 500000, 36, 5),
416(9, 1000000, 40, 5),
417(10, 100000000, 48, 5),
418(1, 3000, 6, 6),
419(2, 5000, 7, 6),
420(3, 10000, 10, 6),
421(4, 15000, 16, 6),
422(5, 30000, 16, 6),
423(6, 100000, 24, 6),
424(7, 250000, 32, 6),
425(8, 500000, 36, 6),
426(9, 1000000, 40, 6),
427(10, 100000000, 48, 6),
428(1, 3000, 10, 7),
429(2, 10000, 12, 7),
430(3, 15000, 16, 7),
431(4, 30000, 16, 7),
432(5, 100000, 24, 7),
433(6, 250000, 32, 7),
434(7, 500000, 36, 7),
435(8, 1000000, 40, 7),
436(9, 100000000, 48, 7);";
437$ret=aggiorna($sql,$dbi,$sql2,$num);
438#if(!$ret) echo "<br>".$num++.") Fallito: $sql"; else echo "<br>".$num++.") Aggiornato<br>";
439
440$sql="ALTER TABLE `".$prefix."_ele_fasce`
441 ADD KEY `id_fascia` (`id_fascia`);";
442$ret=aggiorna($sql,$dbi,'',$num);
443#if(!$ret) echo "<br>".$num++.") Fallito: $sql"; else echo "<br>".$num++.") Aggiornato<br>";
444
445
446
447#if(!$ret)
448# echo "<br>".$num++.") Fallito: $sql";
449#elseif ($ret==1)
450# echo "<br>".$num++.") Index eliminato";
451#else
452# echo "<br>".$num++.") Index aggiunto";
453#$sql="ALTER TABLE `".$prefix."_ele_voti_lista` DROP INDEX if exists `id_cons`";
454echo "<br><br>".++$num.") Ricostruzione e aggioramento indici";
455$tab=$prefix."_ele_voti_ref";
456$ind="id_cons";
457# $sql="ALTER TABLE `".$prefix."_ele_voti_ref` DROP INDEX `id_cons`; ";
458$sql2="ALTER TABLE `".$prefix."_ele_voti_ref` ADD INDEX `id_cons` (`id_cons`, `id_gruppo`) USING BTREE";
459$ret=aggiorna_index($tab, $ind,$dbi,$sql2,$num);
460
461$tab=$prefix."_ele_sezioni";
462$ind="id_cons";
463$sql2="ALTER TABLE `".$prefix."_ele_sezioni` ADD UNIQUE `id_cons` (`id_cons`, `num_sez`) USING BTREE";
464$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
465
466$tab=$prefix."_ele_voti_lista";
467$ind="id_cons";
468$sql2="ALTER TABLE `".$prefix."_ele_voti_lista` ADD INDEX `id_cons` (`id_cons`, `id_sez`, `id_lista`) USING BTREE";
469$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
470
471$tab=$prefix."_ele_voti_gruppo";
472$ind="id_cons";
473#$sql="ALTER TABLE `".$prefix."_ele_voti_gruppo` DROP INDEX if exists `id_cons`";
474$sql2="ALTER TABLE `".$prefix."_ele_voti_gruppo` ADD INDEX `id_cons` (`id_cons`, `id_sez`, `id_gruppo`) USING BTREE";
475$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
476
477$tab=$prefix."_ele_voti_candidati";
478$ind="id_cons";
479#$sql="ALTER TABLE `".$prefix."_ele_voti_candidati` DROP INDEX if exists `id_cons`";
480$sql2="ALTER TABLE `".$prefix."_ele_voti_candidati` ADD INDEX `id_cons` (`id_cons`, `id_sez`, `id_cand`) USING BTREE";
481$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
482
483$tab=$prefix."_ele_lista";
484$ind="id_cons";
485#$sql="ALTER TABLE `".$prefix."_ele_lista` DROP INDEX if exists `id_cons`";
486$sql2="ALTER TABLE `".$prefix."_ele_lista` ADD INDEX `id_cons` (`id_cons`, `id_gruppo`) USING BTREE";
487$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
488
489$tab=$prefix."_ele_lista";
490$ind="PRIMARY";
491#$sql="ALTER TABLE `".$prefix."_ele_lista` DROP INDEX if exists `PRIMARY`";
492$sql2="ADD PRIMARY KEY (`id_lista`) USING BTREE";
493$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
494
495$tab=$prefix."_ele_gruppo";
496$ind="id_cons";
497#$sql="ALTER TABLE `".$prefix."_ele_gruppo` DROP INDEX if exists `id_cons`";
498$sql2="ALTER TABLE `".$prefix."_ele_gruppo` ADD INDEX `id_cons` (`id_cons`, `id_circ`) USING BTREE";
499$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
500
501$tab=$prefix."_ele_gruppo";
502$ind="PRIMARY";
503#$sql="ALTER TABLE `".$prefix."_ele_gruppo` DROP INDEX if exists `PRIMARY`";
504$sql2="ADD PRIMARY KEY (`id_gruppo`) USING BTREE";
505$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
506
507$tab=$prefix."_ele_candidati";
508$ind="id_cons";
509#$sql="ALTER TABLE `".$prefix."_ele_candidati` DROP INDEX if exists `id_cons`";
510$sql2="ALTER TABLE `".$prefix."_ele_candidati` ADD INDEX `id_cons` (`id_cons`, `id_lista`) USING BTREE";
511$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
512
513$tab=$prefix."_ele_candidati";
514$ind="PRIMARY";
515#$sql="ALTER TABLE `".$prefix."_ele_candidati` DROP INDEX if exists `PRIMARY`";
516$sql2="ADD PRIMARY KEY (`id_cand`) USING BTREE";
517$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
518
519$tab=$prefix."_ele_consultazione";
520$ind="descrizione";
521#$sql="ALTER TABLE `".$prefix."_ele_consultazione` DROP INDEX if exists `descrizione`";
522$sql2="ALTER TABLE `".$prefix."_ele_consultazione` ADD UNIQUE `descrizione` (`descrizione`(100))";
523$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
524
525echo "<br><br>".++$num.") Modifica Charset del database";
526if($newcs=='utf8') {
527 $cset='utf8';
528 $ccollate='utf8_general_ci';
529 $preset='latin1';
530}else{
531 $cset='latin1';
532 $ccollate='latin1_swedish_ci';
533 $preset='utf8';
534}
535#$sql="ALTER DATABASE $dbname CHARACTER SET '$cset' COLLATE '$ccollate'";
536#$res = $dbi->prepare("$sql");
537#$res->execute();
538
539$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%')";
540$res = $dbi->prepare("$sql");
541$res->execute();
542$tab='';
543$agg=$res->rowCount();
544
545while(list($nometab,$campo,$def,$tipo,$nul)=$res->fetch(PDO::FETCH_NUM)) {
546 if($tab!=$nometab){
547 $sql="alter table $nometab DEFAULT CHARSET=$cset COLLATE $ccollate";
548 try{
549 $res2 = $dbi->prepare("$sql");
550 $res2->execute();
551 }
552 catch(PDOException $e)
553 {
554 die( $sql . "<br>" . $e->getMessage());
555 }
556 $tab=$nometab; echo "<br><span style=\"color: green;\">- Tabella: $nometab</span>";
557 }
558 if($def!='') $default="DEFAULT '$def'"; else $default='';
559 if($nul=='NO') $nullable='NOT NULL'; else $nullable='NULL';
560 $sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET '$cset' COLLATE '$ccollate' $nullable $default;";
561 try{
562 $res2 = $dbi->prepare("$sql");
563 $res2->execute();
564 }
565 catch(PDOException $e)
566 {
567 $default="DEFAULT $def";
568 $sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET '$cset' COLLATE '$ccollate' $nullable $default;";
569 try{
570 $res2 = $dbi->prepare("$sql");
571 $res2->execute();
572 }
573 catch(PDOException $e)
574 {
575 die( $sql . "<br>" . $e->getMessage());
576 }
577 }
578 echo "<br><span style=\"color: green;\">-- $campo</span>";
579}
580 $sql="SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE TABLE_SCHEMA = '$dbname' and table_collation like '$preset%'";
581 $res = $dbi->prepare("$sql");
582 $res->execute();
583$tab='';
584if(!$agg) $agg=$res->rowCount();
585while(list($nometab)=$res->fetch(PDO::FETCH_NUM)) {
586 $sql="alter table $nometab DEFAULT CHARSET=$cset COLLATE $ccollate";
587 try{
588 $res2 = $dbi->prepare("$sql");
589 $res2->execute();
590 }
591 catch(PDOException $e)
592 {
593 die( $sql . "<br>" . $e->getMessage());
594 }
595 echo "<br><span style=\"color: green;\">- Tabella: $nometab</span>";
596}
597if(!$agg) echo "<br><span style=\"color: green;\">- Nessuna tabella da aggiornare</span>";
598echo "<br><br>";
599?>
Note: See TracBrowser for help on using the repository browser.