Index: trunk/admin/modules/Elezioni/ele_affluenze.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_affluenze.php	(revision 53)
+++ trunk/admin/modules/Elezioni/ele_affluenze.php	(revision 255)
@@ -15,6 +15,7 @@
 }
 
+global $dbi;
 $aid=$_SESSION['aid'];
-$dbi=$_SESSION['dbi'];
+#$dbi=$_SESSION['dbi'];
 $prefix=$_SESSION['prefix'];
 $currentlang=$_SESSION['lang'];
@@ -22,6 +23,10 @@
 $perms=ChiSei(0);
 if ($perms<256 or !$id_cons_gen) die("Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
-$res = mysql_query("SELECT t1.tipo_cons,t2.genere,t1.descrizione FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_tipo as t2 where t1.tipo_cons=t2.tipo_cons and t1.id_cons_gen='$id_cons_gen' " , $dbi);
-list($tipo_cons,$genere,$descr_cons) = mysql_fetch_row($res);
+
+#include_once("modules/Elezioni/query.sql");
+include("modules/Elezioni/funzionidata.php");
+include("modules/Elezioni/ele.php");
+$row=descr_cons();$tipo_cons=$row[0];$genere=$row[1];$descr_cons=$row[2];
+
 if (isset($_GET['min'])) $min=intval($_GET['min']); else $min=0;
 if (isset($_GET['do'])) get_magic_quotes_gpc() ? $do=$param['do']:$do=addslashes($param['do']); else $do='';
@@ -36,6 +41,4 @@
 if (isset($_GET['help'])) $help=intval($_GET['help']);
 
-include("modules/Elezioni/funzionidata.php");
-include("modules/Elezioni/ele.php");
 $offset=15;
 $hiddenInfo = "<input type=\"hidden\" name=\"min\" value=\"$min\">";
@@ -58,7 +61,6 @@
 #		echo "<td bgcolor=\"$bgcolor1\">&nbsp;</td>";
 		echo "<td bgcolor=\"$bgcolor1\">&nbsp;</td></tr>";
-		$res = mysql_query("SELECT * FROM ".$prefix."_ele_rilaff where id_cons_gen=$id_cons_gen order by data,orario", $dbi);
-		$max = mysql_num_rows($res);
-
+		$row=getaffluenze();
+		$max = count($row);
 		echo "<form name=\"rilaff\" action=\"admin.php\">"
 			."<input type=\"hidden\" name=\"op\" value=\"rec_add_aff\">"
@@ -69,6 +71,6 @@
 		echo "<select name= \"mv\" ><option value=\"00\" selected>00</option>"; minuti();
 		echo "</td><td>";
-		$aff = mysql_query("SELECT data_inizio,data_fine FROM ".$prefix."_ele_consultazione where id_cons_gen='$id_cons_gen'", $dbi);
-		list($data,$fine) = mysql_fetch_row($aff);
+		$aff = daticonsultazione();
+		$data=$aff['data_inizio'];$fine=$aff['data_fine'];
 		list ($anno,$mese,$giorno)=explode('-',$data);
 		list ($annof,$mesef,$giornof)=explode('-',$fine);
@@ -84,5 +86,9 @@
 		if ($max != "0") {
 			$i=1;
-			while(list($id_cons2,$orario,$data) = mysql_fetch_row($res)){
+			foreach($row as $aff) 
+				{
+				$id_cons2=$aff[0];
+				$orario=$aff[1];
+				$data=$aff[2];
 				// esplode la data
 				$bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
@@ -108,5 +114,5 @@
 					."</tr>";
 			}
-		}
+		} 
 		echo "</table>";
 	}
@@ -119,15 +125,21 @@
 		$data="$av-$msv-$gv";
 		$orario="$ov:$mv:00";
-		$confr = mysql_query("SELECT data_inizio, data_fine FROM ".$prefix."_ele_consultazione WHERE id_cons_gen ='$id_cons_gen'", $dbi);
-list($dadata, $adata) = mysql_fetch_row($confr);
+		$row = daticonsultazione();
+#		mysql_query("SELECT data_inizio, data_fine FROM ".$prefix."_ele_consultazione WHERE id_cons_gen ='$id_cons_gen'", $dbi);
+$dadata=$row['data_inizio']; $adata=$row['data_fine'];
 $dadata=strtotime($dadata);
 $adata=strtotime($adata);
 $cdata=strtotime($data);
 		// verifica se data e ora esiste e fa l'upgrade
-		$res = mysql_query("select * from ".$prefix."_ele_rilaff where id_cons_gen='$id_cons_gen' and data='$data' and orario='$orario'", $dbi);
-		$tipo= mysql_num_rows($res); 
+		$sql = "select * from ".$prefix."_ele_rilaff where id_cons_gen='$id_cons_gen' and data='$data' and orario='$orario'";
+		$sth = $dbi->prepare("$sql");
+		$sth->execute();	
+		$row = $sth->fetchAll();
+		$tipo= $sth->rowCount(); 
 		if(($tipo==0) and ($dadata <= $cdata) and ($adata >= $cdata)){
 			if(checkdate(intval($msv),intval($gv),intval($av))){
-			$result = mysql_query("insert into ".$prefix."_ele_rilaff values ('$id_cons_gen','$orario','$data')", $dbi)|| die("Impossibile inserire i dati! ".mysql_error());
+			$sql="insert into ".$prefix."_ele_rilaff values ('$id_cons_gen','$orario','$data')";
+			$sth = $dbi->prepare("$sql");
+			$sth->execute();	
 			}
 			Header("Location: admin.php?op=rec_add_aff&id_cons_gen=$id_cons_gen");
@@ -142,8 +154,16 @@
 				die();
 			}else{
-				$res = mysql_query("select id_cons from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen'", $dbi);
-				while (list($id_cons2) = mysql_fetch_row($res))
-					mysql_query("delete from ".$prefix."_ele_voti_parziale where id_cons='$id_cons2' and data='$data' and orario='$orario'", $dbi)|| die("Impossibile cancellare i dati! ".mysql_error());
-				mysql_query("delete from ".$prefix."_ele_rilaff where id_cons_gen='$id_cons_gen' and data='$data' and orario='$orario'", $dbi)|| die("Impossibile cancellare i dati! ".mysql_error());
+				$sql = "select id_cons from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen'";
+				$sth = $dbi->prepare("$sql");
+				$sth->execute();	
+				$row2 = $sth->fetchAll();
+				foreach($row2 as $id_cons2) {
+					$sql = "delete from ".$prefix."_ele_voti_parziale where id_cons='$id_cons2' and data='$data' and orario='$orario'";
+					$sth = $dbi->prepare("$sql");
+					$sth->execute();	
+				}
+				$sql = "delete from ".$prefix."_ele_rilaff where id_cons_gen='$id_cons_gen' and data='$data' and orario='$orario'";
+				$sth = $dbi->prepare("$sql");
+				$sth->execute();	
 				Header("Location: admin.php?op=rec_add_aff&id_cons_gen=$id_cons_gen&contr=$data");
 			}
