source: trunk/admin/modules/Elezioni/ele_candidato.php@ 161

Last change on this file since 161 was 97, checked in by roby, 13 years ago
  • aumentato il numero di anni in crea consultazione
  • inserito controllo per verifica inserimento dati in ele_candidato
File size: 16.7 KB
RevLine 
[2]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/* Modulo Candidati */
9/* Amministrazione */
10/************************************************************************/
11
12if (!defined('ADMIN_FILE')) {
13 die ("You can't access this file directly...");
14}
15
16$aid=$_SESSION['aid'];
17$dbi=$_SESSION['dbi'];
18$prefix=$_SESSION['prefix'];
19$currentlang=$_SESSION['lang'];
20$id_comune=$_SESSION['id_comune'];
21$param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ? $_GET : $_POST;
22$id_cons_gen=$param['id_cons_gen'];
23$perms=ChiSei($id_cons_gen);
24if ($perms<32 or !$id_cons_gen) die("$id_cons_gen -Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
25$res = mysql_query("SELECT t1.tipo_cons,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);
26list($tipo_cons,$id_cons) = mysql_fetch_row($res);
27$res = mysql_query("SELECT genere FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' " , $dbi);
28 list($genere) = mysql_fetch_row($res);
29include("modules/Elezioni/funzionidata.php");
30include("modules/Elezioni/ele.php");
31
32if (isset($param['do'])) get_magic_quotes_gpc() ? $do=$param['do']:$do=addslashes($param['do']); else $do='';
33if (isset($param['min'])) $min=intval($param['min']); else $min=0;
34if (isset($param['ok'])) get_magic_quotes_gpc() ? $ok=$param['ok']:$ok=addslashes($param['ok']); else $ok='';
35if (isset($param['id_lista'])) $id_lista=intval($param['id_lista']); else $id_lista='';
36if (isset($param['id_sez'])) $id_sez=intval($param['id_sez']); else $id_sez='';
37if (isset($param['id_circ'])) {$id_circ=intval($param['id_circ']); $_SESSION['id_circ']=$id_circ;} else
38 if (isset($_SESSION['id_circ'])) $id_circ=intval($_SESSION['id_circ']); else $id_circ='';
39if (isset($param['id_gruppo'])) $id_gruppo=intval($param['id_gruppo']); else $id_gruppo='';
40if (isset($param['id_cand'])) $id_cand=intval($param['id_cand']); else $id_cand='';
41if (isset($param['id_cand2'])) $id_cand2=intval($param['id_cand2']); else $id_cand2='';
42if (isset($param['num_lista'])) $num_lista=intval($param['num_lista']); else $num_lista='';
43if (isset($param['cognome'])) get_magic_quotes_gpc() ? $cognome=$param['cognome']:$cognome=addslashes($param['cognome']); else $cognome='';
44if (isset($param['simbolo'])) get_magic_quotes_gpc() ? $simbolo=$param['simbolo']:$simbolo=addslashes($param['simbolo']); else $simbolo='';
45if (isset($param['nome'])) get_magic_quotes_gpc() ? $nome=$param['nome']:$nome=addslashes($param['nome']); else $nome='';
46if (isset($param['note'])) get_magic_quotes_gpc() ? $note=$param['note']:$note=addslashes($param['note']); else $note='';
47if (isset($param['num_cand'])) $num_cand=intval($param['num_cand']); else $num_cand=0;
48
49// Offset - visualizza il numero di elementi per pagina
50$offset=20;
51
[97]52
[2]53/******************************************************/
54/*Funzione di visualizzazione globale */
55/*****************************************************/
56
57
58function all() {
59 global $param, $bgcolor1, $bgcolor2, $prefix, $dbi, $offset, $min, $tipo_cons, $id_cons,$tipo_cons,$id_lista,$genere,$id_cons_gen,$id_comune,$id_cand,$id_circ,$id_gruppo;
[97]60#patch per bloccare il submit se non e' stata scelta la lista. Proposta da margottid
61echo "<script language=\"Javascript\">\n
62<!--\n
63 function presenza_lista() {\n
64 if (!document.candidato2.id_lista.value) {\n
65 alert('"._SCELTA_LISTA."');\n
66 document.candidato2.id_lista.focus();\n
67 return false;\n
68 }else if(!document.candidato2.cognome.value) {\n
69 alert('"._SCELTA_COGNO."');\n
70 document.candidato2.cognome.focus();\n
71 return false;\n
72
73 }\n
74 return true;\n
75}\n
76//-->\n
77</script>\n";
[2]78 $circo='';$circo2='';
79 $currentlang=$_SESSION['lang'];
80 $res = mysql_query("SELECT circo FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' and lingua='$currentlang'", $dbi);
81 list($cons_circ)= mysql_fetch_row($res);
82 if($cons_circ) //elezioni circoscrizionali
83 {
84 echo "<form name=\"circo\" action=\"admin.php\" method=\"post\">";
85 echo "<br><br><table border=\"1\" width=\"50%\" ><tr bgcolor=\"$bgcolor1\"><td>"._SCEGLI_CIRCO.": </td>";
86 $res = mysql_query("SELECT * FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons'", $dbi);
87 echo "<input type=\"hidden\" name=\"pag\" value=\"admin.php?op=candidato&amp;id_cons_gen=$id_cons_gen&amp;id_circ=\">";
88 echo "<td><select name=\"id_circ\" onChange=\"top.location.href=this.form.pag.value+this.form.id_circ.options[this.form.id_circ.selectedIndex].value;return false\">";
89 echo "<option value=\"\">";
90 while($arr=mysql_fetch_array($res,3)){
91 if (!$id_circ) $id_circ=$arr['id_circ'];
92 $sel= ($arr['id_circ'] == $id_circ) ? "selected":"";
93 echo "<option value=\"".$arr['id_circ']."\" $sel>".$arr['descrizione'];
94 }
95 echo "</select></td></tr></table></form>";
96 $circo="and id_circ='$id_circ'";
97 $circo2="and t2.id_circ='$id_circ'";
98 }
99 if($id_cand)
100 {
101 $res = mysql_query("SELECT * FROM ".$prefix."_ele_candidati where id_cand='$id_cand'", $dbi);
102 $pro= mysql_fetch_array($res, 3);
103 }else{
104 $pro['cognome']='';$pro['num_cand']='';$pro['nome']='';
105 }
106 if (!isset($id_lista)) {
107 $res_lista=mysql_query("SELECT id_lista from ".$prefix."_ele_lista where id_cons=$id_cons $circo and num_lista=1", $dbi);
108 list($id_lista)=mysql_fetch_row($res_lista);
109 }
110 $cond=($id_lista>0) ? "and t1.id_lista=".$id_lista :'';
111 echo "<center><font class=\"title\"><br><b>"._CANDIDATO."</b></font><br><br><table border=\"0\" width=\"100%\"><tr>"
112 ."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._NUM."</b></td>"
113 ."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._COGNOME."</b></td>"
114 ."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._NOME."</b></td>";
115 echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._LISTA."</b></td>";
116
117 if ($genere==3 or $genere==5) {
118 $query= "SELECT
119 t1.id_cand,t1.id_lista,t1.num_cand,t1.cognome,t1.nome, t1.simbolo,
120 t2.simbolo as sim_lista,t2.descrizione, t3.simbolo as sim_gruppo, t3.descrizione
121 FROM ".$prefix."_ele_candidati as t1,
122 ".$prefix."_ele_lista as t2,
123 ".$prefix."_ele_gruppo as t3
124 WHERE t1.id_lista=t2.id_lista
125 and t2.id_gruppo=t3.id_gruppo
126 and t1.id_cons=t2.id_cons
127 and t1.id_cons=$id_cons $circo2
128 $cond
129 order by t2.num_lista, t1.num_cand
130 limit $min,$offset";
131 } else {
132 $query= "SELECT
133 t1.id_cand,t1.id_lista,t1.num_cand,t1.cognome,t1.nome, t1.simbolo,
134 t2.simbolo as sim_lista,t2.descrizione, '', ''
135 FROM ".$prefix."_ele_candidati as t1,
136 ".$prefix."_ele_lista as t2
137 WHERE t1.id_cons=$id_cons
138 and t1.id_cons=t2.id_cons
139 and t1.id_lista=t2.id_lista $circo2
140 $cond
141 order by t2.num_lista,t1.num_cand
142 limit $min,$offset";
143 }
144 echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._FUNZIONI."</b></td></tr>";
145 $result = mysql_query($query, $dbi);
146 if($cons_circ)
147 $res = mysql_query("SELECT count(0) FROM ".$prefix."_ele_candidati as t1,".$prefix."_ele_lista as t2 where t1.id_cons='$id_cons' and t1.id_cons=t2.id_cons and t2.id_circ=$id_circ and t1.id_lista=t2.id_lista $cond ", $dbi);
148 else
149 $res = mysql_query("SELECT count(0) FROM ".$prefix."_ele_candidati as t1 where t1.id_cons='$id_cons' $cond ", $dbi);
150 list($max) = mysql_fetch_row($res);
151 if($id_lista){
152 $numero=$max+1;} else $numero='';
153 //-----------------------lo stemma e la circoscrizione devono essere associati alla lista -
[97]154 echo "<form name=\"candidato2\" action=\"admin.php\" onSubmit=\"return presenza_lista();\">"
[2]155 ."<input type=\"hidden\" name=\"op\" value=\"candidato\">";
156 if ($pro['cognome']) {
157 echo "<input type=\"hidden\" name=\"do\" value=\"update\">";
158 echo "<tr><td><input type=\"text\" name=\"num_cand\" value=\"".$pro['num_cand']."\" size=\"5\"></td>";
159 }else{
160 echo "<input type=\"hidden\" name=\"do\" value=\"add\">";
161 echo "<tr><td><input type=\"text\" name=\"num_cand\" value=\"$numero\" size=\"5\"></td>";
162 }
163 echo "<td><input type=\"text\" name=\"cognome\" maxlength=\"50\" value=\"".$pro['cognome']."\"></td>";
164 echo "<td><input type=\"text\" name=\"nome\" maxlength=\"50\" value=\"".$pro['nome']."\"></td>";
165 //."<td><input type=\"text\" name=\"foto\" maxlength=\"20\"></td>";
166 echo "<input type=\"hidden\" name=\"pag\" value=\"admin.php?op=candidato&amp;id_cons=$id_cons&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;id_circ=$id_circ&amp;id_lista=\">";
167 echo "<td width=\"10%\"><select width=\"10\" name=\"id_lista\" onChange=\"aggiorna()\">";
168 $res= mysql_query("SELECT id_lista,num_lista,descrizione FROM ".$prefix."_ele_lista where id_cons='$id_cons' $circo order by num_lista", $dbi);
169 echo "<option value=\"\">";
170 while(list($id,$numlist,$descr) = mysql_fetch_row($res)) {
171 if (!isset($id_lista)){$id_lista=$id;}
172 $sel= ($id == $id_lista) ? "selected":"";
[37]173 echo "<option width=\"10\" value=\"$id\" $sel>".$numlist.") ".$descr;
174# echo "<option width=\"10\" value=\"$id\" $sel>".$numlist.") ".substr($descr,0,25);
[2]175 }
176 echo "</select></td>";
177 echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">";
178 echo "<input type=\"hidden\" name=\"id_circ\" value=\"$id_circ\">";
179 echo "<input type=\"hidden\" name=\"min\" value=\"$min\">";
180 if ($pro['cognome']) {
181 echo "<td align=\"center\"><input type=\"submit\" name=\"update\" value=\""._MODIFY."\"></td>";
182 echo "<input type=\"hidden\" name=\"id_cand\" value=\"".$pro['id_cand']."\">";
183 }else{
184 echo "<td align=\"center\"><input type=\"submit\" name=\"add\" value=\""._ADD."\"></td>";
185 echo "<input type=\"hidden\" name=\"id_cand\" value=\"$id_cand\">";
186 }
187 echo "</form>";
188 echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n"
189 ."document.candidato2.cognome.focus()\n"
190 ."//-->\n";
191 echo "function vai_a() {\n";
192 echo "window.document.location.href=document.candidato2.pag.value+document.candidato2.id_lista.value\n";
193 echo "}\n";
194 echo "function aggiorna(id_ele) {\n";
195 echo "if (document.candidato2.cognome.value==\"\") {vai_a()}\n";
196 echo "}\n";
197 echo "</script>\n";
198 if ($result)
199 while(list($id_cand,$id_lista2,$num_cand,$cognome, $nome,$simbolo,$simb_lista,
200 $descr_lista,$simb_gruppo,$descr_gruppo) = mysql_fetch_row($result)) {
201 $bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
202 echo "<tr bgcolor=\"$bgcolor1\"><td align=\"center\"><b>$num_cand</b>"
203 ."</td><td align=\"left\"><b>$cognome</b>"
204 ."</td><td align=\"left\"><b>$nome</b>";
205 echo "</td><td align=\"center\"><b>$descr_lista </b>";
206 echo "</td><td align=\"center\" nowrap>[<a
207 href=\"admin.php?op=candidato&amp;do=modify&amp;id_cand=$id_cand&amp;id_circ=$id_circ&amp;id_lista=$id_lista2&amp;id_gruppo=$id_gruppo&amp;id_cons_gen=$id_cons_gen&amp;min=$min\"><img src=\"modules/Elezioni/images/edit.gif\"
208 border=\"0\" align=\"center\"> "._EDIT."</a>]";
209 echo "[<a href=\"admin.php?op=candidato&amp;do=delete&amp;id_cand=$id_cand&amp;id_circ=$id_circ&amp;id_lista=$id_lista2&amp;id_gruppo=$id_gruppo&amp;cognome=$cognome&amp;nome=$nome&amp;id_cons_gen=$id_cons_gen&amp;min=$min\">"._DELETE." <img src=\"modules/Elezioni/images/delete.gif\"
210 border=\"0\" align=\"center\"></a>]";
211 echo "</td></tr>";
212 }
213 echo "</table></center>";
214
215 #'Pagina precedente' e 'Pagina Successiva'
216 echo"<table align=\"center\" width=\"100%\" ><tr>";
217 $prev=$min-$offset;
218 if ($prev>=0) {
219 echo "<td colspan=\"5\" align=\"center\" bgcolor=\"$bgcolor1\"><a href=\"admin.php?op=candidato&amp;id_cand=$id_cand&amp;id_gruppo=$id_gruppo&amp;id_cons=$id_cons&amp;id_circ=$id_circ&amp;id_lista=$id_lista&amp;min=$prev&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune\">";
220 echo "<b>$offset "._PREV_MATCH."</b></a></td>";
221 }
222
223 $next=$min+$offset;
224 if ($next>=($offset-1)) {
225 if($next>=$max) $next = $max;
226 else {
227
228 echo "<td colspan=\"5\" align=\"center\" bgcolor=\"$bgcolor1\"><a href=\"admin.php?op=candidato&amp;id_cand=$id_cand&amp;id_gruppo=$id_gruppo&amp;id_cons=$id_cons&amp;id_lista=$id_lista&amp;min=$next&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune\">";
229 echo "<b>$offset "._NEXT_MATCH."</b></a></td>";
230 }
231 }
232 echo "</tr></table><br>";
233
234}
235
236////////////////////////////////////////////////////////
237// Aggiunge candidato
238////////////////////////////////////////////////////////
239
240
241function candidato($ok, $do,$id_cand, $id_lista,$id_circ, $id_gruppo,$cognome, $nome, $note, $simbolo,$id_cand2,$num_cand) {
242 global $param, $bgcolor1, $bgcolor2, $prefix, $dbi, $descr_cons, $id_cons,$simbolo2,$min,$id_cons_gen,$id_comune,$id_sez;
243$aid=$_SESSION['aid'];
244$perms=ChiSei($id_cons_gen);
245if ($perms >16) {
246 if($id_cand) {
247 $res = mysql_query("SELECT * FROM ".$prefix."_ele_candidati where id_cand='$id_cand'", $dbi);
248 }else{
249 $res = mysql_query("SELECT * FROM ".$prefix."_ele_candidati where id_lista='$id_lista'
250 and id_cons=$id_cons and cognome=$cognome and nome=$nome", $dbi);
251 }
252 $username=$aid;
253 $data=date("Y/m/d");
254 $tempo=date("H:i:s");
255
256 if ($do == "delete") {
257 if ($ok !="1") {
258 ele();
259 echo "<center><br><br>"._DOMCANCELLA." "._CANDIDATO." $cognome $nome ?<br>";
[87]260 echo "[ <a href=\"admin.php?op=candidato&amp;id_cons_gen=$id_cons_gen\">"._NO."</a> ] - [<a href=\"admin.php?op=candidato&amp;do=delete&amp;id_cand=$id_cand&amp;id_gruppo=$id_gruppo&amp;id_cons=$id_cons&amp;id_circ=$id_circ&amp;ok=1&amp;id_cons_gen=$id_cons_gen&amp;id_lista=$id_lista&amp;id_comune=$id_comune&amp;min=$min\">"._YES."</a> ]";
[2]261 }else{
262 $pro= mysql_fetch_array($res, MYSQL_ASSOC);
263 $result = mysql_query("delete from ".$prefix."_ele_candidati where id_cand='$id_cand'", $dbi);
264 mysql_query("insert into ".$prefix."_ele_log values ('$id_cons','$id_sez','$username','$data','$tempo','DELETE:id_lista:$pro[id_lista],cognome:$pro[cognome],nome:$pro[nome]','','".$prefix."_ele_candidati')", $dbi);
265 if (!$result)return;
[87]266 Header("Location: admin.php?op=candidato&id_cons=$id_cons&id_cons_gen=$id_cons_gen&id_comune=$id_comune&id_circ=$id_circ&id_lista=$id_lista&min=$min");
[2]267 }
268 }elseif ($do == "add") {
269 if ($cognome) {
270 // dati gruppo
271 if (!$num_cand){
272 $result = mysql_query("select max(num_cand) from ".$prefix."_ele_candidati where id_lista='$id_lista'", $dbi);
273 if ($result) list($num_cand)=mysql_fetch_row($result);
274 else $num_cand=0;
275 $num_cand++;
276 }
277 $result = mysql_query("select id_gruppo from ".$prefix."_ele_lista where id_lista='$id_lista'", $dbi);
278 list($id_gruppo)=mysql_fetch_row($result);
279 $result = mysql_query("insert into ".$prefix."_ele_candidati(id_cons,id_lista,cognome,nome,note,simbolo,num_cand) values ('$id_cons','$id_lista','$cognome','$nome','$note','$simbolo','$num_cand')", $dbi);
280 mysql_query("insert into ".$prefix."_ele_log values ('$id_cons','$id_sez','$username','$data','$tempo','','ADD:id_lista:$id_lista,cognome:$cognome,nome:$nome','".$prefix."_ele_candidati')", $dbi);
281 if (!$result) return;
[87]282 Header("Location: admin.php?op=candidato&id_cons=$id_cons&id_lista=$id_lista&id_cons_gen=$id_cons_gen&id_comune=$id_comune&id_circ=$id_circ&min=$min");
[2]283 } else {
284 ele();
285 OpenTable();
286 echo "<center>"._GESTIONE." "._CANDIDATO." ";
[87]287 echo "<br><br><a href=\"admin.php?op=candidato&amp;id_cons=$id_cons&amp;id_lista=$id_lista&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;id_circ=$id_circ&amp;min=$min\">"._IMM." "._CANDIDATO."</a></center>";
[2]288 CloseTable();exit;
289 }
290 }elseif ($do == "update") {
291
292 $pro= mysql_fetch_array($res, MYSQL_ASSOC);
293 $result = mysql_query("select id_gruppo from ".$prefix."_ele_lista where id_lista='$id_lista'", $dbi);
294 list($id_gruppo)=mysql_fetch_row($result);
295 $cond='';
296 if (isset($note)) {$cond=", note='$note'";}
297 if (isset($simbolo)) {$cond.=", simbolo='$simbolo'";}
298 $result = mysql_query("update ".$prefix."_ele_candidati set id_lista='$id_lista', cognome='$cognome', nome='$nome', num_cand='$num_cand' $cond where id_cand='$id_cand' ", $dbi);
299 mysql_query("insert into ".$prefix."_ele_log values ('$id_cons','$id_sez','$username','$data','$tempo','UPDATE:id_lista:$pro[id_lista],cognome:$pro[cognome],nome:$pro[nome],num_cand:$pro[num_cand]','id_lista:$id_lista,cognome:$cognome,nome:$nome,num_cand:$num_cand','".$prefix."_ele_candidati')", $dbi);
300 if (!$result) return;
[87]301 Header("Location: admin.php?op=candidato&id_cons=$id_cons&id_lista=$id_lista&id_cons_gen=$id_cons_gen&id_comune=$id_comune&id_circ=$id_circ&min=$min");
[2]302 }
303
304}
305}
306
307
308
309if ($do and $do!='modify')
310 candidato($ok, $do,$id_cand, $id_lista,$id_circ, $id_gruppo,$cognome, $nome, $note, $simbolo,$id_cand2,$num_cand);
311 else ele();
312//if (!$do)ele();
313all();
314echo"</td></tr></table>";
315include("footer.php");
316
317?>
Note: See TracBrowser for help on using the repository browser.