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

Last change on this file since 95 was 87, checked in by roby, 14 years ago
  • Rielaborata la funzione di cancellazione dei dati dello spoglio (in Autorizza comuni) e dell'intera consultazione (se completamente vuota) in Consultazioni (menu superuser).
  • ritocchi vari
File size: 16.1 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/* 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
52/******************************************************/
53/*Funzione di visualizzazione globale */
54/*****************************************************/
55
56
57function all() {
58 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;
59 $circo='';$circo2='';
60 $currentlang=$_SESSION['lang'];
61 $res = mysql_query("SELECT circo FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' and lingua='$currentlang'", $dbi);
62 list($cons_circ)= mysql_fetch_row($res);
63 if($cons_circ) //elezioni circoscrizionali
64 {
65 echo "<form name=\"circo\" action=\"admin.php\" method=\"post\">";
66 echo "<br><br><table border=\"1\" width=\"50%\" ><tr bgcolor=\"$bgcolor1\"><td>"._SCEGLI_CIRCO.": </td>";
67 $res = mysql_query("SELECT * FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons'", $dbi);
68 echo "<input type=\"hidden\" name=\"pag\" value=\"admin.php?op=candidato&amp;id_cons_gen=$id_cons_gen&amp;id_circ=\">";
69 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\">";
70 echo "<option value=\"\">";
71 while($arr=mysql_fetch_array($res,3)){
72 if (!$id_circ) $id_circ=$arr['id_circ'];
73 $sel= ($arr['id_circ'] == $id_circ) ? "selected":"";
74 echo "<option value=\"".$arr['id_circ']."\" $sel>".$arr['descrizione'];
75 }
76 echo "</select></td></tr></table></form>";
77 $circo="and id_circ='$id_circ'";
78 $circo2="and t2.id_circ='$id_circ'";
79 }
80 if($id_cand)
81 {
82 $res = mysql_query("SELECT * FROM ".$prefix."_ele_candidati where id_cand='$id_cand'", $dbi);
83 $pro= mysql_fetch_array($res, 3);
84 }else{
85 $pro['cognome']='';$pro['num_cand']='';$pro['nome']='';
86 }
87 if (!isset($id_lista)) {
88 $res_lista=mysql_query("SELECT id_lista from ".$prefix."_ele_lista where id_cons=$id_cons $circo and num_lista=1", $dbi);
89 list($id_lista)=mysql_fetch_row($res_lista);
90 }
91 $cond=($id_lista>0) ? "and t1.id_lista=".$id_lista :'';
92 echo "<center><font class=\"title\"><br><b>"._CANDIDATO."</b></font><br><br><table border=\"0\" width=\"100%\"><tr>"
93 ."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._NUM."</b></td>"
94 ."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._COGNOME."</b></td>"
95 ."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._NOME."</b></td>";
96 echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._LISTA."</b></td>";
97
98 if ($genere==3 or $genere==5) {
99 $query= "SELECT
100 t1.id_cand,t1.id_lista,t1.num_cand,t1.cognome,t1.nome, t1.simbolo,
101 t2.simbolo as sim_lista,t2.descrizione, t3.simbolo as sim_gruppo, t3.descrizione
102 FROM ".$prefix."_ele_candidati as t1,
103 ".$prefix."_ele_lista as t2,
104 ".$prefix."_ele_gruppo as t3
105 WHERE t1.id_lista=t2.id_lista
106 and t2.id_gruppo=t3.id_gruppo
107 and t1.id_cons=t2.id_cons
108 and t1.id_cons=$id_cons $circo2
109 $cond
110 order by t2.num_lista, t1.num_cand
111 limit $min,$offset";
112 } else {
113 $query= "SELECT
114 t1.id_cand,t1.id_lista,t1.num_cand,t1.cognome,t1.nome, t1.simbolo,
115 t2.simbolo as sim_lista,t2.descrizione, '', ''
116 FROM ".$prefix."_ele_candidati as t1,
117 ".$prefix."_ele_lista as t2
118 WHERE t1.id_cons=$id_cons
119 and t1.id_cons=t2.id_cons
120 and t1.id_lista=t2.id_lista $circo2
121 $cond
122 order by t2.num_lista,t1.num_cand
123 limit $min,$offset";
124 }
125 echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._FUNZIONI."</b></td></tr>";
126 $result = mysql_query($query, $dbi);
127 if($cons_circ)
128 $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);
129 else
130 $res = mysql_query("SELECT count(0) FROM ".$prefix."_ele_candidati as t1 where t1.id_cons='$id_cons' $cond ", $dbi);
131 list($max) = mysql_fetch_row($res);
132 if($id_lista){
133 $numero=$max+1;} else $numero='';
134 //-----------------------lo stemma e la circoscrizione devono essere associati alla lista -
135 echo "<form name=\"candidato2\" action=\"admin.php\">"
136 ."<input type=\"hidden\" name=\"op\" value=\"candidato\">";
137 if ($pro['cognome']) {
138 echo "<input type=\"hidden\" name=\"do\" value=\"update\">";
139 echo "<tr><td><input type=\"text\" name=\"num_cand\" value=\"".$pro['num_cand']."\" size=\"5\"></td>";
140 }else{
141 echo "<input type=\"hidden\" name=\"do\" value=\"add\">";
142 echo "<tr><td><input type=\"text\" name=\"num_cand\" value=\"$numero\" size=\"5\"></td>";
143 }
144 echo "<td><input type=\"text\" name=\"cognome\" maxlength=\"50\" value=\"".$pro['cognome']."\"></td>";
145 echo "<td><input type=\"text\" name=\"nome\" maxlength=\"50\" value=\"".$pro['nome']."\"></td>";
146 //."<td><input type=\"text\" name=\"foto\" maxlength=\"20\"></td>";
147 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=\">";
148 echo "<td width=\"10%\"><select width=\"10\" name=\"id_lista\" onChange=\"aggiorna()\">";
149 $res= mysql_query("SELECT id_lista,num_lista,descrizione FROM ".$prefix."_ele_lista where id_cons='$id_cons' $circo order by num_lista", $dbi);
150 echo "<option value=\"\">";
151 while(list($id,$numlist,$descr) = mysql_fetch_row($res)) {
152 if (!isset($id_lista)){$id_lista=$id;}
153 $sel= ($id == $id_lista) ? "selected":"";
154 echo "<option width=\"10\" value=\"$id\" $sel>".$numlist.") ".$descr;
155# echo "<option width=\"10\" value=\"$id\" $sel>".$numlist.") ".substr($descr,0,25);
156 }
157 echo "</select></td>";
158 echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">";
159 echo "<input type=\"hidden\" name=\"id_circ\" value=\"$id_circ\">";
160 echo "<input type=\"hidden\" name=\"min\" value=\"$min\">";
161 if ($pro['cognome']) {
162 echo "<td align=\"center\"><input type=\"submit\" name=\"update\" value=\""._MODIFY."\"></td>";
163 echo "<input type=\"hidden\" name=\"id_cand\" value=\"".$pro['id_cand']."\">";
164 }else{
165 echo "<td align=\"center\"><input type=\"submit\" name=\"add\" value=\""._ADD."\"></td>";
166 echo "<input type=\"hidden\" name=\"id_cand\" value=\"$id_cand\">";
167 }
168 echo "</form>";
169 echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n"
170 ."document.candidato2.cognome.focus()\n"
171 ."//-->\n";
172 echo "function vai_a() {\n";
173 echo "window.document.location.href=document.candidato2.pag.value+document.candidato2.id_lista.value\n";
174 echo "}\n";
175 echo "function aggiorna(id_ele) {\n";
176 echo "if (document.candidato2.cognome.value==\"\") {vai_a()}\n";
177 echo "}\n";
178 echo "</script>\n";
179 if ($result)
180 while(list($id_cand,$id_lista2,$num_cand,$cognome, $nome,$simbolo,$simb_lista,
181 $descr_lista,$simb_gruppo,$descr_gruppo) = mysql_fetch_row($result)) {
182 $bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
183 echo "<tr bgcolor=\"$bgcolor1\"><td align=\"center\"><b>$num_cand</b>"
184 ."</td><td align=\"left\"><b>$cognome</b>"
185 ."</td><td align=\"left\"><b>$nome</b>";
186 echo "</td><td align=\"center\"><b>$descr_lista </b>";
187 echo "</td><td align=\"center\" nowrap>[<a
188 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\"
189 border=\"0\" align=\"center\"> "._EDIT."</a>]";
190 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\"
191 border=\"0\" align=\"center\"></a>]";
192 echo "</td></tr>";
193 }
194 echo "</table></center>";
195
196 #'Pagina precedente' e 'Pagina Successiva'
197 echo"<table align=\"center\" width=\"100%\" ><tr>";
198 $prev=$min-$offset;
199 if ($prev>=0) {
200 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\">";
201 echo "<b>$offset "._PREV_MATCH."</b></a></td>";
202 }
203
204 $next=$min+$offset;
205 if ($next>=($offset-1)) {
206 if($next>=$max) $next = $max;
207 else {
208
209 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\">";
210 echo "<b>$offset "._NEXT_MATCH."</b></a></td>";
211 }
212 }
213 echo "</tr></table><br>";
214
215}
216
217////////////////////////////////////////////////////////
218// Aggiunge candidato
219////////////////////////////////////////////////////////
220
221
222function candidato($ok, $do,$id_cand, $id_lista,$id_circ, $id_gruppo,$cognome, $nome, $note, $simbolo,$id_cand2,$num_cand) {
223 global $param, $bgcolor1, $bgcolor2, $prefix, $dbi, $descr_cons, $id_cons,$simbolo2,$min,$id_cons_gen,$id_comune,$id_sez;
224$aid=$_SESSION['aid'];
225$perms=ChiSei($id_cons_gen);
226if ($perms >16) {
227 if($id_cand) {
228 $res = mysql_query("SELECT * FROM ".$prefix."_ele_candidati where id_cand='$id_cand'", $dbi);
229 }else{
230 $res = mysql_query("SELECT * FROM ".$prefix."_ele_candidati where id_lista='$id_lista'
231 and id_cons=$id_cons and cognome=$cognome and nome=$nome", $dbi);
232 }
233 $username=$aid;
234 $data=date("Y/m/d");
235 $tempo=date("H:i:s");
236
237 if ($do == "delete") {
238 if ($ok !="1") {
239 ele();
240 echo "<center><br><br>"._DOMCANCELLA." "._CANDIDATO." $cognome $nome ?<br>";
241 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> ]";
242 }else{
243 $pro= mysql_fetch_array($res, MYSQL_ASSOC);
244 $result = mysql_query("delete from ".$prefix."_ele_candidati where id_cand='$id_cand'", $dbi);
245 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);
246 if (!$result)return;
247 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");
248 }
249 }elseif ($do == "add") {
250 if ($cognome) {
251 // dati gruppo
252 if (!$num_cand){
253 $result = mysql_query("select max(num_cand) from ".$prefix."_ele_candidati where id_lista='$id_lista'", $dbi);
254 if ($result) list($num_cand)=mysql_fetch_row($result);
255 else $num_cand=0;
256 $num_cand++;
257 }
258 $result = mysql_query("select id_gruppo from ".$prefix."_ele_lista where id_lista='$id_lista'", $dbi);
259 list($id_gruppo)=mysql_fetch_row($result);
260 $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);
261 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);
262 if (!$result) return;
263 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");
264 } else {
265 ele();
266 OpenTable();
267 echo "<center>"._GESTIONE." "._CANDIDATO." ";
268 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>";
269 CloseTable();exit;
270 }
271 }elseif ($do == "update") {
272
273 $pro= mysql_fetch_array($res, MYSQL_ASSOC);
274 $result = mysql_query("select id_gruppo from ".$prefix."_ele_lista where id_lista='$id_lista'", $dbi);
275 list($id_gruppo)=mysql_fetch_row($result);
276 $cond='';
277 if (isset($note)) {$cond=", note='$note'";}
278 if (isset($simbolo)) {$cond.=", simbolo='$simbolo'";}
279 $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);
280 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);
281 if (!$result) return;
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");
283 }
284
285}
286}
287
288
289
290if ($do and $do!='modify')
291 candidato($ok, $do,$id_cand, $id_lista,$id_circ, $id_gruppo,$cognome, $nome, $note, $simbolo,$id_cand2,$num_cand);
292 else ele();
293//if (!$do)ele();
294all();
295echo"</td></tr></table>";
296include("footer.php");
297
298?>
Note: See TracBrowser for help on using the repository browser.