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

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

continua menu contestuale - correzione per visualizzazione grafici affluenze per referendum

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