source: trunk/client/modules/Elezioni/votanti.php@ 122

Last change on this file since 122 was 122, checked in by roby, 13 years ago
  • client: modifiche per la visualizzazione dei voti validi e non validi per i referendum
  • admin: corretta la gestione degli apici nella funzione di popolamento delle consultazioni
File size: 16.6 KB
Line 
1<?php
2/************************************************************************/
3/* Eleonline - Raccolta e diffusione dei dati elettorali */
4/* by Luciano Apolito & Roberto Gigli */
5/* http://www.eleonline.it */
6/* info@eleonline.it luciano@aniene.net rgigli@libero.it */
7/************************************************************************/
8
9if (!defined('MODULE_FILE')) {
10 die ("Non puoi accedere al file direttamente...");
11}
12$param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ?
13 $_GET : $_POST;
14
15
16
17$id_comune= (isset($param['id_comune'])) ? $param['id_comune']:$siteistat;
18if (isset($param['id_cons_gen'])) $id_cons_gen=intval($param['id_cons_gen']); else $id_cons_gen='';
19if (isset($param['op'])) $op=$param['op']; else $op='';
20if (isset($param['minsez'])) $minsez=intval($param['minsez']); else $minsez='';
21if (isset($param['id_lista'])) $id_lista=intval($param['id_lista']); else $id_lista='';
22if (isset($param['id_circ'])) $id_circ=intval($param['id_circ']); else $id_circ='';
23if (isset($param['csv'])) $csv=intval($param['csv']); else $csv='';
24if (isset($param['min'])) $min=intval($param['min']); else $min= 0;
25if (isset($param['orvert'])) $orvert=intval($param['orvert']); else $orvert='';
26if (isset($param['offset'])) $offset=intval($param['offset']); else $offset='';
27if (isset($param['offsetsez'])) $offsetsez=intval($param['offsetsez']); else $offsetsez='';
28if (isset($param['perc'])) $perc=$param['perc']; else $perc='';
29if (isset($param['info'])) get_magic_quotes_gpc() ? $info=$param['info']:$info=addslashes($param['info']); else $info='';
30if (isset($param['files'])) get_magic_quotes_gpc() ? $files=$param['files']:$files=addslashes($param['files']); else $files='';
31if (isset($param['voti_lista'])) $voti_lista=intval($param['voti_lista']); else $voti_lista= 0;
32if (isset($param['perc_lista'])) $perc_lista=$param['perc_lista']; else $perc_lista= 0;
33if (isset($param['lettera'])) get_magic_quotes_gpc() ? $lettera=$param['lettera']:$lettera=addslashes($param['lettera']); else $lettera='';
34if (isset($param['id_gruppo'])) $id_gruppo=intval($param['id_gruppo']); else $id_gruppo='';
35if (isset($param['tipo_cons'])) $tipo_cons=intval($param['tipo_cons']); else $tipo_cons='';
36# anti-xss nov. 2009
37$id_comune=htmlentities($id_comune);
38$perc=floatval($perc);
39$perc_lista=floatval($perc_lista);
40$datipdf= htmlentities($datipdf);
41$op= htmlentities($op);
42$info= htmlentities($info);
43$files=htmlentities($files);
44$lettera=htmlentities($lettera);
45
46$id_comune=intval($id_comune);
47
48
49//$id_cons_gen=$_GET['id_cons_gen'];
50$res = mysql_query("SELECT t1.tipo_cons,t3.genere,t2.id_cons FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2, ".$prefix."_ele_tipo as t3 where t1.tipo_cons=t3.tipo_cons and t1.id_cons_gen=t2.id_cons_gen and t2.id_cons_gen='$id_cons_gen' and t2.id_comune='$id_comune'" , $dbi);
51list($tipo_cons,$genere,$id_cons) = mysql_fetch_row($res);
52
53if (isset($param['ops'])) $ops=$param['ops']; else $ops='';
54if (isset($param['pag'])) $pag=$param['pag']; else $pag=0;
55if (isset($param['num_ref'])) $num_ref=$param['num_ref'];
56if (isset($param['num_refs'])) $num_refs=$param['num_refs'];
57$bgcolor2='#cacaca';
58//**************************************************************************
59// ELE
60//**************************************************************************
61//controllo_finale($id_cons);
62
63global $prefix, $dbi,$id_circ,$lang, $fascia, $limite;
64
65include_once("modules/Elezioni/language/lang-$lang.php");
66# testata
67
68if($csv==1){
69 include_once("modules/Elezioni/funzioni.php");
70
71 $res = mysql_query("SELECT descrizione FROM ".$prefix."_ele_comuni where id_comune='$id_comune' ", $dbi);
72 list($descr_com) = mysql_fetch_row($res);
73 $descr_com =stripslashes($descr_com);
74 $datipdf .= "<div style=\"margin:0px auto; text-align:center;\">";
75 $siteistat=$id_comune;
76 # salva sull'hardisk lo stemma del comune
77 $logo=verificasimbolo();
78 $immagine= "<img src=\"modules/Elezioni/images/$logo\" alt=\"logo\" align=\"left\"/>";
79
80
81
82
83
84 if($xls!=1) $datipdf .= "<table><tr><td>$immagine</td><td>";
85 $datipdf .= ""._COMUNE." $descr_com <br/>
86 "._RISULTA." "._CONSULTA."<br/>";
87 $datipdf .= "$descr_cons <br />"._DISCLAIMER."";
88 if($xls!=1) $datipdf .= "</td></tr></table>";
89 $datipdf .="</div>";
90
91
92$html = "<style type=\"text/css\">
93 <!--
94
95 .td-89 {
96 width: 89%;
97 border: 1px;
98 text-align: left;
99 }
100 .td-vuoto {
101
102 width: 100%;
103 border: 1px;
104 text-align: left;
105
106}
107
108
109 .td-5 {
110
111 margin: 0px 0 0 0px;
112 width: 5%;
113 /*border: none;*/
114 padding: 0px;
115
116 text-align: center;
117 }
118
119
120
121 .bggray {
122 background: #ffffff;
123 FONT-SIZE: 13px;
124 FONT-FAMILY: Helvetica;
125 border: 1px;
126 }
127
128 .bggray2 {
129 background: #EFEFEF;
130 FONT-SIZE: 13px;
131 FONT-FAMILY: Helvetica;
132 border: 1px;
133 }
134 -->
135 </style>";
136
137
138
139
140}
141
142
143
144
145
146
147
148
149
150
151
152 // icone stampa e grafici
153 if ($csv!=1){
154 if(isset($num_ref)) $curref="&amp;num_ref=$num_ref"; else $curref='';
155 if (!isset($html)) $html='';
156 $html .= "<div>
157 <a href=\"modules.php?name=Elezioni&amp;file=index&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;op=graf_votanti\">
158 "._VER_GRAF." <img class=\"image\" src=\"modules/Elezioni/images/grafici.png\" alt=\"\" /></a>
159 <a href=\"modules.php?name=Elezioni&amp;op=come&amp;file=index&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;info=votanti&amp;csv=1&amp;pag=$pag$curref\">"._VER_STAMPA."
160 <img class=\"image\" src=\"modules/Elezioni/images/printer.png\" alt=\"\" /></a>
161 <a href=\"modules.php?name=Elezioni&amp;op=come&amp;file=index&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;info=votanti&amp;xls=1&csv=1;&amp;pag=$pag$curref\">
162 <img class=\"image\" src=\"modules/Elezioni/images/csv.gif\" alt=\"\" /></a>
163
164<a href=\"modules.php?name=Elezioni&amp;op=come&amp;file=index&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;info=votanti&amp;pdf=1&csv=1;&amp;pag=$pag$curref\">
165 <img class=\"image\" src=\"modules/Elezioni/images/pdf.gif\" alt=\"\" /></a>
166
167
168 </div>";
169 }
170
171
172
173 $res = mysql_query("SELECT sum(maschi),sum(femmine) FROM ".$prefix."_ele_sezioni where id_cons='$id_cons'", $dbi);
174 list($totm,$totf) = mysql_fetch_row($res);
175 $totel=$totm+$totf;
176 if (!IsSet($pag)) {$pag=0;} //inizializza il numero di pagina
177 if (!IsSet($num_ref)) {
178 $num_ref=1;
179 $resg = mysql_query("SELECT id_gruppo from ".$prefix."_ele_gruppo where id_cons=$id_cons", $dbi);
180 $num_refs= mysql_num_rows($resg); //quante pagine?
181 }
182 if(($genere!=4) and $pag==0){ //diverso da liste a piu' candidati
183 $ops=4; //gestione gruppi (anche liste uninominali)
184 }else{
185 $ops=3; //gestione liste
186 }
187
188 $resg = mysql_query("SELECT id_gruppo,num_gruppo from ".$prefix."_ele_gruppo where id_cons=$id_cons and num_gruppo=$num_ref", $dbi);
189 list($idg,$numg) = mysql_fetch_row($resg);
190 $res = mysql_query("SELECT id_sez,num_sez,t1.id_sede as id_sede,t2.id_circ as id_circ FROM ".$prefix."_ele_sezioni as t1,".$prefix."_ele_sede as t2 where t1.id_cons='$id_cons' and t1.id_sede=t2.id_sede order by num_sez ", $dbi);
191 $max = mysql_num_rows($res); //quante sezioni?
192 $res = mysql_query("SELECT id_sez,num_sez,t1.id_sede as id_sede,t2.id_circ as id_circ FROM ".$prefix."_ele_sezioni as t1,".$prefix."_ele_sede as t2 where t1.id_cons='$id_cons' and t1.id_sede=t2.id_sede order by num_sez ", $dbi);
193 $num_sez = mysql_num_rows($res); //quante sezioni?
194 for ($i=1;$i<=$num_sez;$i++){
195 $sezione[$i]=mysql_fetch_array($res, 3); //inizializza l'array delle sezioni
196 $ar[$i]=0;
197 }
198 $tab3="_ele_voti_lista";
199 if ($genere>0) { //se non e' un referendum
200 if (!($genere==4) and $pag==0){ //se non e' una lista uninominale ed e' la prima pagina
201 $tab="SELECT 0,t2.id_sez,t2.num_sez,t2.validi,'0',t2.validi,t2.nulli,t2.bianchi,t2.contestati, t4.id_circ,t2.id_sede,'0' FROM ".$prefix."_ele_sezioni as t2 left join ".$prefix."_ele_sede as t4 on (t2.id_sede=t4.id_sede) where t2.id_cons='$id_cons' and t2.validi+t2.nulli+t2.bianchi+t2.contestati>0 group by t2.id_sez order by t2.num_sez ";
202
203 }else{ // e' una lista uninominale o la seconda pagina
204 $tab="SELECT '0',t1.id_sez,t1.num_sez,sum(t2.voti),t1.solo_gruppo,t1.validi,t1.nulli,t1.bianchi,t1.contestati, t4.id_circ,t1.id_sede,'0'
205 FROM ".$prefix."_ele_sezioni as t1 left join ".$prefix.$tab3." as t2 on (t1.id_sez=t2.id_sez)
206 left join ".$prefix."_ele_sede as t4 on (t1.id_sede=t4.id_sede)
207 where t1.id_cons='$id_cons' and t1.id_cons=t2.id_cons group by t2.id_sez order by t1.num_sez ";
208 }
209
210 $riga1 = "";
211 if($pag==0)$riga1 .="<h2>"._DETTAGLIO." "._VOTIE."</h2>";
212 else $riga1 .="<h2>"._DETTAGLIO." "._VOTIE." "._ASOLA_LISTA."</h2>";
213
214 }else{ // e' un referendum
215 $tab="SELECT t1.id_gruppo,t1.id_sez,t2.num_sez,t1.si,t1.no,t1.validi,t1.nulli,t1.bianchi,t1.contestati, t4.id_circ,t2.id_sede,t3.num_gruppo
216 FROM ".$prefix."_ele_voti_ref as t1 left join ".$prefix."_ele_sezioni as t2 on (t1.id_sez=t2.id_sez)
217 left join ".$prefix."_ele_gruppo as t3 on (t1.id_gruppo=t3.id_gruppo) left join ".$prefix."_ele_sede as t4 on (t2.id_sede=t4.id_sede)
218 where t1.id_cons='$id_cons' and t1.id_gruppo='$idg' order by t2.num_sez ";
219 $riga1 = "<div style=\"margin:0px auto;text-align:center;\">";
220 $riga1 .="<h2>"._DETTAGLIO." "._VOTIE."</h2></div>";
221
222 $des = mysql_query("select descrizione from ".$prefix."_ele_gruppo where id_gruppo='$idg'", $dbi);
223 list($descrizione)=mysql_fetch_array($des);
224 $riga1 .="<h4>$descrizione</h4>";
225 }
226 $res = mysql_query("$tab ", $dbi);
227 $num_scr = mysql_num_rows($res);
228 //$riga2= "<div>"._SEZSCR." $num_scr su $num_sez</div>";//sezioni scrutinate
229
230 $riga2 = "<table style=\"border:1px solid #6A6A6A;\" summary=\"Tabella dei voti espressi\">";
231 $riga3 = "<tr class=\"bggray2\">
232 <td>"._SEZIONI."</td>
233 <td>"._VOTIU."</td>
234 <td>"._VOTID."</td>
235 <td>"._VOTIE."</td>"; //testata con nomi dei campi
236 if ($genere==0) { //se e' un referendum
237 $riga3 .= "<td>"._SI."</td><td>"._NO."</td>";
238 } elseif ((($genere==5) or ($genere==3)) and $pag==1){
239 $riga3 .= "<td>"._ASOLA_LISTA."</td><td>"._ASOLO_GRUPPO."</td>";
240 }
241 $riga3 .= "<td>"._VALIDI."</td><td>"._NULLI."</td><td>"._BIANCHI."</td><td>"._CONTESTATI."</td>"
242 ."</tr>\n";
243 $res = mysql_query("$tab ", $dbi);
244 $num_scr = mysql_num_rows($res);
245 $righe= "";
246 $scrutinate=1;
247 $tot_u=0;$tot_d=0;$tot_voti=0; $tot_si=0;$tot_no=0;$tot_validi=0;$tot_nulli=0;$tot_bianchi=0;$tot_contestati=0;
248 while (list($id_gruppo,$id,$num,$si,$no,$validi,$nulli,$bianchi,$contestati,$id_circ,$id_sede,$gruppo) = mysql_fetch_row($res)){
249 // inserimento numeri di sez non scrutinate
250 while ($scrutinate < $num) {
251 $righe.= "<tr><td><span style=\"color: rgb(255, 0, 0);\">$scrutinate</span></td></tr>\n";
252 $scrutinate++;
253 }
254 $scrutinate++;
255 // fine inserimento
256 $tab2="SELECT max(voti_donne),max(voti_uomini),max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id'";
257 if ($genere==0) $tab2 .= " and id_gruppo=$id_gruppo";
258 $res2 = mysql_query($tab2, $dbi);
259 list($votid,$votiu,$voti) = mysql_fetch_row($res2);
260// $voti=$votiu+$votid;
261 $tot_u+=$votiu;
262 $tot_d+=$votid;
263 $tot_voti+=$voti;
264 $tot_si+=$si;
265 $tot_no+=$no;
266 $tot_validi+=$validi;
267 $tot_nulli+=$nulli;
268 $tot_bianchi+=$bianchi;
269 $tot_contestati+=$contestati;
270 $righe .= "<tr class=\"bggray2\">
271 <td>$num</td>
272 <td>".number_format($votiu,0,',','.')."</td>
273 <td>".number_format($votid,0,',','.')."</td>
274 <td>".number_format($voti,0,',','.')."</td>";
275 if ($genere==0 or ((($genere==5) or ($genere==3)) and $pag==1)){$righe
276 .= "<td>".number_format($si,0,',','.')."</td>
277 <td>".number_format($no,0,',','.')."</td>";}
278
279 $righe .= "<td>".number_format($validi,0,',','.')."</td>
280 <td>$nulli</td>
281 <td>$bianchi</td>
282 <td>$contestati</td></tr>";
283 }
284 if ($num<$num_sez) {
285 for (;$scrutinate<=$num_sez;$scrutinate++) {
286 $righe .= "<tr><td>";
287 $righe .="<span style=\"color: rgb(255, 0, 0);\">$scrutinate</span></td></tr>";
288 }
289 }
290 $righet='';
291 if($num_scr){
292 $righet = "<tr class=\"bggray\">
293 <td ></td>
294 <td>"._VOTIU."</td>
295 <td>"._VOTID."</td>
296 <td>"._VOTIE."</td>"; //testata con nomi dei campi
297 if ($genere==0) { //se e' un referendum
298 $righet .= "<td>"._SI."</td><td>"._NO."</td>";
299 } elseif ((($genere==5) or ($genere==3)) and $pag==1){
300 $righet .= "<td>"._ASOLA_LISTA."</td><td>"._ASOLO_GRUPPO."</td>";
301 }
302 if($totel==0) $totelrip="0.00"; else $totelrip=number_format($tot_voti*100/$totel,2);
303 if($totf==0) $totfrip="0.00"; else $totfrip=number_format($tot_d*100/$totf,2);
304 if($totm==0) $totmrip="0.00"; else $totmrip=number_format($tot_u*100/$totm,2);
305 $righet .= "<td>"._VALIDI."</td><td>"._NULLI."</td><td>"._BIANCHI."</td><td>"._CONTESTATI."</td>"
306 ."</tr>
307
308
309
310 <tr class=\"td-vuotoc\"><td><b>"._TOT."</b></td><td><b>".number_format($tot_u,0,',','.')."</b><br /><i>(".$totmrip." %)</i></td><td><b>".number_format($tot_d,0,',','.')."</b><br /><i>(".$totfrip." %)</i></td><td><b>".number_format($tot_voti,0,',','.')."</b><br /><i>(".$totelrip." %)</i></td>";
311
312 // se e' un referendum o una consultazione con raggruppamenti
313
314 if($tot_validi){
315 if ($genere==0 or ((($genere==5) or ($genere==3)) and $pag==1)){$righet .= "<td><b>".number_format($tot_si,0,',','.')."</b><br /><i>(".number_format($tot_si*100/$tot_validi,2)." %)</i></td><td><b>".number_format($tot_no,0,',','.')."</b><br /><i>(".number_format($tot_no*100/$tot_validi,2)." %)</i></td>";}
316 $righet .= "<td><b>".number_format($tot_validi,0,',','.')."</b><br /><i>(".($tot_voti ? number_format($tot_validi*100/$tot_voti,2):'0.00')." %)</i></td><td><b>"
317 .number_format($tot_nulli,0,',','.')."</b><br /><i>(".($tot_voti ? number_format($tot_nulli*100/$tot_voti,2):'0.00')." %)</i></td><td><b>".number_format($tot_bianchi,0,',','.')."</b><br /><i>(".($tot_voti ? number_format($tot_bianchi*100/$tot_voti,2):'0.00')." %)</i></td><td><b>".number_format($tot_contestati,0,',','.')."</b><br /><i>(".($tot_voti ? number_format($tot_contestati*100/$tot_voti,2):'0.00')." %)</i></td></tr>";
318 }else{
319 if ($genere==0 or ((($genere==5) or ($genere==3)) and $pag==1)){$righet .= "<td><b>".number_format($tot_si,0,',','.')."</b><br /><i>(0.00 %)</i></td><td><b>".number_format($tot_no,0,',','.')."</b><br /><i>(0.00 %)</i></td>";}
320 $righet .= "<td><b>0</b><br /><i>(0.00 %)</i></td><td><b>"
321 .number_format($tot_nulli,0,',','.')."</b><br /><i>(".($tot_voti ? number_format($tot_nulli*100/$tot_voti,2):'0,00')." %)</i></td><td><b>".number_format($tot_bianchi,0,',','.')."</b><br /><i>(".($tot_voti ? number_format($tot_bianchi*100/$tot_voti,2):'0,00')." %)</i></td><td><b>".number_format($tot_contestati,0,',','.')."</b><br /><i>(".($tot_voti ? number_format($tot_contestati*100/$tot_voti,2):'0,00')." %)</i></td></tr>";
322 }
323 }
324 $righe .= "</table>";
325 if(!isset($html)) $html='';
326 $html .= "$riga1";
327 $html .= $riga2."";
328 $html .= $righet;
329 $html .= $riga3;
330 $html .= $righe;
331
332
333 $html .="<div>";
334 if($genere==0){ //se e' referendum
335 if ($xls!='1' && $pdf!='1' && $csv!='1'){
336 #'Pagina precedente' e 'Pagina Successiva'
337 $cur=$num_ref;
338 if ($cur>1) {
339 $num_ref--;
340 $html .= "<a href=\"modules.php?name=Elezioni&amp;op=come&amp;file=index&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;info=votanti&amp;num_ref=$num_ref&amp;num_refs=$num_refs&amp;csv=$csv\">";
341 $html .= "[ <b>"._PREV_MATCH."</b> ]</a>";
342 }
343 if ($cur<$num_refs) {
344 $cur++;
345 $html .= "<a href=\"modules.php?name=Elezioni&amp;op=come&amp;file=index&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;info=votanti&amp;num_ref=$cur&amp;num_refs=$num_refs&amp;csv=$csv\">";
346
347 $html .= "[ <b>"._NEXT_MATCH."</b> ]</a>";
348 }
349}
350}
351if($genere==5 or $genere==3){ //se vi sono raggruppamenti
352 if($csv!=1 and $fascia>$limite){
353
354 $pag=($pag==0 ? 1:0);
355 $html .= "<a href=\"modules.php?name=Elezioni&amp;file=index&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;op=come&amp;info=votanti&amp;pag=$pag&amp;csv=$csv\"><b>";
356 if($pag) $html .= _VOTIL;
357 //_CONTR_CONS;
358 else $html .= _VOTIE;
359 //_CONTR_ESPR;
360 $html .= "</b></a>";
361 }
362 }
363
364
365if($csv==1){
366 $data=date("d-m-y G:i");
367 $html .="<br/><div><i>Stampato: $data</i></div>";
368 $html .="<br/><i>Eleonline by l. apolito & r. gigli - www.eleonline.it</i>";
369 //$html .= $html;
370
371}
372$html .= "</div>";
373
374
375############### stampa
376if ($xls!='1' && $pdf!='1'){
377 echo "$datipdf $html";
378}elseif($xls=="1"){
379 $nomefile="votanti.xls";
380 header ("Content-Type: application/vnd.ms-excel");
381 header ("Content-Disposition: inline; filename=$nomefile");
382
383 echo "$datipdf";
384 echo "$html \n";
385}elseif($pdf=='1'){
386 $nomefile="$descr_cons votanti.pdf";
387
388 $stampa ="$datipdf $html";
389
390 require_once('inc/hpdf403/html2pdf.class.php');
391 $html2pdf = new HTML2PDF('L','A4', 'it');
392 $html2pdf->WriteHTML($stampa, isset($_GET['vuehtml']));
393 $html2pdf->Output($nomefile);
394}
395
396
397if($csv!=1 ) include ("footer.php");
398
399
400
401?>
Note: See TracBrowser for help on using the repository browser.