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

Last change on this file since 399 was 399, checked in by roby, 3 months ago
  • ADMIN

-- Correzione per il caricamento di liste nelle elezioni europee

  • CLIENT

-- Centratura del logo del comune nelle stampe
-- Correzione per casi particolari nel widget gom_affluenze
-- Correzione per caso particolare in grafici

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