Index: trunk/admin/modules/Elezioni/salva_liste.php
===================================================================
--- trunk/admin/modules/Elezioni/salva_liste.php	(revision 259)
+++ trunk/admin/modules/Elezioni/salva_liste.php	(revision 260)
@@ -25,26 +25,26 @@
 
 if (isset($_GET['genere'])) $genere=intval($_GET['genere']); else $genere='';
-if (isset($_GET['id_cons_gen'])) $id_cons_gen=intval($_GET['id_cons_gen']); else $id_cons_gen='';
-if (isset($_GET['id_cons'])) $id_cons=intval($_GET['id_cons']); else $id_cons='';
-if (isset($_GET['op'])) $op=intval($_GET['op']); else $op='';
-if (isset($_GET['id_circ'])) $id_circ=intval($_GET['id_circ']); else $id_circ='';
-if (isset($_GET['id_sez'])) $id_sez=intval($_GET['id_sez']); else $id_sez='';
-if (isset($_GET['id_sede'])) $id_sede=intval($_GET['id_sede']); else $id_sede='';
-if (isset($_GET['id_lista'])) $id_lista=intval($_GET['id_lista']); else $id_lista='';
-if (isset($_GET['valista'])) $valista=intval($_GET['valista']); else $valista='';
-if (isset($_GET['sg'])) $sg=intval($_GET['sg']); else $sg='';
-if (isset($_GET['votinulli'])) $votinulli=intval($_GET['votinulli']); else $votinulli='';
-if (isset($_GET['contestati'])) $contestati=intval($_GET['contestati']); else $contestati='';
-if (isset($_GET['update'])) $update=intval($_GET['update']); else $update='';
-if (isset($_GET['pwd3'])) $pwd3=intval($_GET['pwd3']); else $pwd3='';
-if (isset($_GET['do'])) $do=intval($_GET['do']); else $do='';
+if (isset($_GET['id_cons_gen'])) $id_cons_gen=intval($_GET['id_cons_gen']); else $id_cons_gen='0';
+if (isset($_GET['id_cons'])) $id_cons=intval($_GET['id_cons']); else $id_cons='0';
+if (isset($_GET['op'])) $op=intval($_GET['op']); else $op='0';
+if (isset($_GET['id_circ'])) $id_circ=intval($_GET['id_circ']); else $id_circ='0';
+if (isset($_GET['id_sez'])) $id_sez=intval($_GET['id_sez']); else $id_sez='0';
+if (isset($_GET['id_sede'])) $id_sede=intval($_GET['id_sede']); else $id_sede='0';
+if (isset($_GET['id_lista'])) $id_lista=intval($_GET['id_lista']); else $id_lista='0';
+if (isset($_GET['valista'])) $valista=intval($_GET['valista']); else $valista='0';
+if (isset($_GET['sg'])) $sg=intval($_GET['sg']); else $sg='0';
+if (isset($_GET['votinulli'])) $votinulli=intval($_GET['votinulli']); else $votinulli='0';
+if (isset($_GET['contestati'])) $contestati=intval($_GET['contestati']); else $contestati='0';
+if (isset($_GET['update'])) $update=intval($_GET['update']); else $update='0';
+if (isset($_GET['pwd3'])) $pwd3=intval($_GET['pwd3']); else $pwd3='0';
+if (isset($_GET['do'])) $do=intval($_GET['do']); else $do='0';
 if (isset($_GET['valista'])) $validi=intval($_GET['valista']); else $validi='0';
