source: trunk/client/modules/Elezioni/grafici.php@ 354

Last change on this file since 354 was 352, checked in by roby, 3 years ago

Segue adattamento per php7
modifica gestione consultazioni con e senza voto nullo di lista

File size: 34.1 KB
Line 
1<?php
2
3/************************************************************************/
4/* Eleonline - Raccolta e diffusione dei dati elettorali */
5/* by Luciano Apolito & Roberto Gigli */
6/* http://www.eleonline.it */
7/* info@eleonline.it luciano@aniene.net rgigli@libero.it */
8/************************************************************************/
9
10if (!defined('MODULE_FILE')) {
11 die ("You can't access this file directly...");
12}
13
14
15$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' ";
16$res = $dbi->prepare("$sql");
17$res->execute();
18
19list($descr_cons,$tipo_cons,$genere,$votog,$votol,$votoc,$circo) = $res->fetch(PDO::FETCH_NUM);
20$sql="SELECT t2.id_cons FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_cons_gen='$id_cons_gen' and t2.id_comune='$id_comune'" ;
21$res = $dbi->prepare("$sql");
22$res->execute();
23
24list($id_cons) = $res->fetch(PDO::FETCH_NUM);
25
26
27if($flash=='1') include "class/charts.php";
28
29/***********************************
30/* Grafica affluenze
31/**********************************/
32
33function affluenze_graf(){
34global $bgcolor1, $bgcolor2, $prefix, $dbi, $offset,$genere,$votog,$votol,$votoc,$circo, $min,$id_cons,$tipo_cons,$id_cons_gen,$csv,$id_comune,$id_circ, $tema;
35// icone
36 if ($circo) $circos="and t2.id_circ='$id_circ'";
37 else $circos="";
38 if (!$csv)
39 echo "<div>
40 <a href=\"
41 modules.php?name=Elezioni&amp;op=come&amp;file=index&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;info=affluenze_sez\">"._DETTAGLIO." "._AFFLUENZE."<img class=\"image\" src=\"modules/Elezioni/images/dettagli.png\" alt=\" "._AFFLUENZE."\" /></a>
42 <a href=\" modules.php?name=Elezioni&amp;file=index&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;op=affluenze_graf&amp;csv=1\">"._VER_STAMPA." <img class=\"image\" src=\"modules/Elezioni/images/printer.png\" alt=\"stampa\" /></a></div>";
43
44 // circoscrizionali
45
46 // numero sezioni scrutinate
47 //if ($circo)$circos="and id_circ='$id_circ'";
48 if (!isset($data1)) $data1='';
49 if (!isset($ora_ril)) $ora_ril='';
50 $sql="SELECT count(data) FROM ".$prefix."_ele_voti_parziale as t3 left join ".$prefix."_ele_sezioni as t1 on t3.id_sez=t1.id_sez left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t1.id_cons='$id_cons' and data='$data1' and orario='$ora_ril' $circos group by t3.id_gruppo";
51 $res1 = $dbi->prepare("$sql");
52 $res1->execute();
53
54# mysql_query("select * from ".$prefix."_ele_voti_parziale where id_cons='$id_cons' $circos group by id_sez ",$dbi);
55 $numero=$res1->rowCount();
56 $sql="SELECT t1.* FROM ".$prefix."_ele_sezioni as t1, ".$prefix."_ele_sede as t2 where t1.id_cons='$id_cons' and t1.id_sede=t2.id_sede $circos order by num_sez";
57 $res2 = $dbi->prepare("$sql");
58 $res2->execute();
59
60#mysql_query("select * from ".$prefix."_ele_sezioni where id_cons='$id_cons' $circos",$dbi);
61 $sezioni=$res2->rowCount();
62
63
64
65
66
67// barre
68 $l_size = getimagesize("modules/Elezioni/images/barre/leftbar.gif");
69 $m_size = getimagesize("modules/Elezioni/images/barre/mainbar.gif");
70 $r_size = getimagesize("modules/Elezioni/images/barre/rightbar.gif");
71 $l_size2 = getimagesize("modules/Elezioni/images/barre/leftbar2.gif");
72 $m_size2 = getimagesize("modules/Elezioni/images/barre/mainbar2.gif");
73 $r_size2 = getimagesize("modules/Elezioni/images/barre/rightbar2.gif");
74 // totali
75
76 if($tema=='tour') $andcond="select orario,data from ".$prefix."_ele_voti_parziale where id_cons='$id_cons' order by data desc,orario desc limit 0,1"; else $andcond="select orario,data from ".$prefix."_ele_rilaff where id_cons_gen='$id_cons_gen' order by data,orario";
77
78 $sql="$andcond";
79 $res = $dbi->prepare("$sql");
80 $res->execute();
81
82 while(list($orario,$data) = $res->fetch(PDO::FETCH_NUM)) {
83 list ($ore,$minuti,$secondi)=explode(':',$orario);
84 list ($anno,$mese,$giorno)=explode('-',$data);
85 $tot_v_m=0;$tot_v_d=0;$tot_t=0;
86
87
88 echo "<br /><div><h5>"._VOTANTI." "._ALLE." "._ORE." $ore,$minuti "._DEL." $giorno/$mese/$anno</h5></div>";
89
90 $sql="SELECT count(data) FROM ".$prefix."_ele_voti_parziale as t3 left join ".$prefix."_ele_sezioni as t1 on t3.id_sez=t1.id_sez left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t1.id_cons='$id_cons' and data='$data' and orario='$orario' $circos group by t3.id_gruppo";
91 $res1 = $dbi->prepare("$sql");
92 $res1->execute();
93
94 list($numero)=$res1->fetch(PDO::FETCH_NUM);
95
96
97 $sql="select sum(t3.voti_complessivi), t4.num_gruppo , t4.id_gruppo from ".$prefix."_ele_voti_parziale as t3 left join ".$prefix."_ele_sezioni as t1 on t3.id_sez=t1.id_sez left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede left join ".$prefix."_ele_gruppo as t4 on (t3.id_gruppo=t4.id_gruppo) where t3.id_cons='$id_cons' and t3.orario='$orario' and t3.data='$data' $circos group by t4.num_gruppo, t4.id_gruppo order by t4.num_gruppo ";
98 $res1 = $dbi->prepare("$sql");
99 $res1->execute();
100
101#mysql_query("select sum(t1.voti_complessivi), t2.num_gruppo , t2.id_gruppo from ".$prefix."_ele_voti_parziale as t1 left join ".$prefix."_ele_gruppo as t2 on (t1.id_gruppo=t2.id_gruppo) where t1.id_cons='$id_cons' and t1.orario='$orario' and t1.data='$data' group by t2.num_gruppo,t2.id_gruppo order by t2.num_gruppo " , $dbi);
102
103
104
105
106
107 while(list($voti_t, $num_gruppo,$id_gruppo) = $res1->fetch(PDO::FETCH_NUM)) {
108 $query="select sum(voti_complessivi) from ".$prefix."_ele_voti_parziale where orario='$orario' and data='$data' and id_cons='$id_cons'";
109
110 if ($genere==0){$query.=" and id_gruppo=$id_gruppo";}
111 $sql=$query;
112 $res_aff = $dbi->prepare("$sql");
113 $res_aff->execute();
114
115 $voti_numero=$res_aff->rowCount();
116 $query="SELECT sum(maschi+femmine) FROM ".$prefix."_ele_sezioni as t1, ".$prefix."_ele_sede as t2 where t1.id_cons='$id_cons' and t1.id_sede=t2.id_sede $circos";
117#"select sum(maschi+femmine) from ".$prefix."_ele_voti_parziale as t1 , ".$prefix."_ele_sezioni as t2 where t1.id_cons=$id_cons and t1.id_sez=t2.id_sez and orario='$orario' and data='$data' $circos";
118
119
120# if ($genere==0){$query.=" and id_gruppo=$id_gruppo";}
121 $sql=$query;
122 $res1234 = $dbi->prepare("$sql");
123 $res1234->execute();
124
125 list($tot)=$res1234->fetch(PDO::FETCH_NUM);
126
127 $perc=number_format($voti_t*100/$tot,2);
128 echo "<table class=\"td-80\"><tr class=\"bggray\">";
129 if ($genere==0){echo "<td>Referendum N.</td>";}
130 echo "<td><b>"._VOTANTI."</b></td><td><b>"._PERCE."</b></td>";
131 echo "<td><b>"._SEZIONI."</b></td>";
132 echo "</tr>";
133 echo "<tr class=\"bggray2\">";
134 if ($genere==0){echo "<td><h2>$num_gruppo</h2></td>";}
135 echo "<td>$voti_t</td><td>$perc %</td><td>$numero</td>
136 </tr></table>";
137
138
139 // barre
140
141 echo "<table><tr><td><table><tr><td>&nbsp;"._VOTANTI." : </td><td>
142<img src=\"modules/Elezioni/images/barre/leftbar2.gif\" height=\"$l_size2[1]\" width=\"$l_size2[0]\" alt=\"votanti\" /><img src=\"modules/Elezioni/images/barre/mainbar2.gif\" alt=\"votanti\" height=\"$m_size2[1]\" width=\"". ($perc * 2)."\" /><img src=\"modules/Elezioni/images/barre/rightbar2.gif\" height=\"$r_size2[1]\" width=\"$r_size2[0]\" alt=\"votanti\" /><span class=\"red\"> $perc</span> % ($voti_t)<br /></td></tr>\n";
143
144 $tot_gen=$tot;
145
146
147 echo "<tr><td>&nbsp;"._AVENTI.": </td><td><img src=\"modules/Elezioni/images/barre/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"elettori\" /><img src=\"modules/Elezioni/images/barre/mainbar.gif\" alt=\"elettori\" height=\"$m_size[1]\" width=\"".(100 * 2)."\" /><img src=\"modules/Elezioni/images/barre/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\"elettori\" /> 100 % ($tot_gen)</td></tr></table>";
148 echo "</td></tr></table>";
149
150 }
151
152 }
153}
154
155/*********************************/
156/* Grafica votanti */
157/**********************************/
158
159function graf_votanti(){
160global $op, $prefix, $dbi, $offset, $min,$descr_cons,$genere,$votog,$votol,$votoc,$circo, $id_cons,$tipo_cons,$id_comune,$id_cons_gen,$id_circ,$csv,$w,$l,$siteistat,$flash,$tour,$tema,$copy;
161
162
163$param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ?
164 $_GET : $_POST;
165if (isset($param['anim'])) $anim=intval($param['anim']); else $anim='';
166
167if ($siteistat==$id_comune) $logo="$siteistat"; else $logo=''; // logo per il comune
168$logo=verificasimbolo(); // carica_logo da funzioni.php
169// menu
170 if (!$csv && $anim!=1){ $anim=1;$versione=_VER_HTML;
171 }else{ $anim='';$versione=_VER_FLASH;}
172 if($csv!=1){
173 echo " <div>
174 <a href=\"
175 modules.php?name=Elezioni&amp;op=come&amp;file=index&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;info=votanti\">"._DETTAGLIO." "._VOTANTI."<img class=\"image\" src=\"modules/Elezioni/images/dettagli.png\" alt=\"votanti\" /></a>
176 <a href=\" modules.php?name=Elezioni&amp;file=index&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;op=graf_votanti&amp;csv=1&amp;flash=\">"._VER_STAMPA." <img class=\"image\" src=\"modules/Elezioni/images/printer.png\" alt=\"stampa\" /></a>";
177 if($flash==1)
178 echo "<a href=\" modules.php?name=Elezioni&amp;file=index&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;op=graf_votanti&amp;csv=&amp;anim=$anim\">$versione <img class=\"image\" src=\"modules/Elezioni/images/grafici.gif\" alt=\"flash\" /></a>";
179 echo "</div>";
180 }
181
182
183/* Scelta circoscrizioni da implementare
184if ($circo){ // elenco per scelta circoscrizione
185 echo "<form id=\"test\" action=\"modules.php\"> <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=\">";
186 $res_sez = mysql_query("SELECT id_circ,descrizione,num_circ from ".$prefix."_ele_circoscrizione where id_cons=$id_cons",$dbi);
187 echo "<table><tr><td>Scegli la Circoscrizione: <select name=\"id_circ\" onChange=\"top.location.href=this.form.pagina.value+this.form.id_circ.options[this.form.id_circ.selectedIndex].value;return false\">";
188 while(list($id_rif,$descrizione,$num_cir)=mysql_fetch_row($res_sez)) {
189 if (!$id_circ) $id_circ=$id_rif;
190 $sel = ($id_rif == $id_circ) ? "selected" : "";
191 echo "<option value=\"$id_rif\" $sel>";
192 for ($j=strlen($num_cir);$j<2;$j++) { echo "&nbsp;&nbsp;";}
193 echo $num_cir.") ".$descrizione;
194 }
195 echo "</select></td></tr></table></form>";
196
197 }
198
199
200*/
201
202 if ($genere==0) $tab="ref";elseif($genere=='4' || $votog) $tab="lista";
203 else $tab="gruppo";
204 if (isset($circo) and $circo) $circos="and t2.id_circ='$id_circ'";
205 else $circos='';
206
207 // Verificare per la circoscrizione aprile 2008 Nicola?
208 //if ($genere==0) {$tab="ref";}else{$tab="gruppo";}
209 //if ($votog or $genere==4) {$tab="lista";}else{$tab="gruppo";}
210
211 /*
212 if($circo){
213 if(!$id_circ){
214 $res = mysql_query("select id_circ from ".$prefix."_ele_circoscrizione where id_cons='$id_cons' ", $dbi);
215 list($id_circ)=mysql_fetch_row($res);
216 }
217
218 $res = mysql_query("select t1.id_sez,sum(t1.voti) from ".$prefix."_ele_voti_$tab as t1, ".$prefix."_ele_$tab as t2 where t1.id_$tab=t2.id_$tab and t1.id_cons='$id_cons' and t2.id_circ='$id_circ' group by t1.id_sez", $dbi);
219 }else
220 */
221 if($genere==0)
222 $sql="select t1.* from ".$prefix."_ele_voti_".$tab." as t1 left join ".$prefix."_ele_gruppo as t2 on t1.id_gruppo=t2.id_gruppo where t1.id_cons='$id_cons' $circos group by t1.id_sez ";
223 else
224 $sql="select * from ".$prefix."_ele_sezioni where id_cons='$id_cons' and validi+nulli+bianchi+contestati>0";
225 $res = $dbi->prepare("$sql");
226 $res->execute();
227
228
229 if($res)
230 $numero=$res->rowCount();
231 else
232 $numero=1;
233 $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' $circos";
234 $res = $dbi->prepare("$sql");
235 $res->execute();
236
237 $sezioni=$res->rowCount();
238 if ($numero!=0){
239
240
241
242
243 $sql="SELECT sum(maschi+femmine) 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' $circos";
244 $res1 = $dbi->prepare("$sql");
245 $res1->execute();
246
247 list($tot_aventi) = $res1->fetch(PDO::FETCH_NUM);
248
249 if ($genere!=0) {
250 echo "<center><h2>";
251 echo "<b>"._DETTAGLIO." "._VOTIE."</b> - ";
252 echo "<i> "._SEZSCRU." $numero "._SU." $sezioni </i>";
253 echo "</h2></center>";
254
255 $sql="SELECT sum(validi+nulli+bianchi+contestati) as tot,
256 sum(validi),sum(nulli),sum(bianchi),sum(contestati), '0'
257 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' $circos having tot>0";
258 $res1 = $dbi->prepare("$sql");
259 $res1->execute();
260
261 }else{
262
263 if($tema=='tour'){
264 $sql="SELECT count(0)
265 from ".$prefix."_ele_gruppo where id_cons=$id_cons";
266 $res1 = $dbi->prepare("$sql");
267 $res1->execute();
268
269
270 list($max_ruotag) =$res1->fetch(PDO::FETCH_NUM);
271 if (isset($_SESSION['ruotag'])) { $ruotag=$_SESSION['ruotag'];}
272 else {$ruotag=1;$_SESSION['ruotag']=1;}
273 if ($ruotag>=$max_ruotag) {$ruotag=1;}
274 else {$ruotag++;}
275 $_SESSION['ruotag']=$ruotag;
276 $sql="SELECT count(0) from ".$prefix."_ele_voti_ref AS t1 LEFT JOIN ".$prefix."_ele_gruppo AS t2 ON t1.id_gruppo = t2.id_gruppo WHERE t1.id_cons ='$id_cons' AND t2.num_gruppo ='$ruotag'";
277 $res1 = $dbi->prepare("$sql");
278 $res1->execute();
279
280 list($numero)=$res1->fetch(PDO::FETCH_NUM);
281 echo "<center><h2>";
282 echo "<b>"._DETTAGLIO." "._VOTIE."</b> - ";
283 echo "<i> "._SEZSCRU." $numero "._SU." $sezioni </i>";
284 echo "</h2></center>";
285
286 $sql="SELECT sum( t1.validi + t1.nulli + t1.bianchi + t1.contestati ) AS tot, sum( t1.validi ) , sum( t1.nulli ) , sum( t1.bianchi ) , sum( t1.contestati ) , t1.id_gruppo
287FROM ".$prefix."_ele_voti_ref AS t1 LEFT JOIN ".$prefix."_ele_gruppo AS t2 ON t1.id_gruppo = t2.id_gruppo
288WHERE t1.id_cons ='$id_cons' AND t2.num_gruppo ='$ruotag' GROUP BY t1.id_gruppo HAVING tot >0";
289 $res1 = $dbi->prepare("$sql");
290 $res1->execute();
291
292 } else
293 $sql="SELECT sum(validi+nulli+bianchi+contestati) as tot,
294 sum(validi),sum(nulli),sum(bianchi),sum(contestati), id_gruppo
295 from ".$prefix."_ele_voti_ref where id_cons=$id_cons group by id_gruppo having tot>0";
296 $res1 = $dbi->prepare("$sql");
297 $res1->execute();
298
299 }
300 while (list($tot_votanti,$validi,$nulli,$bianchi,$contestati,$id) = $res1->fetch(PDO::FETCH_NUM)){
301 $arperc=array();
302 $arval=array($validi,$nulli,$bianchi,$contestati);
303 $arperc=arrayperc($arval,$tot_votanti);
304 $tot_votanti=$validi+$bianchi+$nulli+$contestati;
305 $perc_validi=number_format($arperc[0],2);
306 $perc_nulli=number_format($arperc[1],2);
307 $perc_bianchi=number_format($arperc[2],2);
308 $perc_conte=number_format($arperc[3],2);
309 $perc_votanti=number_format($tot_votanti*100/$tot_aventi,2);
310 $non_votanti=($tot_aventi - $tot_votanti);
311 $perc_non=100-$perc_votanti;
312
313 if ($genere==0) {
314 $sql="SELECT num_gruppo,descrizione from ".$prefix."_ele_gruppo where id_gruppo=$id";
315 $res = $dbi->prepare("$sql");
316 $res->execute();
317
318 list($num_gruppo,$descr_gruppo) = $res->fetch(PDO::FETCH_NUM);
319 }
320
321
322
323 $a1=_VALIDI;$b1=_NULLI;$c1=_BIANCHI;$d1=_CONTESTATI;$titolo=""._PERCE." "._VOTIE."";
324 $e1=_VOTANTI;$f1=""._NON." "._VOTANTI."";$titolo2=""._PERCE." "._AFFLUENZE."";
325
326
327
328
329 echo "<table width=\"100%\" class=\"modulo\"><tr>";
330 if ($genere==0) echo "<td colspan=\"2\" valign=\"top\" >";
331 else echo "<td valign=\"top\" >";
332
333 echo "<table cellspacing=\"5\" style=\"text-align:center;\">";
334 if ($genere==0) {echo "<tr><td colspan=\"4\"><h4>"._GRUPPO." $num_gruppo <br/> $descr_gruppo</h4></td></tr>";}
335 echo "
336 <tr class=\"bggray3\"><td style=\"text-align: right;\"><b>"._AVENTI."</b></td><td>$tot_aventi</td><td><span class=\"red\">100%</span></td></td></td></tr>
337
338 <tr class=\"bggray3\"><td style=\"text-align: right;\"><b>"._VOTANTI."</b></td><td>$tot_votanti</td><td><span class=\"red\">$perc_votanti%</span></td></tr>
339
340 <tr class=\"bggray3\"><td style=\"text-align: right;\">"._VALIDI."</td><td>$validi</td><td><span class=\"red\">$perc_validi%</span></td></tr>
341
342 <tr class=\"bggray3\"><td style=\"text-align: right;\">"._NULLI."</td><td>$nulli</td><td><span class=\"red\">$perc_nulli%</span></td></tr>
343
344 <tr class=\"bggray3\"><td style=\"text-align: right;\">"._BIANCHI."</td><td>$bianchi</td><td><span class=\"red\">$perc_bianchi%</span></td></tr>
345
346 <tr class=\"bggray3\"><td style=\"text-align: right;\">"._CONTESTATI."</td><td>$contestati</td><td><span class=\"red\">$perc_conte%</span></td></tr>
347
348 </table>";
349 echo "</td></tr><tr><td style=\"text-align:center;\">
350 <h1>"._PERCE." "._VOTANTI."</h1>";
351 if ($genere==0) echo "<h2> "._GRUPPO." $num_gruppo</h2>";
352
353
354 //if ((!$csv && $flash!=1 && $anim!=1) or ($tour==1 && $flash!=1 && $anim!=1)){ # rotazione x tour marzo 2009 a.l.
355 if ((!$csv && $flash!=1 || $anim!=1) and ($tour!=1)) { # rotazione x tour marzo 2009 a.l.
356 echo "<br /><img alt=\"Grafico\" src=\"modules/Elezioni/grafici/votanti_graf.php?cop=$copy&amp;titolo=$titolo2&amp;e=$perc_votanti&amp;f=$perc_non&amp;e1=$e1&amp;f1=$f1&amp;logo=$logo\" /><br /><br />";
357 }else{
358 // Flash affluenze
359 $gruppos1=array("",_VOTANTI,_NONVOTANTI);
360 $pre1=array("",$perc_votanti,$perc_non);
361 flash_torta($gruppos1,$pre1,50,50);
362 }
363
364 if($csv) echo "</td><td>";else echo "</td></tr><tr><td style=\"text-align:center;\">"; # rotazione x tour marzo 2009 a.l.
365 echo "<h1>"._PERCE." "._VOTIE."</h1>";
366 if ($genere==0) echo "<h2> "._GRUPPO." $num_gruppo<h2> ";
367
368 //$logo=verificasimbolo(); // carica_logo da funzioni.php
369
370 if ((!$csv && $flash!=1 || $anim!=1) and ($tour!=1)){ # rotazione x tour marzo 2009 a.l.
371 echo "<br /><img alt=\"Grafico\" src=\"modules/Elezioni/grafici/voti_graf.php?cop=$copy&amp;titolo=$titolo&amp;a=$perc_validi&amp;b=$perc_nulli&amp;c=$perc_bianchi&amp;d=$perc_conte&amp;a1=$a1&amp;b1=$b1&amp;c1=$c1&amp;d1=$d1&amp;logo=$logo\" /><br /><br />";
372 }else{
373
374 $gruppos2=array("","Validi","Nulli", "Bianchi", "Contestati");
375 $pre2=array("",$perc_validi,$perc_nulli,$perc_bianchi,$perc_conte);
376 flash_torta($gruppos2,$pre2,50,50);
377 }
378
379
380
381 echo "</td></tr></table>";
382
383
384 }
385 }
386
387}
388
389/***********************************
390/* Grafica Gruppo
391/**********************************/
392
393function graf_gruppo($visgralista){
394global $admin, $bgcolor1, $bgcolor5, $prefix, $dbi, $offset, $min,$descr_cons,$genere,$votog,$votol,$votoc,$circo, $id_cons,$id_cons_gen,$id_comune,$id_circ,$tipo_cons,$w,$l,$op,$siteistat,$flash,$tema,$copy;
395if ($siteistat==$id_comune) $logo=$siteistat; else $logo=''; // logo per il comune
396$logo=verificasimbolo(); // carica_logo da funzioni.php
397 if (!$id_circ and $circo){
398 $sql="SELECT id_circ from ".$prefix."_ele_circoscrizione where id_cons=$id_cons order by num_circ limit 0,1";
399 $res_sez = $dbi->prepare("$sql");
400 $res_sez->execute();
401
402 list($id_circ)=$res_sez->fetch(PDO::FETCH_NUM);
403 }
404 $circond='';$circondt1='';
405 if ($genere!=0){$tab="gruppo";}else{$tab="ref";}
406 if ($genere==4 or $visgralista){$tab="lista";}
407 if ($votog){$tab="lista";}
408 $sql="select * from ".$prefix."_ele_voti_$tab where id_cons='$id_cons' group by id_sez ";
409 $res = $dbi->prepare("$sql");
410 $res->execute();
411
412 if ($circo){
413 $sql="select t1.* from ".$prefix."_ele_voti_gruppo as t1, ".$prefix."_ele_gruppo as t2 where t1.id_gruppo=t2.id_gruppo and t1.id_cons='$id_cons' and t2.id_circ=$id_circ group by t1.id_sez ";
414 $res = $dbi->prepare("$sql");
415 $res->execute();
416
417 $sql="select sum(t1.voti) from ".$prefix."_ele_voti_gruppo as t1, ".$prefix."_ele_gruppo as t2 where t1.id_gruppo=t2.id_gruppo and t1.id_cons='$id_cons' and t2.id_circ=$id_circ";
418 $restotv = $dbi->prepare("$sql");
419 $restotv->execute();
420
421 $circond="and id_circ=$id_circ";$circondt1="and t1.id_circ=$id_circ";
422 }
423 if ($res) $numero=$res->rowCount();else $numero=0;
424 $sql="select t2.* from ".$prefix."_ele_sezioni as t2, ".$prefix."_ele_sede as t1 where t2.id_cons='$id_cons' and t1.id_sede=t2.id_sede $circondt1";
425 $res = $dbi->prepare("$sql");
426 $res->execute();
427
428 if ($res) $sezioni=$res->rowCount();else $sezioni=0;
429
430
431 if ($numero>0 ){
432 echo "<center><h2>";
433 if ($genere!=4 and !$visgralista){
434 echo "<b>"._PREFERENZE." "._GRUPPO." $descr_cons </b>";
435 }else{
436 echo "<b>"._PREFERENZE." "._LISTA." $descr_cons </b>";
437 }
438 echo "<i>- "._SEZSCRU." $numero "._SU." $sezioni </i>";
439 echo "</h2></center>";
440
441 if ($genere!=0){
442 // tot voti
443 if (!$circo)
444 $sql="select sum(voti) from ".$prefix."_ele_voti_$tab where id_cons=$id_cons ";
445 else
446 $sql="select sum(t1.voti) from ".$prefix."_ele_voti_$tab as t1 left join ".$prefix."_ele_$tab as t2 on t1.id_$tab=t2.id_$tab where t2.id_circ=$id_circ ";
447 if ($votog)
448 $sql="select sum(voti) from ".$prefix."_ele_voti_lista where id_cons=$id_cons ";
449 $restotv = $dbi->prepare("$sql");
450 $restotv->execute();
451 list($tot) = $restotv->fetch(PDO::FETCH_NUM);
452
453
454 $i=0;
455 // lista o gruppo
456 if ($genere!=4 and !$visgralista){
457
458 if ($votog){
459
460 $sql="select t1.id_gruppo, t1.num_gruppo, t1.descrizione, sum(t2.voti) as somma
461 from ".$prefix."_ele_gruppo as t1,
462 ".$prefix."_ele_voti_lista as t2,
463 ".$prefix."_ele_lista as t3
464 where t1.id_cons='$id_cons'
465 and t2.id_lista=t3.id_lista
466 and t1.id_gruppo=t3.id_gruppo
467 group by t1.id_gruppo
468 order by somma desc";
469 $cosa='id_gruppo';
470
471 }else{
472
473
474 $sql="select t1.id_gruppo, t1.num_gruppo, t1.descrizione, sum(t2.voti) as somma
475 from ".$prefix."_ele_gruppo as t1
476 left join ".$prefix."_ele_voti_$tab as t2 on (t1.id_gruppo=t2.id_gruppo)
477 where t1.id_cons='$id_cons' and t1.id_cons=t2.id_cons $circondt1
478 group by t2.id_gruppo
479 order by somma desc";
480 $cosa='id_gruppo';
481 }
482 $res = $dbi->prepare("$sql");
483 $res->execute();
484
485
486 }else{
487 $sql="select t1.id_lista, t1.num_lista, t1.descrizione, sum(t2.voti) as somma
488 from ".$prefix."_ele_lista as t1
489 left join ".$prefix."_ele_voti_$tab as t2 on (t1.id_lista=t2.id_lista)
490 where t1.id_cons='$id_cons' and t1.id_cons=t2.id_cons $circondt1
491 group by t2.id_lista
492 order by somma desc";
493 $res = $dbi->prepare("$sql");
494 $res->execute();
495 $cosa='id_lista';
496 }
497
498 echo "<table>
499 <tr>
500 <td><br />
501 <table style=\"border-collapse: collapse;\" rules=\"cols\">";
502 // inizio tabella dati
503 // variabili stampa flash
504 $e=0;
505 $gruppos[$e]="";
506 $pre[$e]="";
507 $e=1;
508 // fine
509 $gruppinum=$res->rowCount();
510 $altrivoti=0;
511####calcolo percentuale
512 $arvoti=array();
513 $arperc=array();
514 while (list($id,$num,$descrizione,$voti) = $res->fetch(PDO::FETCH_NUM)){
515 $arvoti[$id]=$voti;
516 }
517 $arperc=arrayperc($arvoti,$tot);
518 $res = $dbi->prepare("$sql");
519 $res->execute();
520
521####
522 $altriperc=0;
523 while (list($id,$num,$descrizione,$voti) = $res->fetch(PDO::FETCH_NUM)){
524
525
526 // verica chi ha preso meno del 3%
527 $menotre=(number_format($voti*100/$tot,2));
528
529 if($menotre>3){
530
531
532
533
534 // funz per il taglio corretto della frase 13 feb 2007
535 //$descrizione=taglio(4,$descrizione);
536
537 $gruppo[$i]=(substr($descrizione,0,21));
538 $gruppos[$e]=(substr($descrizione,0,21)); //flash
539
540
541
542 if (strlen($descrizione)>21) $gruppo[$i].="...";
543 if (strlen($descrizione)>21) $gruppos[$e].="...";
544 $pro[$i]=number_format($arperc[$id],2);
545 $pre[$e]=number_format($arperc[$id],2); //flash
546
547
548 }else{
549 //somma i voti sotto il 3%
550 $altrivoti = $altrivoti + $voti;
551 $altriperc += $arperc[$id];
552 }
553
554
555
556
557
558
559 $votiv=number_format($voti,0,',','.');
560 // formattazione numeri perc
561 $prov=number_format($arperc[$id],2);
562
563 // sviluppo tabella dati
564 $bgcolor1= ($bgcolor1=="#cacaca") ? "#ffffff":"#cacaca";
565 echo "<tr valign=\"top\">
566 <td style=\"vertical-align=:top;\"><b><img src=\"modules.php?name=Elezioni&amp;file=foto&amp;$cosa=$id\" class=\"stemmapic\" alt=\"descrizione\" /></b></td>
567 <td><b>$descrizione</b></td>
568 <td>"._VOTI."</td><td align=\"right\">$votiv</td><td align=\"right\"> <i>($prov%)</i></td>
569 </tr>";
570
571 $e++; // flash
572 $i++;
573 }
574 // aggiunge altri minori al 3%
575 // esiste
576 // corretto 15 aprile 2006
577 if ($altrivoti>0){
578
579 $gruppo[]=_ALTRI;
580 $gruppos[]=_ALTRI;
581 $pro[]=$altriperc; #number_format($altrivoti*100/$tot,3);
582 $pre[]=$altriperc; #number_format($altrivoti*100/$tot,3);
583 }
584
585
586 if ($i<=10) $i=10;
587 $titolo=""._PERCE." "._VOTIE."";
588 $dati1=serialize($pro);
589 //$dati1=urlencode($dati1);
590 //$gruppo=utf8_encode($gruppo);
591 $dati2=serialize($gruppo);
592 $dati2=urlencode($dati2);
593
594 $titolo=urlencode($titolo);
595 if (isset($copy)) $copy=urlencode($copy); else $copy='';
596 $descr_cons=urlencode($descr_cons);
597 if ($genere==4){$w=800;$l=250;}else{$w=750;$l=220;}
598
599
600 echo "</table></td>";
601 global $tema;
602 if($tema!="tour") echo "</tr><tr>";
603 echo "<td style=\"vertical-align=:top;\"><br />";
604 # grafico statico
605 echo "<img src='modules/Elezioni/grafici/barre.php?dati1=$dati1&amp;dati2=$dati2&amp;i=$i&amp;cop=$copy&amp;titolo=$titolo&amp;descr=$descr_cons&amp;l=$l&amp;w=$w&amp;logo=$logo' alt=\"Grafico\" />";
606
607 echo "</td></tr></table><table><tr><td>";
608 # grafico flash
609 if($flash=='1') flash_torta($gruppos,$pre,40,145);
610 $uno='';
611 foreach($gruppos as $k=>$v) $uno.="- $v";
612 $due='due:';
613 foreach($pre as $k=>$v) $due.="- $v";
614 echo "</td></tr></table>";
615
616
617 }else{
618 // tot voti
619 if($tema=='tour'){
620 $sql="SELECT count(0) from ".$prefix."_ele_gruppo where id_cons=$id_cons";
621 $res1 = $dbi->prepare("$sql");
622 $res1->execute();
623
624 list($max_ruotag) =$res1->fetch(PDO::FETCH_NUM);
625 if (isset($_SESSION['ruotag'])) { $ruotag=$_SESSION['ruotag'];}
626 else {$ruotag=1;$_SESSION['ruotag']=1;}
627 $sql="select sum(t1.validi),t1.id_gruppo from ".$prefix."_ele_voti_$tab as t1 left join soraldo_ele_gruppo as t2 on t1.id_gruppo=t2.id_gruppo where t1.id_cons='$id_cons' and t2.num_gruppo='$ruotag' group by t1.id_gruppo";
628 }else
629 $sql="select sum(validi),id_gruppo from ".$prefix."_ele_voti_$tab where id_cons=$id_cons group by id_gruppo";
630 $res = $dbi->prepare("$sql");
631 $res->execute();
632
633 while (list($tot,$id_gruppo) = $res->fetch(PDO::FETCH_NUM)){
634
635 $s=0;
636 $sql="select t1.id_gruppo, t1.num_gruppo, t1.descrizione, sum(t2.si), sum(t2.no)
637 from ".$prefix."_ele_gruppo as t1
638 left join ".$prefix."_ele_voti_$tab as t2 on (t1.id_gruppo=t2.id_gruppo)
639 where t1.id_cons='$id_cons' and t1.id_gruppo='$id_gruppo'
640 group by t1.id_gruppo
641 ";
642 $res1 = $dbi->prepare("$sql");
643 $res1->execute();
644
645
646
647 while (list($id_gruppo,$num_gruppo,$descrizione,$si,$no) = $res1->fetch(PDO::FETCH_NUM)){
648 if($tot){
649 $percsi=number_format($si*100/$tot,3);
650 $percno=number_format($no*100/$tot,3);
651 $percsi=number_format($percsi,2);
652 $percno=number_format($percno,2);
653 }else{ $percsi="0.00"; $percno="0.00";}
654 $gruppo=array("si","no");
655 $gruppos=array("","si","no");// flash
656 $pro=array($percsi,$percno);
657 $pre=array("",$percsi,$percno);//flash
658// echo "<br/><b><center>$descrizione</center><br/><br/>";
659 // sviluppo tabella dati
660 echo "<table><tr><td><table>"; // inizio tabella dati
661 echo "<tr><td style=\"background-color:$bgcolor1;\">$num_gruppo - $descrizione</b></td></tr><tr></table>
662 <table><tr>
663 <td ><b>"._SI.":</b> </td><td>$si</td>
664 <td ><b>%</b> </td><td>$percsi</td>
665 <td ><b>"._NO.":</b> </td><td>$no</td>
666 <td ><b>%</b> </td><td>$percno</td><tr>
667 </table></td><td><center><br />";
668
669 $i=8; // parametro lunghezza tavola
670 $l=30; // larghezza label
671 $titolo="Numero ".$num_gruppo."";
672 $dati1=serialize($pro);
673 //$dati1=urlencode($dati1); //IE
674 $dati2=serialize($gruppo);
675 $dati2=urlencode($dati2);
676 $titolo=urlencode($titolo);
677 if (isset($copy)) $copy=urlencode($copy); else $copy='';
678 $descr=urlencode($descr_cons);
679 echo "<center><img src='modules/Elezioni/grafici/barre.php?dati1=$dati1&amp;dati2=$dati2&amp;i=$i&amp;cop=$copy&amp;titolo=$titolo&amp;descr=$descr&amp;l=$l&amp;w=$w&amp;logo=$logo' alt=\"Grafico\" /></center>";
680
681
682 if($flash=='1')flash_torta($gruppos,$pre,20,70);
683
684
685
686
687
688 echo "</td></tr></table>"; // fine tabella dati
689 $s++;
690 }
691
692
693 }
694
695
696
697 }
698
699 }
700
701
702}
703
704
705
706
707/***********************************
708/* Grafica Candidato
709/**********************************/
710
711function graf_candidato(){
712global $descr_com, $bgcolor1, $bgcolor5,$bgcolor5, $prefix, $dbi, $offset, $min,$descr_cons, $id_cons,$tipo_cons,$copy,$id_comune,$id_istat,$genere,$votog,$votol,$votoc,$circo,$siteistat,$id_circ;
713
714$logo=verificasimbolo(); // carica_logo da funzioni.php
715if($circo) $circos=" and t2.id_circ='$id_circ'"; else $circos='';
716 $tab="ele_voti_candidati";
717
718 $sql="select id_sez from ".$prefix."_ele_voti_candidati where id_sez in (select t1.id_sez from ".$prefix."_ele_sezioni as t1 left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t2.id_cons=$id_cons $circos) group by id_sez";
719 $res = $dbi->prepare("$sql");
720 $res->execute();
721
722 $numero=$res->rowCount();
723 $sql="select t1.id_sez from ".$prefix."_ele_sezioni as t1 left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t2.id_cons=$id_cons $circos";
724 $res = $dbi->prepare("$sql");
725 $res->execute();
726
727 $sezioni=$res->rowCount();
728 if ($numero!=0){
729 echo "<table border=\"0\" align=\"center\"><tr><td>";
730 echo "<h5>"._PREFERENZE." "._CONSI." $descr_cons </h5>";
731 echo "<h5>"._SEZSCRU." $numero "._SU." $sezioni </h5>
732 <h5>I 30 piu' votati</h5>";
733 echo "</td></tr></table>";
734 // tot voti
735 $sql="select sum(voti) from ".$prefix."_ele_voti_candidati where id_sez in (select t1.id_sez from ".$prefix."_ele_sezioni as t1 left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t2.id_cons=$id_cons $circos)";
736 $res = $dbi->prepare("$sql");
737 $res->execute();
738 list($tot) = $res->fetch(PDO::FETCH_NUM);
739
740 // gruppi o liste per simbolo
741
742 if ($genere==4){
743 $scelta="_ele_lista as t2 on (t1.id_lista=t2.id_lista)";
744 }else{
745 $scelta="_ele_lista as t2 on (t1.id_lista=t2.id_lista)";
746 }
747 $i=0;
748 $sql="select t1.id_lista, t1.id_cand, t1.nome , t1.cognome, sum(t3.voti) as somma
749 from ".$prefix."_ele_candidati as t1
750 left join ".$prefix."_ele_voti_candidati as t3 on (t1.id_cand=t3.id_cand)
751 left join ".$prefix.$scelta."
752 where t1.id_cons='$id_cons' $circos
753 group by t3.id_cand
754
755 order by somma desc
756
757 ";
758 $res = $dbi->prepare("$sql");
759 $res->execute();
760
761 $n_candi=$res->rowCount();
762 echo "<table><tr><td><table>"; // inizio tabella dati
763 while (list($id_lista,$id_cand,$nome,$cognome,$voti) = $res->fetch(PDO::FETCH_NUM)){
764 $candidato[$i]=$cognome;
765 if ($tot) $pro[$i]=number_format($voti*100/$tot,2); else $pro[$i]=0;
766 // sviluppo tabella dati
767 $e=$i+1;
768
769 echo "<tr><td>[$e]</td><td><b><img alt=\"$nome $cognome\" src=\"modules.php?name=Elezioni&amp;file=foto&amp;id_lista=$id_lista\" align=\"middle\" width=\"30\"></b></td>
770 <td bgcolor=\"$bgcolor1\"><b>$nome $cognome</b></td>
771 <td bgcolor=\"$bgcolor1\">"._VOTI."</td><td>$voti</td>
772 <td bgcolor=\"$bgcolor1\">%</td><td>$pro[$i]</td></tr>";
773
774 if ($e=='30' || $e==$n_candi){
775
776
777
778 echo "</table></td></tr></table>"; // fine tabella dati
779
780 include("footer.php");
781 exit;
782 }
783
784
785
786 $i++;
787
788
789
790
791 }
792
793 }
794
795}
796
797
798
799function flash_torta($gruppos,$pre,$y,$x){
800//if (!defined('FLASH')) die();
801include_once ("class/charts.php");
802// inizio grafico torta flash
803
804
805
806 $chart[ 'chart_data' ] = array ($gruppos, $pre);
807// $chart[ 'chart_data' ] = array ( array ("","Ciao", "Bella"), array ( "",40, 60));
808 $chart[ 'chart_grid_h' ] = array ( 'thickness'=>0 );
809 $chart[ 'chart_pref' ] = array ( 'rotation_x'=>60 );
810 $chart[ 'chart_rect' ] = array ( 'x'=>$x, 'y'=>$y, 'width'=>350, 'height'=>200, 'positive_alpha'=>0 );
811 $chart[ 'chart_transition' ] = array ( 'type'=>"spin", 'delay'=>.5, 'duration'=>.75, 'order'=>"category" );
812 $chart[ 'chart_type' ] = "3d pie";
813 $chart[ 'chart_value' ] = array ( 'color'=>"000000", 'alpha'=>150, 'font'=>"arial", 'bold'=>true, 'size'=>10, 'position'=>"inside", 'prefix'=>"", 'suffix'=>"", 'decimals'=>2, 'separator'=>"", 'as_percentage'=>true );
814
815 $chart[ 'draw' ] = array ( array ( 'type'=>"text", 'color'=>"000000", 'alpha'=>4, 'size'=>40, 'x'=>50, 'y'=>260, 'width'=>500, 'height'=>50, 'text'=>"56789012345678901234", 'h_align'=>"center", 'v_align'=>"middle" )) ;
816
817 $chart[ 'legend_label' ] = array ( 'layout'=>"horizontal", 'bullet'=>"circle", 'font'=>"arial", 'bold'=>true, 'size'=>10, 'color'=>"000000", 'alpha'=>85 );
818 $chart[ 'legend_rect' ] = array ( 'x'=>0, 'y'=>45, 'width'=>50, 'height'=>210, 'margin'=>10, 'fill_color'=>"00ff00", 'fill_alpha'=>30, 'line_color'=>"000000", 'line_alpha'=>0, 'line_thickness'=>0 );
819 $chart[ 'legend_transition' ] = array ( 'type'=>"dissolve", 'delay'=>0, 'duration'=>4 );
820
821 $chart[ 'series_color' ] = array ( "00ff88", "ffaa00","44aaff", "aa00ff" );
822 $chart[ 'series_explode' ] = array ( 25, 75, 0, 0 );
823 $fileout="";
824/////////////////////////////// MODIFICHE PER TOGLIERE FILETEMP
825// $fileout=SendChartData ( $chart );
826 $xml=SendChartData ( $chart );
827 $max=isset($_SESSION['max']) ? $_SESSION['max']:0;
828 $max++;
829 $cur="xml$max";
830 $_SESSION[$cur]=$xml;
831 $_SESSION['max']=$max;
832 $fileout="modules.php?file=graf&pos=$cur";
833///////////////////////////////
834 echo InsertChart ( "class/charts.swf", "class/charts_library","$fileout" );
835
836 // Fine Grafico torta flash
837 echo "<noembed>Elemento non supportato!<br/>Grafico a torta</noembed>";
838
839
840}
841
842
843
844
845
846
847
848?>
849
850
Note: See TracBrowser for help on using the repository browser.