Index: trunk/admin/modules/Elezioni/ele.php
===================================================================
--- trunk/admin/modules/Elezioni/ele.php	(revision 254)
+++ trunk/admin/modules/Elezioni/ele.php	(revision 255)
@@ -21,7 +21,7 @@
     }
 }
-
+global $dbi;
 $aid=$_SESSION['aid'];
-$dbi=$_SESSION['dbi'];
+#$dbi=$_SESSION['dbi'];
 $id_comune=$_SESSION['id_comune'];
 $prefix=$_SESSION['prefix'];
@@ -42,27 +42,9 @@
 	}	
 }
-
-if ($id_cons_gen) {
-	if ($id_comune and $perms<256)
-		$sql = "SELECT t1.tipo_cons,t1.descrizione,t2.id_cons_gen FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_cons_gen='$id_cons_gen'";
-	else
-		$sql = "SELECT t1.tipo_cons,t1.descrizione,t1.id_cons_gen FROM ".$prefix."_ele_consultazione as t1 where  t1.id_cons_gen='$id_cons_gen'";
-}else{
-	if($perms>128)
-		$sql = "SELECT tipo_cons,descrizione,id_cons_gen FROM ".$prefix."_ele_consultazione order by data_fine desc limit 0,1 ";
-	else
-		$sql = "SELECT t1.tipo_cons,t1.descrizione,t2.id_cons_gen FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2, ".$prefix."_ele_operatori as t3 where t3.id_comune=$id_comune and t3.id_comune=t2.id_comune and t1.id_cons_gen=t2.id_cons_gen and t2.chiusa='0' and (t3.id_cons=t2.id_cons or t3.id_cons=0) and t3.permessi>0 and t3.aid='$aid' order by t1.data_fine desc limit 0,1 ";
-}
-
-	$res = mysql_query("$sql",$dbi);
-	$espandi=0;
-	if (mysql_num_rows($res))
-		list($tipo_cons,$descr_cons,$id_cons_gen) = mysql_fetch_row($res);
-	$res = mysql_query("SELECT t2.id_cons FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_cons_gen='$id_cons_gen' and t2.id_comune='$id_comune'" , $dbi);
-        if (mysql_num_rows($res)) list($id_cons) = mysql_fetch_row($res);
-	else	$espandi=1;
-	if(!isset($tipo_cons))$tipo_cons=0;
-	$res = mysql_query("SELECT genere,voto_g,voto_l,voto_c,circo FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' and lingua='$currentlang'" , $dbi);
-	list($genere,$votog,$votol,$votoc,$conscirc) = mysql_fetch_row($res);
+include_once("modules/Elezioni/query.sql");
+
+$row=setconsultazione(); $tipo_cons=$row[0]; $descr_cons=$row[1];$id_cons_gen=$row[2];
+$row=tipocons(); $genere=$row[0];$votog=$row[1];$votol=$row[2];$votoc=$row[3];$conscirc=$row[4];
+
 if (!$perms) $perms=ChiSei($id_cons_gen);
 	//include("modules/Elezioni/language/lang-$currentlang.php");
@@ -70,8 +52,5 @@
 	//        ELE
 	//**************************************************************************
