Index: trunk/admin/admin.php
===================================================================
--- trunk/admin/admin.php	(revision 416)
+++ trunk/admin/admin.php	(revision 424)
@@ -39,7 +39,5 @@
     $_COOKIE = $HTTP_COOKIE_VARS;
   }
-  if(isset($HTTP_SESSION_VARS)) {
-    $_SESSION = $HTTP_SESSION_VARS;
-  }
+
 }
 
@@ -120,7 +118,12 @@
 #session_start();//MODIFICHE PER GESTIONE SESSIONI
   // gestione sessione
+if (!isset($_SESSION))
+	{
+	session_start();
+	}else session_regenerate_id();
 $a = session_id();
 if(empty($a)) session_start();
 #echo "SID: ".SID."<br>session_id(): ".session_id()."<br>COOKIE: ".$_COOKIE["PHPSESSID"];
+
 
 if (file_exists("config.php")){ 
@@ -134,5 +137,5 @@
     die("<html><body><div style=\"text-align:center\"><br /><br /><img src=\"modules/Elezioni/images/logo.jpg\" alt=\"Eleonline\" title=\"Eleonline\"><br /><br /><strong>Sembra che <a href='http://www.eleonline.it' title='Eleonline'>Eleonline</a> non sia stato ancora installato.<br /><br />Puoi procedere <a href='../install/index.php'>cliccando qui</a> per iniziare l'installazione</strong></div></body></html>");
 }
-
+require_once('variabili.php');
 $dsn = "mysql:host=$dbhost";
 $opt = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false);
@@ -266,5 +269,4 @@
 				$_SESSION['bgcolor2']='#c5c5c5'; 
 				if (!isset($op)) $op='consultazione';
-    				session_regenerate_id();
 			} 
 		}
@@ -326,5 +328,5 @@
 }
 if(!isset($_SESSION['BASE'])) $_SESSION['BASE']=substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['REQUEST_URI'], "/")-16);
-if(!isset($language)) $language=$_SESSION['lang'];
+if(!isset($language) and isset($_SESSION['lang'])) $language=$_SESSION['lang']; else $language='it';
 if (! isset($_SESSION['lang'])) $_SESSION['lang']=$language;
 $currentlang=strlen($_SESSION['lang'])==2 ? $_SESSION['lang']: $language;
@@ -341,5 +343,5 @@
 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 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 
+	$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 $giorniaut 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();
@@ -371,5 +373,5 @@
 /*********************************************************/
 function ChiSei($idcg){
-global $dbi, $msglogout, $id_cons_gen;
+global $dbi, $msglogout, $id_cons_gen,$giorniaut;
 
 $aid=$_SESSION['aid'];
@@ -383,8 +385,13 @@
 $sth->execute();	
 $row = $sth->fetch(PDO::FETCH_BOTH);	
-
+if($row){
 $adminsuper=$row[0];
 $admincomune=$row[1];
-$oper=$row[2]; 
+$oper=$row[2];
+}else{
+$adminsuper=0;
+$admincomune=0;
+$oper=1;
+}	
 	if ($adminsuper==1)
 		return 256;
@@ -395,5 +402,5 @@
 	else {
 #		$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()";
+		$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 $giorniaut day)>CURDATE()";
 		$sth = $dbi->prepare("$sql");
 		$sth->execute();	
@@ -486,4 +493,8 @@
 
 global $siteistat,$perms,$msglogout; 
+if (!isset($_SESSION))
+  {
+    session_start();
+  }
 $language=$_SESSION['lang'];
 $ref="Location: admin.php?"; 
@@ -498,7 +509,7 @@
 $ref=$ref."&language=$language"; 
 $ref.="&msglogout=$msglogout";
-$_SESSION=array();  
-session_unset(); 
-session_destroy(); 
+#$_SESSION=array();
+if (session_status() == PHP_SESSION_ACTIVE)  
+	session_destroy(); 
 session_cache_expire (0); 
 Header($ref); 
@@ -508,5 +519,5 @@
 #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_gen) and isset($id_comune)){ 
 	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'";
@@ -520,5 +531,5 @@
 	} 
 	if(isset($id_cons)) {
-		$sql="SELECT id_sez FROM ".$prefix."_ele_operatori where id_sez>0 and aid='$aid' and id_comune=$id_comune";
+		$sql="SELECT id_sez FROM ".$prefix."_ele_operatori where id_sez>0 and aid='$aid' and id_comune=$id_comune and id_cons=$id_cons";
 		try {
 			$resmod = $dbi->prepare("$sql");
@@ -544,5 +555,5 @@
 		}
 	} 
-$perms=ChiSei($id_cons_gen); 
+$perms=ChiSei($id_cons_gen);
 if($perms==0) {logout();} 
 }
@@ -723,4 +734,7 @@
     include("modules/Elezioni/ele_riepilogovoti.php");
     break;
+case "aggcons":
+    include("modules/Elezioni/ele_restorebackup.php");
+    break;
 case "logout":
 	logout();
