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

Last change on this file since 322 was 265, checked in by roby, 6 years ago
File size: 13.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 ("You can't access this file directly...");
11}
12
13
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 $sez_da=$linka[1]['num_sez'];
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 $z=$linka[$y]['num_sez'];
182 $ar[$z]['numsez']=$linka[$y]['num_sez'];
183 $ar[$z]['elettori']=number_format($linka[$y]['elettori'],0,',','.');
184 $tot_compl+=$linka[$y]['elettori'];
185 $tot_u+=$linka[$y]['maschi'];
186 $tot_d+=$linka[$y]['femmine'];
187
188
189 }
190 $ar[0][1]="<b>".number_format($tot_compl,0,',','.')."</b>";
191
192 $ar['perc'][1]=" ";
193
194 $perc_u=0;$perc_d=0;$perc_c=0;
195 $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";
196 $resril = $dbi->prepare("$sql");
197 $resril->execute();
198 $num_ril= $resril->rowCount(); //numero delle rilevazioni previste
199 if(!isset($html)) $html='';
200 $html .= "<table class=\"td-89\">";
201 $html .= "<tr class=\"bggray\"><td class=\"\">"._SEZIONI."</td><td>"._ISCR_SEZ."</td>";
202
203 $sql="SELECT orario,data FROM ".$prefix."_ele_rilaff where id_cons_gen=$id_cons_gen order by data desc,orario desc limit 0,1";
204 $resuo = $dbi->prepare("$sql");
205 $resuo->execute();
206 list($ultora,$ultdata)=$resuo->fetch(PDO::FETCH_NUM);
207
208
209 $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";
210 $ressomma = $dbi->prepare("$sql");
211 $ressomma->execute();
212
213
214$perc_u=array(); $perc_d=array(); $perc_c=array();
215 while (list($data,$ora,$somma,$votiu,$votid) = $ressomma->fetch(PDO::FETCH_NUM)) {
216 $perc_u[$data.$ora]=0;
217 $perc_d[$data.$ora]=0;
218 $perc_c[$data.$ora]=0;
219 if($votiu or $votid)
220# if(($data==$ultdata) and ($ora==$ultora))
221 {
222 $tot[$data.$ora]="<table class=\"td-89\" width=\"100%\"><tr class=\"bggray2\"><td class=\"td-30\">
223 <b>".number_format($votiu,0,',','.')."</b></td><td class=\"td-30\">
224 <b>".number_format($votid,0,',','.')."</b></td><td>
225 <b>".number_format($somma,0,',','.')."</b></td>
226 </tr></table>";
227 $perc_u[$data.$ora]=number_format($votiu*100/$tot_u,2);
228 $perc_d[$data.$ora]=number_format($votid*100/$tot_d,2);
229 $perc_c[$data.$ora]=number_format($somma*100/$tot_compl,2);
230 }
231 else
232 $tot[$data.$ora]=$somma;
233 }
234 $ud=0;$ora_rif="";
235 while (list($data1,$ora1) = $resril->fetch(PDO::FETCH_NUM))
236 {
237 $ud++;
238 list($hour, $minute, $second) = explode(":", $ora1);
239 $ora_ril=$hour.":".$minute;
240 $html .= "<td";
241 if ($ud==$num_ril and ($perc_u[$data1.$ora1] or $perc_d[$data1.$ora1])) {$ora_rif="$data1.$ora1";}
242 $html .= ">";
243 $data_a=form_data($data1);
244 $html .= "".$data_a."<br />"._ORE." ".$ora_ril;
245 $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";
246 $resaff = $dbi->prepare("$sql");
247 $resaff->execute();
248 list($num_scr) = $resaff->fetch(PDO::FETCH_NUM); //numero delle sezioni inserite
249 $html .= "<br />"._SEZIONI." $num_scr "._SU." $num_sez";
250## if ($ud==$num_ril and ($perc_u or $perc_d)) $html .= "<br />
251 if (($perc_u[$data1.$ora1] or $perc_d[$data1.$ora1])) $html .= "<br />
252
253 <table class=\"td-vuoto\" width=\"100%\"><tr class=\"bggray\">
254 <th class=\"td-30\">"._UOMINI."</th>
255 <th class=\"td-30\">"._DONNE."</th>
256 <th>"._COMPLESSIVI."</th>
257 </tr></table>";
258
259 $html .= "</td>";
260
261 if (isset($tot[$data1.$ora1])){
262## if ($ora_rif=="$data1.$ora1")
263if (($perc_u[$data1.$ora1] or $perc_d[$data1.$ora1])) {
264 $ar['perc'][$data1.$ora1]="<table class=\"td-vuoto\" width=\"100%\"><tr class=\"bggray2\">
265 <td class=\"td-30\"><b><i><span class=\"red\">".$perc_u[$data1.$ora1]."%</span></i></b></td>
266 <td class=\"td-30\"><b><i><span class=\"red\">".$perc_d[$data1.$ora1]."%</span></i></b></td>
267 <td ><span class=\"red\"><b><i>".$perc_c[$data1.$ora1]."%</i></b></span></td>
268 </tr></table>";
269 $ar[0][$data1.$ora1]=$tot[$data1.$ora1];
270 }
271 else
272 {
273 $ar['perc'][$data1.$ora1]="<b><span class=\"red\"><i>
274 ".number_format($tot[$data1.$ora1]*100/$tot_compl,2)."%</i></span></b>";
275 $ar[0][$data1.$ora1]="<b>".(number_format($tot[$data1.$ora1],0,',','.'))."</b>";
276 }
277
278 if (intval(preg_match('/[1-9]/',$tot[$data1.$ora1]))>0) {
279#foreach($ar[['num_sez'] as $i)
280##########
281 $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 ";
282 $resvoti = $dbi->prepare("$sql");
283 $resvoti->execute();
284
285###########
286# for ($i=$sez_da;$i<=$sez_a;$i++)
287 while (list($i)=$resvoti->fetch(PDO::FETCH_NUM))
288 {
289 $ar[$i][$data1.$ora1]="<span style=\"color: rgb(255, 0, 0);\">non rilevata</span>";
290 }
291 }
292 }
293 }
294 $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 ";
295 $resvoti = $dbi->prepare("$sql");
296 $resvoti->execute();
297 $ud=0;
298 while (list($data,$ora,$numsez,$uomini,$donne,$complessivi) = $resvoti->fetch(PDO::FETCH_NUM)) {
299# if ($ora_rif=="$data.$ora")
300 if(($uomini+$donne)>0)
301 $ar[$numsez][$data.$ora]="<table class=\"td-vuoto\" width=\"100%\"><tr class=\"bggray2\">
302 <td class=\"td-30\" width=\"33%\">$uomini</td>
303 <td class=\"td-30\" width=\"33%\">$donne</td>
304 <td >$complessivi</td>
305 </tr></table>";
306 else
307 $ar[$numsez][$data.$ora]=$complessivi;
308 }
309 $html .= "</tr>";
310
311 foreach ($ar as $i => $arr) {
312 $html .= "<tr class=\"bggray2\">";
313 foreach ($arr as $valore)
314 {
315
316 $html .= "<td class=\"bggray2\">$valore</td>";
317 }
318 $html .= "</tr>";
319 }
320
321
322
323 $html .= "</table>";
324
325 if($genere==0){ //se e' referendum
326 #'Pagina precedente' e 'Pagina Successiva'
327 if ($xls!='1' && $pdf!='1' && $csv!='1'){
328 $html .= "<div class=\"modulo\">";
329 $cur=$num_ref;
330 if ($cur>1) {
331
332 $num_ref--;
333 $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\">";
334 $html .= "[ <b>"._PREV_MATCH."</b> ] </a>";
335 }
336 if ($cur<$num_refs) {
337 $cur++;
338 $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\">";
339 $html .= "[ <b>"._NEXT_MATCH."</b> ] </a>";
340 }
341 $html .= "</div>";
342 }
343}
344
345if(!isset($style)) $style='';
346if($csv==1){
347 $data=date("d-m-y G:i");
348 $style .="\t\t\n<br/><br/><br/><div style=\"margin:0px auto;text-align:center;\"><i>Stampato: $data</i></div>";
349 $style .="<br/><div style=\"text-align:center;\"><i>Eleonline by luciano apolito & roberto gigli - www.eleonline.it</i></div>";
350 $style .= "<br/> ";
351
352}
353//$html .= "</div>";
354
355
356############### stampa
357if ($xls!='1' && $pdf!='1'){
358 echo "$datipdf $html $style";
359
360}elseif($xls=="1"){
361 $nomefile="affluenze.xls";
362 header ("Content-Type: application/vnd.ms-excel");
363 header ("Content-Disposition: inline; filename=$nomefile");
364 echo "$datipdf";
365 echo "$html \t\n $style";
366}elseif($pdf=='1'){
367 $nomefile="$descr_cons affluenze.pdf";
368
369 $stampa ="$datipdf $html $style";
370
371 require_once('inc/hpdf403/html2pdf.class.php');
372 $html2pdf = new HTML2PDF('L','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.