-	if(!isset($id_cons))$id_cons=0;
-
-	$res = mysql_query("SELECT t1.limite FROM ".$prefix."_ele_conf as t1 left join ".$prefix."_ele_cons_comune as t2 on t1.id_conf=t2.id_conf where t2.id_cons='$id_cons'" , $dbi);
-	list($limite) = mysql_fetch_row($res);
+
 
 function ele() {
@@ -84,7 +63,8 @@
 	$bullet_red="<img src=\"temi/$tema/images/bullet_red.gif\" alt =\" \" align=\"left\" border=\"0\">";
 	$bgcolor1='#e7e7e7';
-	$sqlcomu="select descrizione from ".$prefix."_ele_comuni where id_comune='$id_comune'";
-	$res = mysql_query($sqlcomu);
-	list($descr_comu)=mysql_fetch_row($res);
+	$row=descr_comune();$descr_comu=$row['descrizione'];
+#	$sqlcomu="select descrizione from ".$prefix."_ele_comuni where id_comune='$id_comune'";
+#	$res = mysql_query($sqlcomu);
+#	list($descr_comu)=mysql_fetch_row($res);
 	$sqlcomu="select fascia from ".$prefix."_ele_cons_comune where id_cons='$id_cons'";
 	$res = mysql_query($sqlcomu);
@@ -104,13 +84,15 @@
 	echo "<input type=\"hidden\" name=\"pag_cons\" value=\"admin.php?id_cons_gen=\">";
 	echo "<input type=\"hidden\" name=\"op\" value=\"ele\">";
-	
-	if ($perms<128) { 
-		$res = mysql_query("select t3.id_cons, t2.descrizione,t4.genere, t2.id_cons_gen, t3.chiusa from ".$prefix."_ele_operatori as t1, ".$prefix."_ele_consultazione as t2, ".$prefix."_ele_cons_comune as t3, ".$prefix."_ele_tipo as t4 where t4.lingua='$currentlang' and t2.tipo_cons=t4.tipo_cons and t1.aid='$aid' and t3.id_cons_gen=t2.id_cons_gen and (t1.id_cons=t3.id_cons or t1.permessi=64) and t1.id_comune=t3.id_comune and t1.id_comune=$id_comune and t3.chiusa='0' order by t2.data_inizio desc", $dbi);
-	}else{
-		$res = mysql_query("SELECT '', t1.descrizione,t2.genere, t1.id_cons_gen,'' FROM ".$prefix."_ele_consultazione as t1,".$prefix."_ele_tipo as t2 where t2.lingua='$currentlang' and t1.tipo_cons=t2.tipo_cons order by t1.data_inizio desc", $dbi);
-		$sqlcomu="select id_comune,descrizione from ".$prefix."_ele_comuni order by descrizione asc";
-	}
+###########################
+$row=elenco_cons();	
+
+
+##################################
 	echo "<font size=-1><b>"._SCELTA_CONS.":</b> </font><select name=\"id_cons_gen\" onChange=\"top.location.href=this.form.pag_cons.value+this.form.id_cons_gen.options[this.form.id_cons_gen.selectedIndex].value;return false\">";
-	while(list($id,$descrizione,$gen2,$idgen,$chiusa) = mysql_fetch_row($res)) { 
+
+	foreach ($row as $riga)
+	{
+	$id=$riga[0];$descrizione=$riga[1];$gen2=$riga[2];$idgen=$riga[3];$chiusa=$riga[4];
+#	while(list() = mysql_fetch_row($res)) { 
 		if (($chiusa==0) OR ($perms>32)) {
 			if (($idgen==$id_cons_gen or !$id_cons_gen)) {
@@ -143,8 +125,9 @@
 	if ($perms==256) // il superuser puo' scegliere il comune su cui lavorare
 	{
-		$rescomu= mysql_query("$sqlcomu",$dbi);
+		$row=elenco_comuni();
 		echo "<select name=\"id_comune\" onChange=\"top.location.href=this.form.pag_cons.value+$id_cons_gen+'&amp;id_comune='+this.form.id_comune.options[this.form.id_comune.selectedIndex].value;return false\"><option value=\"\">";
-		while (list($id,$descrizione)=mysql_fetch_row($rescomu))
+		foreach($row as $riga)
 		{
+		$id=$riga[0];$descrizione=$riga[1];
 		$sel=($id == $id_comune) ? "selected":"";
 		echo "<option value=\"$id\" $sel>$descrizione";
@@ -292,5 +275,5 @@
 
 	//echo "<hr /><a href=\"../client/modules.php\" target=\"_blank\">$bullet Guarda il sito</a><br /><hr />";
-	echo "<a href=\"admin.php?op=logout\">$bullet "._ESCI."</a>";
+	echo "<a href=\"admin.php?op=logout\">$bullet "._ESCI.$_SESSION['aid']."</a>";
 	echo "</td></tr></table>";
 	// continua la tabella su ele.voti con le sezioni
