Index: trunk/admin/aggiornadb.php
===================================================================
--- trunk/admin/aggiornadb.php	(revision 361)
+++ trunk/admin/aggiornadb.php	(revision 362)
@@ -1,15 +1,19 @@
 <?php
 
-#implementare controllo con: SHOW INDEX FROM tua_tabella WHERE tua_tabella.tua_colonna='nome_colonna';
+#imposta il charset su utf8, qualsiasi altro valore per cambiarlo in latin1;
+$newcs='utf8'; 
+
 @require_once("config.php"); 
 	try{
-	$dbi = new PDO("mysql:host=$dbhost;charset=latin1", $dbuname, $dbpass, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION)); 
-     	$sql = "use $dbname";
-    	$dbi->exec($sql);
-        }
+		$dbi = new PDO("mysql:host=$dbhost", $dbuname, $dbpass, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION)); 
+    	$sql = "use $dbname";
+    	$dbi->exec($sql);	
+    }
 	catch(PDOException $e)
 	{
 	    die( $sql . "<br>" . $e->getMessage());
 	} 
+
+
 ###############
 function aggiorna($sql,$dbi,$sql2,$num){
@@ -95,7 +99,28 @@
 $num=0;		
 
+if(controllo($prefix.'_authors','admincomune',++$num))
+{
+	$sql="update `".$prefix."_authors` set admincomune='1' where aid='admin'";
+	$ret=aggiorna($sql,$dbi,'',$num);
+	$sql="update `".$prefix."_authors` set admincomune='0' where aid!='admin'";
+	$ret=aggiorna($sql,$dbi,'',$num);
+	echo "Aggiornata la tabella dei permessi<br>";
+}	
+
 if(!controllo($prefix.'_config','versione',++$num))
 {
 	$sql="alter table `".$prefix."_config` change column `Versione` `versione` int(3)";
+	$ret=aggiorna($sql,$dbi,'',$num);
+}	
+
+if(!controllo($prefix.'_config','versione',++$num))
+{
+	$sql="alter table `".$prefix."_config` change column `Versione` `versione` int(3)";
+	$ret=aggiorna($sql,$dbi,'',$num);
+}	
+
+if(!controllo($prefix.'_config','secret',++$num))
+{
+	$sql="alter table `".$prefix."_config` DROP `secret`";
 	$ret=aggiorna($sql,$dbi,'',$num);
 }	
@@ -374,15 +399,26 @@
 
 echo "<br>Modifica Charset del database<br>";
-#$sql="ALTER DATABASE $dbname CHARACTER SET 'utf8' COLLATE 'utf8_general_ci'";
+if($newcs=='utf8') {
+	$cset='utf8';
+	$ccollate='utf8_general_ci';
+	$preset='latin1';
+}else{
+	$cset='latin1';
+	$ccollate='latin1_swedish_ci';
+	$preset='utf8';
+}
+#$sql="ALTER DATABASE $dbname CHARACTER SET '$cset' COLLATE '$ccollate'";
 #$res = $dbi->prepare("$sql");
 #$res->execute();
-# alter table $table DEFAULT CHARSET=utf8 COLLATE utf8_general_ci
-$sql="SELECT table_name,column_name,column_default,column_type,is_nullable FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '$dbname' and (character_set_name='latin1' or collation_name like 'latin%')";
+
+$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%')";
 $res = $dbi->prepare("$sql");
 $res->execute();
 $tab='';
+
+
 while(list($nometab,$campo,$def,$tipo,$nul)=$res->fetch(PDO::FETCH_NUM)) {
 	if($tab!=$nometab){
-		$sql="alter table $nometab DEFAULT CHARSET=utf8 COLLATE utf8_general_ci";
+		$sql="alter table $nometab DEFAULT CHARSET=$cset COLLATE $ccollate";
 		try{
 			$res2 = $dbi->prepare("$sql");
@@ -397,5 +433,5 @@
 	if($def!='') $default="DEFAULT '$def'"; else $default='';
 	if($nul=='NO') $nullable='NOT NULL'; else $nullable='NULL';
-	$sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' $nullable $default;"; 	
+	$sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET '$cset' COLLATE '$ccollate' $nullable $default;"; 	
 	echo "-- $campo<br>";
 	try{
@@ -406,5 +442,5 @@
 		{
 			$default="DEFAULT $def";
-			$sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' $nullable $default;"; 	
+			$sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET '$cset' COLLATE '$ccollate' $nullable $default;"; 	
 			try{
 					$res2 = $dbi->prepare("$sql");
@@ -417,10 +453,10 @@
 		}
 }
- $sql="SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE TABLE_SCHEMA = '$dbname' and table_collation like 'latin%'";
+ $sql="SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE TABLE_SCHEMA = '$dbname' and table_collation like '$preset%'";
  $res = $dbi->prepare("$sql");
  $res->execute();
 $tab='';
 while(list($nometab)=$res->fetch(PDO::FETCH_NUM)) {
-		$sql="alter table $nometab DEFAULT CHARSET=utf8 COLLATE utf8_general_ci";
+		$sql="alter table $nometab DEFAULT CHARSET=$cset COLLATE $ccollate";
 		try{
 	echo "Tabella: $nometab <br>";
