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

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