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

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