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

Last change on this file since 404 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
RevLine 
[2]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}
[257]14global $dbi,$tipo_cons;
[2]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!");
[255]21
[2]22if (isset($param['min'])) $min=intval($param['min']); else $min=0;
23if (isset($param['ok'])) $ok=intval($param['ok']); else $ok=0;
[344]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='';
[2]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='';
[344]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;
[45]44if (isset($param['help'])) $help=intval($param['help']);
[2]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;
[255]56if (isset($param['id_cons_gen'])){
[336]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;
[255]60} else {
[336]61 $id_cons_gen=0;
62 $tipo_cons=0;
[255]63}
[2]64/******************************************************/
65/*Funzione di visualizzazione globale */
66/*****************************************************/
67
68function all() {
[45]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;
[2]70$language=$_SESSION['lang'];
71if (($perms>64)) {
[79]72############# Controllo flag per cancellazione consultazione
73 echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n"
74 ."//-->\n";
75 echo "function del_cons() {\n";
[91]76 echo "if (document.getElementById('pwd3').checked==false) {\n";
[306]77 echo "document.getElementById('update').value=\""._MODIFY."\" \n";
[91]78 echo "document.getElementById('do').value=\"update\" \n";
[79]79 echo "}else{\n";
[91]80 echo "document.getElementById('update').value=\""._DELETE." "._CONSULTA."\" \n";
81 echo "document.getElementById('do').value=\"delete\" \n";
[79]82 echo "} \n";
83 echo "} \n";
84 echo "</script>\n";
[358]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>";
[79]117#########################
118 if (isset($help)) include("language/$language/ele_consultazioni.html");
[45]119
[2]120 if ($do == "modify") {
[255]121 $pro = daticonsultazione();
122 $tip = datitipo($pro['tipo_cons'],$language);
[2]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\">"
[91]127 ."<input type=\"hidden\" id=\"do\" name=\"do\" value=\"update\">"
[2]128 ."<input type=\"hidden\" name=\"id_cons_gen\" value=\"".$pro['id_cons_gen']."\">"
[79]129 ."<table width=\"100%\"><tr><td>"._MODIFY." ".$pro['descrizione']." <br><br>";
[2]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 }
[79]143 echo "</td></tr><tr><td>"._TIPO."</td><td>$gencons</td></tr>";
[2]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\" >";
[79]147 echo "<option value=\"$dig1\" selected>$dig1</option>";giorno(0,0);
[2]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\" >";
[79]155 echo "<option value=\"$dfg1\" selected>$dfg1</option>";giorno(0,0);
[2]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();
[79]160 echo "</td></tr><tr>";
[358]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>";
[79]167 else echo "<td></td>";
[358]168 echo "</tr><tr><td><input type=\"submit\" id=\"update\" name=\"update\" value=\""._MODIFY."\">"
[2]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\">"
[45]175 ."<hr><h6>"
176 ._ADD." "._CONSULTA."<br><br>";
[79]177 echo _DEFCONS.":</h6><br><table width=\"100%\">";
[255]178 $row = elenco_tipi();
[45]179 echo "<tr><td><b>"._TIPO." :</b></td><td>";
[2]180 echo "<select name=\"tipocons\" >";
[255]181 foreach($row as $res){
182 $idtipo=$res['tipo_cons'];$destipo=$res['descrizione'];
[2]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>";
[79]194 echo "<select name= \"dig\" ><option value=\"$dig\" selected>$dig</option>"; giorno(0,0);
[2]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>";
[79]200 echo "<select name= \"dfg\" ><option value=\"$dfg\" selected>$dfg</option>"; giorno(0,0);
[2]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>";
[255]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'];
[2]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\"
[79]228 border=\"0\" align=\"middle\" alt=\"Edit\"> "._EDIT."</a>]"
[2]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) {
[79]258 if ($do == "delete") {
[255]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();
[2]265 Header("Location: admin.php?op=consultazione");
[79]266 }
[2]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;
[255]285 $sql="insert into ".$prefix."_ele_consultazione (descrizione,data_inizio,data_fine,tipo_cons) values ('$descr_cons2','$data_inizio','$data_fine','$tipocons')";
[358]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 }
[2]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";
[255]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'";
[358]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 }
[257]314 if (!$sth->rowCount()) return;
[2]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")
[79]325 if (isset($param['do']) and $do!='modify')
[2]326 consultazione($ok, $id_cons_gen,$tipocons, $data_in, $data_fine,$do, $dig, $dim, $dia, $dfg, $dfm, $dfa, $duplica,$referendum,$liste,$gruppi,$ballo,$votigruppo);
[79]327# else consultazione('', $id_cons_gen,'','','','','','','','','','','','','','','','','');
[2]328ele();
329all();
[79]330echo"</td></tr></table></div>";
[2]331include("footer.php");
332
333
334
335?>
Note: See TracBrowser for help on using the repository browser.