source: trunk/client/modules/Elezioni/gruppo.php@ 65

Last change on this file since 65 was 65, checked in by roby, 14 years ago

creata funzione per gestione calcolo percentuali in visualizzazione completa di arrotondamento (applicata solo ai totali in visualizzazione griglia per verifica)

File size: 31.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 luciano@aniene.net rgigli@libero.it */
7/************************************************************************/
8
9if (!defined('MODULE_FILE')) {
10 die ("You can't access this file directly...");
11}
12if ($xls=='1') include("modules/Elezioni/language/lang-$lang.php");
13
14
15$param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ?
16 $_GET : $_POST;
17
18if (isset($param['id_cons_gen'])) $id_cons_gen=intval($param['id_cons_gen']); else $id_cons_gen='';
19//if (isset($param['op'])) $op=$param['op']; else $op='';
20if (isset($param['minsez'])) $minsez=intval($param['minsez']); else $minsez='';
21if (isset($param['id_lista'])) $id_lista=intval($param['id_lista']); else $id_lista='';
22if (isset($param['id_circ'])) $id_circ=intval($param['id_circ']); else $id_circ='';
23if (isset($param['csv'])) $csv=intval($param['csv']); else $csv='';
24if (isset($param['min'])) $min=intval($param['min']); else $min= 0;
25if (isset($param['orvert'])) $orvert=intval($param['orvert']); else $orvert='';
26if (isset($param['offset'])) $offset=intval($param['offset']); else $offset='';
27if (isset($param['offsetsez'])) $offsetsez=intval($param['offsetsez']); else $offsetsez='';
28if (isset($param['perc'])) $perc=$param['perc']; else $perc='';
29if (isset($param['info'])) get_magic_quotes_gpc() ? $info=$param['info']:$info=addslashes($param['info']); else $info='';
30if (isset($param['files'])) get_magic_quotes_gpc() ? $files=$param['files']:$files=addslashes($param['files']); else $files='';
31if (isset($param['voti_lista'])) $voti_lista=intval($param['voti_lista']); else $voti_lista= 0;
32if (isset($param['perc_lista'])) $perc_lista=$param['perc_lista']; else $perc_lista= 0;
33if (isset($param['lettera'])) get_magic_quotes_gpc() ? $lettera=$param['lettera']:$lettera=addslashes($param['lettera']); else $lettera='';
34if (isset($param['id_gruppo'])) $id_gruppo=intval($param['id_gruppo']); else $id_gruppo='';
35#if (isset($param['tipo_cons'])) $tipo_cons=intval($param['tipo_cons']); else $tipo_cons='';
36
37# anti-xss nov. 2009
38$id_comune=htmlentities($id_comune);
39$id_comune=intval($id_comune);
40$perc=htmlentities($perc);
41$perc_lista=floatval($perc_lista);
42#$datipdf= htmlentities($datipdf);
43$op= htmlentities($op);
44$info= htmlentities($info);
45$files=htmlentities($files);
46$lettera=htmlentities($lettera);
47
48
49
50
51
52
53
54include("crea_pagina.php");
55$res = mysql_query("SELECT descrizione from ".$prefix."_ele_comuni where id_comune='$id_comune'" , $dbi);
56list($descr_comune) = mysql_fetch_row($res);
57
58$res = mysql_query("SELECT t1.descrizione, t1.tipo_cons,t2.genere, t2.voto_g, t2.voto_l, t2.voto_c, t2.circo FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_tipo as t2 where t1.tipo_cons=t2.tipo_cons and t1.id_cons_gen='$id_cons_gen' ", $dbi);
59list($descr_cons,$tipo_cons,$genere,$votog,$votol,$votoc,$circo) = mysql_fetch_row($res);
60$res = mysql_query("SELECT t2.id_cons FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_cons_gen='$id_cons_gen' and t2.id_comune='$id_comune'" , $dbi);
61list($id_cons) = mysql_fetch_row($res);
62
63
64
65
66
67
68
69////////////////////////////////////////////////////////////
70// Visualizza i dati per liste, gruppi e referendum, per sezione o circoscrizione
71////////////////////////////////////////////////////////////
72
73function gruppo_circo(){
74 global $prefix, $dbi, $descr_cons, $id_cons, $id_cons_gen,$tipo_cons,$votog,$votol,$votoc,$circo, $genere,$id_gruppo,$id_lista,$bgcolor1,$bgcolor2,$id_comune,$descr_comune,$id_circ;
75 global $id_comune,$id_cons_gen,$op,$minsez,$id_lista,$id_circ,$csv,$min,
76 $orvert,$offset,$offsetsez,$perc,$info,$files;
77 #Denominazione pagine
78 if($op=="gruppo_circo") $pagina=_GRUPPO." "._PER." "._CIRCO;
79 if($op=="gruppo_sezione") $pagina=_GRUPPO." "._PER." "._SEZIONI;
80 if($op=="lista_circo") $pagina=_LISTA." "._PER." "._CIRCO;
81 if($op=="lista_sezione") $pagina=_LISTA." "._PER." "._SEZIONI;
82 if($op=="candidato_circo") $pagina=_CONSI." "._PER." "._CIRCO;
83 if($op=="candidato_sezione") $pagina=_CONSI." "._PER." "._SEZIONI;
84 if($op=="consiglieri") $pagina=_CALCONS;
85
86
87
88
89 if (strstr( $op,'circo')) { //$op=='gruppo_circo' or $op=='lista_circo') {
90 $tab1="circ";
91 $tab2="t5.num_circ,t5.descrizione";
92 $tab3="t5.num_circ";
93 $tipo1=_DA." "._CIRCO;
94 $tipo2=_CIRCOS;
95 $tipo3=_CIRCO;
96 }else{
97 $tab1="sez";
98 $tab2="t3.num_sez,''";
99 $tab3="t3.num_sez";
100 $tipo1=_DA." "._SEZIONE;
101 $tipo2=_SEZIONI;
102 $tipo3=_SEZIONE;
103 }
104 if (strstr( $op,"gruppo")){
105 $tab="gruppo";
106 }elseif (strstr( $op,'lista')) {
107 $tab="lista";
108 }else{
109 $tab="candidati";
110 }
111 if ($orvert) {
112 $righe='';
113 $colonne='checked';
114 }else{
115 $righe='checked';
116 $colonne='';
117 }
118 if ($genere>0) { //se non e' un referendum
119
120
121 $voticompl=0;
122 if (!($offset)) $offset=25;
123 if (!($min)) $min=1;
124 if (!($offsetsez)) $offsetsez=20;
125 if (!($minsez)) $minsez=1;
126 if ($min>$offset) {
127 $appo=$min;
128 $min=$offset;
129 $offset=$appo;
130 }
131 if ($minsez>$offsetsez) {
132 $appo=$minsez;
133 $minsez=$offsetsez;
134 $offsetsez=$appo;
135 }
136 if (!$csv){
137 echo "<form id=\"voti\" method=\"post\" action=\"modules.php\">";
138 echo "<div><input type=\"hidden\" name=\"pag\" value=\"modules.php?name=Elezioni&amp;op=$op&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;id_circ=$id_circ&amp;id_lista=\"></input>";
139 echo "<input type=\"hidden\" name=\"pagina\" value=\"modules.php?name=Elezioni&amp;op=$op&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;id_circ=\"></input>";
140 }
141 $condcirc='';
142 if ($circo){ //gestione circoscrizionali
143 if(!$id_circ){
144 $res_cir = mysql_query("SELECT id_circ from ".$prefix."_ele_circoscrizione where id_cons=$id_cons and num_circ=1",$dbi); //se non si e' scelta una circoscr. prende la prima
145 list($id_circ)=mysql_fetch_row($res_cir);
146 }
147 $res_cir = mysql_query("SELECT num_circ from ".$prefix."_ele_circoscrizione where id_circ=$id_circ",$dbi); //estrae il numero della circoscrizione
148 list($num_circ)=mysql_fetch_row($res_cir);
149 $condcirc="and id_circ=$id_circ"; //variabile aggiunta nelle select per le circ.
150 $res_sez = mysql_query("SELECT count(t1.num_sez) from ".$prefix."_ele_sezioni as t1, ".$prefix."_ele_sede as t2 where t1.id_cons=$id_cons and t1.id_sede=t2.id_sede and t2.id_circ=$id_circ",$dbi); //numero di sezioni nella circoscrizione
151 $res_min = mysql_query("SELECT min(t1.num_sez) from ".$prefix."_ele_sezioni as t1, ".$prefix."_ele_sede as t2 where t1.id_cons=$id_cons and t1.id_sede=t2.id_sede and t2.id_circ=$id_circ",$dbi); //setta minsez sulla prima sezione della circoscrizione
152 list($minsez)=mysql_fetch_row($res_min);
153 }
154 else
155 $res_sez = mysql_query("SELECT count(num_sez) from ".$prefix."_ele_sezioni where id_cons=$id_cons",$dbi);
156 list($tot_sez)=mysql_fetch_row($res_sez);
157 $num_sez=$tot_sez;//mysql_data_seek($res_sez,0);
158 if ($circo) $offsetsez=$num_sez+$minsez-1;//setta offsetsez sull'ultima sezione della circoscrizione
159 if(strstr( $op,"circo")) {
160 $res_sez = mysql_query("SELECT count(num_circ) from ".$prefix."_ele_circoscrizione where id_cons=$id_cons",$dbi); //estrae il numero delle circoscrizioni
161 list($num_sez)=mysql_fetch_row($res_sez);
162 }
163#Tolgo la scelta della circoscrizione o collegio perché gestita per tutte le pagine in index.php
164/* if ($circo){ // elenco per scelta circoscrizione
165 $res_sez = mysql_query("SELECT id_circ,descrizione,num_circ from ".$prefix."_ele_circoscrizione where id_cons=$id_cons",$dbi);
166 echo "<div >"._SCELTA_CIR.":
167 <select name=\"id_circ\" class=\"modulo\" onChange=\"top.location.href=this.form.pagina.value+this.form.id_circ.options[this.form.id_circ.selectedIndex].value;return false\">";
168 while(list($id_rif,$descrizione,$num_cir)=mysql_fetch_row($res_sez)) {
169 if (!$id_circ) $id_circ=$id_rif;
170 $sel = ($id_rif == $id_circ) ? "selected=\"selected\"" : "";
171 echo "<option value=\"$id_rif\" $sel>";
172 for ($j=strlen($num_cir);$j<2;$j++) { echo "&nbsp;&nbsp;";}
173 echo $num_cir.") ".$descrizione."</option>";
174 }
175 echo "</select></div>";
176
177 }
178*/
179 $visvot='';
180 if(strstr( $op,'candidato')){
181// $numliste=mysql_num_rows($res_lis);
182 $visvot="cand";
183 if (!$csv){
184 $res_lis = mysql_query("SELECT id_lista, descrizione,num_lista from ".$prefix."_ele_lista where id_cons=$id_cons $condcirc order by num_lista",$dbi);
185 //elenco delle liste per la scelta
186 echo "<p>Scegli la lista:
187 <select name=\"id_lista\" class=\"modulo\" onChange=\"top.location.href=this.form.pag.value+this.form.id_lista.options[this.form.id_lista.selectedIndex].value;return false\">";
188 while(list($id_rif,$descrizione,$num_lis) = mysql_fetch_row($res_lis)) {
189 if (!$id_lista) $id_lista=$id_rif;
190 $sel = ($id_rif == $id_lista) ? "selected=\"selected\"" : "";
191 echo "<option value=\"$id_rif\" $sel>";
192 for ($j=strlen($num_lis);$j<2;$j++) { echo "&nbsp;&nbsp;";}
193 echo $num_lis.") ".$descrizione."</option>";
194 }
195 echo "</select></p>";
196 }
197 $res_scr = mysql_query("SELECT count(t1.id_sez) from ".$prefix."_ele_voti_$tab as t1, ".$prefix."_ele_$tab as t2 where t2.id_lista=$id_lista and t1.id_cand=t2.id_cand group by t1.id_cand",$dbi);
198 $res_cand = mysql_query("SELECT id_cand, concat(cognome,' ', nome), num_cand from ".$prefix."_ele_$tab where id_cons=$id_cons and id_lista=$id_lista order by num_cand",$dbi);
199 if ($circo) $condcirc="and t5.id_circ=$id_circ";
200 $res_voti = mysql_query("select $tab2, t1.num_cand, concat(t1.cognome,' ', t1.nome), sum(t2.voti),'','','','',''
201 from ".$prefix."_ele_candidati as t1, ".$prefix."_ele_voti_candidati as t2, "
202 .$prefix."_ele_sezioni as t3, ".$prefix."_ele_sede as t4, ".$prefix."_ele_circoscrizione as t5
203 where t1.id_lista=$id_lista
204 and t1.id_cons=$id_cons
205 and t1.id_cand=t2.id_cand
206 and t2.id_sez=t3.id_sez
207 and t3.id_sede=t4.id_sede
208 and t4.id_circ=t5.id_circ $condcirc
209 group by t1.num_cand,$tab3
210 order by $tab3,t1.num_cand",$dbi);
211
212 }else{
213 if (!$csv)
214 echo "<input type=\"hidden\" name=\"id_lista\" value=\"\"></input>";
215
216 // camera e senato nel 2006 aggiunte le somme della coalizione
217 // divise per circo e sez. in quanto nella tabella del gruppo
218 // all'atto dell'immsione non viene fatta la somma
219 // quindi leggere prima i voti di lista e poi agganciali al gruppo
220 // la var $tab diviene lista, $tab15 diviene gruppo in caso di somma
221 // dei voti di lista...oltre naturalmnte alle condizioni messe in variabile
222 // 4 aprile 2006 by luc
223 if ($votog && $tab=="gruppo"){ // camera e senato 2006
224 $t="t9";
225 $tab="lista";
226 $tab15="gruppo";
227 $add_1= ",".$prefix."_ele_gruppo as t9";
228 $and_1="and t1.id_gruppo=t9.id_gruppo";
229 }else{
230 $t="t1";
231 $tab15=$tab;
232 $add_1='';
233 $and_1='';
234 }
235 // fine della modifica
236
237 $res_scr = mysql_query("SELECT count(id_sez) from ".$prefix."_ele_voti_$tab15 where id_cons='$id_cons' group by id_$tab15",$dbi); //numero sezioni scrutinate
238 $res_cand = mysql_query("SELECT id_$tab15, descrizione, num_$tab15 from ".$prefix."_ele_$tab15 where id_cons='$id_cons' $condcirc order by num_$tab15",$dbi);
239 if ($circo) $condcirc="and t5.id_circ=$id_circ";
240 if ($tab=="gruppo")
241 $votigl=" sum(t3.validi),sum(t3.nulli),sum(t3.bianchi),sum(t3.contestati),sum(t3.voti_nulli)";
242 else
243 if ($votog) $votigl=" (t3.validi_lista),(t3.nulli),(t3.bianchi),(t3.contestati_lista),(t3.voti_nulli_lista)";
244 else $votigl=" sum(t3.validi_lista),sum(t3.nulli),sum(t3.bianchi),sum(t3.contestati_lista),sum(t3.voti_nulli_lista)";
245
246
247
248
249
250 $res_voti = mysql_query("select $tab2, $t.num_$tab15, $t.descrizione, sum(t2.voti), $votigl
251 from
252 ".$prefix."_ele_$tab as t1,
253 ".$prefix."_ele_voti_$tab as t2,
254 ".$prefix."_ele_sezioni as t3,
255 ".$prefix."_ele_sede as t4,
256 ".$prefix."_ele_circoscrizione as t5
257 $add_1
258
259 where t1.id_cons=$id_cons
260 and t1.id_$tab=t2.id_$tab
261 $and_1
262
263 and t2.id_sez=t3.id_sez
264 and t3.id_sede=t4.id_sede
265 and t4.id_circ=t5.id_circ $condcirc
266
267
268 group by $t.num_$tab15,$tab3
269 order by $tab3,$t.num_$tab15",$dbi);
270 }
271 if ($res_scr) list($tot_scr)=mysql_fetch_row($res_scr);else $tot_scr=0;
272 if ($res_cand) $num_cand=mysql_num_rows($res_cand); else $num_cand=0;
273 if(!$circo){
274 if (!(0 < $minsez and $minsez<=$num_sez)) $minsez=1;
275 if (!(0<$offsetsez and $offsetsez<=$num_sez)) $offsetsez=$num_sez;
276 }
277 if (!(0 < $min and $min<=$num_cand)) $min=1;
278 if (!(0<$offset and $offset<=$num_cand)) $offset=$num_cand;
279 if (!$csv) {
280 echo "<br /><table>
281 <tr><td><h5>$pagina</h5></td></tr>";
282 echo "<tr><td>"._DA.":&nbsp; <select name=\"min\" class=\"modulo\">";
283 while(list($id_rif,$descrizione,$num_lis) = mysql_fetch_row($res_cand)) {
284 if (!$min) $min=$num_lis;
285 $sel = ($num_lis == $min) ? "selected=\"selected\"" : "";
286 echo "<option value=\"$num_lis\" $sel>";
287 for ($j=strlen($num_lis);$j<2;$j++) { echo "&nbsp;&nbsp;";}
288 echo $num_lis.") ".$descrizione."</option>";
289
290 }
291 echo "</select></td></tr>";
292 echo "<tr><td>&nbsp;&nbsp;"._A.":&nbsp; <select name=\"offset\" class=\"modulo\">";
293 mysql_data_seek($res_cand,0);
294 while(list($id_rif,$descrizione,$num_lis) = mysql_fetch_row($res_cand)) {
295 if (!$offset) $offset=$num_lis;
296 $sel = ($num_lis == $offset) ? "selected=\"selected\"" : "";
297 echo "<option value=\"$num_lis\" $sel>";
298 for ($j=strlen($num_lis);$j<2;$j++) { echo "&nbsp;&nbsp;";}
299 echo $num_lis.") ".$descrizione."</option>";
300
301 }
302 echo "</select></td></tr></table>";
303 echo "<table><tr><td>";
304 if(!$circo)
305 echo "$tipo1 n. <input name=\"minsez\" value=\"$minsez\" size=\"4\" ></input>";
306 echo "</td>";
307 echo "<td>";
308 if(!$circo)
309 echo _A." n. <input name=\"offsetsez\" value=\"$offsetsez\" size=\"4\" ></input> (max. $num_sez)";
310 echo "</td>
311 <td align=\"right\">"._MOSTRA." $tipo2 <br/>"._PERCOL."<input type=\"radio\" name=\"orvert\" $righe value=\"0\"></input><br/>"._PERRIGHE." <input
312 type=\"radio\" name=\"orvert\" $colonne value=\"1\"></input>";
313 echo "<input type=\"hidden\" name=\"name\" value=\"Elezioni\"></input>
314 </td></tr>";
315$diff=($offsetsez-$minsez);
316if ($minsez>1){
317 $minsez_p= ($minsez-$diff)>1 ? $minsez-$diff-1:1;
318
319 $offsetsez_p=$offsetsez-$diff-1;
320 echo "<tr><td valign=\"middle\"><div align=\"right\"><a href=\"modules.php?name=Elezioni&amp;file=index&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;op=$op&amp;min=$min&amp;offset=$offset&amp;minsez=$minsez_p&amp;offsetsez=$offsetsez_p&amp;perc=$perc&amp;id_lista=$id_lista\"> <- Precedenti</a></div></td>";
321}else{echo "<tr><td></td>";}
322if ($offsetsez<$num_sez){
323 $minsez_s=$minsez+$diff+1;
324 $offsetsez_s= ($offsetsez+$diff)>$num_sez ? $num_sez: $offsetsez+$diff+1;
325
326 echo "<td><div><a href=\"modules.php?name=Elezioni&amp;file=index&amp;op=$op&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;orvert=$orvert&amp;min=$min&amp;offset=$offset&amp;minsez=$minsez_s&amp;offsetsez=$offsetsez_s&amp;perc=$perc&amp;id_lista=$id_lista\"> Successive -></a></div></td><td></td></tr>";
327}else{echo "<td></td><td></td></tr>";}
328
329
330
331 echo "<tr>";
332 if (!strstr( $op,'candidato')) {
333 echo "<td>"._VIS_PERC.": <input type=\"checkbox\" name=\"perc\" value=\"true\"";
334 if($perc=='true') echo " checked=\"true\"";
335 echo "></input></td>";
336 }
337 echo "<td>";
338 echo "<input type=\"hidden\" name=\"op\" value=\"$op\"></input>";
339 echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"></input>";
340 echo "<input type=\"hidden\" name=\"id_comune\" value=\"$id_comune\"></input>";
341
342 echo "<input type=\"hidden\" name=\"pag2\" value=\"modules.php?name=Elezioni&amp;op=$op&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;csv=1&amp;orvert=$orvert&amp;min=$min&amp;offset=$offset&amp;minsez=$minsez&amp;offsetsez=$offsetsez&amp;perc=$perc&amp;id_lista=\"></input>";
343
344 echo "<input type=\"submit\" name=\"update\" value=\""._OK."\"></input>";
345
346
347 #### recupera dati stampa supporti diversi dati
348 //echo "</tr><tr><td><b>"._COMUNE." $descr_comune</b> - "._RISULTATI.": $descr_cons <br/>";
349 //echo "tot:$tot_scr";
350 //if ($tipo_cons!=4 && $tot_scr) echo " - Sezioni scrutinate: $tot_scr su $tot_sez";
351
352 # liste e gruppi da.... a
353 if (!strstr( $op,'candidato')) {
354 $res_cand2 = mysql_query("SELECT descrizione from ".$prefix."_ele_$tab15 where id_cons='$id_cons' and num_$tab15 ='$min'",$dbi);
355 list($descrizione)= mysql_fetch_row($res_cand2);
356 $list1 ="da $descrizione ";
357
358
359
360 $res_cand3 = mysql_query("SELECT descrizione from ".$prefix."_ele_$tab15 where id_cons='$id_cons' and num_$tab15 ='$offset'",$dbi);
361 list($descrizione)= mysql_fetch_row($res_cand3);
362 $list1 .=" a $descrizione <br/>";
363
364 }else{$list1='';}
365
366 # nome della lista
367 if (!isset($list2)) $list2='';
368 if (strstr( $op,'candidato')) {
369 $res_lis2 = mysql_query("SELECT num_lista, descrizione from ".$prefix."_ele_lista where id_lista=$id_lista",$dbi);
370 list($num_lista2,$descr_lista2)= mysql_fetch_row($res_lis2);
371 $list2 .=" Lista n. $num_lista2 - $descr_lista2 <br/>";
372
373 $res_cand4 = mysql_query("SELECT concat(cognome,' ', nome) from ".$prefix."_ele_$tab where id_cons=$id_cons and id_lista=$id_lista and num_cand=$min",$dbi);
374 list($descrizione)= mysql_fetch_row($res_cand4);
375 $list3 ="da $descrizione ";
376 $res_cand5 = mysql_query("SELECT concat(cognome,' ', nome) from ".$prefix."_ele_$tab where id_cons=$id_cons and id_lista=$id_lista and num_cand=$offset",$dbi);
377 list($descrizione)= mysql_fetch_row($res_cand5);
378 $list3 .="a $descrizione <br/>";
379
380 }else{ $list2 .='';$list3='';}
381
382
383 $datipdf="<b>"._COMUNE." $descr_comune</b> - "._RISULTATI.": $descr_cons<br/><b>$pagina</b><br/><br/> $list1 $list2 $list3
384 dalla $tipo3 n. <b>$minsez</b> alla $tipo3 n. <b>$offsetsez</b> di <b>$num_sez</b> $tipo2<br/><br/>";
385
386
387
388
389
390 # verificare la stampa sulle circoscrizioni
391 if(!$circo){
392 echo "</td><td><a href=\"".$_SERVER['PHP_SELF']."?name=Elezioni&amp;op=$op&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;csv=1&amp;orvert=$orvert&amp;min=$min&amp;offset=$offset&amp;minsez=$minsez&amp;offsetsez=$offsetsez&amp;perc=$perc&amp;id_lista=$id_lista&amp;datipdf=$datipdf\" ><img class=\"image\" src=\"modules/Elezioni/images/printer.gif\" alt=\"Stampa\" /></a>";
393 echo "<a href=\"".$_SERVER['PHP_SELF']."?name=Elezioni&amp;op=$op&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;csv=1&amp;orvert=$orvert&amp;min=$min&amp;offset=$offset&amp;minsez=$minsez&amp;offsetsez=$offsetsez&amp;perc=$perc&amp;id_lista=$id_lista&amp;xls=1&amp;datipdf=$datipdf\" ><img class=\"image\" src=\"modules/Elezioni/images/csv.gif\" alt=\"Export Csv\" /></a>";
394 echo "<a href=\"".$_SERVER['PHP_SELF']."?name=Elezioni&amp;op=$op&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;csv=1&amp;orvert=$orvert&amp;min=$min&amp;offset=$offset&amp;minsez=$minsez&amp;offsetsez=$offsetsez&amp;perc=$perc&amp;id_lista=$id_lista&amp;pdf=1&amp;datipdf=$datipdf\" ><img class=\"image\" src=\"modules/Elezioni/images/pdf.gif\" alt=\"Export Pdf\" /></a>";
395 }
396 echo "</td></tr></table></div></form>";
397
398 if (strstr( $op,'candidato')) echo $list2;
399
400
401 }
402 if (!$csv){
403 //echo "<table border=\"0\" width=\"100%\"><tr><td align=\"center\"><h5> Sezioni scrutinate";
404 //if ($tipo_cons!=4) echo ": $tot_scr su $tot_sez";
405 //echo "</h5></td></tr></table>";
406 }
407 $y=1;
408 $ar[0][0]=$tipo2;
409 $ra[0][0]=$tipo2;
410 $num_sez++;
411 $voticompl=0;
412 $ominsez=$minsez-1;
413 $sevaltot=0;
414 $senultot=0;
415 $sebiatot=0;
416 $secontot=0;
417 $sevnutot=0;
418 ////////////////////////////////////////////////////////////////////
419 // sandro: carica i numeri di sezione dal DB - giugno 2009
420 // caso: sezioni in collegi diversi non consecutive
421 if($circo) { $secirco=" and t2.id_circ=$id_circ";} else $secirco="and t1.num_sez >= $minsez and t1.num_sez <= $offsetsez";
422 $numsezioni = $offsetsez-$ominsez;
423 $res_numsez = mysql_query("SELECT t1.num_sez from ".$prefix."_ele_sezioni as t1, ".$prefix."_ele_sede as t2 where t1.id_cons=$id_cons and t1.id_sede=t2.id_sede $secirco order by t1.num_sez",$dbi);
424 for ($z=1;$z<=($offsetsez-$ominsez);$z++) {
425 $res=mysql_fetch_row($res_numsez);
426 $ar[$z][0]=$res[0];
427 $pos[$z]=$res[0];
428 }
429 if (!isset($pos)) $pos[0]=0;
430 $minpos=min($pos);
431 $maxpos=max($pos);
432 ////////////////////////////////////////////////////////////////////
433 if ($res_voti)
434 while (list($num_circ,$desc_circ,$num_cand,$nome,$voti,$sevalidi,$senulli,$sebianchi,$secontestati,$sevonulli) = mysql_fetch_row($res_voti)){
435 if ($num_circ<$minpos or $num_circ>$maxpos) continue;
436 $z=array_search($num_circ, $pos);
437 if (!isset($votitot[($z)])) {
438 $votitot[($z)]=0;
439 $sevaltot+=$sevalidi;
440 $senultot+=$senulli;
441 $sebiatot+=$sebianchi;
442 $secontot+=$secontestati;
443 $sevnutot+=$sevonulli;
444 }
445 $votitot[($z)]+=$voti;
446 $voticompl+=$voti;
447 }
448 if ($voticompl) mysql_data_seek($res_voti,0);
449 $piuvot=0;
450 if ($visvot!='cand') $piuvot=5;
451
452
453
454
455 for ($y=$min;$y<=($offset+$piuvot);$y++) $ar[0][$y]="&nbsp;";
456 for ($z=1;$z<=($offsetsez-$ominsez);$z++)
457 for ($y=$min;$y<=($offset+$piuvot);$y++) $ar[$z][$y]="&nbsp;"; //inizializza le celle interne
458 $onetime="";
459 if ($res_voti)
460 while (list($num_circ,$desc_circ,$num_cand,$nome,$voti,$sevalidi,$senulli,$sebianchi,$secontestati,$sevonulli) = mysql_fetch_row($res_voti)){
461 if ($num_cand>=$min and $num_cand<=$offset){
462 $z=array_search($num_circ, $pos);
463 if($num_circ>=$minpos and $num_circ <=$maxpos){
464 $ar[0][$num_cand]=$num_cand.") ".$nome;
465 if ($desc_circ && $onetime!=$desc_circ) {$ar[($z)][0].=") ".$desc_circ; $onetime=$desc_circ;}
466 $percento=$voti;
467 if ($perc=='true' and $votitot[($z)])
468 {
469 $percento=$voti."<br /><span class=\"red\"><i>".number_format($voti*100/$votitot[($z)],2)." %</i></span>";
470 }
471 $ar[($z)][$num_cand]=$percento;
472 }
473 if (!isset($temp[$num_cand])) $temp[$num_cand]=0;
474 $temp[$num_cand]+=$voti;
475
476 }
477 if ($visvot!='cand'){
478 $posvoti=($offset);
479 $ar[0][$posvoti+1]='<b>Voti Validi</b>';
480 $ar[0][$posvoti+2]='<b>Schede Nulle</b>';
481 $ar[0][$posvoti+3]='<b>Schede Bianche</b>';
482 $ar[0][$posvoti+4]='<b>Voti Contestati</b>';
483 $ar[0][$posvoti+5]='<b>Voti Nulli</b>';
484 if (($maxpos)>=$num_circ and $minpos<=$num_circ){
485 $posvoti++;
486 $ar[($z)][$posvoti++]="<b>$sevalidi</b>";
487 $ar[($z)][$posvoti++]="<b>$senulli</b>";
488 $ar[($z)][$posvoti++]="<b>$sebianchi</b>";
489 $ar[($z)][$posvoti++]="<b>$secontestati</b>";
490 $ar[($z)][$posvoti]="<b>$sevonulli</b>";
491 }
492 }
493 }
494 if (($offsetsez+1)>=$num_sez){
495 $ar[(2+$offsetsez-$minsez)][0]="<b>"._TOT."<br />"._COMPLESSIVO."</b>";
496 if(isset($temp)) {
497######################
498 if($tab15=="gruppo"){
499 $votigl=" sum(validi),sum(nulli),sum(bianchi),sum(contestati),sum(voti_nulli)";
500 }else{
501 /* if ($votog) $votigl=" (validi_lista),(nulli),(bianchi),(contestati_lista),(voti_nulli_lista)";
502 else */
503 $votigl=" sum(validi_lista),sum(nulli),sum(bianchi),sum(contestati_lista),sum(voti_nulli_lista)";
504 }
505 $resv = mysql_query("SELECT $votigl from ".$prefix."_ele_sezioni where id_cons='$id_cons'",$dbi);
506 list ($sevaltot,$senultot,$sebiatot,$secontot,$sevnutot)= mysql_fetch_row($resv);
507 $voticompl=$sevaltot+$senultot+$sebiatot+$secontot+$sevnutot;
508 $resvt = mysql_query("SELECT voti from ".$prefix."_ele_voti_$tab15 where id_cons='$id_cons'",$dbi);
509 list($votlt)=mysql_fetch_row($resvt);
510 $temp3=arrayperc($temp,$sevaltot);
511 while (list($key,$voti)= each($temp)) {
512 $percento="<b>$voti</b>";
513 if ($perc=='true' and $voticompl)
514 {
515 # $valperc2=round($valperc,2);
516 $percento="<b>$voti<br /><span class=\"red\"><i>".$temp3[$key]." %</i></span></b>";
517 }
518 $ar[2+$offsetsez-$minsez][$key]=$percento;
519 }
520 }
521 if ($visvot!='cand') {
522 $key=$offset+1;
523 $tmp=array($sevaltot,$senultot,$sebiatot,$secontot,$sevnutot);
524 $temp3=arrayperc($tmp,$voticompl);
525 #foreach($temp3 as $key=>$val) echo "$key: $val<br>";
526 while(list($k,$voti)= each($tmp)) {
527
528 if ($perc=='true' and $voticompl)
529 {
530 $valperc=number_format($voti*100/$voticompl,3);
531 $valperc=number_format($valperc,2);
532 $percento="<b>$voti<br /><span class=\"red\"><i>".$temp3[$k]." %</i></span></b>";
533 } else $percento="<b>$voti</b>";
534 $ar[2+$offsetsez-$minsez][++$key]=$percento;
535
536 }
537 }
538 }
539 if($orvert!=1) {
540 $i=0;
541 foreach ( $ar as $riga) {
542 $y=0;
543 foreach($riga as $cella) {
544 $ra[$y++][$i]=$cella;
545 }
546 $i++;
547 }
548 crea_tabella($ra);
549 }else{
550 crea_tabella($ar);
551 }
552//e' un referendum
553 }else{
554 $res_lis = mysql_query("SELECT id_gruppo, descrizione,num_gruppo from ".$prefix."_ele_gruppo where id_cons=$id_cons order by num_gruppo",$dbi);
555 $numliste=mysql_num_rows($res_lis);
556
557 if (!isset($offset)) $offset=10;
558 if (!isset($min)) $min=1;
559 if (!isset($offsetsez)) $offsetsez=25; //lo 0 viene sostituito dal totale di sezioni presenti
560 if (!isset($minsez)) $minsez=1;
561 echo "<form id=\"voti\" method=\"post\" action=\"modules.php\">";
562 echo "<div><input type=\"hidden\" name=\"name\" value=\"Elezioni\"></input>";
563 echo "<input type=\"hidden\" name=\"op\" value=\"$op\"></input>";
564 echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"></input>";
565 echo "<input type=\"hidden\" name=\"id_comune\" value=\"$id_comune\"></input>";
566 echo "<table><tr><td>"._SCELTA." "._CONSULTAZIONE.": <select name=\"id_gruppo\">";
567 while(list($id_rif,$descrizione,$num_lis) = mysql_fetch_row($res_lis)) {
568 if (!$id_gruppo) $id_gruppo=$id_rif;
569 $sel = ($id_rif == $id_gruppo) ? "selected=\"selected\"" : "";
570 echo "<option value=\"$id_rif\" $sel>";
571 for ($j=strlen($num_lis);$j<2;$j++) { echo "&nbsp;&nbsp;";}
572 echo $num_lis.") ".strip_tags(substr($descrizione,0,50))."</option>";
573 }
574 echo "</select></td></tr>";
575 echo "<tr><td>"._VIS_PERC.": <input type=\"checkbox\" name=\"perc\" value=\"true\"";
576 if($perc=='true') echo " checked=\"true\"";
577 echo "></td>";
578 echo "<td><input type=\"submit\" name=\"update\" value=\""._OK."\"></td></tr></table></form>";
579 $res_ref= mysql_query("select num_gruppo,descrizione from ".$prefix."_ele_gruppo where id_gruppo=$id_gruppo", $dbi);
580 $res = mysql_query("select $tab2, t1.num_gruppo, t1.descrizione , t1.simbolo,
581 sum(t2.si), sum(t2.no),sum(t2.validi), sum(t2.nulli),sum(t2.bianchi), sum(t2.contestati)
582 from ".$prefix."_ele_gruppo as t1
583 left join ".$prefix."_ele_voti_ref as t2 on (t1.id_gruppo=t2.id_gruppo)
584 left join ".$prefix."_ele_sezioni as t3 on (t2.id_sez=t3.id_sez)
585 left join ".$prefix."_ele_sede as t4 on (t3.id_sede=t4.id_sede)
586 left join ".$prefix."_ele_circoscrizione as t5 on (t4.id_circ=t5.id_circ)
587 where t1.id_cons='$id_cons' and t1.id_gruppo=$id_gruppo
588 group by t2.id_gruppo,$tab3
589 order by $tab3, t1.num_gruppo
590 ", $dbi);
591 $num_sez=mysql_num_rows($res);
592 list($num_gruppo,$descr)= mysql_fetch_row($res_ref);
593 echo "<table><tr><td><b>Referendum n. ".$num_gruppo.") </b></td><td>".$descr."</td></tr></table></form>";
594 $y=1;
595 $ar[0][0]=$tipo2;
596 $ar[0][1]=_SI;
597 $ar[0][2]=_NO;
598 $ar[0][3]=_VALIDI;
599 $ar[0][4]=_NULLI;
600 $ar[0][5]=_BIANCHI;
601 $ar[0][6]=_CONTESTATI;
602
603 while (list($num_gruppo,$desc_ref) = mysql_fetch_row($res_ref)){
604 $ar[0][$i++]= $num_gruppo.") ".$desc_ref;
605 $ar[1][$y++]= "SI";
606 $ar[1][$y++]= "NO";
607 }
608 $num_sez++;
609 $tot_si=0;
610 $tot_no=0;
611 $tot_va=0;
612 $tot_nu=0;
613 $tot_bi=0;
614 $tot_co=0;
615 while (list($num_circ,$desc_circ,$num_gruppo,$desc_ref,$simbolo,$si,$no,$validi,$nulli,$bianchi, $contestati) = mysql_fetch_row($res)){
616 $i=1;
617 $votanti=$validi+$nulli+$bianchi+$contestati;
618 $tot_si+=$si;
619 $tot_no+=$no;
620 $tot_va+=$validi;
621 $tot_nu+=$nulli;
622 $tot_bi+=$bianchi;
623 $tot_co+=$contestati;
624 $ar[$num_circ][0]=$num_circ."<br />".$desc_circ;
625 if($validi){
626 $ar[$num_circ][$i++]= $perc=='true' ? $si."<br /><span class=\"red\">".number_format($si*100/$validi,2)."%</span>":$si;
627 $ar[$num_circ][$i++]= $perc=='true' ? $no."<br /><span class=\"red\">".number_format($no*100/$validi,2)."%</span>":$no;
628 }else{
629 $ar[$num_circ][$i++]= $perc=='true' ? $si."<br /><span class=\"red\">0.00%</span>":$si;
630 $ar[$num_circ][$i++]= $perc=='true' ? $no."<br /><span class=\"red\">0.00%</span>":$no;
631 }
632 if($votanti){
633 $ar[$num_circ][$i++]= $perc=='true' ? $validi."<br /><span class=\"red\">".number_format($validi*100/$votanti,2)."%</span>":$validi;
634 $ar[$num_circ][$i++]= $perc=='true' ? $nulli."<br /><span class=\"red\">".number_format($nulli*100/$votanti,2)."%</span>":$nulli;
635 $ar[$num_circ][$i++]= $perc=='true' ? $bianchi."<br /><span class=\"red\">".number_format($bianchi*100/$votanti,2)."%</span>":$bianchi;
636 $ar[$num_circ][$i++]= $perc=='true' ? $contestati."<br /><span class=\"red\">".number_format($contestati*100/$votanti,2)."%</span>":$contestati;
637 }else{
638 $ar[$num_circ][$i++]= $perc=='true' ? $validi."<br /><span class=\"red\">0.00%</span>":$validi;
639 $ar[$num_circ][$i++]= $perc=='true' ? $nulli."<br /><span class=\"red\">0.00%</span>":$nulli;
640 $ar[$num_circ][$i++]= $perc=='true' ? $bianchi."<br /><span class=\"red\">0.00%</span>":$bianchi;
641 $ar[$num_circ][$i++]= $perc=='true' ? $contestati."<br /><span class=\"red\">0.00%</span>":$contestati;
642 }
643 }
644 $i=1;
645 $tot_vo=$tot_va+$tot_nu+$tot_bi+$tot_co;
646# if($tot_va==0) $tot_va=1;
647# if($tot_vo==0) $tot_vo=1;
648 $ar[$num_sez][0]=_TOT."<br />"._COMPLESSIVO;
649 if($tot_va){
650 $ar[$num_sez][$i++]= $perc=='true' ? $tot_si."<br /><span class=\"red\">".number_format($tot_si*100/$tot_va,2)."%</span>":$tot_si;
651 $ar[$num_sez][$i++]= $perc=='true' ? $tot_no."<br /><span class=\"red\">".number_format($tot_no*100/$tot_va,2)."%</span>":$tot_no;
652 }else{
653 $ar[$num_sez][$i++]= $perc=='true' ? $tot_si."<br /><span class=\"red\">0.00%</span>":$tot_si;
654 $ar[$num_sez][$i++]= $perc=='true' ? $tot_no."<br /><span class=\"red\">0.00%</span>":$tot_no;
655 }
656 if($tot_vo){
657 $ar[$num_sez][$i++]= $perc=='true' ? $tot_va."<br /><span class=\"red\">".number_format($tot_va*100/$tot_vo,2)."%</span>":$tot_va;
658 $ar[$num_sez][$i++]= $perc=='true' ? $tot_nu."<br /><span class=\"red\">".number_format($tot_nu*100/$tot_vo,2)."%</span>":$tot_nu;
659 $ar[$num_sez][$i++]= $perc=='true' ? $tot_bi."<br /><span class=\"red\">".number_format($tot_bi*100/$tot_vo,2)."%</span>":$tot_bi;
660 $ar[$num_sez][$i++]= $perc=='true' ? $tot_co."<br /><span class=\"red\">".number_format($tot_co*100/$tot_vo,2)."%</span>":$tot_co;
661 }else{
662 $ar[$num_sez][$i++]= $perc=='true' ? $tot_va."<br /><span class=\"red\">0.00%</span>":$tot_va;
663 $ar[$num_sez][$i++]= $perc=='true' ? $tot_nu."<br /><span class=\"red\">0.00%</span>":$tot_nu;
664 $ar[$num_sez][$i++]= $perc=='true' ? $tot_bi."<br /><span class=\"red\">0.00%</span>":$tot_bi;
665 $ar[$num_sez][$i++]= $perc=='true' ? $tot_co."<br /><span class=\"red\">0.00%</span>":$tot_co;
666 }
667 crea_tabella($ar);
668 }
669 if ($csv) echo "</body>\n</html>";
670}
671
672?>
Note: See TracBrowser for help on using the repository browser.