source: trunk/client/modules/Elezioni/affluenzephp5.php@ 360

Last change on this file since 360 was 348, checked in by roby, 3 years ago

Ripristino compatibilità con php <= 5.6

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