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

Last change on this file since 21 was 21, checked in by roby, 14 years ago

Correzione per gestione accentate nei grafici e sostituita eregi in admin

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