source: trunk/client/modules/Elezioni/blocchi/cerca_candidato.php@ 265

Last change on this file since 265 was 265, checked in by roby, 5 years ago
File size: 4.5 KB
Line 
1<?php
2/************************************************************************/
3/* Eleonline - Raccolta e diffusione dei dati elettorali */
4/* by Roberto Gigli & Luciano Apolito */
5/* http://www.eleonline.it */
6/* info@eleonline.it luciano@aniene.net rgigli@libero.it */
7/************************************************************************/
8/* widget cerca candidato
9 by luciano apolito 2015 */
10
11
12if (!defined('MODULE_FILE')) {
13 die ("You can't access this file dirrectly...");
14}
15global $id_comune;
16
17# validatore form
18echo '
19 <script type="text/javascript">
20function validateForm()
21 {
22 var x=document.forms["form_candi"]["cognome"].value;
23 if (x==null || x=="")
24 {
25
26 return false;
27 }
28 }
29</script>
30';
31
32# form
33echo '
34 <div><h5>Cerca il candidato</h5>
35 <form method="post" name="form_candi" action="" onsubmit="return validateForm()" >
36 Inserisci il cognome o/e il nome intero del candidato da cercare<br/>
37 <input type="text" name="cognome" maxlength="30" size="10" value="">';
38echo "<input type=\"hidden\" name=\"id_comune\" value=\"$id_comune\">";
39echo '<input type="submit" value="Cerca">
40 </form>
41 </div>
42';
43
44if(isset($_SESSION['cerca_cand'])) $cerca_cand=$_SESSION['cerca_cand']; else $cerca_cand="";
45echo $cerca_cand;
46$_SESSION['cerca_cand']='';
47
48
49$url=$_SERVER['REQUEST_URI']; // url della pagina per il reload
50
51$param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ? $_GET : $_POST;
52if (isset($param['cognome'])) get_magic_quotes_gpc() ? $cognome=$param['cognome']:$cognome=addslashes($param['cognome']); else $cognome='';
53$chiave="$cognome";
54global $id_comune;
55
56
57if($cognome!=''){
58 # divide nome e cognome
59 $arr = explode(" ", $cognome);
60 $num_arr=count($arr);
61 if ($num_arr==2){
62 $cognome=$arr[0];
63 $nome=$arr[1];
64 $numeratore= " AND "; // cognome e nome
65 }else{
66 $nome=$cognome;
67 $numeratore= " OR "; // cognome o nome
68 }
69
70 $sql="SELECT * FROM ".$prefix."_ele_candidati where ((cognome like '%$cognome%' $numeratore nome like '%$nome%') OR (cognome like '%$nome%'
71 $numeratore nome like '%$cognome%')) and id_cons in(select id_cons from ".$prefix."_ele_cons_comune where id_comune='$id_comune')";
72 $res = $dbi->prepare("$sql");
73 $res->execute();
74
75 $num_tot = $res->rowCount();
76 $sql="SELECT * FROM ".$prefix."_ele_candidati where ((cognome like '%$cognome%' $numeratore nome like '%$nome%') OR (cognome like '%$nome%' $numeratore nome like '%$cognome%')) and id_cons in(select id_cons from ".$prefix."_ele_cons_comune where id_comune='$id_comune') ORDER BY id_cand DESC LIMIT 0,7";
77 $res = $dbi->prepare("$sql");
78 $res->execute();
79
80 while (list($id_cand,$id_cons2,$id_lista,$cognome,$nome,$note,$simbolo,$num_candidato) = $res->fetch(PDO::FETCH_NUM)) {
81 $sql="SELECT id_cons_gen FROM ".$prefix."_ele_cons_comune where id_cons='$id_cons2'" ;
82 $resl = $dbi->prepare("$sql");
83 $resl->execute();
84
85 list($id_cons_gen_cand) = $res1->fetch(PDO::FETCH_NUM);
86 $sql="SELECT descrizione, tipo_cons FROM ".$prefix."_ele_consultazione where id_cons_gen='$id_cons_gen_cand'" ;
87 $res2 = $dbi->prepare("$sql");
88 $res2->execute();
89
90 list($descr_consultazione,$tipo_consul) = $res2->fetch(PDO::FETCH_NUM);
91 $sql="SELECT descrizione FROM ".$prefix."_ele_lista where id_lista='$id_lista'" ;
92 $res3 = $dbi->prepare("$sql");
93 $res3->execute();
94
95 list($descr_lista) = $res3->fetch(PDO::FETCH_NUM);
96
97 $sql="select * from ".$prefix."_ele_sezioni where id_cons='$id_cons2'";
98 $res4 = $dbi->prepare("$sql");
99 $res4->execute();
100
101 $sezioni=$res4->rowCount();
102 $cerca_cand .= "<div style=\"text-align:left\"><hr/>";
103 $cerca_cand .= "<img src=\"modules.php?name=Elezioni&amp;file=foto&amp;id_lista=$id_lista\" width=\"30\" heigth=\"30\" align=\"left\">";
104
105 if($tipo_consul!='4'){ // non Ú circoscrizione
106 $cerca_cand .="<a href=\"modules.php?name=Elezioni&amp;id_cons_gen=$id_cons_gen_cand&amp;id_comune=$id_comune&amp;op=candidato_sezione&amp;min=$num_candidato&amp;offset=$num_candidato&amp;id_lista=$id_lista&amp;orvert=1&amp;offsetsez=$sezioni&id_circ=\">
107 $cognome $nome</a> $descr_consultazione - $descr_lista ";
108 }else{
109 $cerca_cand .= "$cognome $nome</a> $descr_consultazione - $descr_lista ";
110 }
111 $cerca_cand .='</div>';
112
113 }
114
115 $cerca_cand .="<hr/>Trovati n.$num_tot con chiave <b>$chiave</b>";
116 if($num_tot>="8") $cerca_cand .="<br/>Raffina la ricerca...";
117
118 $_SESSION['cerca_cand']=$cerca_cand;
119 header("location:$url ");
120 //$cognome='';
121}
122
123
124
125?>
Note: See TracBrowser for help on using the repository browser.