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

Last change on this file since 67 was 64, checked in by roby, 15 years ago

icorretto calcolo percentuali in visualizzazione riepilogo voti (da completare con arrotondamento percentuali) + vari aggiustamenti

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