Index: trunk/admin/admin.php
===================================================================
--- trunk/admin/admin.php	(revision 405)
+++ trunk/admin/admin.php	(revision 406)
@@ -340,6 +340,6 @@
 if (isset($_GET['id_cons_gen'])) {$id_cons_gen=intval($_GET['id_cons_gen']);}
 else {
-	$oggi=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-3,date("Y")));
-	$sql="select t1.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_comune=$id_comune and t1.data_fine>'$oggi' and t2.id_cons in (select id_cons from ".$prefix."_ele_operatori where aid='$aid' and permessi>0) limit 0,1"; # TEST: and id_sez>0 
+#	$oggi=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-3,date("Y")));
+	$sql="select t1.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_comune=$id_comune and date_add(t1.data_fine, interval 3 day)>CURDATE() and t2.id_cons in (select id_cons from ".$prefix."_ele_operatori where aid='$aid' and permessi>0) limit 0,1"; # TEST: and id_sez>0 
 	$rese = $dbi->prepare("$sql");
 	$rese->execute();
@@ -370,6 +370,6 @@
 /* Login Function                                        */
 /*********************************************************/
-function ChiSei($id_cons_gen){
-global $dbi, $msglogout;
+function ChiSei($idcg){
+global $dbi, $msglogout, $id_cons_gen;
 
 $aid=$_SESSION['aid'];
@@ -377,5 +377,5 @@
 $pwd=$_SESSION['pwd'];
 $id_comune=$_SESSION['id_comune'];
-
+#echo "prima: $idcg - dopo: $id_cons_gen<br>";
 $perms=0;
 $sql="select adminsuper, admincomune, adminop  from ".$prefix."_authors where aid='$aid' and pwd='$pwd' and (id_comune='$id_comune' or id_comune=0)";
@@ -394,14 +394,16 @@
 	elseif($oper) {$msglogout=1; return 0;} # id_cons='$id_cons' and 
 	else {
-		$oggi=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-3,date("Y")));
-		$sql="select t1.id_cons from ".$prefix."_ele_cons_comune as t1, ".$prefix."_ele_consultazione as t2 where t1.id_cons_gen=t2.id_cons_gen and t1.id_cons_gen='$id_cons_gen' and t1.chiusa='0' and t1.id_comune='$id_comune' and t2.data_fine>$oggi";
+#		$oggi=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-3,date("Y")));
+		$sql="select t1.id_cons, t1.id_cons_gen from ".$prefix."_ele_cons_comune as t1, ".$prefix."_ele_consultazione as t2 where t1.id_cons_gen=t2.id_cons_gen and t1.chiusa='0' and t1.id_comune='$id_comune' and date_add(t2.data_fine, interval 3 day)>CURDATE()";
 		$sth = $dbi->prepare("$sql");
-		$sth->execute();	#die("TEST: $sql");	
-		if(!$sth->rowCount()) {$msglogout=1; $perms=0; return $perms;}
-		list($id_cons) = $sth->fetch(PDO::FETCH_NUM);
+		$sth->execute();	
+		if(!$sth->rowCount()) { $msglogout=1; $perms=0; return $perms;}
+		list($id_cons,$idcg) = $sth->fetch(PDO::FETCH_NUM);           
+		if (!$id_cons_gen) $id_cons_gen=$idcg; 
 		$sql="select permessi from ".$prefix."_ele_operatori where id_cons='$id_cons' and aid='$aid'";
 		$sth = $dbi->prepare("$sql");
-		$sth->execute();	#die("TEST: $sql");	
+		$sth->execute();		
 		list($perms) = $sth->fetch(PDO::FETCH_NUM);
+		return $perms;
 	}
 }
