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

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