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

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