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

Last change on this file since 94 was 82, checked in by roby, 14 years ago

client - visualizza schede scrutinate e percentuale di scutinio al posto di sezioni
client - corretta la gestione delle affluenze per collegio

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