Index: trunk/admin/modules/Elezioni/salva_ref.php
===================================================================
--- trunk/admin/modules/Elezioni/salva_ref.php	(revision 366)
+++ trunk/admin/modules/Elezioni/salva_ref.php	(revision 407)
@@ -43,63 +43,60 @@
 
 global $prefix,$id_parz,$fileout;
-$sql="select num_gruppo,id_gruppo from ".$prefix."_ele_gruppo where id_cons='$id_cons' ORDER BY num_gruppo  ";
-$resultg = $dbi->prepare("$sql");
-$resultg->execute();
+$sql="SELECT chiusa FROM ".$prefix."_ele_cons_comune where id_cons='$id_cons' ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+list($chiusa)=$res->fetch(PDO::FETCH_NUM);
+if(!$chiusa){
+	$sql="select num_gruppo,id_gruppo from ".$prefix."_ele_gruppo where id_cons='$id_cons' ORDER BY num_gruppo  ";
+	$resultg = $dbi->prepare("$sql");
+	$resultg->execute();
 
-if (!isset($fileout)) $fileout='';
+	if (!isset($fileout)) $fileout='';
 
-if ($fileout) while (!$fp = fopen($fileout,"a"));
+	if ($fileout) while (!$fp = fopen($fileout,"a"));
 
-##################
-	if($do==1) {
-		$sql="delete from ".$prefix."_ele_voti_ref where id_cons='$id_cons' and id_sez=$id_sez";
-		$res = $dbi->prepare("$sql");
-		$res->execute();
-		$sql="delete from ".$prefix."_ele_controlli where id_cons='$id_cons' and id_sez=$id_sez";
-		$res = $dbi->prepare("$sql");
-		$res->execute();
-	}else{
-		while(list($i,$idgruppo)=$resultg->fetch(PDO::FETCH_BOTH)) {
-			$gruv="id_gruppo$i";$siv="si$i";$nov="no$i";$valv="val$i";$biav="bia$i";$conv="con$i";$nulv="nul$i";
-			if($_GET[$siv]=='' and $_GET[$nov]=='' and $_GET[$biav]=='' and $_GET[$conv]=='' and $_GET[$nulv]=='') continue;
-			if (isset($_GET[$gruv])) $id_gruppo[$i]=intval($_GET[$gruv]); else $id_gruppo[$i]='0';
-			if (isset($_GET[$siv])) $si[$i]=intval($_GET[$siv]); else $si[$i]='0';
-			if (isset($_GET[$nov])) $no[$i]=intval($_GET[$nov]); else $no[$i]='0';
-			if (isset($_GET[$valv])) $val[$i]=intval($_GET[$valv]); else $val[$i]='0';
-			if (isset($_GET[$biav])) $bia[$i]=intval($_GET[$biav]); else $bia[$i]='0';
-			if (isset($_GET[$conv])) $con[$i]=intval($_GET[$conv]); else $con[$i]='0';
-			if (isset($_GET[$nulv])) $nul[$i]=intval($_GET[$nulv]); else $nul[$i]='0';
+	##################
+		if($do==1) {
+			$sql="delete from ".$prefix."_ele_voti_ref where id_cons='$id_cons' and id_sez=$id_sez";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+			$sql="delete from ".$prefix."_ele_controlli where id_cons='$id_cons' and id_sez=$id_sez";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+		}else{
+			while(list($i,$idgruppo)=$resultg->fetch(PDO::FETCH_BOTH)) {
+				$gruv="id_gruppo$i";$siv="si$i";$nov="no$i";$valv="val$i";$biav="bia$i";$conv="con$i";$nulv="nul$i";
+				if($_GET[$siv]=='' and $_GET[$nov]=='' and $_GET[$biav]=='' and $_GET[$conv]=='' and $_GET[$nulv]=='') continue;
+				if (isset($_GET[$gruv])) $id_gruppo[$i]=intval($_GET[$gruv]); else $id_gruppo[$i]='0';
+				if (isset($_GET[$siv])) $si[$i]=intval($_GET[$siv]); else $si[$i]='0';
+				if (isset($_GET[$nov])) $no[$i]=intval($_GET[$nov]); else $no[$i]='0';
+				if (isset($_GET[$valv])) $val[$i]=intval($_GET[$valv]); else $val[$i]='0';
+				if (isset($_GET[$biav])) $bia[$i]=intval($_GET[$biav]); else $bia[$i]='0';
+				if (isset($_GET[$conv])) $con[$i]=intval($_GET[$conv]); else $con[$i]='0';
+				if (isset($_GET[$nulv])) $nul[$i]=intval($_GET[$nulv]); else $nul[$i]='0';
 
-			$sql="select num_gruppo from ".$prefix."_ele_voti_ref where id_gruppo='$idgruppo'  and id_sez=$id_sez";
-			$result = $dbi->prepare("$sql");
-			$result->execute();
-			if($result->rowCount()) {
-				$sql="update  ".$prefix."_ele_voti_ref set si='".$si[$i]."',no='".$no[$i]."',validi='".$val[$i]."',bianchi='".$bia[$i]."',contestati='".$con[$i]."',nulli='".$nul[$i]."' where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='".$id_gruppo[$i]."'";
-				$res = $dbi->prepare("$sql");
-				$res->execute();
-			}elseif($val[$i]!=''){
-				$sql="insert into  ".$prefix."_ele_voti_ref values('$id_cons','$idgruppo','$id_sez','$i','".$si[$i]."','".$no[$i]."','".$val[$i]."','".$nul[$i]."','".$bia[$i]."','".$con[$i]."')";  
-				$res = $dbi->prepare("$sql");
-				$res->execute();
-			
+				$sql="select num_gruppo from ".$prefix."_ele_voti_ref where id_gruppo='$idgruppo'  and id_sez=$id_sez";
+				$result = $dbi->prepare("$sql");
+				$result->execute();
+				if($result->rowCount()) {
+					$sql="update  ".$prefix."_ele_voti_ref set si='".$si[$i]."',no='".$no[$i]."',validi='".$val[$i]."',bianchi='".$bia[$i]."',contestati='".$con[$i]."',nulli='".$nul[$i]."' where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='".$id_gruppo[$i]."'";
+					$res = $dbi->prepare("$sql");
+					$res->execute();
+				}elseif($val[$i]!=''){
+					$sql="insert into  ".$prefix."_ele_voti_ref values('$id_cons','$idgruppo','$id_sez','$i','".$si[$i]."','".$no[$i]."','".$val[$i]."','".$nul[$i]."','".$bia[$i]."','".$con[$i]."')";  
+					$res = $dbi->prepare("$sql");
+					$res->execute();
+				
+				}
 			}
+			include("ele_controlli.php");
+			controllo_votir($id_cons,$id_sez);
 		}
-		include("ele_controlli.php");
-		controllo_votir($id_cons,$id_sez);
-	}
-
-
-
-include("ele_colora_sez.php");
-if ($fileout) fclose($fp);
+	include("ele_colora_sez.php");
+	if ($fileout) fclose($fp);
+}
 $BASE=substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['REQUEST_URI'], "/")-16);
 Header("Location: ".$BASE."admin.php?op=voti&id_cons_gen=$id_cons_gen&id_circ=$id_circ&id_sede=$id_sede&id_sez=$id_sez&do=spoglio&ops=$ops");
 #################################
 
-
-
-
-	
-
-
 ?>
