source: trunk/client/modules/Elezioni/funzioni.php@ 228

Last change on this file since 228 was 228, checked in by roby, 9 years ago

admin: correzione nella gestione della modifica dei dati del comune
client: visualizzazione del widget "02_risultati" anche per le circoscrizionali e per comuni con più collegi

File size: 13.2 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
10
11/*******************************************************
12 #'Pagina precedente' e 'Pagina Successiva' #
13 immettere nel file da dividere la lettura
14 del numero complessivo dei dati:
15 Es: $max=sql_num_rows($res);
16
17 l'offset settato al numero dei dati da
18 visualizzare per pagina:
19 Es: $offset=5;
20
21 l'azzeramento della variabile $min
22 Es: if (!isset($min)) $min=0;
23
24 il nome del file (opzione) da ricaricare)
25 Es: $file="gruppopercsez"; // nome op per pagine
26
27
28*/
29
30
31
32function page($id_cons,$go,$max,$min,$prev,$next,$offset,$file){
33global $lettera,$ordine,$id_comune;
34
35
36 echo"<br /><div class=\"modulo\">";
37 $prev=$min-$offset;
38 if ($prev>=0) {
39 echo "<a href=\"modules.php?name=Elezioni&amp;op=$go&amp;min=$prev&amp;id_cons_gen=$id_cons&amp;id_comune=$id_comune&amp;file=$file&amp;lettera=$lettera&amp;ordine=$ordine\">";
40 echo "[ <b>$offset "._PREV_MATCH."</b> ]</a>";
41 }
42
43 $next=$min+$offset;
44 if ($next>=($offset-1)) {
45 if($next>=$max) $next = $max;
46 else {
47
48 echo "<a href=\"modules.php?name=Elezioni&amp;op=$go&amp;min=$next&amp;id_cons_gen=$id_cons&amp;id_comune=$id_comune&amp;file=$file&amp;lettera=$lettera&amp;ordine=$ordine\">";
49 echo " [<b>$offset "._NEXT_MATCH."</b> ] </a>";
50 }
51 }
52 echo "</div><br /><br/>";
53
54}
55
56
57
58
59
60// *********************************
61// Funzioni formattazione data
62// ***********************************
63
64
65function giorno()
66{
67$giorni= array('--','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
68foreach($giorni as $gi)
69 $giorno .= "<option value=$gi>$gi</option>";
70$giorno .= "</select>";
71echo "$giorno";
72}
73
74
75function mese()
76{
77$mesi= array('--','01','02','03','04','05','06','07','08','09','10','11','12');
78foreach($mesi as $me)
79 $mese .= "<option value=$me>$me </option>";
80$mese .= "</select>";
81echo "$mese";
82}
83
84function anno()
85{
86$curr=date("Y",time());
87$anni=array('--',$curr--,$curr--,$curr--,$curr--,$curr--,$curr--,$curr--);
88foreach($anni as $an)
89 $anno .= "<option value=$an>$an</option>";
90$anno .= "</select>";
91echo "$anno";
92}
93
94function ore()
95{
96$ore= array('00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24');
97foreach($ore as $ori)
98 $ore .= "<option value=$ori>$ori</option>";
99$ore .= "</select>";
100echo "$ore";
101}
102
103
104function minuti()
105{
106$minuti= array('00','01','02','03','04','05','06','07','08','09','10','11','12','13','14',
107'15', '16', '17', '18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33',
108'34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50',
109'51','52','53','54','55','56','57','58','59');
110foreach($minuti as $minu)
111 $minuti .= "<option value=$minu>$minu </option>";
112$minuti .= "</select>";
113echo "$minuti";
114}
115
116function secondi()
117{
118$secondi= array('00','01','02','03','04','05','06','07','08','09','10','11','12','13','14',
119'15', '16', '17', '18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33',
120'34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50',
121'51','52','53','54','55','56','57','58','59');
122foreach($secondi as $sec)
123 $secondi .= "<option value=$sec>$sec</option>";
124$secondi .= "</select>";
125echo "$secondi";
126}
127
128
129
130function form_data($data)
131
132 {
133 list($anno,$mese,$giorno) = explode("-", $data) ;
134 if ($giorno>0)
135 return("$giorno-$mese-$anno");
136 else
137 return("&nbsp; ");
138 }
139
140
141function taglio($parole,$descrizione)
142{
143
144/* funzione per il taglio di una frase giusta senza
145troncare le parole by luc 13 febbraio 2007
146uso:
147taglio(numero di parole, frase)
148*/
149
150$lunghezza=strlen($descrizione);
151$altra='0';
152$testo='';
153$lettera='';
154
155
156for ($x=0;$x<$parole;$x++){
157 if($testo!='')$testo .=" ";
158
159 for ($j=$altra;$j<$lunghezza;$j++){
160 $lettera=$descrizione{$j};
161 if ($lettera!=" "){
162 $testo .=$lettera;
163 }else{
164 $altra=$j+1; $j=$lunghezza;
165 }
166
167 }
168}
169
170
171return "$testo";
172
173}
174#### legge freed rss 1.0
175
176function readrss($url) {
177
178
179 $rdf = parse_url($url);
180 $fp = fsockopen($rdf['host'], 80, $errno, $errstr, 15);
181 if (!$fp) {
182 $content = "";
183 echo $content;
184 return;
185 }
186
187 if ($fp) {
188 if (!empty($rdf['query']))
189 $rdf['query'] = "?" . $rdf['query'];
190
191 fputs($fp, "GET " . $rdf['path'] . $rdf['query'] . " HTTP/1.0\r\n");
192 fputs($fp, "HOST: " . $rdf['host'] . "\r\n\r\n");
193 $string = "";
194
195 while(!feof($fp)) {
196 $pagetext = fgets($fp,300);
197 $string .= chop($pagetext);
198 }
199
200
201
202
203 fputs($fp,"Connection: close\r\n\r\n");
204 fclose($fp);
205 $items = explode("</item>",$string);
206 $content ="<h5>Risultati </h5>";
207 $content .= "<span class=\"content\">";
208
209 for ($i=0;$i<20;$i++) {
210 $link = preg_replace("/.*<link>/","",$items[$i]);
211 $link = preg_replace("/</link>.*/","",$link);
212 $title2 = preg_replace("/.*<title>/","",$items[$i]);
213 $title2 = preg_replace("/</title>.*/","",$title2);
214 $title2 = stripslashes($title2);
215 $descr = preg_replace("/.*<description>/","",$items[$i]);
216 $descr = preg_replace("/</description>.*/","",$descr );
217 $descr = stripslashes($descr );
218
219 if (empty($items[$i]) AND $cont != 1) {
220 $content = "";
221
222 $cont = 0;
223
224 echo $content;
225 return;
226 } else {
227 if (strcmp($link,$title2) AND !empty($items[$i])) {
228 $cont = 1;
229 $content .= "<strong><big>&middot;</big></strong> <a href=\"$link\" target=\"new\">$title2</a> $descr<br />\n";
230 }
231 }
232
233 }
234
235
236 }
237
238 if (($cont == 0) OR (empty($content))) {
239 $content = "<span class=\"content\">Problema feed rss</span>";
240 }
241
242 echo $content;
243
244}
245### legge i risultati e li reinvia
246### richiamare con
247### list ($gruppo,$pro)=grupporss();
248
249function grupporss() {
250global $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,$circondt1 ;
251
252
253
254
255 //if($genere=='4' || $tipo_cons>='10') $tab="ele_voti_lista";
256 if($genere=='4' || $votog) $tab="ele_voti_lista";
257 else $tab="ele_voti_gruppo";
258 if($id_circ and !$circondt1) $circondt1="and t1.id_circ=$id_circ";
259
260
261 $res = mysql_query("select * from ".$prefix."_$tab where id_cons='$id_cons' group by id_sez ",$dbi);
262
263 if ($res) $numero=mysql_num_rows($res);else $numero=0;
264 $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);
265 if ($res) $sezioni=mysql_num_rows($res);else $sezioni=0;
266 if ($numero>0){
267 if ($genere!=0){
268 $restotv = mysql_query("select sum(voti) from ".$prefix."_$tab where id_cons='$id_cons' ", $dbi);
269 list($tot) = mysql_fetch_row($restotv);
270 $i=0;
271 // lista o gruppo
272 if ($genere!=4){
273 if ($votog){
274 $res = mysql_query("select t1.id_gruppo, t1.num_gruppo, t1.descrizione, sum(t2.voti) as somma
275 from ".$prefix."_ele_gruppo as t1,
276 ".$prefix."_ele_voti_lista as t2,
277 ".$prefix."_ele_lista as t3
278 where t1.id_cons='$id_cons'
279 and t2.id_lista=t3.id_lista
280 and t1.id_gruppo=t3.id_gruppo
281 group by t1.id_gruppo
282 order by somma desc", $dbi);
283 }else{
284 $res = mysql_query("select t1.id_gruppo, t1.num_gruppo, t1.descrizione, sum(t2.voti) as somma
285 from ".$prefix."_ele_gruppo as t1
286 left join ".$prefix."_ele_voti_gruppo as t2 on (t1.id_gruppo=t2.id_gruppo)
287 where t1.id_cons='$id_cons' and t1.id_cons=t2.id_cons $circondt1
288 group by t2.id_gruppo
289 order by somma desc", $dbi);
290 }
291 }else{
292 $res = mysql_query("select t1.id_lista, t1.num_lista, t1.descrizione, sum(t2.voti) as somma
293 from ".$prefix."_ele_lista as t1
294 left join ".$prefix."_$tab as t2 on (t1.id_lista=t2.id_lista)
295 where t1.id_cons='$id_cons' and t1.id_cons=t2.id_cons
296 group by t2.id_lista
297 order by somma desc", $dbi);
298 }
299 $gruppinum=mysql_num_rows($res);
300 $altrivoti=0;
301###### gestione percentuali
302 $arperc=array();
303 $arval=array();
304 $arvaltot=0;
305 while (list($id,$num,$descrizione,$voti) = mysql_fetch_row($res)){
306 $arval[$id]=$voti;
307 $arvaltot+=$voti;
308 }
309 $arperc=arrayperc($arval,$arvaltot);
310 mysql_data_seek($res,0);
311 while (list($id,$num,$descrizione,$voti) = mysql_fetch_row($res)){
312 // funz per il taglio corretto della frase 13 feb 2007
313 $descrizione=substr($descrizione,0,20);
314 $gruppo[$i]=ucwords(strtolower($descrizione));
315 if ($tot!='' and $tot!='0')
316 $pro[$i]=number_format($voti*100/$tot,3);
317 $pro[$i]=number_format($arperc[$id],2); // arrotondamento
318 $i++;
319 }
320
321
322
323
324 $titolo=""._PERCE." "._VOTIE."";
325 return array($gruppo,$pro);
326 }
327
328 }
329}
330
331function caricablocchi(){
332#### carica i blocchi presenti in modules/Elezioni/blocchi
333#### nome del file da carica xx_nome.php
334#### dove xx sta per un numero per visualizzare in ordine
335### 01_votanto.php Ú un nome valido
336### off_votanto.php per disabilitare la visualizzazione
337
338
339
340$list = array();
341$bl=opendir('modules/Elezioni/blocchi');
342 while ($file = readdir($bl)) {
343 if (!is_dir("modules/Elezioni/blocchi/$file") and (!preg_match('/^\./',$file)) and !stristr($file,"off_")) {
344 array_push($list, $file);
345 }
346 }
347 closedir($bl);
348
349 if(count($list)>0)
350 sort($list);
351 for ($item_num=0; $item_num < count($list); $item_num++) {
352 $tmp=preg_replace('/^[0-9][0-9]_/i',"",$list[$item_num]);
353 $title=str_replace("_"," ",str_replace(".php","",$tmp));
354 // backward theme compatibility
355
356 include ("modules/Elezioni/blocchi/$list[$item_num]");
357
358 //echo "<br />";
359 }
360}
361
362function block($pos){
363
364global $prefix,$dbi;
365
366 if($pos=="dx") $p=0; elseif($pos=="sx")$p=1;else $p='';
367
368 $resblk = mysql_query("SELECT * FROM ".$prefix."_ele_widget where pos_or='$p' and attivo='1' order by pos_ver asc", $dbi);
369 if($resblk){
370 while ($row = mysql_fetch_array($resblk)) {
371 $nome=$row['nome_file'];
372 include ("modules/Elezioni/blocchi/$nome");
373 }
374 }
375}
376
377function check_block($pos){
378# verifica se ci sono blocchi nel db
379global $prefix,$dbi;
380if($pos=="dx") $p=0; elseif($pos=="sx")$p=1;else $p='';
381
382 $reschk = mysql_query("SELECT * FROM ".$prefix."_ele_widget where pos_or='$p' and attivo='1' order by pos_ver asc", $dbi);
383 if ($reschk) $numero=mysql_num_rows($reschk);else $numero=0;
384
385 return $numero;
386
387}
388
389
390function arrayperc($temp,$sevaltot)
391{
392
393 $temp2tot=0;$temp2=array();$temp3=array();
394 while (list($key,$voti)= each($temp)) {
395 if($sevaltot>0){
396 $temp4=(ceil($voti*10000/$sevaltot)-($voti*10000/$sevaltot));
397 if ($temp4) $temp2[$key]=$temp4;
398 $valperc=number_format($voti*100/$sevaltot,2);
399 $temp3[$key]=$valperc;
400 $temp2tot+=$valperc;
401 }
402 }
403 if($temp2tot>100 && ($temp2tot-100)>0.01)
404 //if($temp2tot>100)
405 while ($temp2tot>100){
406 foreach ($temp2 as $key => $val) {
407 if ($val == max($temp2)) {$temp3[$key]-=0.01;$temp2tot-=0.01;$temp2[$key]=0; break;}
408 }
409 }
410 if("$temp2tot"=="100" or $temp2tot==0) return($temp3);
411 while ($temp2tot<100.00){
412 foreach ($temp2 as $key => $val) {
413 if ($val == min($temp2)) {$temp3[$key]+=0.01;$temp2tot+=0.01;$temp2[$key]=1;break;}
414 }
415
416 }
417 return($temp3);
418
419
420}
421
422# ritorna l'estensione del file
423function file_extension($filename)
424{
425 $path_info = pathinfo($filename);
426 return $path_info['extension'];
427}
428
429
430# verifica stemma e lo salva come file per pdf e grafici
431function verificasimbolo()
432{
433 global $prefix,$dbi,$id_comune,$ins_logo;
434 if($ins_logo=="0"){
435 $logo="vuoto.jpg"; //var nel config.php
436 }else{
437
438 $res = mysql_query("SELECT simbolo,stemma FROM ".$prefix."_ele_comuni where id_comune='$id_comune' ", $dbi);
439 list($simbolo,$stemma) = mysql_fetch_row($res);
440 if($simbolo!=''){
441 if (!file_exists("modules/Elezioni/images/$simbolo")) {
442
443 if(!is_writeable("modules/Elezioni/images"))
444 die("la dir modules/Elezioni/images non ha i permessi di scrittura. Correggere per continuare");
445
446 $filename=$simbolo;
447 $file=fopen("modules/Elezioni/images/$filename",'w');
448 if (fwrite($file,$stemma));
449 $close = fclose($file);
450 }
451 $logo=$simbolo;
452 }else{
453 $logo="logo.gif";
454 }
455
456 }return $logo;
457}
458
459# funzione per verifica se esiste il voto disgunto tra sindaco e lista nelle amministrative siciliane
460function isdisgiunto(){
461global $prefix,$dbi,$id_cons,$limite,$fascia,$ops;
462 #voti di lista e di gruppo completamente disgiunti
463 $result = mysql_query("select infdisgiunto, supdisgiunto from ".$prefix."_ele_conf as t2 left join ".$prefix."_ele_cons_comune as t1 on t1.id_conf=t2.id_conf where id_cons = '$id_cons' ", $dbi);
464 $glsep='';
465 if ($result) {
466 list($infdis,$supdis)=mysql_fetch_row($result);
467 if((($fascia>$limite and $supdis) or ($fascia<$limite and $infdis)) and $ops==3)
468 $glsep='_lista';
469 }
470return $glsep;
471}
472
473
474?>
Note: See TracBrowser for help on using the repository browser.