source: trunk/client/modules/Elezioni/affluenze-inc.php@ 430

Last change on this file since 430 was 425, checked in by roby, 5 months ago
  • CLIENT

-- ulteriore modifica alla funzione di calcolo per l'attribuzione dei seggi per compatibilità con alcune installazioni
-- modifica alla funzione di visualizzazione dell'elenco delle affluenze per la gestione di casi particolari

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