@@ -416,5 +418,5 @@
 
 function login() {
-    global $param,$prefix,$dbi,$multicomune,$siteistat,$language,$tema, $id_cons_gen, $perms, $msglogout;
+    global $param,$prefix,$dbi,$multicomune,$siteistat,$language,$tema, $perms, $msglogout;#, $id_cons_gen
     if (isset($param['id_comune'])) $id_comune=intval($param['id_comune']);
     if (!isset($id_comune)) $id_comune=0;
@@ -433,5 +435,4 @@
     include ("header.php");
     echo "<div align=\"middle\"><font class=\"title\"><b>"._GESTIONE."</b></font></center>";
-    echo "<br>";  # method=\"post\" 
 	if ($msglogout==1) echo "<h1 style=\"color:red;\">Utente non autorizzato</h1><br>";
 	elseif ($msglogout==2) echo "<h1 style=\"color:red;\">Nome Utente non presente in archivio</h1><br>";
@@ -506,7 +507,7 @@
 #include("TEST tema: $tema--");
 #include("modules/Elezioni/language/lang-".$_SESSION['lang'].".php");
-
+#die( "$sql <br> TEST id_cons_gen:$id_cons_gen:".$_SESSION['id_cons_gen']);
 if(isset($id_cons_gen) and isset($id_comune)){
-	if(!isset($id_cons)){
+	if(!isset($id_cons)){ 
 #		$sql = "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'";
 		$sql = "SELECT id_cons from ".$prefix."_ele_comuni where id_comune='$id_comune'";
@@ -531,17 +532,17 @@
 			die();
 		}
-		list($id_sez) = $resmod->fetch(PDO::FETCH_NUM); #die("qui:$id_sez:$sql");
-		if($id_sez) { 
-			$oggi=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-3,date("Y")));
-			$sql="select t1.id_cons_gen,t1.descrizione,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_comune=$id_comune and t1.data_fine>'$oggi' and t2.id_cons in (select id_cons from ".$prefix."_ele_operatori where aid='$aid' and id_sez>0 and permessi>0)";
+		list($id_sez) = $resmod->fetch(PDO::FETCH_NUM); 
+		if($id_sez) {
+			$sql="select t1.id_cons_gen,t1.descrizione,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_comune=$id_comune and date_add(t1.data_fine, interval 3 day)>CURDATE() and t2.id_cons in (select id_cons from ".$prefix."_ele_operatori where aid='$aid' and id_sez>0 and permessi>0)";
 			$resmod = $dbi->prepare("$sql");
 			$resmod->execute();
 			if ($resmod->rowCount()>0) {
-				$tema='Futura2'; #die( "TEST id_cons:$id_cons:".$_SESSION['aid']);
+				list($id_cons_gen, $desc,$id_cons)=$resmod->fetch(PDO::FETCH_NUM);
+				$tema='Futura2'; 
 				$_SESSION['tema']=$tema;
 			} #else {die("TEST: $sql"); logout();}
 		}
-	}
-$perms=ChiSei($id_cons_gen); #die("qui".$_SESSION['aid']);
+	} 
+$perms=ChiSei($id_cons_gen); 
 if($perms==0) {logout();} 
 }
@@ -551,5 +552,5 @@
 //if (isset($param['op'])) $op=$param['op']; else $op='ele';
 #
-#die("TEST: qui $aid $id_cons $id_sez ".$_SESSION['aid']);
+#die("TEST: qui2 op:$op - $aid $id_cons $id_sez ".$_SESSION['aid']);
 
 if (isset($_SESSION['aid']) AND $_SESSION['remote']==$_SERVER['REMOTE_ADDR']) {
Index: trunk/admin/modules/Elezioni/query.sql
===================================================================
--- trunk/admin/modules/Elezioni/query.sql	(revision 405)
+++ trunk/admin/modules/Elezioni/query.sql	(revision 406)
@@ -1,3 +1,3 @@
-<?php
+ <?php
 
 if (!defined('ADMIN_FILE')) {
@@ -66,5 +66,6 @@
 	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 ";
+		$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 date_add(t1.data_fine, interval 3 day)>CURDATE() and t3.aid='$aid' order by t1.data_fine desc limit 0,1 "; 
+
 }
 	$sth = $dbi->prepare("$sql");
@@ -96,9 +97,13 @@
 {
 global $perms,$dbi,$prefix,$currentlang,$aid,$id_comune;
-	if ($perms<128) { 
-		$sql="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 t1.permessi>0 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";
+
+	if ($perms<64) {
+		$sql="select t2.id_cons,t1.descrizione,t4.genere,t1.id_cons_gen,t2.chiusa from ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2, ".$prefix."_ele_tipo as t4 where t1.id_cons_gen=t2.id_cons_gen and t2.id_comune=$id_comune and t1.tipo_cons=t4.tipo_cons and date_add(t1.data_fine, interval 3 day)>CURDATE() and t2.id_cons in (select id_cons from ".$prefix."_ele_operatori where aid='$aid' and permessi>0)";
+	}
+	elseif ($perms<128) { 
+		$sql="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 t1.permessi>0 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 order by t2.data_inizio desc";
 	}else{
 		$sql="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";
-	}
+	} #die("$sql");
 	$sth = $dbi->prepare("$sql");
 	$sth->execute();	
Index: trunk/admin/versione.php
===================================================================
--- trunk/admin/versione.php	(revision 405)
+++ trunk/admin/versione.php	(revision 406)
@@ -1,5 +1,5 @@
 <?php
 
-$versione = "3.0 rev 405";
+$versione = "3.0 rev 406";
 $version_number = $versione;
 $datarel = "28 febbraio 2024";