-if (isset($_GET['nulli'])) get_magic_quotes_gpc() ? $nulli=$_GET['nulli']:$nulli=intval($_GET['nulli']); else $nulli='';
-if (isset($_GET['bianchi'])) get_magic_quotes_gpc() ? $bianchi=$_GET['bianchi']:$bianchi=addslashes($_GET['bianchi']); else $bianchi='';
-if (isset($_GET['contestati'])) get_magic_quotes_gpc() ? $contestati=$_GET['contestati']:$contestati=addslashes($_GET['contestati']); else $contestati='';
-if (isset($_GET['votinulli'])) get_magic_quotes_gpc() ? $votinulli=$_GET['votinulli']:$votinulli=addslashes($_GET['votinulli']); else $votinulli='01-01-1900';
-if (isset($_GET['id_comune'])) $id_comune=intval($_GET['id_comune']); else $id_comune='';
-if (isset($_GET['ops'])) $ops=intval($_GET['ops']); else $ops='';
-if (isset($_GET['delete'])) $delete=intval($_GET['delete']); else $delete='';
+if (isset($_GET['nulli'])) $nulli=intval($_GET['nulli']); else $nulli='0';
+if (isset($_GET['bianchi'])) $bianchi=addslashes($_GET['bianchi']); else $bianchi='0';
+if (isset($_GET['contestati'])) $contestati=addslashes($_GET['contestati']); else $contestati='0';
+if (isset($_GET['votinulli'])) $votinulli=addslashes($_GET['votinulli']); else $votinulli='0';
+if (isset($_GET['id_comune'])) $id_comune=intval($_GET['id_comune']); else $id_comune='0';
+if (isset($_GET['ops'])) $ops=intval($_GET['ops']); else $ops='3';
+if (isset($_GET['delete'])) $delete=intval($_GET['delete']); else $delete='0';
 if (isset($_GET['circo'])) get_magic_quotes_gpc() ? $circo=$_GET['circo']:$circo=addslashes($_GET['circo']); else $circo='';
 
@@ -82,8 +82,14 @@
 # if($id_lista){
 	if($pwd3==1) {
+		$sql="delete from ".$prefix."_ele_voti_candidati where id_cons='$id_cons' and id_sez='$id_sez'";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+		$sql="delete from ".$prefix."_ele_controlli where tipo='candidato' and id_sez='$id_sez' ";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
 		$sql="delete from ".$prefix."_ele_voti_lista where id_cons='$id_cons' and id_sez='$id_sez'";
 		$res = $dbi->prepare("$sql");
 		$res->execute();
-		$sql="delete from ".$prefix."_ele_voti_candidati where id_cons='$id_cons' and id_sez='$id_sez'";
+		$sql="delete from ".$prefix."_ele_controlli where tipo='lista' and id_sez='$id_sez' ";
 		$res = $dbi->prepare("$sql");
 		$res->execute();
@@ -91,4 +97,5 @@
 		$res = $dbi->prepare("$sql");
 		$res->execute();
+		
 	}elseif($id_lista){
 		$sql="SELECT disgiunto FROM ".$prefix."_ele_cons_comune where id_cons='$id_cons' ";
@@ -155,10 +162,6 @@
 	
 function controllo_votil($id_cons,$id_sez,$id_lista){
-	global $prefix,$dbi,$id_sede,$id_cons_gen;
+	global $prefix,$dbi,$id_sede,$id_cons_gen,$validi;
 		##############################
-	$sql="select * from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'";
-	$resc = $dbi->prepare("$sql");
-	$resc->execute();
-	$conta=$resc->rowCount();
 	$err=0; $err2=0;
 	if($id_lista){
@@ -185,15 +188,28 @@
 		$resref = $dbi->prepare("$sql");
 		$resref->execute();
+		$totlis=0;
+		$totgru=0;
+		$totsg=0;
+		$totsl=0;
+        $sql="SELECT validi,validi_lista,contestati_lista,voti_nulli_lista,solo_lista FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez'";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+    	list($votiv,$validil,$contestatil,$nullil,$solol) = $res->fetch(PDO::FETCH_NUM);
 		while (list($idg,$votig,$svg)=$resref->fetch(PDO::FETCH_NUM)) {
 			$sql="SELECT sum(voti), sum(solo_lista) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez' and id_lista in (select id_lista from ".$prefix."_ele_lista where id_gruppo='$idg')";
 			$res2 = $dbi->prepare("$sql");
 			$res2->execute();
+			$totgru+=$votig;
+			$totsg+=$svg;
 			if($res2->rowCount()){
-				list($votil,$svl)=$res2->fetch(PDO::FETCH_NUM); 
-				if(($votig+$svl)!=($votil+$svg)) 
-					$err=1;include("if(($votig+$svl)!=($votil+$svg))");
+				list($votil,$svl)=$res2->fetch(PDO::FETCH_NUM);
+				$totlis+=$votil;
+				$totsl+=$svl;
+				if(($votig+$svl)<($votil+$svg))
+					$err=1; 
 			}
-		}	
-
+			
+		}
+		if ($validil+$contestatil+$nullil+$solol+$totsg!=$votiv and $validil+$contestatil+$nullil+$solol>0) $err=1;
 	}
 
