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

Last change on this file since 2 was 2, checked in by root, 15 years ago

importo il progetto

File size: 16.0 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.") ".substr($descr,0,25);
155 }
156 echo "</select></td>";
157 echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">";
158 echo "<input type=\"hidden\" name=\"id_circ\" value=\"$id_circ\">";
159 echo "<input type=\"hidden\" name=\"min\" value=\"$min\">";
160 if ($pro['cognome']) {
161 echo "<td align=\"center\"><input type=\"submit\" name=\"update\" value=\""._MODIFY."\"></td>";
162 echo "<input type=\"hidden\" name=\"id_cand\" value=\"".$pro['id_cand']."\">";
163 }else{
164 echo "<td align=\"center\"><input type=\"submit\" name=\"add\" value=\""._ADD."\"></td>";
165 echo "<input type=\"hidden\" name=\"id_cand\" value=\"$id_cand\">";
166 }
167 echo "</form>";
168 echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n"
169 ."document.candidato2.cognome.focus()\n"
170 ."//-->\n";
171 echo "function vai_a() {\n";
172 echo "window.document.location.href=document.candidato2.pag.value+document.candidato2.id_lista.value\n";
173 echo "}\n";
174 echo "function aggiorna(id_ele) {\n";
175 echo "if (document.candidato2.cognome.value==\"\") {vai_a()}\n";
176 echo "}\n";
177 echo "</script>\n";
178 if ($result)
179 while(list($id_cand,$id_lista2,$num_cand,$cognome, $nome,$simbolo,$simb_lista,
180 $descr_lista,$simb_gruppo,$descr_gruppo) = mysql_fetch_row($result)) {
181 $bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
182 echo "<tr bgcolor=\"$bgcolor1\"><td align=\"center\"><b>$num_cand</b>"
183 ."</td><td align=\"left\"><b>$cognome</b>"
184 ."</td><td align=\"left\"><b>$nome</b>";
185 echo "</td><td align=\"center\"><b>$descr_lista </b>";
186 echo "</td><td align=\"center\" nowrap>[<a
187 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\"
188 border=\"0\" align=\"center\"> "._EDIT."</a>]";
189 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\"
190 border=\"0\" align=\"center\"></a>]";
191 echo "</td></tr>";
192 }
193 echo "</table></center>";
194
195 #'Pagina precedente' e 'Pagina Successiva'
196 echo"<table align=\"center\" width=\"100%\" ><tr>";
197 $prev=$min-$offset;
198 if ($prev>=0) {
199 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\">";
200 echo "<b>$offset "._PREV_MATCH."</b></a></td>";
201 }
202
203 $next=$min+$offset;
204 if ($next>=($offset-1)) {
205 if($next>=$max) $next = $max;
206 else {
207
208 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\">";
209 echo "<b>$offset "._NEXT_MATCH."</b></a></td>";
210 }
211 }
212 echo "</tr></table><br>";
213
214}
215
216////////////////////////////////////////////////////////
217// Aggiunge candidato
218////////////////////////////////////////////////////////
219
220
221function candidato($ok, $do,$id_cand, $id_lista,$id_circ, $id_gruppo,$cognome, $nome, $note, $simbolo,$id_cand2,$num_cand) {
222 global $param, $bgcolor1, $bgcolor2, $prefix, $dbi, $descr_cons, $id_cons,$simbolo2,$min,$id_cons_gen,$id_comune,$id_sez;
223$aid=$_SESSION['aid'];
224$perms=ChiSei($id_cons_gen);
225if ($perms >16) {
226 if($id_cand) {
227 $res = mysql_query("SELECT * FROM ".$prefix."_ele_candidati where id_cand='$id_cand'", $dbi);
228 }else{
229 $res = mysql_query("SELECT * FROM ".$prefix."_ele_candidati where id_lista='$id_lista'
230 and id_cons=$id_cons and cognome=$cognome and nome=$nome", $dbi);
231 }
232 $username=$aid;
233 $data=date("Y/m/d");
234 $tempo=date("H:i:s");
235
236 if ($do == "delete") {
237 if ($ok !="1") {
238 ele();
239 echo "<center><br><br>"._DOMCANCELLA." "._CANDIDATO." $cognome $nome ?<br>";
240 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\">"._YES."</a> ]";
241 }else{
242 $pro= mysql_fetch_array($res, MYSQL_ASSOC);
243 $result = mysql_query("delete from ".$prefix."_ele_candidati where id_cand='$id_cand'", $dbi);
244 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);
245 if (!$result)return;
246 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");
247 }
248 }elseif ($do == "add") {
249 if ($cognome) {
250 // dati gruppo
251 if (!$num_cand){
252 $result = mysql_query("select max(num_cand) from ".$prefix."_ele_candidati where id_lista='$id_lista'", $dbi);
253 if ($result) list($num_cand)=mysql_fetch_row($result);
254 else $num_cand=0;
255 $num_cand++;
256 }
257 $result = mysql_query("select id_gruppo from ".$prefix."_ele_lista where id_lista='$id_lista'", $dbi);
258 list($id_gruppo)=mysql_fetch_row($result);
259 $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);
260 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);
261 if (!$result) return;
262 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");
263 } else {
264 ele();
265 OpenTable();
266 echo "<center>"._GESTIONE." "._CANDIDATO." ";
267 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\">"._IMM." "._CANDIDATO."</a></center>";
268 CloseTable();exit;
269 }
270 }elseif ($do == "update") {
271
272 $pro= mysql_fetch_array($res, MYSQL_ASSOC);
273 $result = mysql_query("select id_gruppo from ".$prefix."_ele_lista where id_lista='$id_lista'", $dbi);
274 list($id_gruppo)=mysql_fetch_row($result);
275 $cond='';
276 if (isset($note)) {$cond=", note='$note'";}
277 if (isset($simbolo)) {$cond.=", simbolo='$simbolo'";}
278 $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);
279 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);
280 if (!$result) return;
281 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");
282 }
283
284}
285}
286
287
288
289if ($do and $do!='modify')
290 candidato($ok, $do,$id_cand, $id_lista,$id_circ, $id_gruppo,$cognome, $nome, $note, $simbolo,$id_cand2,$num_cand);
291 else ele();
292//if (!$do)ele();
293all();
294echo"</td></tr></table>";
295include("footer.php");
296
297?>
Note: See TracBrowser for help on using the repository browser.