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

Last change on this file since 2 was 2, checked in by root, 15 years ago

importo il progetto

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