Index: trunk/admin/modules/Elezioni/ele_consultazioni.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_consultazioni.php	(revision 344)
+++ trunk/admin/modules/Elezioni/ele_consultazioni.php	(revision 358)
@@ -83,4 +83,36 @@
 	echo "} \n";
 	echo "</script>\n";
+	
+	##############  onsubmit=\"check_aid()\"
+/*	echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n"
+	."//-->\n";
+	echo "function check_aid() {
+          var elem=document.getElementById('descrcons'); var num=elem.length; alert (\"Please fill in your first name.\".num);
+    for (i=0; i < elem.length; i++) { var sel=elem[i].value;
+        if (elem[i].value == document.consultazione.descr_cons2.value) {
+            document.consultazione.descr_cons2.style.backgroundColor = \"#ccc\";
+               document.consultazione.descr_cons2.focus();
+               return false;
+        }
+    }
+	return false;
+	}
+	
+	    function hide(){
+          var elem = document.getElementById('descrcons');
+          elem.style.display = 'none';
+        }";
+
+	echo "</script>\n"; */
+###################
+	$sql="select descrizione from ".$prefix."_ele_consultazione";
+	$sth = $dbi->prepare("$sql"); 
+	$sth->execute();	
+	$row = $sth->fetch(PDO::FETCH_NUM);
+	echo "<select id=\"descrcons\" style=\"visibility:hidden;\">";
+	while(list($val)=$sth->fetch(PDO::FETCH_NUM)) {
+		echo "<option value=\"$val\">$val</option>";
+	}
+	echo "</select>";
 #########################
 	if (isset($help)) include("language/$language/ele_consultazioni.html");
@@ -127,9 +159,12 @@
 		echo "<option value=\"$dfa1\" selected>$dfa1</option>"; anno();
 		echo "</td></tr><tr>";
-		$resdel = daticonscom();
-		if(count($resdel)==0)
-			echo "<td><fieldset><legend>"._SPUNTALABEL1."</legend><label id=\"prov\">"._VIASPUNTAELIMINA." <input type=\"checkbox\" id=\"pwd3\"name=\"pwd3\" value=\"\" onclick=\"del_cons()\"></label></fieldset></td>";
+		$sql="SELECT t1.tipo_cons,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'";
+		$sth = $dbi->prepare("$sql");
+		$sth->execute();
+		$resdel=$sth->rowCount();	
+		if($resdel==0)
+			echo "<td colspan=\"2\"><fieldset><legend>"._SPUNTALABEL1."</legend><label id=\"prov\">"._VIASPUNTAELIMINA." <input type=\"checkbox\" id=\"pwd3\"name=\"pwd3\" value=\"\" onclick=\"del_cons()\" size=\"200px\"></label></fieldset></td>";
 		else echo "<td></td>";
-		echo "<td><input type=\"submit\" id=\"update\" name=\"update\" value=\""._MODIFY."\">"
+		echo "</tr><tr><td><input type=\"submit\" id=\"update\" name=\"update\" value=\""._MODIFY."\">"
 		."</td></tr></table></form>";
 	} else {
@@ -249,7 +284,13 @@
 				$id_consulta=$id_cons_gen;
 				$sql="insert into ".$prefix."_ele_consultazione (descrizione,data_inizio,data_fine,tipo_cons) values ('$descr_cons2','$data_inizio','$data_fine','$tipocons')";
-				$sth = $dbi->prepare("$sql");
-				$sth->execute();	
-
+				try {
+					$sth = $dbi->prepare("$sql");
+					$sth->execute();
+				}catch(PDOException $e) {
+					if ($e->getCode() == 23000) 
+						echo "<h2 style=\"color:red;\">     Inserimento fallito: Esiste giÃ  una consultazione con il nome \"$descr_cons2\"</h2";
+					else
+						echo "<h2 style=\"color:red;\">     Inserimento fallito: ". $e->getMessage()."</h2";
+				}	
 			} else {
 		        OpenTable();
@@ -262,6 +303,13 @@
 			$data_fine="$dfa-$dfm-$dfg";
 			$sql="update  ".$prefix."_ele_consultazione set  descrizione='$descr_cons2',data_inizio='$data_inizio',data_fine='$data_fine' WHERE id_cons_gen='$id_cons_gen'";
-			$sth = $dbi->prepare("$sql");
-			$sth->execute();	
+			try {
+				$sth = $dbi->prepare("$sql");
+				$sth->execute();
+			}catch(PDOException $e) {
+				if ($e->getCode() == 23000) 
+					echo "<h2 style=\"color:red;\">     Inserimento fallito: Esiste giÃ  una consultazione con il nome \"$descr_cons2\"</h2";
+				else
+					echo "<h2 style=\"color:red;\">     Inserimento fallito: ". $e->getMessage()."</h2";
+			}	
 			if (!$sth->rowCount()) return;
 			Header("Location: admin.php?op=consultazione&id_cons_gen=$id_cons_gen");
