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

Last change on this file since 80 was 71, checked in by roby, 15 years ago

client: visualizzazione affluenze per maschi e femmine anche per orari precedenti l'ultima rilevazione

File size: 13.5 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
161 $ar[$i]['numsez']=$linka[$y]['num_sez'];
162 $ar[$i]['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 $ar[0][1]="<b>".number_format($tot_compl,0,',','.')."</b>";
169
170 $ar['perc'][1]=" ";
171
172 $perc_u=0;$perc_d=0;$perc_c=0;
173# $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);
174 $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);
175 $num_ril= mysql_num_rows($resril); //numero delle rilevazioni previste
176 if(!isset($html)) $html='';
177 $html .= "<table class=\"td-89\">";
178 $html .= "<tr class=\"bggray\"><td class=\"\">"._SEZIONI."</td><td>"._ISCR_SEZ."</td>";
179# $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);
180
181 $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);
182 list($ultora,$ultdata)=mysql_fetch_row($resuo);
183
184
185
186 $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);
187#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 ");
188$perc_u=array(); $perc_d=array(); $perc_c=array();
189 while (list($data,$ora,$somma,$votiu,$votid) = mysql_fetch_row($ressomma)) {
190 $perc_u[$data.$ora]=0;
191 $perc_d[$data.$ora]=0;
192 $perc_c[$data.$ora]=0;
193 if($votiu or $votid)
194# if(($data==$ultdata) and ($ora==$ultora))
195 {
196 $tot[$data.$ora]="<table class=\"td-89\" width=\"100%\"><tr class=\"bggray2\"><td class=\"td-30\">
197 <b>".number_format($votiu,0,',','.')."</b></td><td class=\"td-30\">
198 <b>".number_format($votid,0,',','.')."</b></td><td>
199 <b>".number_format($somma,0,',','.')."</b></td>
200 </tr></table>";
201 $perc_u[$data.$ora]=number_format($votiu*100/$tot_u,2);
202 $perc_d[$data.$ora]=number_format($votid*100/$tot_d,2);
203 $perc_c[$data.$ora]=number_format($somma*100/$tot_compl,2);
204 }
205 else
206 $tot[$data.$ora]=$somma;
207 }
208 $ud=0;$ora_rif="";
209 while (list($data1,$ora1) = mysql_fetch_row($resril))
210 {
211 $ud++;
212 list($hour, $minute, $second) = explode(":", $ora1);
213 $ora_ril=$hour.":".$minute;
214 $html .= "<td";
215 if ($ud==$num_ril and ($perc_u[$data1.$ora1] or $perc_d[$data1.$ora1])) {$ora_rif="$data1.$ora1";}
216 $html .= ">";
217 $data_a=form_data($data1);
218 $html .= "".$data_a."<br />"._ORE." ".$ora_ril;
219 $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);
220 list($num_scr) = mysql_fetch_row($resaff); //numero delle sezioni inserite
221 $html .= "<br />"._SEZIONI." $num_scr "._SU." $num_sez";
222## if ($ud==$num_ril and ($perc_u or $perc_d)) $html .= "<br />
223 if (($perc_u[$data1.$ora1] or $perc_d[$data1.$ora1])) $html .= "<br />
224
225 <table class=\"td-vuoto\" width=\"100%\"><tr class=\"bggray\">
226 <th class=\"td-30\">"._UOMINI."</th>
227 <th class=\"td-30\">"._DONNE."</th>
228 <th>"._COMPLESSIVI."</th>
229 </tr></table>";
230
231 $html .= "</td>";
232
233 if (isset($tot[$data1.$ora1])){
234## if ($ora_rif=="$data1.$ora1")
235if (($perc_u[$data1.$ora1] or $perc_d[$data1.$ora1])) {
236 $ar['perc'][$data1.$ora1]="<table class=\"td-vuoto\" width=\"100%\"><tr class=\"bggray2\">
237 <td class=\"td-30\"><b><i><span class=\"red\">".$perc_u[$data1.$ora1]."%</span></i></b></td>
238 <td class=\"td-30\"><b><i><span class=\"red\">".$perc_d[$data1.$ora1]."%</span></i></b></td>
239 <td ><span class=\"red\"><b><i>".$perc_c[$data1.$ora1]."%</i></b></span></td>
240 </tr></table>";
241 $ar[0][$data1.$ora1]=$tot[$data1.$ora1];
242 }
243 else
244 {
245 $ar['perc'][$data1.$ora1]="<b><span class=\"red\"><i>
246 ".number_format($tot[$data1.$ora1]*100/$tot_compl,2)."%</i></span></b>";
247 $ar[0][$data1.$ora1]="<b>".(number_format($tot[$data1.$ora1],0,',','.'))."</b>";
248 }
249
250 if (intval(preg_match('/[1-9]/',$tot[$data1.$ora1]))>0) {
251#foreach($ar[['num_sez'] as $i)
252 for ($i=$sez_da;$i<=$sez_a;$i++)
253 {
254 $ar[$i][$data1.$ora1]="<span style=\"color: rgb(255, 0, 0);\">non rilevata</span>";
255 }
256 }
257 }
258 }
259 $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);
260# $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);
261 $ud=0;
262#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 ");
263 while (list($data,$ora,$numsez,$uomini,$donne,$complessivi) = mysql_fetch_row($resvoti)) {
264# if ($ora_rif=="$data.$ora")
265 if(($uomini+$donne)>0)
266 $ar[$numsez][$data.$ora]="<table class=\"td-vuoto\" width=\"100%\"><tr class=\"bggray2\">
267 <td class=\"td-30\" width=\"33%\">$uomini</td>
268 <td class=\"td-30\" width=\"33%\">$donne</td>
269 <td >$complessivi</td>
270 </tr></table>";
271 else
272 $ar[$numsez][$data.$ora]=$complessivi;
273 }
274 $html .= "</tr>";
275
276 foreach ($ar as $i => $arr) {
277 $html .= "<tr class=\"bggray2\">";
278 foreach ($arr as $valore)
279 {
280
281 $html .= "<td class=\"bggray2\">$valore</td>";
282 }
283 $html .= "</tr>";
284 }
285
286
287
288 $html .= "</table>";
289
290 if($genere==0){ //se e' referendum
291 #'Pagina precedente' e 'Pagina Successiva'
292 $html .= "<div class=\"modulo\">";
293 $cur=$num_ref;
294 if ($cur>1) {
295
296 $num_ref--;
297 $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\">";
298 $html .= "[ <b>"._PREV_MATCH."</b> ] </a>";
299 }
300 if ($cur<$num_refs) {
301 $cur++;
302 $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\">";
303 $html .= "[ <b>"._NEXT_MATCH."</b> ] </a>";
304 }
305 $html .= "</div>";
306 }
307
308
309if(!isset($style)) $style='';
310if($csv==1){
311 $data=date("d-m-y G:i");
312 $style .="\t\t\n<br/><br/><br/><div style=\"margin:0px auto;text-align:center;\"><i>Stampato: $data</i></div>";
313 $style .="<br/><div style=\"text-align:center;\"><i>Eleonline by l. apolito & r. gigli - www.eleonline.it</i></div>";
314 $style .= "<br/> ";
315
316}
317$html .= "</div>";
318
319
320############### stampa
321if ($xls!='1'){
322 echo "$datipdf $html $style";
323}else{
324 $nomefile="export.xls";
325 header ("Content-Type: application/vnd.ms-excel");
326 header ("Content-Disposition: inline; filename=$nomefile");
327
328 echo "$datipdf";
329 echo "$html \t\n $style";
330}
331
332
333if($csv!=1 ) include ("footer.php");
334
335?>
Note: See TracBrowser for help on using the repository browser.