source: trunk/admin/aggiornadb.php@ 371

Last change on this file since 371 was 371, checked in by roby, 21 months ago

In client:

  • rivista la funzione di esportazione pdf, xls e stampe
  • tema futura2: eliminato il taglio a 30 caratteri del nome della consultazione
  • modificata la barra da 2D a 3D per i grafici di affluenza e votanti

In admin:

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