Index: trunk/admin/modules/Elezioni/ele_cons_comuni.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_cons_comuni.php	(revision 122)
+++ trunk/admin/modules/Elezioni/ele_cons_comuni.php	(revision 256)
@@ -13,6 +13,6 @@
 }
 
+global $dbi;
 $aid=$_SESSION['aid'];
-$dbi=$_SESSION['dbi'];
 $prefix=$_SESSION['prefix'];
 if($param)
@@ -23,8 +23,9 @@
 $perms=ChiSei(0);
 if ($perms<64 or !$id_cons_gen) die("Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
-$res = mysql_query("SELECT tipo_cons,descrizione FROM ".$prefix."_ele_consultazione where id_cons_gen='$id_cons_gen' " , $dbi);
-list($tipo_cons,$descr_cons) = mysql_fetch_row($res);
 include("modules/Elezioni/funzionidata.php");
 include("modules/Elezioni/ele.php");
+$row=descr_cons();
+$tipo_cons=$row[0];$descr_cons=$row[2];
+
 if (isset($param['do'])) get_magic_quotes_gpc() ? $do=$param['do']:$do=addslashes($param['do']); else $do='';
 if (isset($param['ok'])) get_magic_quotes_gpc() ? $ok=$param['ok']:$ok=addslashes($param['ok']); else $ok='';
@@ -48,9 +49,11 @@
 
 	if (isset($help)) include("language/$language/ele_cons_comuni.html");
-
+	$row=descr_comune();
 	$res = mysql_query("SELECT id_cons FROM ".$prefix."_ele_comuni where id_comune=$id_comune", $dbi);
-	if (isset($res)) list($idpred) = mysql_fetch_row($res); else $idpred='';
-	$res = mysql_query("SELECT t1.id_cons, t2.descrizione FROM ".$prefix."_ele_cons_comune as t1 left join ".$prefix."_ele_consultazione as t2 on t1.id_cons_gen=t2.id_cons_gen where t1.id_comune='$id_comune' " , $dbi);
-	$max = mysql_num_rows($res);
+	if (count($row)) $idpred = $row[2]; else $idpred='';
+#	$res = mysql_query("SELECT t1.id_cons, t2.descrizione FROM ".$prefix."_ele_cons_comune as t1 left join ".$prefix."_ele_consultazione as t2 on t1.id_cons_gen=t2.id_cons_gen where t1.id_comune='$id_comune' " , $dbi);
+	$row=elenco_cons_comune();
+	
+	$max = count($row);
 	echo "<table border=\"0\" width=\"100%\" align=\"left\"><tr><td>";
 	echo "<form name=\"imppred\" action=\"admin.php\">";
@@ -58,5 +61,5 @@
    	."&nbsp;<b>"._CONSPRED."</b>&nbsp;</td><td><select name=\"predefinita\">";
 	echo "<option value=\"\">";
-	while($arr=mysql_fetch_array($res,3)){
+	foreach($row as $arr){
 		$sel='';
 		if (($idpred))
@@ -77,10 +80,17 @@
 	."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._COPIA." "._NUM." "._ELETTORI."</b></td>"
 	."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._FUNZIONI."</b></td></tr>";
-	$result = mysql_query("select t2.chiusa,t2.id_cons,t1.* from ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2, ".$prefix."_ele_tipo as t3 where t1.tipo_cons=t3.tipo_cons and t2.id_comune='$id_comune' and t1.id_cons_gen=t2.id_cons_gen and t2.id_cons!=$id_cons ORDER BY data_fine desc LIMIT $min,$offset", $dbi);
+	$sql = "select t2.chiusa,t2.id_cons,t1.* from ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2, ".$prefix."_ele_tipo as t3 where t1.tipo_cons=t3.tipo_cons and t2.id_comune='$id_comune' and t1.id_cons_gen=t2.id_cons_gen and t2.id_cons!=$id_cons ORDER BY data_fine desc LIMIT $min,$offset";
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();	
+	$row = $sth->fetchAll();
 	$i=0;
-	while(list($chiusa,$id_cons2,$idconsgen2, $descr_cons, $data_inizio, $data_fine,$tipo) = mysql_fetch_row($result)) {
+	foreach($row as $arr) {
+		$chiusa=$arr[0];$id_cons2=$arr[1];$idconsgen2=$arr[2]; $descr_cons=$arr[3]; $data_inizio=$arr[4]; $data_fine=$arr[5];$tipo=$arr[6];
 		$bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
-		$ressez = mysql_query("select count(id_cons) from ".$prefix."_ele_sezioni where id_cons='$id_cons2'", $dbi);
-		list($somma)=mysql_fetch_row($ressez);
+		$sql = "select count(id_cons) from ".$prefix."_ele_sezioni where id_cons='$id_cons2'";
+		$sth = $dbi->prepare("$sql");
+		$sth->execute();	
+		$row = $sth->fetch(PDO::FETCH_BOTH);
+		$somma=$row[0];
 		$data_inizio=form_data($data_inizio);$data_fine=form_data($data_fine);
 		echo "<tr bgcolor=\"$bgcolor1\" align=\"center\" ><td align=\"left\" ><a href=\"admin.php?op=cons_comuni&amp;id_cons_gen=$idconsgen2\"><b>$descr_cons</b></a></td>"
@@ -141,42 +151,80 @@
 if ($perms>32) {
 	$sql="select id_cons from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' and id_comune=$id_comune";
-	$res=mysql_query("$sql",$dbi);
-	list($id_consulta)=mysql_fetch_row($res);
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();	
+	$row = $sth->fetch(PDO::FETCH_BOTH);
+	$id_consulta=$row[0];
 	$sql="select t1.descrizione from ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t2.id_cons='$id_cons2' and t1.id_cons_gen=t2.id_cons_gen";
-	$res=mysql_query("$sql",$dbi);
-	list($descr_cons2)=mysql_fetch_row($res);
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();	
+	$row = $sth->fetch(PDO::FETCH_BOTH);
+		
+	$descr_cons2=$row[0];
 	if ($do == "add") {
 		if ($id_cons2) {
 			// copia circoscrizione
-			$res=mysql_query("select * from ".$prefix."_ele_circoscrizione where id_cons='$id_consulta'", $dbi);
-			while (list($id,$idcirc,$num,$des2)=mysql_fetch_row($res)){
-			$des=addslashes($des2);
- $resconnew=mysql_query("select count(0) from ".$prefix."_ele_circoscrizione where id_cons='$id_cons2' and num_circ='$num'", $dbi);
-list($contr_circ)=mysql_fetch_row($resconnew);
-if (! $contr_circ){
-				mysql_query("insert into ".$prefix."_ele_circoscrizione (id_cons,num_circ,descrizione) values ('$id_cons2',$num,'$des')", $dbi) || die("Impossibile inserire i dati delle circoscrizioni! ".mysql_error());
-}
-				$res0=mysql_query("select id_circ from ".$prefix."_ele_circoscrizione where id_cons=$id_cons2 and num_circ=$num", $dbi);
-				list($id_circ)=mysql_fetch_row($res0);
+			$sql="select * from ".$prefix."_ele_circoscrizione where id_cons='$id_consulta'";
+			$sth = $dbi->prepare("$sql");
+			$sth->execute();	
+			$row = $sth->fetchAll();
+			foreach($row as $arr){
+				$id=$arr[0];$idcirc=$arr[1];$num=$arr[2];$des2=$arr[3];
+				$des=addslashes($des2);
+				$sql="select count(0) from ".$prefix."_ele_circoscrizione where id_cons='$id_cons2' and num_circ='$num'";
+				$sth = $dbi->prepare("$sql");
+				$sth->execute();	
+				$row = $sth->fetch(PDO::FETCH_BOTH);
+				$contr_circ=$row[0];
+				if (! $contr_circ){
+					sql="insert into ".$prefix."_ele_circoscrizione (id_cons,num_circ,descrizione) values ('$id_cons2',$num,'$des')";
+					$sth = $dbi->prepare("$sql");
+					$sth->execute();	
+
+				}
+				$sql="select id_circ from ".$prefix."_ele_circoscrizione where id_cons=$id_cons2 and num_circ=$num";
+				$sth = $dbi->prepare("$sql");
+				$sth->execute();	
+				$row = $sth->fetch(PDO::FETCH_BOTH);
+				$id_circ=$row[0];
 				// copia sede
-				$res1=mysql_query("select * from ".$prefix."_ele_sede where id_cons='$id_consulta' and id_circ='$idcirc'", $dbi);
-				while(list($id1,$idsede1,$idcirc1,$ind2,$tel,$tel2,$fax,$resp,$mappa2,$filemappa2)=mysql_fetch_row($res1)){
+				$sql="select * from ".$prefix."_ele_sede where id_cons='$id_consulta' and id_circ='$idcirc'";
+				$sth = $dbi->prepare("$sql");
+				$sth->execute();	
+				$row = $sth->fetchAll();
+				foreach($row as $row2) {
+					$id1=$row2[0];$idsede1=$row2[1];$idcirc1=$row2[2];$ind2=$row2[3];$tel=$row2[4];$tel2=$row2[5];$fax=$row2[6];$resp=$row2[7];$mappa2=$row2[8];$filemappa2=$row2[9];
 					$filemappa=addslashes($filemappa2);
 					$mappa=addslashes($mappa2);
 					$ind=addslashes($ind2);
- $ressednew=mysql_query("select count(0) from ".$prefix."_ele_sede where id_cons='$id_cons2' and indirizzo='$ind'", $dbi);
-list($contr_sed)=mysql_fetch_row($ressednew);
-if (! $contr_sed){
-					mysql_query("insert into ".$prefix."_ele_sede (id_cons,id_circ,indirizzo,telefono1,telefono2,fax,responsabile,mappa,filemappa) values ('$id_cons2','$id_circ','$ind','$tel','$tel2','$fax','$resp','$mappa','$filemappa')", $dbi) || die("Impossibile inserire i dati delle sedi! ".mysql_error());
-}
-					$res2=mysql_query("select id_sede from ".$prefix."_ele_sede where id_cons=$id_cons2 and id_circ=$id_circ and indirizzo='$ind'", $dbi);
+					$sql="select count(0) from ".$prefix."_ele_sede where id_cons='$id_cons2' and indirizzo='$ind'";
+					$sth = $dbi->prepare("$sql");
+					$sth->execute();	
+					$row = $sth->fetch(PDO::FETCH_BOTH);
+					$contr_sed=$row[0];
+					if (! $contr_sed){
+						$sql="insert into ".$prefix."_ele_sede (id_cons,id_circ,indirizzo,telefono1,telefono2,fax,responsabile,mappa,filemappa) values ('$id_cons2','$id_circ','$ind','$tel','$tel2','$fax','$resp','$mappa','$filemappa')";
+						$sth = $dbi->prepare("$sql");
+						$sth->execute();	
+					}
+					$sql"select id_sede from ".$prefix."_ele_sede where id_cons=$id_cons2 and id_circ=$id_circ and indirizzo='$ind'";
 					list($id_sede)=mysql_fetch_row($res2);
+					$sth = $dbi->prepare("$sql");
+					$sth->execute();	
+					$row = $sth->fetch(PDO::FETCH_BOTH);
+					$id_sede=$row[0];
 					//copia sezione
-					$res3=mysql_query("select * from ".$prefix."_ele_sezioni where id_cons=$id_consulta and id_sede=$idsede1", $dbi);
-					while (list($id3,$idsez3,$idsede3,$numero,$maschi3,$femmine3,$validi3,$nulli3,
-						$bianchi3,$contest3,$sg3,$aut_m,$aut_f)=mysql_fetch_row($res3)){
+					$sql="select * from ".$prefix."_ele_sezioni where id_cons=$id_consulta and id_sede=$idsede1";
+					$sth = $dbi->prepare("$sql");
+					$sth->execute();	
+					$row = $sth->fetchAll();
+					foreach($row as $arr2)
+					{
+						$id3=$arr2[0];$idsez3=$arr2[1];$idsede3=$arr2[2];$numero=$arr2[3];$maschi3=$arr2[4];$femmine3=$arr2[5];$validi3=$arr2[6];$nulli3=$arr2[7];
+						$bianchi3=$arr2[8];$contest3=$arr2[9];$sg3,$aut_m=$arr2[10];$aut_f=$arr2[11];
 						if ($elettori=='true') $sql="insert into ".$prefix."_ele_sezioni (id_cons,id_sede,num_sez,maschi,femmine) values ('$id_cons2','$id_sede','$numero','$maschi3','$femmine3')";
 						else $sql="insert into ".$prefix."_ele_sezioni (id_cons,id_sede,num_sez) values ('$id_cons2','$id_sede','$numero')";
-						mysql_query("$sql", $dbi) || die("Impossibile inserire i dati delle sezioni! ".mysql_error());
+						$sth = $dbi->prepare("$sql");
+						$sth->execute();	
+
 					}
 				}
@@ -191,5 +239,8 @@
 			echo "[ <a href=\"admin.php?op=cons_comuni&amp;id_cons_gen=$id_cons_gen\">"._NO."</a> ] - [<a href=\"admin.php?op=cons_comuni&amp;do=elettori&amp;id_cons_gen=$id_cons_gen&amp;id_cons2=$id_cons2&amp;ok=1\">"._YES."</a> ]";exit;
 		}else{
-		$result = mysql_query("update ".$prefix."_ele_sezioni as t1, ".$prefix."_ele_sezioni as t2 set t1.maschi=t2.maschi, t1.femmine=t2.femmine WHERE t1.id_cons=$id_cons2 and t2.id_cons=$id_consulta and t1.num_sez=t2.num_sez", $dbi);
+		$sql="update ".$prefix."_ele_sezioni as t1, ".$prefix."_ele_sezioni as t2 set t1.maschi=t2.maschi, t1.femmine=t2.femmine WHERE t1.id_cons=$id_cons2 and t2.id_cons=$id_consulta and t1.num_sez=t2.num_sez";
+		$sth = $dbi->prepare("$sql");
+		$result=$sth->execute();	
+
 		if (!$result) return;
 		Header("Location: admin.php?op=cons_comuni&id_cons_gen=$id_cons_gen");
@@ -198,8 +249,14 @@
 	if ($do == "update") {
 		if ($predefinita) 
-			$result = mysql_query("update  ".$prefix."_ele_comuni set  id_cons='$predefinita' WHERE id_comune='$id_comune'", $dbi);
-		else
-			$result = mysql_query("update  ".$prefix."_ele_cons_comune set  chiusa='$chiusa' WHERE id_cons2='$id_cons2'", $dbi);
-		if (!$result) return;
+		{
+			$sql="update  ".$prefix."_ele_comuni set  id_cons='$predefinita' WHERE id_comune='$id_comune'";
+			$sth = $dbi->prepare("$sql");
+			$result=$sth->execute();	
+		}else{
+			$sql"update  ".$prefix."_ele_cons_comune set  chiusa='$chiusa' WHERE id_cons2='$id_cons2'";
+			$sth = $dbi->prepare("$sql");
+			$result=$sth->execute();	
+		}
+			if (!$result) return;
 		Header("Location: admin.php?op=cons_comuni&id_cons_gen=$id_cons_gen");
    	} 
