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

Last change on this file since 356 was 356, checked in by roby, 3 years ago
File size: 47.9 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}
12if ($xls=='1' or $pdf=='1') {
13include_once("modules/Elezioni/language/lang-$lang.php");
14include_once("modules/Elezioni/funzioni.php");
15}
16$param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ?
17 $_GET : $_POST;
18
19if (isset($param['id_cons_gen'])) $id_cons_gen=intval($param['id_cons_gen']); else $id_cons_gen='';
20//if (isset($param['op'])) $op=$param['op']; else $op='';
21if (isset($param['minsez'])) $minsez=intval($param['minsez']); else $minsez='';
22if (isset($param['id_lista'])) $id_lista=intval($param['id_lista']); else $id_lista='';
23if (isset($param['id_circ'])) $id_circ=intval($param['id_circ']); else $id_circ='';
24if (isset($param['csv'])) $csv=intval($param['csv']); else $csv='';
25if (isset($param['min'])) $min=intval($param['min']); else $min= 0;
26if (isset($param['orvert'])) $orvert=intval($param['orvert']); else $orvert='';
27if (isset($param['offset'])) $offset=intval($param['offset']); else $offset='';
28if (isset($param['offsetsez'])) $offsetsez=intval($param['offsetsez']); else $offsetsez='';
29if (isset($param['perc'])) $perc=$param['perc']; else $perc='';
30if (isset($param['info'])) $info=addslashes($param['info']); else $info='';
31if (isset($param['files'])) $files=addslashes($param['files']); else $files='';
32if (isset($param['voti_lista'])) $voti_lista=intval($param['voti_lista']); else $voti_lista= 0;
33if (isset($param['perc_lista'])) $perc_lista=$param['perc_lista']; else $perc_lista= 0;
34if (isset($param['lettera'])) $lettera=addslashes($param['lettera']); else $lettera='';
35if (isset($param['id_gruppo'])) $id_gruppo=intval($param['id_gruppo']); else $id_gruppo='';
36#if (isset($param['tipo_cons'])) $tipo_cons=intval($param['tipo_cons']); else $tipo_cons='';
37if (isset($param['pdf'])) $pdf=intval($param['pdf']); else $pdf='';
38if (isset($param['orienta'])) $orienta=addslashes($param['orienta']); else $orienta='';
39if (isset($param['datipdf'])) $datipdf=addslashes($param['datipdf']); else $datipdf='';
40if (isset($param['formato'])) $formato=addslashes($param['formato']); else $formato='';
41# anti-xss nov. 2009
42$id_comune=htmlentities($id_comune);
43$id_comune=intval($id_comune);
44$perc=htmlentities($perc);
45$perc_lista=floatval($perc_lista);
46#$datipdf= htmlentities($datipdf);
47$op= htmlentities($op);
48$info= htmlentities($info);
49$files=htmlentities($files);
50$lettera=htmlentities($lettera);
51$orienta=htmlentities($orienta);
52$formato=htmlentities($formato);
53
54
55
56$test=phpversion();
57if($test>=5.6)
58 include("crea_paginaphp7.php");
59else
60 include("crea_paginaphp5.php");
61
62$sql="SELECT descrizione from ".$prefix."_ele_comuni where id_comune='$id_comune'" ;
63$res = $dbi->prepare("$sql");
64$res->execute();
65
66list($descr_comune) = $res->fetch(PDO::FETCH_NUM);
67
68$sql="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' ";
69$res = $dbi->prepare("$sql");
70$res->execute();
71
72list($descr_cons,$tipo_cons,$genere,$votog,$votol,$votoc,$circo) = $res->fetch(PDO::FETCH_NUM);
73$sql="SELECT t2.id_cons,t2.solo_gruppo,t2.disgiunto 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'" ;
74$res = $dbi->prepare("$sql");
75$res->execute();
76
77list($id_cons,$dettnulli,$disgiunto) = $res->fetch(PDO::FETCH_NUM);
78
79
80
81
82
83
84
85////////////////////////////////////////////////////////////
86// Visualizza i dati per liste, gruppi e referendum, per sezione o circoscrizione
87////////////////////////////////////////////////////////////
88
89function gruppo_circo(){
90 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;
91 global $id_comune,$id_cons_gen,$op,$minsez,$id_lista,$id_circ,$csv,$min,$orienta,$formato,$dettnulli,$disgiunto,
92 $orvert,$offset,$offsetsez,$perc,$info,$files,$nomefile;
93 $nomefile="";
94 #Denominazione pagine
95 if($op=="gruppo_circo") $pagina=_GRUPPO." "._PER." "._CIRCO;
96 if($op=="gruppo_sezione") $pagina=_GRUPPO." "._PER." "._SEZIONI;
97 if($op=="lista_circo") $pagina=_LISTA." "._PER." "._CIRCO;
98 if($op=="lista_sezione") $pagina=_LISTA." "._PER." "._SEZIONI;
99 if($op=="candidato_circo") $pagina=_CONSI." "._PER." "._CIRCO;
100 if($op=="candidato_sezione") $pagina=_CONSI." "._PER." "._SEZIONI;
101 if($op=="consiglieri") $pagina=_CALCONS;
102 if (strstr( $op,'circo')) { //$op=='gruppo_circo' or $op=='lista_circo') {
103 $tab1="circ";
104 $tab2="t5.num_circ,t5.descrizione";
105 $tab3="t5.num_circ";
106 $tipo1=_DA." "._CIRCO;
107 $tipo2=_CIRCOS;
108 $tipo3=_CIRCO;
109 }else{
110 $tab1="sez";
111 $tab2="t3.num_sez,''";
112 $tab3="t3.num_sez";
113 $tipo1=_DA." "._SEZIONE;
114 $tipo2=_SEZIONI;
115 $tipo3=_SEZIONE;
116 }
117 if (strstr( $op,"gruppo")){
118 $tab="gruppo";
119 }elseif (strstr( $op,'lista')) {
120 $tab="lista";
121 }else{
122 $tab="candidati";
123 }
124 if ($orvert) {
125 $righe='';
126 $colonne='checked';
127 }else{
128 $righe='checked';
129 $colonne='';
130 }
131
132 if ($orienta) {
133 $land='';
134 $port='checked';
135 }else{
136 $land='checked';
137 $port='';
138 }
139
140 if ($formato) {
141 $A3='';
142 $A4='checked';
143 }else{
144 $A3='checked';
145 $A4='';
146 }
147
148
149
150 if ($genere>0) { //se non e' un referendum
151
152
153 $voticompl=0;
154 if (!($offset)) $offset=25;
155 if (!($min)) $min=1;
156 if (!($offsetsez)) $offsetsez=22;
157 if (!($minsez)) $minsez=1;
158 if ($min>$offset) {
159 $appo=$min;
160 $min=$offset;
161 $offset=$appo;
162 }
163 if ($minsez>$offsetsez) {
164 $appo=$minsez;
165 $minsez=$offsetsez;
166 $offsetsez=$appo;
167 }
168 if (!$csv){
169 echo "<form id=\"voti\" method=\"post\" action=\"modules.php\">";
170 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>";
171 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>";
172 }
173 $condcirc='';
174 $condcircns="";
175 if ($circo){ //gestione circoscrizionali
176 if(!$id_circ){
177 $sql="SELECT id_circ from ".$prefix."_ele_circoscrizione where id_cons=$id_cons and num_circ=1";
178 $res_cir = $dbi->prepare("$sql");
179 $res_cir->execute();
180 //se non si e' scelta una circoscr. prende la prima
181 list($id_circ)=$res_cir->fetch(PDO::FETCH_NUM);
182 }
183 $sql="SELECT num_circ from ".$prefix."_ele_circoscrizione where id_circ=$id_circ";
184 $res_cir = $dbi->prepare("$sql");
185 $res_cir->execute();
186 //estrae il numero della circoscrizione
187 list($num_circ)=$res_cir->fetch(PDO::FETCH_NUM);
188 $condcirc="and id_circ=$id_circ"; //variabile aggiunta nelle select per le circ.
189 $condcircns="and t2.id_circ=$id_circ";
190 $sql="SELECT count(t1.num_sez),min(t1.num_sez),max(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";
191 $res_sez = $dbi->prepare("$sql");
192 $res_sez->execute();
193 //numero di sezioni nella circoscrizione
194 $sql="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";
195 $res_min = $dbi->prepare("$sql");
196 $res_min->execute();
197 //setta minsez sulla prima sezione della circoscrizione
198 list($minsez)=$res_min->fetch(PDO::FETCH_NUM);
199 }
200 elseif (strstr( $op,'circo')){
201 $sql="SELECT count(num_circ),min(num_circ),max(num_circ) from ".$prefix."_ele_circoscrizione where id_cons=$id_cons $condcirc";
202 $res_sez = $dbi->prepare("$sql");
203 $res_sez->execute();
204 }
205 else{
206 $sql="SELECT count(num_sez),min(num_sez),max(num_sez) from ".$prefix."_ele_sezioni where id_cons=$id_cons $condcirc";
207 $res_sez = $dbi->prepare("$sql");
208 $res_sez->execute();
209 }
210 if($res_sez->rowCount()) list($tot_sez,$numsezmin,$numsezmax)=$res_sez->fetch(PDO::FETCH_NUM);
211 else {$tot_sez=0;$numsezmin=0;$numsezmax=0;}
212 $sql="SELECT count(t1.num_sez) from ".$prefix."_ele_sezioni as t1 left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t1.id_cons=$id_cons $condcircns";
213 $res_sez = $dbi->prepare("$sql");
214 $res_sez->execute();
215
216 list($tuttelesez)=$res_sez->fetch(PDO::FETCH_NUM);
217
218 $num_sez=$tot_sez;//mysql_data_seek($res_sez,0);
219 if ($circo) $offsetsez=$numsezmax; //$num_sez+$minsez-1;//setta offsetsez sull'ultima sezione della circoscrizione
220
221 $visvot='';
222
223 if (!$csv) echo "<div><h5>$pagina</h5></div>";
224 if (!$csv) echo "<div style=\" text-align:left; margin-left:20px;\">";
225
226 if(strstr( $op,'candidato')){
227// $numliste=mysql_num_rows($res_lis);
228 $visvot="cand";
229 if (!$csv){
230 $sql="SELECT id_lista, descrizione,num_lista from ".$prefix."_ele_lista where id_cons=$id_cons $condcirc order by num_lista";
231 $res_lis = $dbi->prepare("$sql");
232 $res_lis->execute();
233
234 //elenco delle liste per la scelta
235 echo "<p>"._SCEGLI_LISTA.":
236 <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\">";
237 while(list($id_rif,$descrizione,$num_lis) = $res_lis->fetch(PDO::FETCH_NUM)) {
238 if (!$id_lista) $id_lista=$id_rif;
239 $sel = ($id_rif == $id_lista) ? "selected=\"selected\"" : "";
240 echo "<option value=\"$id_rif\" $sel>";
241 for ($j=strlen($num_lis);$j<2;$j++) { echo "&nbsp;&nbsp;";}
242 echo $num_lis.") ".$descrizione."</option>";
243 }
244 echo "</select></p>";
245 }
246 $sql="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";
247 $res_scr = $dbi->prepare("$sql");
248 $res_scr->execute();
249
250 $sqlc="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";
251 $res_cand = $dbi->prepare("$sqlc");
252 $res_cand->execute();
253
254 if ($circo) $condcirc="and t5.id_circ=$id_circ";
255
256 $sqlvoti="select $tab2, t1.num_cand, concat(t1.cognome,' ', t1.nome) as nome, sum(t2.voti),'','','','',''
257 from ".$prefix."_ele_candidati as t1, ".$prefix."_ele_voti_candidati as t2, "
258 .$prefix."_ele_sezioni as t3, ".$prefix."_ele_sede as t4, ".$prefix."_ele_circoscrizione as t5
259 where t1.id_lista=$id_lista
260 and t1.id_cons=$id_cons
261 and t1.id_cand=t2.id_cand
262 and t2.id_sez=t3.id_sez
263 and t3.id_sede=t4.id_sede
264 and t4.id_circ=t5.id_circ $condcirc
265 group by t1.num_cand,$tab2, t1.cognome,t1.nome
266 order by $tab3,t1.num_cand";
267 $res_voti = $dbi->prepare("$sqlvoti");
268 $res_voti->execute();
269 }else{
270 if (!$csv)
271 echo "<input type=\"hidden\" name=\"id_lista\" value=\"\"></input>";
272
273 // camera e senato nel 2006 aggiunte le somme della coalizione
274 // divise per circo e sez. in quanto nella tabella del gruppo
275 // all'atto dell'immsione non viene fatta la somma
276 // quindi leggere prima i voti di lista e poi agganciali al gruppo
277 // la var $tab diviene lista, $tab15 diviene gruppo in caso di somma
278 // dei voti di lista...oltre naturalmnte alle condizioni messe in variabile
279 // 4 aprile 2006 by luc
280#echo "TEST; Condizione scelta lista/gruppo: if ($votog && $tab==gruppo)<br>circo: $circo -- condcirc: $condcirc<br>";
281 $tabns=$tab;
282 if ($votog && $tab=="gruppo"){ // camera e senato 2006
283 $t="t9";
284 $tab="lista";
285 $tabns=$tab;
286 $tab15="gruppo";
287 $add_1= ",".$prefix."_ele_gruppo as t9";
288 $and_1="and t1.id_gruppo=t9.id_gruppo";
289 }else{
290 $t="t1";
291 $tab15=$tab;
292 $add_1='';
293 $and_1='';
294 }
295 if(($genere==5 and $circo)) $condcircns="and ".$prefix."_ele_$tabns.id_circ=$id_circ"; else $condcircns="";
296 // fine della modifica
297 $sql="SELECT count(".$prefix."_ele_voti_$tabns.id_sez) from ".$prefix."_ele_voti_$tabns left join ".$prefix."_ele_$tabns on ".$prefix."_ele_voti_$tabns.id_$tabns=".$prefix."_ele_$tabns.id_$tabns where ".$prefix."_ele_voti_$tabns.id_cons='$id_cons' $condcircns group by ".$prefix."_ele_voti_$tabns.id_$tabns";
298//echo "TEST: numero sezioni scrutinate: $sql";
299 $res_scr = $dbi->prepare("$sql");
300 $res_scr->execute();
301 //numero sezioni scrutinate
302 $sqlc="SELECT id_$tab15, descrizione, num_$tab15 from ".$prefix."_ele_$tab15 where id_cons='$id_cons' $condcirc order by num_$tab15";
303 $res_cand = $dbi->prepare("$sqlc");
304 $res_cand->execute();
305
306 if ($circo) $condcirc="and t5.id_circ=$id_circ";
307 if ($tab=="gruppo" or $genere==4 or ($genere==5 and $votog) or defined('_NULLISTA'))
308 $votigl=" sum(t3.validi),sum(t3.nulli),sum(t3.bianchi),sum(t3.contestati),sum(t3.voti_nulli)";
309 else
310 if ($votog) $votigl=" (t3.validi_lista),(t3.nulli),(t3.bianchi),(t3.contestati),(t3.voti_nulli_lista+t3.voti_nulli)";
311 else $votigl=" sum(t3.validi_lista),sum(t3.nulli),sum(t3.bianchi),sum(t3.contestati_lista),sum(t3.voti_nulli_lista+t3.voti_nulli)";
312 $sqlvoti="select $tab2, $t.num_$tab15, $t.descrizione, sum(t2.voti), $votigl
313 from
314 ".$prefix."_ele_$tab as t1,
315 ".$prefix."_ele_voti_$tab as t2,
316 ".$prefix."_ele_sezioni as t3,
317 ".$prefix."_ele_sede as t4,
318 ".$prefix."_ele_circoscrizione as t5
319 $add_1
320
321 where t1.id_cons=$id_cons
322 and t1.id_$tab=t2.id_$tab
323 $and_1
324
325 and t2.id_sez=t3.id_sez
326 and t3.id_sede=t4.id_sede
327 and t4.id_circ=t5.id_circ $condcirc
328
329
330 group by $t.num_$tab15,$tab3,$tab2, $t.descrizione
331 order by $tab3,$t.num_$tab15";
332 $res_voti = $dbi->prepare("$sqlvoti");
333 $res_voti->execute();
334 }
335 if ($res_scr) list($tot_scr)=$res_scr->fetch(PDO::FETCH_NUM);else $tot_scr=0;
336 if ($res_cand) $num_cand=$res_cand->rowCount(); else $num_cand=0;
337 if(!$circo){
338 if (!(0 < $minsez and $minsez<=$numsezmax)) $minsez=1;
339 if (!(0<$offsetsez and $offsetsez<=$numsezmax)) $offsetsez=$numsezmax;
340 }
341 if (!(0 < $min and $min<=$num_cand)) $min=1;
342 if (!(0<$offset and $offset<=$num_cand)) $offset=$num_cand;
343 if (!$csv) {
344 if(strstr( $op,'lista')){$scelta=_SCEGLI_LISTA;}else{$scelta=_SCEGLI_CANDI;}
345 echo "<p>$scelta "._DA.":&nbsp; <select name=\"min\" class=\"modulo\">";
346 while(list($id_rif,$descrizione,$num_lis) = $res_cand->fetch(PDO::FETCH_NUM)) {
347 if (!$min) $min=$num_lis;
348 $sel = ($num_lis == $min) ? "selected=\"selected\"" : "";
349 echo "<option value=\"$num_lis\" $sel>";
350 for ($j=strlen($num_lis);$j<2;$j++) { echo "&nbsp;&nbsp;";}
351 echo $num_lis.") ".$descrizione."</option>";
352 }
353 echo "</select>";
354 echo "&nbsp;&nbsp;"._A.":&nbsp; <select name=\"offset\" class=\"modulo\">";
355 $res_cand = $dbi->prepare("$sqlc");
356 $res_cand->execute();
357
358 while(list($id_rif,$descrizione,$num_lis) = $res_cand->fetch(PDO::FETCH_NUM)) {
359 if (!$offset) $offset=$num_lis;
360 $sel = ($num_lis == $offset) ? "selected=\"selected\"" : "";
361 echo "<option value=\"$num_lis\" $sel>";
362 for ($j=strlen($num_lis);$j<2;$j++) { echo "&nbsp;&nbsp;";}
363 echo $num_lis.") ".$descrizione."</option>";
364
365 }
366 echo "</select></p>";
367 //echo "<div style=\"text-align:left; margin-left:20px;\">";
368 if(!$circo){
369 echo "<p>"._SCEGLI." $tipo1 n. <input name=\"minsez\" value=\"$minsez\" size=\"4\" ></input>";
370 echo _A." n. <input name=\"offsetsez\" value=\"$offsetsez\" size=\"4\" ></input> (max. $numsezmax)";
371 }
372 # pagine
373############
374 if(!$offsetsez) $offsetsez=0;
375 if (strstr( $op,'circo'))
376 $sql="SELECT count(num_circ) from ".$prefix."_ele_circoscrizione where id_cons=$id_cons and num_circ>=$minsez and num_circ<=$offsetsez";
377
378
379 else
380 $sql="SELECT count(num_sez) from ".$prefix."_ele_sezioni where id_cons=$id_cons and num_sez>=$minsez and num_sez<=$offsetsez";
381 $resnsez = $dbi->prepare("$sql");
382 $resnsez->execute();
383 list($diff)=$resnsez->fetch(PDO::FETCH_NUM);
384 ########
385 # $diff=($offsetsez-$minsez);
386 if ($minsez>1 and !$circo){
387 $minsez_p= ($minsez-$diff)>1 ? $minsez-$diff:1;
388 $offsetsez_p=$offsetsez-$diff;
389 echo "<div style=\"float: right; width:200px;margin-left:10px;margin-right:400px;font-size:12px \"><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\"> <- $tipo2 Precedenti</a></div>";
390 }else{echo "";}
391 if ($offsetsez<$numsezmax){
392 $minsez_s=$minsez+$diff;
393 $offsetsez_s= ($offsetsez+$diff)>$num_sez ? $num_sez: $offsetsez+$diff;
394 echo "<div style=\"float: left; width:200px; margin-left:10px;\"><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\"> $tipo2 Successive -></a></div>";
395 }else{echo "";}
396 if(!$circo)
397 echo "<div style=\"margin-left:10px;\"><br/>"._MOSTRA." $tipo2 "._PERCOL."<input type=\"radio\" name=\"orvert\" $righe value=\"0\"></input>"._PERRIGHE." <input
398 type=\"radio\" name=\"orvert\" $colonne value=\"1\"></input>";
399 echo "<input type=\"hidden\" name=\"name\" value=\"Elezioni\"></input></div>";
400 echo "<p>";
401 if (!strstr( $op,'candidato')) {
402 echo ""._VIS_PERC.": <input type=\"checkbox\" name=\"perc\" value=\"true\"";
403 if($perc=='true') echo " checked=\"true\"";
404 echo "></input><br/>";
405 }
406 echo "";
407 if($circo)
408 echo "<input type=\"hidden\" name=\"id_circ\" value=\"$id_circ\"></input>";
409 echo "<input type=\"hidden\" name=\"op\" value=\"$op\"></input>";
410 echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"></input>";
411 echo "<input type=\"hidden\" name=\"id_comune\" value=\"$id_comune\"></input>";
412
413 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>";
414
415 echo " <input type=\"submit\" name=\"update\" value=\""._RICARICA."\"></input></p></div></form>";
416
417
418 #### recupera dati stampa supporti diversi dati
419 //echo "</tr><tr><td><b>"._COMUNE." $descr_comune</b> - "._RISULTATI.": $descr_cons <br/>";
420 //echo "tot:$tot_scr";
421 //if ($tipo_cons!=4 && $tot_scr) echo " - Sezioni scrutinate: $tot_scr su $tuttelez";
422
423 # liste e gruppi da.... a
424 if (!strstr( $op,'candidato')) {
425 $sql="SELECT descrizione from ".$prefix."_ele_$tab15 where id_cons='$id_cons' and num_$tab15 ='$min'";
426 $res_cand2 = $dbi->prepare("$sql");
427 $res_cand2->execute();
428
429 list($descrizione)= $res_cand2->fetch(PDO::FETCH_NUM);
430 $list1 ="da $descrizione ";
431
432
433
434 $sql="SELECT descrizione from ".$prefix."_ele_$tab15 where id_cons='$id_cons' and num_$tab15 ='$offset'";
435 $res_cand3 = $dbi->prepare("$sql");
436 $res_cand3->execute();
437
438 list($descrizione)= $res_cand3->fetch(PDO::FETCH_NUM);
439 $list1 .=" a $descrizione <br/>";
440
441 }else{$list1='';}
442
443 # nome della lista
444 if (!isset($list2)) $list2='';
445 if (strstr( $op,'candidato')) {
446 $sql="SELECT num_lista, descrizione from ".$prefix."_ele_lista where id_lista=$id_lista";
447 $res_lis2 = $dbi->prepare("$sql");
448 $res_lis2->execute();
449
450 list($num_lista2,$descr_lista2)= $res_lis2->fetch(PDO::FETCH_NUM);
451 $nomefile=" Lista n. $num_lista2 - $descr_lista2 ";
452 $list2 .=" Lista n. $num_lista2 - $descr_lista2 <br/>";
453
454 $sql="SELECT concat(cognome,' ', nome) from ".$prefix."_ele_$tab where id_cons=$id_cons and id_lista=$id_lista and num_cand=$min";
455 $res_cand4 = $dbi->prepare("$sql");
456 $res_cand4->execute();
457
458 list($descrizione)= $res_cand4->fetch(PDO::FETCH_NUM);
459 $list3 ="da $descrizione ";
460 $sql="SELECT concat(cognome,' ', nome) from ".$prefix."_ele_$tab where id_cons=$id_cons and id_lista=$id_lista and num_cand=$offset";
461 $res_cand5 = $dbi->prepare("$sql");
462 $res_cand5->execute();
463
464 list($descrizione)= $res_cand5->fetch(PDO::FETCH_NUM);
465 $list3 .="a $descrizione <br/>";
466
467 }else{ $list2 .='';$list3='';}
468 if(!isset($tab15)) $tab15='';
469 $nomefile.="$descr_cons $tab15";
470 $_SESSION['nomefile']=strip_tags(str_replace(" ", "_", $nomefile));
471 $datipdf="<b>"._COMUNE." $descr_comune</b> - "._RISULTATI.": $descr_cons<br/><b>$pagina</b><br/><br/> $list1 $list2 $list3 ";
472# verificare la stampa sulle circoscrizioni
473 echo "<div style=\"text-align:right;width:65%;margin-left:10px;margin-right:0px;font-size:12px; \">";
474 echo "<table style=\"text-align:center;margin-right:0px;border-top : 1px solid Blue;width: 280px;\"><tr style=\" background:#eceff5;\"><td>"._ESPORTA."<br />";
475 if($circo){ echo "<a href=\"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=$id_lista&amp;id_circ=$id_circ&amp;datipdf=$datipdf\" ><img class=\"image\" src=\"modules/Elezioni/images/printer.gif\" alt=\"Stampa\" /></a>";
476 }else{
477 echo "<a href=\"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=$id_lista&amp;datipdf=$datipdf\" ><img class=\"image\" src=\"modules/Elezioni/images/printer.gif\" alt=\"Stampa\" /></a>";
478 echo "<a href=\"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=$id_lista&amp;xls=1&amp;datipdf=$datipdf\" ><img class=\"image\" src=\"modules/Elezioni/images/csv.gif\" alt=\"Export Csv\" /></a>";
479 echo "<img class=\"image\" src=\"modules/Elezioni/images/rss.png\" alt=\"Export rss\" />";
480 echo " </td>";
481 # stampa pdf
482 echo "<td>";
483 echo "<form id=\"pdf\" method=\"post\" action=\"modules.php\">";
484 echo "<input type=\"hidden\" name=\"id_circ\" value=\"$id_circ\"></input>";
485 echo "<input type=\"hidden\" name=\"op\" value=\"$op\"></input>";
486 echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"></input>";
487 echo "<input type=\"hidden\" name=\"id_comune\" value=\"$id_comune\"></input>";
488 echo "<input type=\"hidden\" name=\"csv\" value=\"1\"></input>";
489 echo "<input type=\"hidden\" name=\"orvert\" value=\"$orvert\"></input>";
490 echo "<input type=\"hidden\" name=\"min\" value=\"$min\"></input>";
491 echo "<input type=\"hidden\" name=\"offset\" value=\"$offset\"></input>";
492 echo "<input type=\"hidden\" name=\"minsez\" value=\"$minsez\"></input>";
493 echo "<input type=\"hidden\" name=\"offsetsez\" value=\"$offsetsez\"></input>";
494 echo "<input type=\"hidden\" name=\"perc\" value=\"$perc\"></input>";
495 echo "<input type=\"hidden\" name=\"id_lista\" value=\"$id_lista\"></input>";
496 echo "<input type=\"hidden\" name=\"pdf\" value=\"1\"></input>";
497 echo "<input type=\"hidden\" name=\"datipdf\" value=\"$datipdf\"></input>";
498 # echo "<input type=\"hidden\" name=\"name\" value=\"$elezioni\"></input>";
499 echo "<input type=\"hidden\" name=\"name\" value=\"Elezioni\"></input>";
500 echo "<input type=\"image\" name=\"submit\" src=\"modules/Elezioni/images/pdf.gif\" align=\"left\">";
501 echo "&nbsp; L &nbsp;<input type=\"radio\" name=\"orienta\" $land value=\"L\"></input>P &nbsp;<input
502 type=\"radio\" name=\"orienta\" $port value=\"P\"></input><br />";
503 echo "&nbsp; A3<input type=\"radio\" name=\"formato\" $A3 value=\"A3\"></input>A4<input
504 type=\"radio\" name=\"formato\" $A4 value=\"A4\"></input>";
505 echo " </form></td></tr></table> ";
506 }
507 echo "</div></br />";
508 }
509 if (!$csv){
510 echo "<h5> Sezioni scrutinate";
511 if ($tipo_cons!=4) ;echo ": $tot_scr su $tuttelesez &nbsp;&nbsp;&nbsp; ";
512 echo "</h5>&nbsp;";
513 }
514 $y=1;
515 $ar[0][0]=$tipo3;
516 $ra[0][0]=$tipo3;
517 $num_sez++;
518 $voticompl=0;
519 $ominsez=$minsez-1;
520 $valar=array();$percar=array();
521 ////////////////////////////////////////////////////////////////////
522 // sandro: carica i numeri di sezione dal DB - giugno 2009
523 // caso: sezioni in collegi diversi non consecutive
524 if (strstr( $op,'circo'))
525 $sql="select num_circ,id_circ from ".$prefix."_ele_circoscrizione where id_cons='$id_cons' and num_circ>='$minsez' and num_circ<='$offsetsez' order by num_circ";
526 else{
527 if($circo) { $secirco=" and t2.id_circ=$id_circ";} else $secirco="and t1.num_sez >= $minsez and t1.num_sez <= $offsetsez";
528 $numsezioni = $offsetsez-$ominsez;
529 $sql="SELECT t1.num_sez,t1.id_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";
530 }
531 $res_numsez = $dbi->prepare("$sql");
532 $res_numsez->execute();
533 $sevaltot=0;
534 $senultot=0;
535 $sebiatot=0;
536 $secontot=0;
537 $sevnutot=0;
538 while($res=$res_numsez->fetch(PDO::FETCH_NUM)) {
539 $z=$res[0];
540##############inserimento percentuale di scrutinio nella sezione
541 $scruvalidi=0;
542 $scrunulli=0;
543 $grpercscru=0;
544 $altri=0;
545 $votiscru=0;
546 if($op=="gruppo_sezione"){
547 $sqlr="select sum(validi),sum(solo_lista) from ".$prefix."_ele_sezioni where id_sez='".$res[1]."'";
548 $sqlv="select sum(voti) from ".$prefix."_ele_voti_gruppo where id_sez='".$res[1]."'";
549 $resperc = $dbi->prepare("$sqlr");
550 $resperc->execute();
551 $votiperc = $dbi->prepare("$sqlv");
552 $votiperc->execute();
553 }
554 elseif($op=="lista_sezione"){
555 $sqlr="select sum(validi),sum(contestati_lista+solo_gruppo+voti_nulli_lista) from ".$prefix."_ele_sezioni where id_sez='".$res[1]."'";
556 $sqlv="select sum(voti) from ".$prefix."_ele_voti_lista where id_sez='".$res[1]."'";
557 $resperc = $dbi->prepare("$sqlr");
558 $resperc->execute();
559 $votiperc = $dbi->prepare("$sqlv");
560 $votiperc->execute();
561 }
562 if (isset($resperc) and $resperc)
563 list($scruvalidi,$scrunulli)=$resperc->fetch(PDO::FETCH_NUM);
564 if (isset($votiperc) and $votiperc)
565 list($votiscru)=$votiperc->fetch(PDO::FETCH_NUM);
566 $sql="select sum(voti_complessivi) from ".$prefix."_ele_voti_parziale where id_sez='".$res[1]."' group by data,orario order by data desc, orario desc limit 0,1 ";
567 $resperc = $dbi->prepare("$sql");
568 $resperc->execute();
569
570 if ($resperc)
571 list($totschede)=$resperc->fetch(PDO::FETCH_NUM);
572 if (isset($scruvalidi) and $scruvalidi>0 )
573 $grpercscru=$votiscru ? number_format(($votiscru+$scrunulli)*100/$scruvalidi,0) : 0;
574
575################### <span class=\"red\"><i>".$temp3[$key]." %</i></span>
576 $ar[$z][0]=$res[0]; if($grpercscru) {$ar[$z][0].="<br /><span class=\"red\"><i>$grpercscru%</i></span>";if(!strstr($ar[0][0],'scrutinio')) $ar[0][0].="<br /><span class=\"red\"><i>% scrutinio</i></span>"; }
577 $pos[$z]=$res[0];
578 #$valar[$z]=array();
579 }
580 if (!isset($pos)) $pos[0]=0;
581 $minpos=min($pos);
582 $maxpos=max($pos);
583 ////////////////////////////////////////////////////////////////////
584 if ($tab=="gruppo" or $genere==4 or ($genere==5 and $votog) or defined('_NULLISTA'))
585 $sqlvoti2="select $tab3, sum(t3.validi),sum(t3.nulli),sum(t3.bianchi),sum(t3.contestati),sum(t3.voti_nulli) from ".$prefix."_ele_circoscrizione as t5, ".$prefix."_ele_sezioni as t3, ".$prefix."_ele_sede as t4 where t5.id_cons=$id_cons and t5.id_circ=t4.id_circ and t3.id_sede=t4.id_sede group by $tab3";
586 else
587 if (strstr( $op,'circo')) $sqlvoti2="select t1.num_circ, sum(t3.validi_lista),sum(t3.voti_nulli_lista),sum(t3.contestati_lista),sum(t3.solo_gruppo),sum(t3.voti_nulli_lista+t3.voti_nulli) from ".$prefix."_ele_circoscrizione as t1, ".$prefix."_ele_sezioni as t3, ".$prefix."_ele_sede as t4 where t1.id_cons=$id_cons and t1.id_circ=t4.id_circ and t3.id_sede=t4.id_sede group by t1.num_circ";
588# togli circo vai con modo tab3, genere=2 e =4 prende stringa madre (poi va sistemato il tipo camera 2001 che registra i voti di lista sui gruppi
589# camera 2008 e 2001 --> tipo cons=6 non funziona
590
591 else $sqlvoti2="select t3.num_sez, (t3.validi_lista),(t3.voti_nulli_lista),(t3.contestati_lista),(t3.solo_gruppo),(t3.voti_nulli_lista+t3.voti_nulli) from ".$prefix."_ele_sezioni as t3 where t3.id_cons=$id_cons ";
592 $res_voti = $dbi->prepare("$sqlvoti2");
593 $res_voti->execute();
594# echo "TEST: ---- $sqlvoti2";
595 ///////////////////////////
596 if ($res_voti->rowCount())
597 while (list($num_circ,$sevalidi,$senulli,$sebianchi,$secontestati,$sevonulli) = $res_voti->fetch(PDO::FETCH_NUM)){
598# if($genere==4) $sevalidi=$voti;
599 $z=array_search($num_circ, $pos);
600 if (!isset($votitot[($z)])) {
601 $votitot[($z)]=0;
602 if($sevalidi) $sevaltot+=$sevalidi;
603 if($senulli) $senultot+=$senulli;
604 if($sebianchi) $sebiatot+=$sebianchi;
605 if($secontestati) $secontot+=$secontestati;
606 if($sevonulli) $sevnutot+=$sevonulli;
607 }
608# $votitot[($z)]+=$voti;
609# if(!isset($valsez[$z])) $valsez[$z]=0;
610 $valsez[$z]=$sevalidi;
611 $nulsez[$z]=$senulli;
612 $biasez[$z]=$sebianchi;
613 $consez[$z]=$secontestati;
614 $vonsez[$z]=$sevonulli;
615# $voticompl+=$voti;
616 }
617 if ($voticompl) {
618 $res_voti = $dbi->prepare("$sqlvoti");
619 $res_voti->execute();
620 }
621 $piuvot=0;
622
623 if ($visvot!='cand') if($tab15=="gruppo" or $genere==4 or ($genere==5 and $votog) or defined('_NULLISTA')) $piuvot=5; else $piuvot=4;
624 for ($y=$min;$y<=($offset+$piuvot);$y++) $ar[0][$y]="&nbsp;";
625 if (strstr( $op,'circo'))
626 $sql="select num_circ from ".$prefix."_ele_circoscrizione where id_cons='$id_cons' and num_circ>='$minsez' and num_circ<='$offsetsez' order by num_circ";
627 else
628 $sql="select num_sez from ".$prefix."_ele_sezioni where id_cons='$id_cons' and num_sez>='$minsez' and num_sez<='$offsetsez' order by num_sez";
629 $lis_sez = $dbi->prepare("$sql");
630 $lis_sez->execute();
631 $nsezsel=$lis_sez->rowCount();
632 while(list($z)=$lis_sez->fetch(PDO::FETCH_NUM))
633 {
634 for ($y=$min;$y<=($offset+$piuvot);$y++) $ar[$z][$y]="&nbsp;";} //inizializza le celle interne
635
636###################################################################
637# for ($y=$min;$y<=($offset+$piuvot);$y++) $ar[0][$y]="&nbsp;";
638# for ($z=1;$z<=($offsetsez-$ominsez);$z++)
639 # for ($y=$min;$y<=($offset+$piuvot);$y++) $ar[$z][$y]="&nbsp;"; //inizializza le celle interne
640 $onetime="";
641 if ($res_voti)
642 {
643 while (list($num_circ,$desc_circ,$num_cand,$nome,$voti,$sevalidi,$senulli,$sebianchi,$secontestati,$sevonulli) = $res_voti->fetch(PDO::FETCH_NUM)){
644 $z=array_search($num_circ, $pos);
645 $valar[($z)][$num_cand]=$voti;
646 }
647
648 foreach ($valar as $key=>$val){
649 if(isset($votitot[($key)]))
650 $percar[$key]=arrayperc($val,$votitot[($key)]);
651
652 }
653 # if($res_voti->rowCount()) {
654 $res_voti = $dbi->prepare("$sqlvoti");
655 $res_voti->execute();
656 #}
657
658 while (list($num_circ,$desc_circ,$num_cand,$nome,$voti,$sevalidi,$senulli,$sebianchi,$secontestati,$sevonulli) = $res_voti->fetch(PDO::FETCH_NUM)){
659 if($num_cand<$min or $num_cand>$offset) continue;
660 if($genere==4) $sevalidi=$voti;
661
662 if (!isset($temp[$num_cand])) $temp[$num_cand]=0;
663 $temp[$num_cand]+=$voti;
664 $z=array_search($num_circ, $pos);
665 if (!$z) continue;
666 if ($num_cand>=$min and $num_cand<=$offset){
667 if($num_circ>=$minpos and $num_circ <=$maxpos){
668 $ar[0][$num_cand]=$num_cand.") ".$nome;
669 if ($desc_circ && $onetime!=$desc_circ) {$ar[($z)][0].=") ".$desc_circ; $onetime=$desc_circ;}
670 $percento=$voti;
671 if ($perc=='true' and $votitot[($z)])
672 {
673 $percento=$voti."<br /><span class=\"red\" style=\"font-size:80%;\"><i>".number_format($percar[$z][$num_cand],2)." %</i></span>";
674 }
675
676 $ar[($z)][$num_cand]=$percento;
677 }
678 }
679 if (!strstr( $op,'candidato')){
680 if (!isset($tempar[$num_cand])) $tempar[$num_cand]=0;
681 $tempar[$num_cand]+=$voti;
682 }
683 if ($visvot!='cand'){
684 $posvoti=($offset);
685 if($tab15=="gruppo" or $genere==4 or ($genere==5 and $votog) or defined('_NULLISTA')){
686 $ar[0][$posvoti+1]='<b>Voti Validi</b>';
687 $ar[0][$posvoti+2]='<b>Schede Nulle</b>';
688 $ar[0][$posvoti+3]='<b>Schede Bianche</b>';
689 $ar[0][$posvoti+4]='<b>Voti Contestati</b>';
690 $ar[0][$posvoti+5]='<b>Voti Nulli</b>';
691 }else{
692 $ar[0][$posvoti+1]='<b>Voti Validi</b>';
693 $ar[0][$posvoti+2]='<b>Voti Nulli</b>';
694 $ar[0][$posvoti+3]='<b>Voti Contestati</b>';
695 $ar[0][$posvoti+4]='<b>Solo Gruppo</b>';
696 }
697 if (($maxpos)>=$num_circ and $minpos<=$num_circ){
698 //$posvoti++;
699 $ar[($z)][$posvoti+1]="<b>$valsez[$z]</b>";
700 $ar[($z)][$posvoti+2]="<b>$nulsez[$z]</b>";
701 $ar[($z)][$posvoti+3]="<b>$biasez[$z]</b>";
702 $ar[($z)][$posvoti+4]="<b>$consez[$z]</b>";
703 if($tab15=="gruppo" or $genere==4 or ($genere==5 and $votog) or defined('_NULLISTA')) $ar[($z)][$posvoti+5]="<b>$vonsez[$z]</b>";
704 }
705 }
706 }
707 }
708
709 if (($offsetsez+1)>=$num_sez){
710 $ar[(1+$numsezmax)][0]="<b>"._TOT."<br />"._COMPLESSIVO."</b>";
711 if(isset($temp)) {
712 if (!isset($tab15) or !$tab15) $tab15="candidati";
713 if($tab15=="gruppo" or $genere==4 or ($genere==5 and $votog) or defined('_NULLISTA')){
714 if($votog) $tab15="lista";
715 $votigl=" sum(validi),sum(nulli),sum(bianchi),sum(contestati),sum(voti_nulli)";
716 }elseif($votog){
717 $votigl=" sum(validi),sum(nulli),sum(bianchi),sum(contestati),sum(voti_nulli)";
718 }else{
719 # if($dettnulli)
720 $votigl=" sum(validi_lista),sum(voti_nulli_lista),sum(contestati_lista),sum(solo_gruppo),0";
721# else $votigl=" sum(validi_lista),sum(nulli),sum(bianchi),sum(contestati_lista),sum(voti_nulli_lista+voti_nulli)";
722 }
723 if($circo)
724 $sql="SELECT $votigl from ".$prefix."_ele_sezioni AS t1 LEFT JOIN soraldo_ele_sede AS t2 ON t1.id_sede = t2.id_sede WHERE t1.id_cons='$id_cons' and t2.id_circ=$id_circ";
725 else
726 $sql="SELECT $votigl from ".$prefix."_ele_sezioni as t1 where t1.id_cons='$id_cons' and t1.id_sez=(select t2.id_sez from ".$prefix."_ele_voti_$tab15 as t2 where t2.id_sez=t1.id_sez group by t2.id_sez)";
727 $resv = $dbi->prepare("$sql");
728 $resv->execute(); #echo "TEST2: --- $sql";
729 list ($sevaltot,$senultot,$sebiatot,$secontot,$sevnutot)= $resv->fetch(PDO::FETCH_NUM);
730 $voticompl=$sevaltot+$senultot+$sebiatot+$secontot+$sevnutot;
731 $sql="SELECT voti from ".$prefix."_ele_voti_$tab15 where id_cons='$id_cons'";
732 $resvt = $dbi->prepare("$sql");
733 $resvt->execute();
734 if($resvt) list($votlt)=$resvt->fetch(PDO::FETCH_NUM); else $votlt=0;
735 if($perc) $temp3=arrayperc($temp,$sevaltot);
736
737 foreach($temp as $key=>$voti) {
738 if ($perc=='true' and $voticompl)
739 {
740 $percento="<b>$voti<br /><span class=\"red\"><i>".$temp3[$key]." %</i></span></b>";
741 } else
742 $percento="<b>$voti</b>";
743 $ar[1+$numsezmax][$key]=$percento;
744 }
745 }
746 if ($visvot!='cand') {
747 $key=$offset+1;
748
749# if(!defined('_NULLISTA'))
750 if($tab15=="gruppo" or $genere==4 or ($genere==5 and $votog) or defined('_NULLISTA'))
751 $tmp=array($sevaltot,$senultot,$sebiatot,$secontot,$sevnutot);
752 else $tmp=array($sevaltot,$senultot,$sebiatot,$secontot);
753 if($perc) $temp3=arrayperc($tmp,$voticompl);
754
755 foreach($tmp as $k=>$voti) {
756 if ($perc=='true' and $voticompl)
757 {
758 $percento="<b>$voti<br /><span class=\"red\"><i>".$temp3[$k]." %</i></span></b>";
759 } else $percento="<b>$voti</b>";
760 $ar[1+$numsezmax][++$key]=$percento;
761
762 }
763 }
764 }
765 if($orvert!=1) {
766 $i=0;
767 foreach ( $ar as $riga) {
768 $y=0;
769 foreach($riga as $cella) {
770 $ra[$y++][$i]=$cella;
771 }
772 $i++;
773 }
774 crea_tabella($ra);
775 }else{
776 crea_tabella($ar);
777 }
778//e' un referendum
779 }else{
780 $sql="SELECT id_gruppo, descrizione,num_gruppo from ".$prefix."_ele_gruppo where id_cons=$id_cons order by num_gruppo";
781 $res_lis = $dbi->prepare("$sql");
782 $res_lis->execute();
783
784 if($res_lis) $numliste=$res_lis->rowCount(); else $numliste=0;
785
786 if (!isset($offset)) $offset=10;
787 if (!isset($min)) $min=1;
788 if (!isset($offsetsez)) $offsetsez=25; //lo 0 viene sostituito dal totale di sezioni presenti
789 if (!isset($minsez)) $minsez=1;
790 if (!$csv){
791 echo "<div><h5>$pagina</h5></div>";
792 echo "<form id=\"voti\" method=\"post\" action=\"modules.php\">";
793 echo "<div style=\"text-align:left;width:700px;margin:auto;font-size:12px \">
794 <input type=\"hidden\" name=\"name\" value=\"Elezioni\"></input>";
795 echo "<input type=\"hidden\" name=\"op\" value=\"$op\"></input>";
796 echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"></input>";
797 echo "<input type=\"hidden\" name=\"id_comune\" value=\"$id_comune\"></input>";
798 echo ""._SCELTA." "._CONSULTAZIONE.": <select name=\"id_gruppo\">";
799 if($res_lis)
800 while(list($id_rif,$descrizione,$num_lis) = $res_lis->fetch(PDO::FETCH_NUM)) {
801 if (!$id_gruppo) $id_gruppo=$id_rif;
802 $sel = ($id_rif == $id_gruppo) ? "selected=\"selected\"" : "";
803 echo "<option value=\"$id_rif\" $sel>";
804 for ($j=strlen($num_lis);$j<2;$j++) { echo "&nbsp;&nbsp;";}
805 echo $num_lis.") ".strip_tags(substr($descrizione,0,50))."</option>";
806 }
807 echo "</select>";
808 echo "<br />"._VIS_PERC.": <input type=\"checkbox\" name=\"perc\" value=\"true\"";
809 if($perc=='true') echo " checked=\"true\"";
810 echo ">";
811 echo "<br /><input type=\"submit\" name=\"update\" value=\""._RICARICA."\"></form></div>";
812
813
814
815 }
816
817 $sql="select num_gruppo,descrizione from ".$prefix."_ele_gruppo where id_gruppo=$id_gruppo";
818 $res_ref = $dbi->prepare("$sql");
819 $res_ref ->execute();
820
821 $sql="select $tab2, t1.num_gruppo, t1.descrizione , t1.simbolo,
822 sum(t2.si), sum(t2.no),sum(t2.validi), sum(t2.nulli),sum(t2.bianchi), sum(t2.contestati)
823 from ".$prefix."_ele_gruppo as t1
824 left join ".$prefix."_ele_voti_ref as t2 on (t1.id_gruppo=t2.id_gruppo)
825 left join ".$prefix."_ele_sezioni as t3 on (t2.id_sez=t3.id_sez)
826 left join ".$prefix."_ele_sede as t4 on (t3.id_sede=t4.id_sede)
827 left join ".$prefix."_ele_circoscrizione as t5 on (t4.id_circ=t5.id_circ)
828 where t1.id_cons='$id_cons' and t1.id_gruppo=$id_gruppo
829 group by t2.id_gruppo,$tab2, t1.num_gruppo, t1.descrizione , t1.simbolo
830 order by $tab3, t1.num_gruppo
831 ";
832 $res = $dbi->prepare("$sql");
833 $res->execute();
834
835 if($res) $num_sez=$res->rowCount(); else $num_sez=0;
836 if($res_ref) list($num_gruppo,$descr)= $res_ref->fetch(PDO::FETCH_NUM); else {$num_gruppo=0;$descr='';}
837
838 if (!$csv){
839 # stampa
840
841 $datipdf="<b>"._COMUNE." $descr_comune</b> - "._RISULTATI.": $descr_cons<br/><b>$pagina</b><br/><br/> ";
842 $datipdf .="<br/><b>Referendum n. ".$num_gruppo." </b><br/>".$descr."";
843 echo "<div style=\"text-align:right;width:900px;margin-left:10px;margin-right:20px;font-size:12px \">";
844 echo "<table style=\"text-align:center;margin-right:0px;border-top : 1px solid Blue;width: 140px;\"><tr style=\" background:#eceff5;\"><td>"._ESPORTA."<br />";
845
846 echo "<a href=\"modules.php?name=Elezioni&amp;op=$op&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;csv=1&amp;perc=$perc&amp;id_gruppo=$id_gruppo&amp;datipdf=$datipdf\" ><img class=\"image\" src=\"modules/Elezioni/images/printer.gif\" alt=\"Stampa\" /></a>";
847 echo "<a href=\"modules.php?name=Elezioni&amp;op=$op&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;csv=1&amp;perc=$perc&amp;id_gruppo=$id_gruppo&amp;xls=1&amp;datipdf=$datipdf\" ><img class=\"image\" src=\"modules/Elezioni/images/csv.gif\" alt=\"Export Csv\" /></a>";
848
849 //echo "<a href=\"modules.php?name=Elezioni&amp;op=$op&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;csv=1&amp;perc=$perc&amp;id_gruppo=$id_gruppo&amp;pdf=1&amp;datipdf=$datipdf\" ><img class=\"image\" src=\"modules/Elezioni/images/pdf.gif\" alt=\"Export Pdf\" /></a>";
850
851
852 echo "<img class=\"image\" src=\"modules/Elezioni/images/rss.png\" alt=\"Export rss\" />";
853
854 echo " </td></tr>";
855
856
857 echo "<form id=\"pdf\" method=\"post\" action=\"modules.php\">";
858
859 echo "<input type=\"hidden\" name=\"id_circ\" value=\"$id_circ\"></input>";
860 echo "<input type=\"hidden\" name=\"op\" value=\"$op\"></input>";
861 echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"></input>";
862 echo "<input type=\"hidden\" name=\"id_comune\" value=\"$id_comune\"></input>";
863 echo "<input type=\"hidden\" name=\"csv\" value=\"1\"></input>";
864 echo "<input type=\"hidden\" name=\"orvert\" value=\"$orvert\"></input>";
865 echo "<input type=\"hidden\" name=\"min\" value=\"$min\"></input>";
866 echo "<input type=\"hidden\" name=\"offset\" value=\"$offset\"></input>";
867 echo "<input type=\"hidden\" name=\"minsez\" value=\"$minsez\"></input>";
868 echo "<input type=\"hidden\" name=\"offsetsez\" value=\"$offsetsez\"></input>";
869 echo "<input type=\"hidden\" name=\"perc\" value=\"$perc\"></input>";
870 echo "<input type=\"hidden\" name=\"id_gruppo\" value=\"$id_gruppo\"></input>";
871 echo "<input type=\"hidden\" name=\"pdf\" value=\"1\"></input>";
872 echo "<input type=\"hidden\" name=\"datipdf\" value=\"$datipdf\"></input>";
873 echo "<input type=\"hidden\" name=\"name\" value=\"Elezioni\"></input>";
874
875 echo "<tr><td>";
876 echo "<input type=\"image\" name=\"submit\" src=\"modules/Elezioni/images/pdf.gif\" align=\"left\">";
877 echo "&nbsp; L &nbsp;<input type=\"radio\" name=\"orienta\" $land value=\"L\"></input>P &nbsp;<input
878 type=\"radio\" name=\"orienta\" $port value=\"P\"></input><br />";
879 echo "&nbsp; A3<input type=\"radio\" name=\"formato\" $A3 value=\"A3\"></input>A4<input
880 type=\"radio\" name=\"formato\" $A4 value=\"A4\"></input>";
881
882
883 echo " </td></tr></table></form> ";
884
885
886
887
888
889
890
891
892
893 echo "</div>";
894
895
896// numero sezioni scrutinate
897 $sql="select t3.id_sez from ".$prefix."_ele_voti_ref 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' group by t3.id_sez ";
898 $res4 = $dbi->prepare("$sql");
899 $res4->execute();
900
901 $numero=$res4->rowCount();
902 $sql="select t1.* from ".$prefix."_ele_sezioni as t1 left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t1.id_cons='$id_cons' ";
903 $res5 = $dbi->prepare("$sql");
904 $res5->execute();
905
906 $sezioni=$res5->rowCount();
907 if ($numero!=0) echo "<h5><i> "._SEZSCRU." $numero "._SU." $sezioni </i></h5>";
908
909}
910 $sql="select count(0) from ".$prefix."_ele_sezioni where id_cons='$id_cons'";
911 $res5 = $dbi->prepare("$sql");
912 $res5->execute();
913
914 list($num_sez) = $res5->fetch(PDO::FETCH_NUM);
915
916
917
918
919
920 if (!$csv)echo "<b>Referendum n. ".$num_gruppo." </b><br />".$descr."";
921
922 $y=1;
923 $ar[0][0]=$tipo2;
924 $ar[0][1]=_SI;
925 $ar[0][2]=_NO;
926 $ar[0][3]=_VALIDI;
927 $ar[0][4]=_NULLI;
928 $ar[0][5]=_BIANCHI;
929 $ar[0][6]=_CONTESTATI;
930 if($res_ref)
931 while (list($num_gruppo,$desc_ref) = $res_ref->fetch(PDO::FETCH_NUM)){
932 $ar[0][$i++]= $num_gruppo.") ".$desc_ref;
933 $ar[1][$y++]= "SI";
934 $ar[1][$y++]= "NO";
935 }
936 $num_sez++;
937 $tot_si=0;
938 $tot_no=0;
939 $tot_va=0;
940 $tot_nu=0;
941 $tot_bi=0;
942 $tot_co=0;
943 if($res)
944 while (list($num_circ,$desc_circ,$num_gruppo,$desc_ref,$simbolo,$si,$no,$validi,$nulli,$bianchi, $contestati) = $res->fetch(PDO::FETCH_NUM)){
945 $i=1;
946 $votanti=$validi+$nulli+$bianchi+$contestati;
947 $tot_si+=$si;
948 $tot_no+=$no;
949 $tot_va+=$validi;
950 $tot_nu+=$nulli;
951 $tot_bi+=$bianchi;
952 $tot_co+=$contestati;
953 $ar[$num_circ][0]=$num_circ."<br />".$desc_circ;
954 if($validi){
955 $ar[$num_circ][$i++]= $perc=='true' ? $si."<br /><span class=\"red\"><i>".number_format($si*100/$validi,2)."%</i></span>":$si;
956 $ar[$num_circ][$i++]= $perc=='true' ? $no."<br /><span class=\"red\"><i>".number_format($no*100/$validi,2)."%</i></span>":$no;
957 }else{
958 $ar[$num_circ][$i++]= $perc=='true' ? $si."<br /><span class=\"red\"><i>0.00%</i></span>":$si;
959 $ar[$num_circ][$i++]= $perc=='true' ? $no."<br /><span class=\"red\"><i>0.00%</i></span>":$no;
960 }
961 if($votanti){
962 $ar[$num_circ][$i++]= $perc=='true' ? $validi."<br /><span class=\"red\"><i>".number_format($validi*100/$votanti,2)."%</i></span>":$validi;
963 $ar[$num_circ][$i++]= $perc=='true' ? $nulli."<br /><span class=\"red\"><i>".number_format($nulli*100/$votanti,2)."%</i></span>":$nulli;
964 $ar[$num_circ][$i++]= $perc=='true' ? $bianchi."<br /><span class=\"red\"><i>".number_format($bianchi*100/$votanti,2)."%</i></span>":$bianchi;
965 $ar[$num_circ][$i++]= $perc=='true' ? $contestati."<br /><span class=\"red\"><i>".number_format($contestati*100/$votanti,2)."%</i></span>":$contestati;
966 }else{
967 $ar[$num_circ][$i++]= $perc=='true' ? $validi."<br /><span class=\"red\"><i>0.00%</i></span>":$validi;
968 $ar[$num_circ][$i++]= $perc=='true' ? $nulli."<br /><span class=\"red\"><i>0.00%</i></span>":$nulli;
969 $ar[$num_circ][$i++]= $perc=='true' ? $bianchi."<br /><span class=\"red\"><i>0.00%</i></span>":$bianchi;
970 $ar[$num_circ][$i++]= $perc=='true' ? $contestati."<br /><span class=\"red\"><i>0.00%</i></span>":$contestati;
971 }
972 }
973 $i=1;
974 $tot_vo=$tot_va+$tot_nu+$tot_bi+$tot_co;
975# if($tot_va==0) $tot_va=1;
976# if($tot_vo==0) $tot_vo=1;
977 $ar[$num_sez][0]=_TOT."<br />"._COMPLESSIVO;
978 if($tot_va){
979 $ar[$num_sez][$i++]= $perc=='true' ? $tot_si."<br /><span class=\"red\">".number_format($tot_si*100/$tot_va,2)."%</span>":$tot_si;
980 $ar[$num_sez][$i++]= $perc=='true' ? $tot_no."<br /><span class=\"red\">".number_format($tot_no*100/$tot_va,2)."%</span>":$tot_no;
981 }else{
982 $ar[$num_sez][$i++]= $perc=='true' ? $tot_si."<br /><span class=\"red\">0.00%</span>":$tot_si;
983 $ar[$num_sez][$i++]= $perc=='true' ? $tot_no."<br /><span class=\"red\">0.00%</span>":$tot_no;
984 }
985 if($tot_vo){
986 $ar[$num_sez][$i++]= $perc=='true' ? $tot_va."<br /><span class=\"red\">".number_format($tot_va*100/$tot_vo,2)."%</span>":$tot_va;
987 $ar[$num_sez][$i++]= $perc=='true' ? $tot_nu."<br /><span class=\"red\">".number_format($tot_nu*100/$tot_vo,2)."%</span>":$tot_nu;
988 $ar[$num_sez][$i++]= $perc=='true' ? $tot_bi."<br /><span class=\"red\">".number_format($tot_bi*100/$tot_vo,2)."%</span>":$tot_bi;
989 $ar[$num_sez][$i++]= $perc=='true' ? $tot_co."<br /><span class=\"red\">".number_format($tot_co*100/$tot_vo,2)."%</span>":$tot_co;
990 }else{
991 $ar[$num_sez][$i++]= $perc=='true' ? $tot_va."<br /><span class=\"red\">0.00%</span>":$tot_va;
992 $ar[$num_sez][$i++]= $perc=='true' ? $tot_nu."<br /><span class=\"red\">0.00%</span>":$tot_nu;
993 $ar[$num_sez][$i++]= $perc=='true' ? $tot_bi."<br /><span class=\"red\">0.00%</span>":$tot_bi;
994 $ar[$num_sez][$i++]= $perc=='true' ? $tot_co."<br /><span class=\"red\">0.00%</span>":$tot_co;
995 }
996 crea_tabella($ar);
997 }
998 if ($csv) echo "</body>\n</html>";
999}
1000
1001?>
Note: See TracBrowser for help on using the repository browser.