source: trunk/admin/modules/Elezioni/ele_sezione.php@ 429

Last change on this file since 429 was 377, checked in by roby, 2 years ago

DB

  • modifica tabella sezioni con inserimento constraint per controllo duplicati nel numero di sezione

ADMIN

  • modifica della funzione di connessione al db nel file admin.php per compatibilità con php5
  • modifica della funzione di inserimento delle sezioni con inserimento avvisi per errori di inserimento
  • modificata la funzione di aggiornamento del DB ( admin/aggiornadb.php ) per gestire l'aggiornamento degli indici PRIMARY, aggiunto il controllo della tabella soraldo_ele_liste e il nuovo contraint per la tabella soraldo_ele_sezioni
File size: 11.7 KB
Line 
1<?php
2/************************************************************************/
3/* Eleonline - Raccolta e diffusione dei dati elettorali */
4/* by Roberto Gigli & Luciano Apolito */
5/* http://www.eleonline.it */
6/* info@eleonline.it luciano@aniene.net rgigli@libero.it */
7/************************************************************************/
8/* Modulo sezioni */
9/* Amministrazione */
10/************************************************************************/
11if (!defined('ADMIN_FILE')) {
12 die ("You can't access this file directly...");
13}
14$id_comune=$_SESSION['id_comune'];
15$id_cons_gen=$_GET['id_cons_gen'];
16$perms=ChiSei($id_cons_gen);
17if ($perms<32 or !$id_cons_gen) die("Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
18
19
20$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' and t2.id_comune='$id_comune'";
21$res = $dbi->prepare("$sql");
22$res->execute();
23list($tipo_cons,$id_cons) = $res->fetch(PDO::FETCH_NUM);
24if (isset($param['do'])) $do=addslashes($param['do']); else $do='';
25if (isset($param['mex'])) $mex=addslashes($param['mex']); else $mex='';
26if (isset($param['id_sede'])) $id_sede=intval($param['id_sede']); else $id_sede='';
27if (isset($param['min'])) $min=intval($param['min']); else $min=0;
28if (isset($param['ok'])) $ok=intval($param['ok']); else $ok='';
29if (isset($param['id_sez'])) $id_sez=intval($param['id_sez']); else $id_sez='';
30if (isset($param['aut_m'])) $aut_m=intval($param['aut_m']); else $aut_m='';
31if (isset($param['aut_f'])) $aut_f=intval($param['aut_f']); else $aut_f='';
32if (isset($param['maschi'])) $maschi=intval($param['maschi']); else $maschi='';
33if (isset($param['femmine'])) $femmine=intval($param['femmine']); else $femmine='';
34if (isset($param['id_sez2'])) $id_sez2=intval($param['id_sez2']); else $id_sez2='';
35if (isset($param['num_sez'])) $num_sez=intval($param['num_sez']); else $num_sez='';
36
37include("modules/Elezioni/funzionidata.php");
38include("modules/Elezioni/ele.php");
39// Offset - visualizza il numero di elementi per pagina
40$offset=10;
41$hiddenInfo = "<input type=\"hidden\" name=\"min\" value=\"$min\">";
42
43
44/******************************************************/
45/*Funzione di visualizzazione globale */
46/*****************************************************/
47
48function all() {
49 global $admin, $bgcolor1, $bgcolor2, $prefix, $dbi, $offset, $min, $id_cons,$id_cons_gen,$mex;
50# OpenTable();
51 $y=0;
52 $sql="SELECT * FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' ";
53 $res = $dbi->prepare("$sql");
54 $res->execute();
55 $numsez = $res->rowCount();
56 $sql="SELECT max(num_sez) FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' ";
57 $res = $dbi->prepare("$sql");
58 $res->execute();
59 list($max) = $res->fetch(PDO::FETCH_NUM);
60 if($numsez!=$max) $mex="Sembra che sia stata saltata una sezione, controllate prego";
61 echo "<center><font class=\"title\"><a NAME=riga><b>"._SEZIONE."</b></a></font><br>";
62 if($mex!='')
63 echo "<h2 style=\"background-color:red;color:white;\">$mex</h2>";
64 echo "<br><table border=\"0\" width=\"95%\"><tr>"
65 ."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._NUM."</b></td>"
66 ."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._INDIRIZZO."</b></td>"
67 ."<td bgcolor=\"$bgcolor1\" align=\"center\" ><b>"._MASCHI."</b></td>"
68 ."<td bgcolor=\"$bgcolor1\" align=\"center\" ><b>"._FEMMINE."</b></td>"
69 ."<td bgcolor=\"$bgcolor1\" align=\"center\" ><b>"._TOTS." "._ISCRITTI."</b></td>"
70 ."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._FUNZIONI."</b></td></tr>";
71 echo "<tr align=\"center\"><form name=\"sezi\" action=\"admin.php\">"
72 ."<input type=\"hidden\" name=\"op\" value=\"sezione\">"
73 ."<input type=\"hidden\" name=\"do\" value=\"add\">";
74
75 $nuova= $max+1;
76 $sql="SELECT id_sede FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' and num_sez='$max' ";
77 $res = $dbi->prepare("$sql");
78 $res->execute();
79 list($id_sede_old) = $res->fetch(PDO::FETCH_NUM);
80
81 echo "<td><input type=\"text\" name=\"num_sez\" value=\"$nuova\" size=\"5\"></td>";
82
83 echo "<td><select name=\"id_sede\">";
84 $sql="SELECT id_sede,indirizzo FROM ".$prefix."_ele_sede where id_cons='$id_cons' order by indirizzo";
85 $res = $dbi->prepare("$sql");
86 $res->execute();
87 while(list($id,$indir) = $res->fetch(PDO::FETCH_NUM)) {
88 if ($id == $id_sede_old) {
89 $sel = "selected";
90 } else {
91 $sel = "";
92 }
93 echo "<option value=\"$id\" $sel>$indir";
94 }
95 echo "</select></td>";
96 //*************************************
97
98 echo "<td><input type=\"text\" name=\"maschi\" size=\"4\"></td>";
99
100
101 echo "<td><input type=\"text\" name=\"femmine\" size=\"4\"></td>";
102
103 echo "<td><input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">";
104 echo "<input type=\"hidden\" name=\"min\" value=\"$min\">"
105 ."</td><td><input type=\"submit\" name=\"add\" value=\""._ADD."\"></td></tr>"
106 ."</form>";
107
108
109
110
111
112 $sql="select id_cons, id_sez, id_sede, num_sez, maschi, femmine, autorizzati_m, autorizzati_f from ".$prefix."_ele_sezioni where id_cons='$id_cons' ORDER BY num_sez LIMIT $min,$offset";
113 $result = $dbi->prepare("$sql");
114 $result->execute();
115 while(list($id_cons2,$id_sez,$id_sede,$num_sez, $maschi, $femmine,$aut_m,$aut_f) = $result->fetch(PDO::FETCH_NUM)) {
116 $bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
117 // dati circoscrizione
118 $sql="select indirizzo from ".$prefix."_ele_sede where id_sede='$id_sede'";
119 $result1 = $dbi->prepare("$sql");
120 $result1->execute();
121 list($indir)=$result1->fetch(PDO::FETCH_NUM);
122 $totali=$maschi+$femmine+$aut_m+$aut_f;
123 $y++;
124 echo "<form name=\"sez$y\" action=\"admin.php\">"
125 ."<input type=\"hidden\" name=\"op\" value=\"sezione\">"
126 ."<input type=\"hidden\" name=\"do\" value=\"update\">"
127 ."<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">"
128 ."<input type=\"hidden\" name=\"min\" value=\"$min\">"
129 ."<input type=\"hidden\" name=\"id_sez2\" value=\"$id_sez\">"
130 ."<input type=\"hidden\" name=\"num_sez\" value=\"$num_sez\">";
131
132 echo "<tr bgcolor=\"$bgcolor1\"><td align=\"right\" size=\"90\"><b>$num_sez</b></td>";
133 echo "<td align=\"right\" size=\"120\"><select name=\"id_sede\">";
134 $sql="SELECT id_sede,indirizzo FROM ".$prefix."_ele_sede where id_cons='$id_cons' order by indirizzo";
135 $res = $dbi->prepare("$sql");
136 $res->execute();
137 while(list($id,$indir) = $res->fetch(PDO::FETCH_NUM)) {
138 if ($id == $id_sede) {
139 $sel = "selected";
140 } else {
141 $sel = "";
142 }
143 echo "<option value=\"$id\" $sel>$indir";
144 }
145 echo "</select></td>";
146
147 echo "<td align=\"center\"><b><input type=\"text\" size=\"4\" name=\"maschi\" value=\"$maschi\"></b>";
148 echo "</td><td align=\"center\"><b><input type=\"text\" size=\"4\" name=\"femmine\" value=\"$femmine\"></b>";
149 echo "</td><td align=\"center\"><b>$totali</b>"
150 ."</td><td align=\"center\" nowrap><table><tr><td align=\"center\" width=\"50%\">"
151 ."<input type=\"submit\" name=\"update$y\" value=\""._OK."\">" ;
152 echo "</td><td align=\"center\" nowrap width=\"50%\">"
153 ."[<a href=\"admin.php?op=sezione&amp;do=delete&amp;id_sede=$id_sede&amp;id_sez=$id_sez&amp;id_cons_gen=$id_cons_gen&amp;num_sez=$num_sez&amp;min=$min\">"._DELETE."<img src=\"modules/Elezioni/images/delete.gif\"
154 border=\"0\" align=\"center\"></a>]</td></tr></table>";
155 echo "</td></tr></form>\n";
156 }
157 echo "</table></center>";
158 echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n"
159 ."document.sez2.maschi.focus()\n"
160 ."document.sez2.maschi.select()\n"
161 ."//-->\n"
162 ."</script>\n";
163
164 #'Pagina precedente' e 'Pagina Successiva'
165 echo"<table align=\"center\" width=\"100%\"><tr>";
166 if ($min<$offset and $min!=0) $min=$offset;
167 $prev=$min-$offset;
168
169 if ($prev>=0) {
170 echo "<td colspan=\"5\" align=\"center\" bgcolor=\"$bgcolor1\"><a href=\"admin.php?op=sezione&amp;id_sede=$id_sede&amp;id_sez=$id_sez&amp;id_cons_gen=$id_cons_gen&amp;min=$prev\">";
171 echo "<b>"._PREV_MATCH."</b></a></td>";
172 }
173
174 $next=$min+$offset;
175 if ($next>=($offset-1)) {
176 if($next>=$max) $next = $max;
177 else {
178
179 echo "<td colspan=\"5\" align=\"center\" bgcolor=\"$bgcolor1\"><a href=\"admin.php?op=sezione&amp;id_sede=$id_sede&amp;id_sez=$id_sez&amp;id_cons_gen=$id_cons_gen&amp;min=$next\">";
180 echo "<b>"._NEXT_MATCH."</b></a></td>";
181 }
182 }
183 echo "</tr></table><br>";
184#CloseTable();
185#include("footer.php");
186}
187
188
189
190function sezione($ok, $do,$id_sede,$id_sez, $num_sez, $aut_ma, $aut_fe, $maschi, $femmine, $id_sez2,$min) {
191global $admin, $bgcolor1, $bgcolor2, $prefix, $dbi, $descr_cons, $id_cons,$id_cons_gen;
192$perms=ChiSei($id_cons_gen);
193if ($perms>16) {
194 $aut_m=intval($aut_ma);
195 $aut_f=intval($aut_fe);
196 if ($do == "delete") {
197 if ($ok !="1") {
198 ele();
199 echo "<center><br><br>"._DOMCANCELLA." "._NUM." "._SEZIONE." $num_sez ?<br>";
200 echo "[ <a href=\"admin.php?op=sezione&amp;id_cons_gen=$id_cons_gen&amp;min=$min\">"._NO."</a> ] - [<a href=\"admin.php?op=sezione&amp;do=delete&amp;id_sede=$id_sede&amp;id_sez=$id_sez&amp;id_cons_gen=$id_cons_gen&amp;ok=1&amp;min=$min\">"._YES."</a> ]";
201 include("footer.php");
202 die();
203 }else{
204 $sql="delete from ".$prefix."_ele_voti_candidati where id_sez='$id_sez'";
205 $res = $dbi->prepare("$sql");
206 $res->execute();
207 $sql="delete from ".$prefix."_ele_voti_lista where id_sez='$id_sez'";
208 $res = $dbi->prepare("$sql");
209 $res->execute();
210 $sql="delete from ".$prefix."_ele_voti_gruppo where id_sez='$id_sez'";
211 $res = $dbi->prepare("$sql");
212 $res->execute();
213 $sql="delete from ".$prefix."_ele_voti_ref where id_sez='$id_sez'";
214 $res = $dbi->prepare("$sql");
215 $res->execute();
216 $sql="delete from ".$prefix."_ele_voti_parziale where id_sez='$id_sez'";
217 $res = $dbi->prepare("$sql");
218 $res->execute();
219 $sql="delete from ".$prefix."_ele_sezioni where id_sez='$id_sez'";
220 $res = $dbi->prepare("$sql");
221 $res->execute();
222 Header("Location: admin.php?op=sezione&id_cons_gen=$id_cons_gen&min=$min");
223 }
224 }elseif ($do == "add") {
225 if ($num_sez) {
226 $sql="insert into ".$prefix."_ele_sezioni (id_cons,id_sede,num_sez,maschi,femmine, autorizzati_m,autorizzati_f,colore) values ('$id_cons', '$id_sede', '$num_sez','$maschi','$femmine','$aut_m', '$aut_f','#FAFAD2')";
227 $res = $dbi->prepare("$sql");
228 $mex='';
229 try
230 {
231 $res->execute();
232 }
233 catch(PDOException $e)
234 {
235 if ($e->errorInfo[1] == 1062) $mex="Numero di sezione duplicato, dati non memorizzati";
236 }
237 Header("Location: admin.php?op=sezione&id_cons_gen=$id_cons_gen&min=$min&mex=$mex");
238 } else {
239 ele();
240 OpenTable();
241 echo "<center>"._GESTIONE." "._SEZIONE." ";
242 echo "<br><br><a href=\"admin.php?op=sezione&amp;id_cons_gen=$id_cons_gen&amp;min=$min\">"._IMM." "._SEZIONE."</a></center>";
243 CloseTable();
244 }
245 }elseif ($do == "update") {
246 $sql="update ".$prefix."_ele_sezioni set id_sede='$id_sede', maschi='$maschi', femmine='$femmine', autorizzati_m='$aut_m', autorizzati_f='$aut_f' where id_sez='$id_sez2' ";
247 $res = $dbi->prepare("$sql");
248 $res->execute();
249 $num_sez--;
250 Header("Location: admin.php?op=sezione&id_cons_gen=$id_cons_gen&min=$num_sez");
251 }
252
253}
254}
255
256
257
258
259
260if ($op=="sezione"){
261 sezione($ok, $do,$id_sede,$id_sez, $num_sez, $aut_m, $aut_f, $maschi, $femmine, $id_sez2, $min);
262}
263ele();
264all();
265 echo"</td></tr></table>";
266include ("footer.php");
267
268?>
269
Note: See TracBrowser for help on using the repository browser.