source: trunk/admin/modules/Elezioni/ele_consultazioni.php@ 422

Last change on this file since 422 was 358, checked in by roby, 3 years ago

Admin: aggiunta la funzione di gestione dello spoglio per la singola sezione tramite tema per cellulari

File size: 15.0 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 Consultazioni */
9/* Amministrazione */
10/************************************************************************/
11if (!defined('ADMIN_FILE')) {
12 die ("You can't access this file directly...");
13}
14global $dbi,$tipo_cons;
15$aid=$_SESSION['aid'];
16$prefix=$_SESSION['prefix'];
17$param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ? $_GET : $_POST;
18$perms=ChiSei(0);
19//if ($perms<128 or !$id_cons_gen) die("Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
20if ($perms!=256) die("Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
21
22if (isset($param['min'])) $min=intval($param['min']); else $min=0;
23if (isset($param['ok'])) $ok=intval($param['ok']); else $ok=0;
24if (isset($param['data_in'])) $data_in=addslashes($param['data_in']); else $data_in='';
25if (isset($param['data_fine'])) $data_fine=addslashes($param['data_fine']); else $data_fine='';
26if (isset($param['do'])) $do=addslashes($param['do']); else $do='';
27if (isset($param['dig'])) $dig=intval($param['dig']); else $dig=date("d",time());
28if (isset($param['dim'])) $dim=intval($param['dim']); else $dim=date("m",time());
29if (isset($param['dia'])) $dia=intval($param['dia']); else $dia=date("Y",time());
30if (isset($param['dfg'])) $dfg=intval($param['dfg']); else $dfg=date("d",time());
31if (isset($param['dfm'])) $dfm=intval($param['dfm']); else $dfm=date("m",time());
32if (isset($param['dfa'])) $dfa=intval($param['dfa']); else $dfa=date("Y",time());
33if (isset($param['duplica'])) $duplica=intval($param['duplica']); else $duplica='';
34if (isset($param['referendum'])) $referendum=addslashes($param['referendum']); else $referendum='';
35if (isset($param['liste'])) $liste=addslashes($param['liste']); else $liste='';
36if (isset($param['gruppi'])) $gruppi=addslashes($param['gruppi']); else $gruppi='';
37if (isset($param['votigruppo'])) $votigruppo=addslashes($param['votigruppo']); else $votigruppo='';
38if (isset($param['votilista'])) $votilista=addslashes($param['votilista']); else $votilista='';
39if (isset($param['voticandi'])) $voticandi=addslashes($param['voticandi']); else $voticandi='';
40if (isset($param['ballo'])) $ballo=addslashes($param['ballo']); else $ballo='';
41if (isset($param['circo'])) $circo=addslashes($param['circo']); else $circo='';
42if (isset($param['descr_cons2'])) $descr_cons2=addslashes($param['descr_cons2']); else $descr_cons2='';
43if (isset($param['tipocons'])) $tipocons=addslashes($param['tipocons']); else $tipocons=$tipo_cons;
44if (isset($param['help'])) $help=intval($param['help']);
45$id_comune=$_SESSION['id_comune'];
46
47//die("dig:$dig dim:$dim dia:$dia");
48
49include("modules/Elezioni/funzionidata.php");
50include("modules/Elezioni/ele.php");
51
52// Offset - visualizza il numero di elementi per pagina
53
54 $offset=10;
55 if (!isset($min)) $min=0;
56if (isset($param['id_cons_gen'])){
57 $id_cons_gen=intval($param['id_cons_gen']);
58 $row=descr_cons();
59 if(isset($row[0])) $tipo_cons=$row[0]; else $tipo_cons=0;
60} else {
61 $id_cons_gen=0;
62 $tipo_cons=0;
63}
64/******************************************************/
65/*Funzione di visualizzazione globale */
66/*****************************************************/
67
68function all() {
69 global $genere, $bgcolor1, $bgcolor2, $bgcolor6, $prefix, $dbi, $offset, $min, $id_cons_gen, $perms,$tipo_cons, $tipocons,$do, $dig, $dim, $dia, $dfg, $dfm, $dfa, $help;
70$language=$_SESSION['lang'];
71if (($perms>64)) {
72############# Controllo flag per cancellazione consultazione
73 echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n"
74 ."//-->\n";
75 echo "function del_cons() {\n";
76 echo "if (document.getElementById('pwd3').checked==false) {\n";
77 echo "document.getElementById('update').value=\""._MODIFY."\" \n";
78 echo "document.getElementById('do').value=\"update\" \n";
79 echo "}else{\n";
80 echo "document.getElementById('update').value=\""._DELETE." "._CONSULTA."\" \n";
81 echo "document.getElementById('do').value=\"delete\" \n";
82 echo "} \n";
83 echo "} \n";
84 echo "</script>\n";
85
86 ############## onsubmit=\"check_aid()\"
87/* echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n"
88 ."//-->\n";
89 echo "function check_aid() {
90 var elem=document.getElementById('descrcons'); var num=elem.length; alert (\"Please fill in your first name.\".num);
91 for (i=0; i < elem.length; i++) { var sel=elem[i].value;
92 if (elem[i].value == document.consultazione.descr_cons2.value) {
93 document.consultazione.descr_cons2.style.backgroundColor = \"#ccc\";
94 document.consultazione.descr_cons2.focus();
95 return false;
96 }
97 }
98 return false;
99 }
100
101 function hide(){
102 var elem = document.getElementById('descrcons');
103 elem.style.display = 'none';
104 }";
105
106 echo "</script>\n"; */
107###################
108 $sql="select descrizione from ".$prefix."_ele_consultazione";
109 $sth = $dbi->prepare("$sql");
110 $sth->execute();
111 $row = $sth->fetch(PDO::FETCH_NUM);
112 echo "<select id=\"descrcons\" style=\"visibility:hidden;\">";
113 while(list($val)=$sth->fetch(PDO::FETCH_NUM)) {
114 echo "<option value=\"$val\">$val</option>";
115 }
116 echo "</select>";
117#########################
118 if (isset($help)) include("language/$language/ele_consultazioni.html");
119
120 if ($do == "modify") {
121 $pro = daticonsultazione();
122 $tip = datitipo($pro['tipo_cons'],$language);
123 list($dia1,$dim1,$dig1) = explode("-",$pro['data_inizio']=="0000-00-00" ? " - - ": $pro['data_inizio']) ;
124 list($dfa1,$dfm1,$dfg1) = explode("-",$pro['data_fine']=="0000-00-00" ? " - - ": $pro['data_fine']) ;
125 echo "<form name=\"consultazione\" method=\"post\" action=\"admin.php\" >"
126 ."<input type=\"hidden\" name=\"op\" value=\"consultazione\">"
127 ."<input type=\"hidden\" id=\"do\" name=\"do\" value=\"update\">"
128 ."<input type=\"hidden\" name=\"id_cons_gen\" value=\"".$pro['id_cons_gen']."\">"
129 ."<table width=\"100%\"><tr><td>"._MODIFY." ".$pro['descrizione']." <br><br>";
130 switch ($genere) {
131 case "0" : $gencons=_GENCONS0;break;
132 case "1" : $gencons=_GENCONS1;break;
133 case "2" : $gencons=_GENCONS2;break;
134 case "3" : $gencons=_GENCONS3;break;
135 case "4" : $gencons=_GENCONS4;break;
136 case "5" : if($tip['voto_c'])
137 $gencons=_GENCONS3;
138 else
139 $gencons=_GENCONS5;
140 break;
141 default :$gencons="";
142 }
143 echo "</td></tr><tr><td>"._TIPO."</td><td>$gencons</td></tr>";
144 echo "<tr bgcolor=\"$bgcolor2\"><td>"._DESCR. "</td><td><input name=\"descr_cons2\" value=\"".$pro['descrizione']."\" size=\"15\"></td></tr>";
145 echo "<tr><td>"._DATAIN." :</td><td>";
146 echo "<select name=\"dig\" >";
147 echo "<option value=\"$dig1\" selected>$dig1</option>";giorno(0,0);
148 echo "<select name=\"dim\" >";
149 echo "<option value= \"$dim1\" selected>$dim1</option>"; mese();
150 echo "<select name= \"dia\" >";
151 echo "<option value=\"$dia1\" selected>$dia1</option>"; anno();
152 echo "</td></tr>";
153 echo "<tr><td>"._DATAFINE." :</td><td>";
154 echo "<select name=\"dfg\" >";
155 echo "<option value=\"$dfg1\" selected>$dfg1</option>";giorno(0,0);
156 echo "<select name= \"dfm\" >";
157 echo "<option value= \"$dfm1\" selected>$dfm1</option>"; mese();
158 echo "<select name= \"dfa\" >";
159 echo "<option value=\"$dfa1\" selected>$dfa1</option>"; anno();
160 echo "</td></tr><tr>";
161 $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'";
162 $sth = $dbi->prepare("$sql");
163 $sth->execute();
164 $resdel=$sth->rowCount();
165 if($resdel==0)
166 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>";
167 else echo "<td></td>";
168 echo "</tr><tr><td><input type=\"submit\" id=\"update\" name=\"update\" value=\""._MODIFY."\">"
169 ."</td></tr></table></form>";
170 } else {
171 echo "<form name=\"consultazione\" action=\"admin.php\">"
172 ."<input type=\"hidden\" name=\"op\" value=\"consultazione\">"
173 ."<input type=\"hidden\" name=\"do\" value=\"add\">"
174 ."<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">"
175 ."<hr><h6>"
176 ._ADD." "._CONSULTA."<br><br>";
177 echo _DEFCONS.":</h6><br><table width=\"100%\">";
178 $row = elenco_tipi();
179 echo "<tr><td><b>"._TIPO." :</b></td><td>";
180 echo "<select name=\"tipocons\" >";
181 foreach($row as $res){
182 $idtipo=$res['tipo_cons'];$destipo=$res['descrizione'];
183 if ($idtipo == $tipo_cons) {
184 $sel = "selected";
185 } else {
186 $sel = "";
187 }
188
189 echo "<option value=\"$idtipo\" $sel>$destipo";
190 }
191 echo "</select>";
192 echo "<tr><td><b>"._DESCR. "</b></td><td><input type=\"text\" name=\"descr_cons2\" maxlength=\"100\"></td></tr>"
193 ."<tr><td><b>"._DATAIN. "</b></td><td>";
194 echo "<select name= \"dig\" ><option value=\"$dig\" selected>$dig</option>"; giorno(0,0);
195 echo "<select name= \"dim\" ><option value=\"$dim\" selected>$dim</option>"; mese();
196 echo "<select name= \"dia\" ><option value=\"$dia\" selected>$dia</option>"; anno() ;
197 echo "</td></tr>"
198
199 ."<tr><td><b>"._DATAFINE. "</b></td><td>";
200 echo "<select name= \"dfg\" ><option value=\"$dfg\" selected>$dfg</option>"; giorno(0,0);
201 echo "<select name= \"dfm\" ><option value=\"$dfm\" selected>$dfm</option>"; mese();
202 echo "<select name= \"dfa\" ><option value=\"$dfa\" selected>$dfa</option>"; anno() ;
203 echo "</td></tr>"
204 ."</table>"
205 ."<input type=\"submit\" name=\"add\" value=\""._ADD."\">"
206 ."</form>";
207 }
208 echo "<center><font class=\"title\"><b>"._MODIFY." "._CONSULTA."</b></font><br><br><table border=\"0\" width=\"100%\">"
209 ."<tr><td bgcolor=\"$bgcolor1\" align=\"center\">&nbsp;<b>"._DESCR."</b>&nbsp;</td>"
210 ."<td bgcolor=\"$bgcolor1\" align=\"center\">&nbsp;<b>"._DATAIN."</b>&nbsp;</td>"
211 ."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._DATAFINE."</b></td>"
212 ."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._FUNZIONI."</b></td></tr>";
213 $res = elenco_consultazioni();
214 $max = count($res);
215 $sql="select * from ".$prefix."_ele_consultazione ORDER BY data_fine desc LIMIT $min,$offset";
216 $sth = $dbi->prepare("$sql");
217 $sth->execute();
218 $row = $sth->fetchAll();
219 foreach($row as $res) {
220 $id=$res['id_cons_gen']; $descr_cons=$res['descrizione']; $data_inizio=$res['data_inizio']; $data_fine=$res['data_fine'];$tipo=$res['tipo_cons'];
221 $data_inizio=form_data($data_inizio);$data_fine=form_data($data_fine);
222 $bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
223 echo "<tr ><td bgcolor=\"$bgcolor1\" align=\"left\" ><a href=\"admin.php?op=ele&amp;id_cons_gen=$id\"><b>$descr_cons</b></a>"
224 ."</td><td align=\"center\" >$data_inizio</td>"
225 ."<td align=\"center\">$data_fine"
226 ."</td><td align=\"center\" nowrap bgcolor=\"$bgcolor1\">[<a
227 href=\"admin.php?op=consultazione&amp;do=modify&amp;id_cons_gen=$id\"><img src=\"modules/Elezioni/images/edit.gif\"
228 border=\"0\" align=\"middle\" alt=\"Edit\"> "._EDIT."</a>]"
229 ."</td></tr>";
230 }
231 echo "</table></center>";
232#'Pagina precedente' e 'Pagina Successiva'
233 echo"<table align=\"center\" width=\"100%\" bgcolor=\"$bgcolor1\"><tr>";
234 $prev=$min-$offset;
235 if ($prev>=0) {
236 echo "<td colspan=\"5\" align=\"center\" bgcolor=\"$bgcolor2\"><a href=\"admin.php?op=consultazione&amp;id_cons_gen=$id_cons_gen&amp;min=$prev\">";
237 echo "<b>$offset "._PREV_MATCH."</b></a></td>";
238 }
239 $next=$min+$offset;
240 if ($next>=($offset-1)) {
241 if($next>=$max) $next = $max;
242 else {
243 echo "<td colspan=\"5\" align=\"center\" bgcolor=\"$bgcolor2\"><a href=\"admin.php?op=consultazione&amp;id_cons_gen=$id_cons_gen&amp;min=$next\">";
244 echo "<b>$offset "._NEXT_MATCH."</b></a></td>";
245 }
246 }
247 echo "</tr></table><br>";
248}
249}
250
251
252
253function consultazione($ok, $id_cons_gen,$tipocons, $data_in, $data_fine,$do, $dig, $dim, $dia, $dfg, $dfm, $dfa, $duplica,$referendum,$liste,$gruppi,$ballo,$votigruppo) {
254 global $bgcolor1, $bgcolor2, $prefix, $dbi, $descr_cons2,$tipo_cons,$perms,$do,$votilista,$voticandi,$circo;
255
256
257if ($perms>=128) {
258 if ($do == "delete") {
259 $sql="delete from ".$prefix."_ele_rilaff where id_cons_gen='$id_cons_gen'";
260 $sth = $dbi->prepare("$sql");
261 $sth->execute();
262 $sql="delete from ".$prefix."_ele_consultazione where id_cons_gen='$id_cons_gen'";
263 $sth = $dbi->prepare("$sql");
264 $sth->execute();
265 Header("Location: admin.php?op=consultazione");
266 }
267 if ($do == "add") {
268 if ($descr_cons2) {
269 if($referendum=='true') {
270 $genere=0;
271 } elseif ($ballo=='true') {
272 $genere=1;
273 }else{
274 $genere=2;
275 if($liste!='true') {$genere+=2;}
276 if($gruppi=='true') {$genere+=1;}
277 }
278 $votigruppo=$votigruppo=='true'? 1:0;
279 $votilista=$votilista=='true'? 1:0;
280 $voticandi=$voticandi=='true'? 1:0;
281 $circo=$circo=='true'? 1:0;
282 $data_inizio="$dia-$dim-$dig";
283 $data_fine="$dfa-$dfm-$dfg";
284 $id_consulta=$id_cons_gen;
285 $sql="insert into ".$prefix."_ele_consultazione (descrizione,data_inizio,data_fine,tipo_cons) values ('$descr_cons2','$data_inizio','$data_fine','$tipocons')";
286 try {
287 $sth = $dbi->prepare("$sql");
288 $sth->execute();
289 }catch(PDOException $e) {
290 if ($e->getCode() == 23000)
291 echo "<h2 style=\"color:red;\"> Inserimento fallito: Esiste già una consultazione con il nome \"$descr_cons2\"</h2";
292 else
293 echo "<h2 style=\"color:red;\"> Inserimento fallito: ". $e->getMessage()."</h2";
294 }
295 } else {
296 OpenTable();
297 echo "<center>"._GESTIONE." "._CONSULTAZIONE."";
298 echo "<br><br><a href=\"admin.php?op=consultazione&amp;id_cons_gen=$id_cons_gen\">"._IMMCONS."</a></center>";
299 CloseTable();
300 }
301 }else if ($do == "update") {
302 $data_inizio="$dia-$dim-$dig";
303 $data_fine="$dfa-$dfm-$dfg";
304 $sql="update ".$prefix."_ele_consultazione set descrizione='$descr_cons2',data_inizio='$data_inizio',data_fine='$data_fine' WHERE id_cons_gen='$id_cons_gen'";
305 try {
306 $sth = $dbi->prepare("$sql");
307 $sth->execute();
308 }catch(PDOException $e) {
309 if ($e->getCode() == 23000)
310 echo "<h2 style=\"color:red;\"> Inserimento fallito: Esiste già una consultazione con il nome \"$descr_cons2\"</h2";
311 else
312 echo "<h2 style=\"color:red;\"> Inserimento fallito: ". $e->getMessage()."</h2";
313 }
314 if (!$sth->rowCount()) return;
315 Header("Location: admin.php?op=consultazione&id_cons_gen=$id_cons_gen");
316 }
317 }
318}
319
320function help_cons()
321{
322//da mettere
323}
324if ($op=="consultazione")
325 if (isset($param['do']) and $do!='modify')
326 consultazione($ok, $id_cons_gen,$tipocons, $data_in, $data_fine,$do, $dig, $dim, $dia, $dfg, $dfm, $dfa, $duplica,$referendum,$liste,$gruppi,$ballo,$votigruppo);
327# else consultazione('', $id_cons_gen,'','','','','','','','','','','','','','','','','');
328ele();
329all();
330echo"</td></tr></table></div>";
331include("footer.php");
332
333
334
335?>
Note: See TracBrowser for help on using the repository browser.