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

Last change on this file since 425 was 424, checked in by roby, 3 weeks ago
  • ADMIN

-- Inserito il file admin/variabili.php che contiene le variabili per personalizzare il software
-- Nuovo sistema di backup, permette di avere una installazione di produzione ed una che può essere facilmente aggiornata con i dati della prima
-- Modificato il file dei controlli
-- Modificata la scheda Tabella dei totali

  • CLIENT

-- Inserito il file client/variabili.php che contiene le variabili per personalizzare il software
-- Modificata per compatibilità con alcune installazioni la funzione di assegnazione dei seggi
-- Modificato il colore dei link per il tema -altro-

File size: 25.4 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 `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' and `".$prefix."_authors`.`adminsuper` != '1'";
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>".++$num.") Aggiornamento tabella ".$prefix."_ele_conf";
328$sql="update `".$prefix."_ele_conf` SET `supdisgiunto` = '1' WHERE `soraldo_ele_conf`.`id_conf` = 7;";
329$ret=aggiorna($sql,$dbi,'',$num);
330
331echo "<br><br>".++$num.") Aggiornamento dei valori di default: ".$prefix."_ele_voti_lista";
332$sql="ALTER TABLE `".$prefix."_ele_voti_lista` CHANGE `num_lista` `num_lista` INT(2) UNSIGNED NULL DEFAULT '0';";
333$ret=aggiorna($sql,$dbi,'',$num);
334
335echo "<br><br>".++$num.") Aggiornamento tabella ".$prefix."_ele_voti_lista";
336$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;";
337$ret=aggiorna($sql,$dbi,'',$num);
338##############################################
339
340echo "<br><br>".++$num.") Aggiornamento dei valori di default: ".$prefix."_ele_gruppo";
341$sql="ALTER TABLE `".$prefix."_ele_gruppo` CHANGE `num_circ` `num_circ` INT(2) UNSIGNED NOT NULL DEFAULT '1';";
342$ret=aggiorna($sql,$dbi,'',$num);
343
344$sql="ALTER TABLE `".$prefix."_authors` CHANGE `adminsuper` `adminsuper` TINYINT(2) NOT NULL DEFAULT '0';";
345$ret=aggiorna($sql,$dbi,'',$num);
346
347$sql="ALTER TABLE `".$prefix."_ele_lista` CHANGE `num_gruppo` `num_gruppo` INT(2) UNSIGNED NOT NULL DEFAULT '0';";
348$ret=aggiorna($sql,$dbi,'',$num);
349
350$sql="ALTER TABLE `".$prefix."_ele_lista` CHANGE `num_circ` `num_circ` INT(2) UNSIGNED NOT NULL DEFAULT '1';";
351$ret=aggiorna($sql,$dbi,'',$num);
352
353echo "<br><br>".++$num.") Aggiornamento della tabella _ele_conf per la nuova gestione della L.R. Sicilia";
354$sql="UPDATE `".$prefix."_ele_conf` SET `inffisso` = '1' WHERE `id_conf` = 4;";
355$ret=aggiorna($sql,$dbi,'',$num);
356
357echo "<br><br>".++$num.") Aggiornamento del campo numero candidato della tabella _ele_voti_candidati per le consultazioni precedenti all'aggiunta del campo stesso";
358$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;";
359$ret=aggiorna($sql,$dbi,'',$num);
360
361echo "<br><br>".++$num.") Ricostruzione della tabella ".$prefix."_ele_fasce`";
362$sql="DROP TABLE `".$prefix."_ele_fasce`";
363$ret=aggiorna($sql,$dbi,'',$num);
364
365$sql="CREATE TABLE `".$prefix."_ele_fasce` (
366 `id_fascia` int(2) NOT NULL,
367 `abitanti` int(11) NOT NULL,
368 `seggi` int(4) NOT NULL,
369 `id_conf` int(11) DEFAULT 1
370) ENGINE=MyISAM DEFAULT CHARSET 'utf8';";
371
372
373$sql2="INSERT INTO `".$prefix."_ele_fasce` (`id_fascia`, `abitanti`, `seggi`, `id_conf`) VALUES
374(1, 3000, 12, 1),
375(2, 10000, 16, 1),
376(3, 15000, 20, 1),
377(4, 30000, 20, 1),
378(5, 100000, 30, 1),
379(6, 250000, 40, 1),
380(7, 500000, 46, 1),
381(8, 1000000, 50, 1),
382(9, 100000000, 60, 1),
383(1, 3000, 12, 2),
384(2, 10000, 16, 2),
385(3, 15000, 20, 2),
386(4, 30000, 20, 2),
387(5, 100000, 30, 2),
388(6, 250000, 40, 2),
389(7, 500000, 46, 2),
390(8, 1000000, 50, 2),
391(9, 100000000, 60, 2),
392(1, 3000, 9, 3),
393(2, 5000, 9, 3),
394(4, 15000, 16, 3),
395(3, 10000, 12, 3),
396(5, 30000, 16, 3),
397(6, 100000, 24, 3),
398(7, 250000, 32, 3),
399(8, 500000, 36, 3),
400(9, 1000000, 40, 3),
401(10, 100000000, 48, 3),
402(1, 3000, 6, 4),
403(2, 5000, 7, 4),
404(3, 10000, 12, 4),
405(4, 15000, 16, 4),
406(5, 30000, 16, 4),
407(6, 100000, 24, 4),
408(7, 250000, 32, 4),
409(8, 500000, 36, 4),
410(9, 1000000, 40, 4),
411(10, 100000000, 48, 4),
412(1, 3000, 9, 5),
413(2, 5000, 9, 5),
414(3, 10000, 12, 5),
415(4, 15000, 16, 5),
416(5, 30000, 16, 5),
417(6, 100000, 24, 5),
418(7, 250000, 32, 5),
419(8, 500000, 36, 5),
420(9, 1000000, 40, 5),
421(10, 100000000, 48, 5),
422(1, 3000, 6, 6),
423(2, 5000, 7, 6),
424(3, 10000, 10, 6),
425(4, 15000, 16, 6),
426(5, 30000, 16, 6),
427(6, 100000, 24, 6),
428(7, 250000, 32, 6),
429(8, 500000, 36, 6),
430(9, 1000000, 40, 6),
431(10, 100000000, 48, 6),
432(1, 3000, 10, 7),
433(2, 10000, 12, 7),
434(3, 15000, 16, 7),
435(4, 30000, 16, 7),
436(5, 100000, 24, 7),
437(6, 250000, 32, 7),
438(7, 500000, 36, 7),
439(8, 1000000, 40, 7),
440(9, 100000000, 48, 7);";
441$ret=aggiorna($sql,$dbi,$sql2,$num);
442#if(!$ret) echo "<br>".$num++.") Fallito: $sql"; else echo "<br>".$num++.") Aggiornato<br>";
443
444$sql="ALTER TABLE `".$prefix."_ele_fasce`
445 ADD KEY `id_fascia` (`id_fascia`);";
446$ret=aggiorna($sql,$dbi,'',$num);
447#if(!$ret) echo "<br>".$num++.") Fallito: $sql"; else echo "<br>".$num++.") Aggiornato<br>";
448
449
450
451#if(!$ret)
452# echo "<br>".$num++.") Fallito: $sql";
453#elseif ($ret==1)
454# echo "<br>".$num++.") Index eliminato";
455#else
456# echo "<br>".$num++.") Index aggiunto";
457#$sql="ALTER TABLE `".$prefix."_ele_voti_lista` DROP INDEX if exists `id_cons`";
458echo "<br><br>".++$num.") Ricostruzione e aggioramento indici";
459$tab=$prefix."_ele_voti_ref";
460$ind="id_cons";
461# $sql="ALTER TABLE `".$prefix."_ele_voti_ref` DROP INDEX `id_cons`; ";
462$sql2="ALTER TABLE `".$prefix."_ele_voti_ref` ADD INDEX `id_cons` (`id_cons`, `id_gruppo`) USING BTREE";
463$ret=aggiorna_index($tab, $ind,$dbi,$sql2,$num);
464
465$tab=$prefix."_ele_sezioni";
466$ind="id_cons";
467$sql2="ALTER TABLE `".$prefix."_ele_sezioni` ADD UNIQUE `id_cons` (`id_cons`, `num_sez`) USING BTREE";
468$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
469
470$tab=$prefix."_ele_voti_lista";
471$ind="id_cons";
472$sql2="ALTER TABLE `".$prefix."_ele_voti_lista` ADD INDEX `id_cons` (`id_cons`, `id_sez`, `id_lista`) USING BTREE";
473$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
474
475$tab=$prefix."_ele_voti_gruppo";
476$ind="id_cons";
477#$sql="ALTER TABLE `".$prefix."_ele_voti_gruppo` DROP INDEX if exists `id_cons`";
478$sql2="ALTER TABLE `".$prefix."_ele_voti_gruppo` ADD INDEX `id_cons` (`id_cons`, `id_sez`, `id_gruppo`) USING BTREE";
479$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
480
481$tab=$prefix."_ele_voti_candidati";
482$ind="id_cons";
483#$sql="ALTER TABLE `".$prefix."_ele_voti_candidati` DROP INDEX if exists `id_cons`";
484$sql2="ALTER TABLE `".$prefix."_ele_voti_candidati` ADD INDEX `id_cons` (`id_cons`, `id_sez`, `id_cand`) USING BTREE";
485$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
486
487$tab=$prefix."_ele_lista";
488$ind="id_cons";
489#$sql="ALTER TABLE `".$prefix."_ele_lista` DROP INDEX if exists `id_cons`";
490$sql2="ALTER TABLE `".$prefix."_ele_lista` ADD INDEX `id_cons` (`id_cons`, `id_gruppo`) USING BTREE";
491$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
492
493$tab=$prefix."_ele_lista";
494$ind="PRIMARY";
495#$sql="ALTER TABLE `".$prefix."_ele_lista` DROP INDEX if exists `PRIMARY`";
496$sql2="ADD PRIMARY KEY (`id_lista`) USING BTREE";
497$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
498
499$tab=$prefix."_ele_gruppo";
500$ind="id_cons";
501#$sql="ALTER TABLE `".$prefix."_ele_gruppo` DROP INDEX if exists `id_cons`";
502$sql2="ALTER TABLE `".$prefix."_ele_gruppo` ADD INDEX `id_cons` (`id_cons`, `id_circ`) USING BTREE";
503$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
504
505$tab=$prefix."_ele_gruppo";
506$ind="PRIMARY";
507#$sql="ALTER TABLE `".$prefix."_ele_gruppo` DROP INDEX if exists `PRIMARY`";
508$sql2="ADD PRIMARY KEY (`id_gruppo`) USING BTREE";
509$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
510
511$tab=$prefix."_ele_candidati";
512$ind="id_cons";
513#$sql="ALTER TABLE `".$prefix."_ele_candidati` DROP INDEX if exists `id_cons`";
514$sql2="ALTER TABLE `".$prefix."_ele_candidati` ADD INDEX `id_cons` (`id_cons`, `id_lista`) USING BTREE";
515$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
516
517$tab=$prefix."_ele_candidati";
518$ind="PRIMARY";
519#$sql="ALTER TABLE `".$prefix."_ele_candidati` DROP INDEX if exists `PRIMARY`";
520$sql2="ADD PRIMARY KEY (`id_cand`) USING BTREE";
521$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
522
523$tab=$prefix."_ele_consultazione";
524$ind="descrizione";
525#$sql="ALTER TABLE `".$prefix."_ele_consultazione` DROP INDEX if exists `descrizione`";
526$sql2="ALTER TABLE `".$prefix."_ele_consultazione` ADD UNIQUE `descrizione` (`descrizione`(100))";
527$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
528
529echo "<br><br>".++$num.") Modifica Charset del database";
530if($newcs=='utf8') {
531 $cset='utf8';
532 $ccollate='utf8_general_ci';
533 $preset='latin1';
534}else{
535 $cset='latin1';
536 $ccollate='latin1_swedish_ci';
537 $preset='utf8';
538}
539#$sql="ALTER DATABASE $dbname CHARACTER SET '$cset' COLLATE '$ccollate'";
540#$res = $dbi->prepare("$sql");
541#$res->execute();
542
543$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%')";
544$res = $dbi->prepare("$sql");
545$res->execute();
546$tab='';
547$agg=$res->rowCount();
548
549while(list($nometab,$campo,$def,$tipo,$nul)=$res->fetch(PDO::FETCH_NUM)) {
550 if($tab!=$nometab){
551 $sql="alter table $nometab DEFAULT CHARSET=$cset COLLATE $ccollate";
552 try{
553 $res2 = $dbi->prepare("$sql");
554 $res2->execute();
555 }
556 catch(PDOException $e)
557 {
558 die( $sql . "<br>" . $e->getMessage());
559 }
560 $tab=$nometab; echo "<br><span style=\"color: green;\">- Tabella: $nometab</span>";
561 }
562 if($def!='') $default="DEFAULT '$def'"; else $default='';
563 if($nul=='NO') $nullable='NOT NULL'; else $nullable='NULL';
564 $sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET '$cset' COLLATE '$ccollate' $nullable $default;";
565 try{
566 $res2 = $dbi->prepare("$sql");
567 $res2->execute();
568 }
569 catch(PDOException $e)
570 {
571 $default="DEFAULT $def";
572 $sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET '$cset' COLLATE '$ccollate' $nullable $default;";
573 try{
574 $res2 = $dbi->prepare("$sql");
575 $res2->execute();
576 }
577 catch(PDOException $e)
578 {
579 die( $sql . "<br>" . $e->getMessage());
580 }
581 }
582 echo "<br><span style=\"color: green;\">-- $campo</span>";
583}
584 $sql="SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE TABLE_SCHEMA = '$dbname' and table_collation like '$preset%'";
585 $res = $dbi->prepare("$sql");
586 $res->execute();
587$tab='';
588if(!$agg) $agg=$res->rowCount();
589while(list($nometab)=$res->fetch(PDO::FETCH_NUM)) {
590 $sql="alter table $nometab DEFAULT CHARSET=$cset COLLATE $ccollate";
591 try{
592 $res2 = $dbi->prepare("$sql");
593 $res2->execute();
594 }
595 catch(PDOException $e)
596 {
597 die( $sql . "<br>" . $e->getMessage());
598 }
599 echo "<br><span style=\"color: green;\">- Tabella: $nometab</span>";
600}
601if(!$agg) echo "<br><span style=\"color: green;\">- Nessuna tabella da aggiornare</span>";
602echo "<br><br>";
603?>
Note: See TracBrowser for help on using the repository browser.