source: trunk/client/modules/Elezioni/affluenze.php@ 371

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

In client:

  • rivista la funzione di esportazione pdf, xls e stampe
  • tema futura2: eliminato il taglio a 30 caratteri del nome della consultazione
  • modificata la barra da 2D a 3D per i grafici di affluenza e votanti

In admin:

  • corretta la segnalazione di errore per rosatellum su incongruità di voti al solo gruppo diversi dalla somma dei viti alle liste collegate
  • inserito check box per eliminazione del file della mappa nella riga di inserimento sede
File size: 14.2 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 ("You can't access this file directly...");
11}
12
13require_once('inc/hpdf5/autoload.php');
14use Spipu\Html2Pdf\Html2Pdf;
15use Spipu\Html2Pdf\Exception\Html2PdfException;
16use Spipu\Html2Pdf\Exception\ExceptionFormatter;
17
18if (isset($param['id_cons_gen'])) $id_cons_gen=intval($param['id_cons_gen']); else $id_cons_gen='';
19if (isset($param['num_ref'])) $num_ref=intval($param['num_ref']);
20if (isset($param['num_refs'])) $num_refs=intval($param['num_refs']);
21if (isset($param['id_comune'])) $id_comune=intval($param['id_comune']);
22if (isset($param['xls'])) $xls=intval($param['xls']);
23if (isset($param['pdf'])) $pdf=intval($param['pdf']);
24$sql="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'";
25$res = $dbi->prepare("$sql");
26$res->execute();
27list($tipo_cons,$genere,$id_cons) = $res->fetch(PDO::FETCH_NUM);
28global $lang,$circo,$id_circ;
29
30if (isset($circo) and $circo) $circos="and t2.id_circ='$id_circ'";
31else $circos='';
32
33# testata
34include_once("modules/Elezioni/language/lang-$lang.php");
35if($csv==1){
36 include_once("modules/Elezioni/funzioni.php");
37
38 $sql="SELECT descrizione FROM ".$prefix."_ele_comuni where id_comune='$id_comune' ";
39 $res = $dbi->prepare("$sql");
40 $res->execute();
41 list($descr_com) = $res->fetch(PDO::FETCH_NUM);
42 $descr_com =stripslashes($descr_com);
43 $datipdf .= "<div style=\"margin:0px auto; text-align:center;\">";
44 $siteistat=$id_comune;
45 # salva sull'hardisk lo stemma del comune
46 $logo=verificasimbolo();
47 $immagine= "<img src=\"modules/Elezioni/images/$logo\" alt=\"logo\" align=\"left\"/>";
48
49 if($xls!=1) $datipdf .= "<table><tr><td>$immagine</td><td>";
50
51 $datipdf .= ""._COMUNE." $descr_com <br />
52 "._RISULTA." "._CONSULTA."<br/ >";
53 $datipdf .= "$descr_cons<br />"._DISCLAIMER."
54 <br /><b>"._DETTAGLIO." "._AFFLUENZE."</b>";
55 if($xls!=1) $datipdf .= "</td></tr></table>";
56 $datipdf .="</div>";
57
58 $html = "<style type=\"text/css\">
59 <!--
60
61 .td-89 {
62 width: 89%;
63 border: 1px;
64 text-align: left;
65 }
66 .td-vuoto {
67
68 width: 100%;
69 border: 1px;
70 text-align: left;
71
72}
73
74
75 .td-5 {
76
77 margin: 0px 0 0 0px;
78 width: 5%;
79 /*border: none;*/
80 padding: 0px;
81
82 text-align: center;
83 }
84
85
86
87 .bggray {
88 background: #ffffff;
89 FONT-SIZE: 13px;
90 FONT-FAMILY: Helvetica;
91 border: 1px;
92 }
93
94 .bggray2 {
95 background: #EFEFEF;
96 FONT-SIZE: 13px;
97 FONT-FAMILY: Helvetica;
98 border: 1px;
99 }
100 -->
101 </style>";
102
103
104
105
106}
107
108
109
110
111
112
113
114 // referendum
115
116 $posref='';
117 if (!IsSet($num_ref)) {
118 $num_ref=1;
119 $sql="SELECT id_gruppo from ".$prefix."_ele_gruppo where id_cons='$id_cons'";
120 $resg = $dbi->prepare("$sql");
121 $resg->execute();
122 $num_refs= $resg->rowCount(); //quante pagine?
123 }
124 if($genere=='0'){
125 $sql="SELECT id_gruppo from ".$prefix."_ele_gruppo where id_cons='$id_cons' and num_gruppo='$num_ref'";
126 $resg = $dbi->prepare("$sql");
127 $resg->execute();
128 list($id_gruppo)=$resg->fetch(PDO::FETCH_NUM);
129 $posref="&amp;num_ref=$num_ref&amp;num_refs=$num_refs";
130
131 }
132 // icone stampa e grafici
133
134 if (!$csv){
135 if(!isset($html)) $html='';
136 $html .= "<div>
137 <a href=\"modules.php?name=Elezioni&amp;file=index&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;op=affluenze_graf\">
138 "._VER_GRAF." <img class=\"image\" src=\"modules/Elezioni/images/grafici.png\" alt=\"\" /></a>
139 <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=affluenze_sez$posref&amp;csv=1\">"._VER_STAMPA."
140 <img class=\"image\" src=\"modules/Elezioni/images/printer.png\" alt=\"\" /></a>
141 <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=affluenze_sez$posref&amp;csv=1&amp;xls=1\">
142 <img class=\"image\" src=\"modules/Elezioni/images/csv.gif\" alt=\"\" /></a>
143<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=affluenze_sez$posref&amp;csv=1&amp;pdf=1\">
144 <img class=\"image\" src=\"modules/Elezioni/images/pdf.gif\" alt=\"\" /></a>
145
146 </div>
147
148 <h2><b>"._DETTAGLIO." "._AFFLUENZE."</b></h2>";
149 }
150
151 // descrizione
152 if ($genere==0){
153 $sql="select descrizione from ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
154 $des = $dbi->prepare("$sql");
155 $des->execute();
156 list($descrizione)=$des->fetch(PDO::FETCH_NUM);
157 if(!isset($html)) $html='';
158 $html .= "<div><h4>$descrizione</h4></div>";
159 }
160
161
162 $cond= $genere==0 ? "and t3.id_gruppo='$id_gruppo'" : "";
163 $i=1;
164
165
166 $sql="SELECT num_sez,id_sez,t1.id_sede, t2.id_circ,maschi,femmine,(maschi+femmine) as elettori FROM ".$prefix."_ele_sezioni as t1, ".$prefix."_ele_sede as t2 where t1.id_cons='$id_cons' and t1.id_sede=t2.id_sede $circos order by num_sez";
167 $res = $dbi->prepare("$sql");
168 $res->execute();
169 while ($linka[$i++] = $res->fetch(PDO::FETCH_BOTH));
170# while (list($appo) = mysql_fetch_array($res)) {$i=$appo['num_sez']; $linka[$i] = $appo;echo "\nnum:$i:".$linka[$i]['num_sez'];}die();
171 $num_sez = $res->rowCount(); //numero totale delle sezioni
172 if (isset($linka[1]['num_sez'])) $sez_da=$linka[1]['num_sez']; else $sez_da=0;
173 $sez_a=$sez_da+$num_sez-1;
174 $tot_compl=0;$tot_u=0;$tot_d=0;
175// $ar['riga1'][0]="<hr>";
176 $tot= array();
177 $ar[0][0]="<b>TOTALI</b>";
178 $ar['perc'][0]="Perc.";
179// $ar['riga2'][0]="<hr>";
180# foreach($linka['num_sez'] as $i)
181$y=1;
182for ($i=$sez_da;$i<=$sez_a;$i++,$y++) {
183# $ar[$i]['numsez']=$i;
184 if(!isset($linka[$y]['num_sez'])) { $linka[$y]['num_sez']=0; $linka[$y]['elettori']=0;}
185 $z=$linka[$y]['num_sez'];
186 $ar[$z]['numsez']=$linka[$y]['num_sez'];
187 $ar[$z]['elettori']=number_format($linka[$y]['elettori'],0,',','.');
188 $tot_compl+=$linka[$y]['elettori'];
189 $tot_u+=$linka[$y]['maschi'];
190 $tot_d+=$linka[$y]['femmine'];
191
192
193 }
194 $ar[0][1]="<b>".number_format($tot_compl,0,',','.')."</b>";
195
196 $ar['perc'][1]=" ";
197
198 $perc_u=0;$perc_d=0;$perc_c=0;
199 $sql="SELECT t1.data,t1.orario FROM ".$prefix."_ele_rilaff as t1 left join ".$prefix."_ele_voti_parziale as t2 on t2.data=t1.data and t2.orario=t1.orario left join ".$prefix."_ele_cons_comune as t3 on t3.id_cons_gen=t1.id_cons_gen where t1.id_cons_gen='$id_cons_gen' and t3.id_cons=t2.id_cons group by t1.data,t1.orario order by t1.data,t1.orario";
200 $resril = $dbi->prepare("$sql");
201 $resril->execute();
202 $num_ril= $resril->rowCount(); //numero delle rilevazioni previste
203 if(!isset($html)) $html='';
204 $html .= "<table class=\"td-89\">";
205 $html .= "<tr class=\"bggray\"><td class=\"\">"._SEZIONI."</td><td>"._ISCR_SEZ."</td>";
206
207 $sql="SELECT orario,data FROM ".$prefix."_ele_rilaff where id_cons_gen=$id_cons_gen order by data desc,orario desc limit 0,1";
208 $resuo = $dbi->prepare("$sql");
209 $resuo->execute();
210 list($ultora,$ultdata)=$resuo->fetch(PDO::FETCH_NUM);
211
212
213 $sql="select t3.data,t3.orario,sum(t3.voti_complessivi),sum(t3.voti_uomini),sum(t3.voti_donne) from ".$prefix."_ele_voti_parziale as t3 left join ".$prefix."_ele_sezioni as t1 on t3.id_sez=t1.id_sez left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t3.id_cons='$id_cons' $circos $cond group by t3.data,t3.orario,t3.id_gruppo order by t3.data,t3.orario";
214 $ressomma = $dbi->prepare("$sql");
215 $ressomma->execute();
216
217
218$perc_u=array(); $perc_d=array(); $perc_c=array();
219 while (list($data,$ora,$somma,$votiu,$votid) = $ressomma->fetch(PDO::FETCH_NUM)) {
220 $perc_u[$data.$ora]=0;
221 $perc_d[$data.$ora]=0;
222 $perc_c[$data.$ora]=0;
223 if($votiu or $votid)
224# if(($data==$ultdata) and ($ora==$ultora))
225 {
226 $tot[$data.$ora]="<table style=\"width:180px;\"><tr class=\"bggray2\"><td style=\"width:33%;text-align:center;\">
227 <b>".number_format($votiu,0,',','.')."</b></td><td style=\"width:33%;text-align:center;\">
228 <b>".number_format($votid,0,',','.')."</b></td><td style=\"width:33%;text-align:center;\">
229 <b>".number_format($somma,0,',','.')."</b></td>
230 </tr></table>";
231 $perc_u[$data.$ora]=number_format($votiu*100/$tot_u,2);
232 $perc_d[$data.$ora]=number_format($votid*100/$tot_d,2);
233 $perc_c[$data.$ora]=number_format($somma*100/$tot_compl,2);
234 }
235 else
236 $tot[$data.$ora]=$somma;
237 }
238 $ud=0;$ora_rif="";
239 while (list($data1,$ora1) = $resril->fetch(PDO::FETCH_NUM))
240 {
241 $ud++;
242 list($hour, $minute, $second) = explode(":", $ora1);
243 $ora_ril=$hour.":".$minute;
244 $html .= "<td";
245 if ($ud==$num_ril and (isset($perc_u[$data1.$ora1]) or isset($perc_d[$data1.$ora1]))) {$ora_rif="$data1.$ora1";}
246 $html .= ">";
247 $data_a=form_data($data1);
248 $html .= "".$data_a."<br />"._ORE." ".$ora_ril;
249 $sql="SELECT count(data) FROM ".$prefix."_ele_voti_parziale as t3 left join ".$prefix."_ele_sezioni as t1 on t3.id_sez=t1.id_sez left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t1.id_cons='$id_cons' and data='$data1' and orario='$ora_ril' $circos group by t3.id_gruppo";
250 $resaff = $dbi->prepare("$sql");
251 $resaff->execute();
252 list($num_scr) = $resaff->fetch(PDO::FETCH_NUM); //numero delle sezioni inserite
253 $html .= "<br />"._SEZIONI." $num_scr "._SU." $num_sez";
254## if ($ud==$num_ril and ($perc_u or $perc_d)) $html .= "<br />
255 if (isset($perc_u[$data1.$ora1]) or isset($perc_d[$data1.$ora1])) $html .= "<br />
256
257 <table style=\"width:180px;\"><tr class=\"bggray\">
258 <th style=\"width:28%;text-align:center;\">"._UOMINI."</th>
259 <th style=\"width:28%;text-align:center;\">"._DONNE."</th>
260 <th style=\"width:28%;text-align:center;\">"._COMPLESSIVI."</th>
261 </tr></table>";
262
263 $html .= "</td>";
264
265 if (isset($tot[$data1.$ora1])){
266## if ($ora_rif=="$data1.$ora1")
267if (($perc_u[$data1.$ora1] or $perc_d[$data1.$ora1])) {
268 $ar['perc'][$data1.$ora1]="<table style=\"width:180px;\"><tr class=\"bggray2\">
269 <td style=\"width:33%;text-align:center;\"><b><i><span class=\"red\">".$perc_u[$data1.$ora1]."%</span></i></b></td>
270 <td style=\"width:33%;text-align:center;\"><b><i><span class=\"red\">".$perc_d[$data1.$ora1]."%</span></i></b></td>
271 <td style=\"width:33%;text-align:center;\" ><span class=\"red\"><b><i>".$perc_c[$data1.$ora1]."%</i></b></span></td>
272 </tr></table>";
273 $ar[0][$data1.$ora1]=$tot[$data1.$ora1];
274 }
275 else
276 {
277 $ar['perc'][$data1.$ora1]="<b><span class=\"red\"><i>
278 ".number_format($tot[$data1.$ora1]*100/$tot_compl,2)."%</i></span></b>";
279 $ar[0][$data1.$ora1]="<b>".(number_format($tot[$data1.$ora1],0,',','.'))."</b>";
280 }
281
282 if (intval(preg_match('/[1-9]/',$tot[$data1.$ora1]))>0) {
283#foreach($ar[['num_sez'] as $i)
284##########
285 $sql="select t1.num_sez from ".$prefix."_ele_sezioni as t1 left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t2.id_cons='$id_cons' $circos order by t1.num_sez ";
286 $resvoti = $dbi->prepare("$sql");
287 $resvoti->execute();
288
289###########
290# for ($i=$sez_da;$i<=$sez_a;$i++)
291 while (list($i)=$resvoti->fetch(PDO::FETCH_NUM))
292 {
293 $ar[$i][$data1.$ora1]="<span style=\"color: rgb(255, 0, 0);\">non rilevata</span>";
294 }
295 }
296 }
297 }
298 $sql="select t3.data,t3.orario,t1.num_sez,voti_uomini, voti_donne, voti_complessivi from ".$prefix."_ele_voti_parziale as t3 left join ".$prefix."_ele_sezioni as t1 on t3.id_sez=t1.id_sez left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t3.id_cons='$id_cons' $circos $cond order by data,orario,t1.num_sez ";
299 $resvoti = $dbi->prepare("$sql");
300 $resvoti->execute();
301 $ud=0;
302 while (list($data,$ora,$numsez,$uomini,$donne,$complessivi) = $resvoti->fetch(PDO::FETCH_NUM)) {
303# if ($ora_rif=="$data.$ora")
304 if(($uomini+$donne)>0)
305 $ar[$numsez][$data.$ora]="<table style=\"width:180px;\"><tr class=\"bggray2\">
306 <td style=\"width:33%;text-align:center;\">$uomini</td>
307 <td style=\"width:33%;text-align:center;\">$donne</td>
308 <td style=\"width:33%;text-align:center;\">$complessivi</td>
309 </tr></table>";
310 else
311 $ar[$numsez][$data.$ora]=$complessivi;
312 }
313 $html .= "</tr>";
314
315 foreach ($ar as $i => $arr) {
316 $html .= "<tr class=\"bggray2\">";
317 foreach ($arr as $valore)
318 {
319
320 $html .= "<td class=\"bggray2\" style=\"text-align:center;\">$valore</td>";
321 }
322 $html .= "</tr>";
323 }
324
325
326
327 $html .= "</table>";
328
329 if($genere==0){ //se e' referendum
330 #'Pagina precedente' e 'Pagina Successiva'
331 if ($xls!='1' && $pdf!='1' && $csv!='1'){
332 $html .= "<div class=\"modulo\">";
333 $cur=$num_ref;
334 if ($cur>1) {
335
336 $num_ref--;
337 $html .= "<a href=\"modules.php?name=Elezioni&amp;op=come&amp;info=affluenze_sez&amp;id_cons_gen=$id_cons_gen&amp;num_ref=$num_ref&amp;num_refs=$num_refs&amp;id_comune=$id_comune\">";
338 $html .= "[ <b>"._PREV_MATCH."</b> ] </a>";
339 }
340 if ($cur<$num_refs) {
341 $cur++;
342 $html .= "<a href=\"modules.php?name=Elezioni&amp;op=come&amp;info=affluenze_sez&amp;id_cons_gen=$id_cons_gen&amp;num_ref=$cur&amp;num_refs=$num_refs&amp;id_comune=$id_comune\">";
343 $html .= "[ <b>"._NEXT_MATCH."</b> ] </a>";
344 }
345 $html .= "</div>";
346 }
347}
348
349if(!isset($style)) $style='';
350if($csv==1){
351 $data=date("d-m-y G:i");
352 $style .="\t\t\n<br/><br/><br/><div style=\"margin:0px auto;text-align:center;\"><i>Stampato: $data</i></div>";
353 $style .="<br/><div style=\"text-align:center;\"><i>Eleonline by luciano apolito e roberto gigli - www.eleonline.it</i></div>";
354 $style .= "<br/> ";
355
356}
357//$html .= "</div>";
358
359
360############### stampa
361if ($xls!='1' && $pdf!='1'){
362 echo "$datipdf $html $style";
363
364}elseif($xls=="1"){
365 $nomefile="affluenze.xls";
366 header ("Content-Type: application/vnd.ms-excel");
367 header ("Content-Disposition: inline; filename=$nomefile");
368 header("Pragma: no-cache");
369 header("Expires: 0");
370 $datipdf = mb_convert_encoding($datipdf , "HTML-ENTITIES", "UTF-8");
371 echo "$datipdf";
372 echo "$html \t\n $style";
373}elseif($pdf=='1'){
374 $nomefile="$descr_cons affluenze.pdf";
375
376 $stampa ="$datipdf $html $style";
377
378 $html2pdf = new Html2Pdf('P','A4', 'it');
379 $html2pdf->WriteHTML($stampa, isset($_GET['vuehtml']));
380 $html2pdf->Output($nomefile);
381}
382
383
384if($csv!=1 ) include ("footer.php");
385
386?>
Note: See TracBrowser for help on using the repository browser.