source: trunk/admin/modules/Elezioni/ele_associazioni.php@ 187

Last change on this file since 187 was 187, checked in by roby, 12 years ago

admin: sostituisce rev 186

File size: 17.2 KB
Line 
1<?php
2
3/************************************************************************/
4/* Eleonline - Raccolta e diffusione dei dati elettorali */
5/* by Roberto Gigli & Luciano Apolito */
6/* http://www.eleonline.it */
7/* info@eleonline.it luciano@aniene.net rgigli@libero.it */
8/************************************************************************/
9/* Modulo Autorizzazione Comuni */
10/* Amministrazione */
11/************************************************************************/
12# e' l'unico file in cui Ú presente un controllo su tipo_cons, per ora va bene così. Per toglierlo va inserito un campo-flag in ele_tipo per indicare se per il tipo di consultazione si dovra' procedere al calcolo dell'assegnazione dei seggi
13if (!defined('ADMIN_FILE')) {
14 die ("You can't access this file directly...");
15}
16
17$aid=$_SESSION['aid'];
18$dbi=$_SESSION['dbi'];
19$prefix=$_SESSION['prefix'];
20$id_comune=$_SESSION['id_comune'];
21$id_cons_gen=intval($_GET['id_cons_gen']);
22$perms=ChiSei(0);
23if ($perms<128 or !$id_cons_gen) die("$perms Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
24$res = mysql_query("SELECT t1.tipo_cons,t1.descrizione,t2.id_cons,t2.id_conf FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_comune='$id_comune' " , $dbi);
25list($tipo_cons,$descr_cons,$id_cons,$id_conf) = mysql_fetch_row($res);
26
27$res = mysql_query("SELECT genere FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' " , $dbi);
28 list($genere) = mysql_fetch_row($res);
29
30include("modules/Elezioni/funzionidata.php");
31include("modules/Elezioni/ele.php");
32if (isset($_GET['descr_comu'])) get_magic_quotes_gpc() ? $descr_comu=$param['descr_comu']:$descr_comu=addslashes($param['descr_comu']); else $descr_comu='';
33if (isset($_GET['do'])) get_magic_quotes_gpc() ? $do=$param['do']:$do=addslashes($param['do']); else $do='';
34if (isset($_GET['ok'])) $ok=intval($_GET['ok']); else $ok='';
35if (isset($_GET['id_cons_comu'])) $id_cons_comu=intval($_GET['id_cons_comu']); else $id_cons_comu='';
36if (isset($_GET['id_collegio'])) $id_collegio=intval($_GET['id_collegio']); else $id_collegio='';
37if (isset($_GET['idcomune'])) $idcomune=intval($_GET['idcomune']); else $idcomune='';
38if (isset($_GET['idcomunenew'])) $idcomunenew=intval($_GET['idcomunenew']); else $idcomunenew='';
39if (isset($_GET['chiusa'])) $chiusa=intval($_GET['chiusa']); else $chiusa='';
40if (isset($_GET['id_conf'])) $id_conf=intval($_GET['id_conf']); else $id_conf=0;
41if (isset($_GET['min'])) $min=intval($_GET['min']); else $min=0;
42if (isset($_GET['help'])) $help=intval($_GET['help']);
43if (isset($_GET['pwd4'])) $pwd4=intval($_GET['pwd4']);
44if (isset($_GET['preferenze'])) $preferenze=intval($_GET['preferenze']); else $preferenze=1;
45
46$offset=15;
47$hiddenInfo = "<input type=\"hidden\" name=\"min\" value=\"$min\">";
48
49
50 /******************************************************/
51 /*Funzione di visualizzazione globale */
52 /*****************************************************/
53 //
54 function all() {
55 global $user, $admin, $bgcolor1, $bgcolor2, $prefix,$descr_cons, $dbi,$id_cons,$desc,$indirizzo,$centralino,$fax,$id_cons_gen,$id_collegio,$idcomune,$chiusa,$id_conf,$tipo_cons,$language,$help,$preferenze;
56$aid=$_SESSION['aid'];
57$dbi=$_SESSION['dbi'];
58$prefix=$_SESSION['prefix'];
59############# Controllo flag per cancellazione consultazione
60 echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n"
61 ."//-->\n";
62 echo "function del_cons() {\n";
63 echo "if (document.getElementById('pwd3').checked==false) {\n";
64 echo "if (document.getElementById('chiusa').selectedIndex==3) document.getElementById('chiusa').options[0].selected=true \n";
65 echo "document.getElementById('pwd4').checked=false \n";
66 echo "document.getElementById('trspunta').style.visibility='hidden' \n";
67 echo "} \n";
68 echo "else document.getElementById('trspunta').style.visibility='visible' \n";
69# echo "if (document.getElementById('chiusa').options[3].selected==false) { \n";
70 echo "if (document.getElementById('chiusa').selectedIndex!=3) { \n";
71 echo "document.getElementById('add').value=\""._MODIFY."\" \n";
72 echo "document.getElementById('do').value=\"update\" \n";
73 echo "}else{\n";
74 echo "if (document.getElementById('pwd4').checked==false) \n";
75 echo "document.getElementById('add').value=\""._DELETE." "._DATI."\" \n";
76 echo "else document.getElementById('add').value=\""._DELETE." "._CONSULTA."\" \n";
77 echo "document.getElementById('do').value=\"delete\" \n";
78 echo "} \n";
79 echo "} \n";
80 echo "</script>\n";
81
82
83#########################
84 if (isset($help)) include("language/$language/ele_associazioni.html");
85 OpenTable();
86 echo "<tr><td><hr><br>";
87 $res = mysql_query("SELECT descrizione FROM ".$prefix."_ele_consultazione where id_cons_gen='$id_cons_gen'" , $dbi);
88 list ($descr_cons) = mysql_fetch_row($res);
89//inserire avviso su mancanza dei permessi
90 echo "<form name=\"model\" action=\"admin.php\">";
91 echo "<table width=\"100%\" border=\"3\">";
92 echo "<tr align=\"center\"><td bgcolor=\"$bgcolor1\"><b>"._CONSULTA."</b></td>";
93# echo "<td bgcolor=\"$bgcolor1\"><b>"._COLLEGI."</b></td>";
94 echo "<td bgcolor=\"$bgcolor1\"><b>"._DEFCOMUNE."</b></td>";
95 echo "<td width=\"10%\" bgcolor=\"$bgcolor1\"><b>"._PREFERENZE."</b></td>";
96 echo "<td bgcolor=\"$bgcolor1\"><b>"._STATO."</b></td><td bgcolor=\"$bgcolor1\">";
97 if($tipo_cons==3)
98 echo "<b>"._CONF."</b>";
99 echo "<input type=\"hidden\" name=\"op\" value=\"associazioni\">";
100# echo "<input type=\"hidden\" name=\"pag_cons\" value=\"admin.php?op=associazioni&amp;id_cons_gen=\">";
101 echo "</td></tr>";
102 echo "<tr align=\"center\"><td>";
103 echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">$descr_cons</td>";
104# $ressede = mysql_query("SELECT id_collegio, descrizione from ".$prefix."_ele_collegi where id_cons_gen='$id_cons_gen' order by descrizione desc", $dbi);
105# if ($num_coll=mysql_num_rows($ressede)){
106# echo "<td><select name=\"id_collegio\">";
107# while(list($id,$descr_coll)=mysql_fetch_row($ressede)){
108# $sel= ($id == $id_collegio) ? "selected":"";
109# echo "<option value=\"$id\" $sel>$descr_coll";
110# }
111# echo "</select></td>";
112# } else echo "<td></td>";
113 $rescomu = mysql_query("SELECT id_comune, descrizione from ".$prefix."_ele_comuni order by descrizione asc", $dbi);
114 echo "<td>";
115 if($idcomune) {
116 while ($listele=mysql_fetch_array($rescomu))
117 if($listele['id_comune']==$idcomune) {
118 echo $listele['descrizione'];
119 echo "<input type=\"hidden\" name=\"idcomunenew\" value=\"$idcomune\">";
120 }
121
122 }else{
123 echo "<select name=\"idcomunenew\">";
124 echo "<option value=\"0\"> ";
125 while(list($id,$descr_comu)=mysql_fetch_row($rescomu)){
126 $sel= ($id == $idcomune) ? "selected":"";
127 echo "<option value=\"$id\" $sel>$descr_comu";
128 }
129 echo "</select>";
130 }
131 echo "</td>";
132 echo "<td><input type=\"text\" name=\"preferenze\" value=\"$preferenze\" size=\"2\"></td>";
133 $selez['0']='';
134 $selez['1']='';
135 $selez['2']='';
136 $selez['3']='';
137 $selez[$chiusa]="selected";
138 echo "<td><select name=\"chiusa\" id=\"chiusa\" onChange=\"javascript:del_cons()\">";
139 echo "<option value=\"0\" ".$selez[0].">"._ATTIVA;
140 echo "<option value=\"1\" ".$selez[1].">"._CHIUSA;
141 echo "<option value=\"2\" ".$selez[2].">"._NULLA;
142
143 if($idcomune) echo "<option value=\"3\" ".$selez[3].">"._ELIMINA;
144 echo "</select></td>";
145 if($tipo_cons==3){
146 $rescomu = mysql_query("SELECT id_conf, descrizione from ".$prefix."_ele_conf order by descrizione asc", $dbi);
147 echo "<td><select name=\"id_conf\">";
148 echo "<option value=\"0\"> ";
149 while(list($id,$descr_conf)=mysql_fetch_row($rescomu)){
150 $sel='';
151 if ($idcomune and $id == $id_conf) $sel="selected"; elseif ($id==1) $sel="selected";
152 echo "<option value=\"$id\" $sel>$descr_conf";
153 }
154 echo "</select></td>";
155 }
156 unset($sel);
157 echo "<td><input type=\"hidden\" name=\"ok\" value=0>";
158 echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">";
159 if ($idcomune) {
160 echo "<input type=\"hidden\" id=\"do\" name=\"do\" value=\"update\">";
161 echo "<input type=\"hidden\" name=\"idcomune\" value=\"$idcomune\">";
162 echo "<input type=\"submit\" id=\"add\" name=\"add\" value=\""._MODIFY."\" ></td></tr>";
163 echo "<tr><td colspan=\"5\"><fieldset><legend>"._SPUNTALABEL1."</legend><label id=\"prov1\">"._SPUNTAELIMINA." <input type=\"checkbox\" id=\"pwd3\" name=\"pwd3\" value=\"\" onclick=\"javascript:del_cons()\"></label></fieldset></td></tr>";
164# <div id=\"trspunta\" style=\"visibility:hidden\"> </div>
165 echo "<tr id=\"trspunta\" style=\"visibility:hidden\"><td colspan=\"4\"><fieldset><legend>"._SPUNTALABEL2."</legend><label id=\"prov\">"._VIASPUNTAELIMINA." <input type=\"checkbox\" id=\"pwd4\" name=\"pwd4\" value=\"1\" onclick=\"javascript:del_cons()\"></label></fieldset>";
166 }else{
167 echo "<input type=\"hidden\" name=\"do\" value=\"add\">";
168 echo "<input type=\"submit\" name=\"add\" value=\""._ADD."\">";
169 }
170 $i=0;
171 echo "</td></tr></table></form>";
172############
173 echo "<hr><br><table width=\"100%\" border=\"3\">";
174 echo "<tr align=\"center\"><td width=\"25%\" bgcolor=\"$bgcolor1\"><b>"._CONSULTA."</b></td>";
175# echo "<td bgcolor=\"$bgcolor1\"><b>"._COLLEGI."</b></td>";
176 echo "<td width=\"25%\" bgcolor=\"$bgcolor1\"><b>"._DEFCOMUNE."</b></td>";
177 echo "<td width=\"10%\" bgcolor=\"$bgcolor1\"><b>"._PREFERENZE."</b></td>";
178 echo "<td width=\"10%\" bgcolor=\"$bgcolor1\"><b>"._STATO."</b></td>";
179 if($tipo_cons==3)
180 echo "<td bgcolor=\"$bgcolor1\"><b>"._CONF."</b></td>";
181 echo "<td width=\"10\" bgcolor=\"$bgcolor1\"><b>&nbsp;"._FUNZIONI."</td></tr>";
182###############
183
184# if ($num_coll>0)
185# $resmod = mysql_query("SELECT t1.id_collegio,t1.id_comune,t2.descrizione as descr,t1.id_cons, t3.descrizione, t4.chiusa,t4.id_conf FROM ".$prefix."_ele_comu_collegi as t1, ".$prefix."_ele_collegi as t2, ".$prefix."_ele_comuni as t3, ".$prefix."_ele_cons_comune as t4 where t1.id_cons_gen='$id_cons_gen' and t1.id_collegio=t2.id_collegio and t1.id_comune=t3.id_comune and t1.id_comune=t4.id_comune and t2.id_cons_gen=t4.id_cons_gen order by t2.descrizione, t3.descrizione", $dbi);
186# else
187 $resmod = mysql_query("SELECT '',t1.id_comune,'',t1.id_cons, t2.descrizione, t1.chiusa, t1.id_conf, preferenze FROM ".$prefix."_ele_cons_comune as t1, ".$prefix."_ele_comuni as t2 where t1.id_cons_gen='$id_cons_gen' and t1.id_comune=t2.id_comune order by t2.descrizione", $dbi);
188 while (list($id_collegio,$id_comune2,$descr_coll,$id_cons_comu,$descr_comu, $chiusa,$id_conf,$preferenze2) = mysql_fetch_row($resmod)){ //elenco dei modelli inseriti
189 $resconf = mysql_query("SELECT descrizione FROM ".$prefix."_ele_conf where id_conf='$id_conf'", $dbi);
190 list($descr_conf) = mysql_fetch_row($resconf);
191 $i++;
192 $bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
193 echo "<tr><td colspan=\"6\">";
194 echo "<form name=\"modello$i\" action=\"admin.php\">"
195 ."<input type=\"hidden\" name=\"op\" value=\"associazioni\">";
196// echo "<input type=\"hidden\" name=\"do\" value=\"update\">";
197# echo "<input type=\"hidden\" name=\"id_collegio\" value=\"$id_collegio\">";
198 echo "<input type=\"hidden\" name=\"idcomune\" value=\"$id_comune2\">";
199 echo "<input type=\"hidden\" name=\"id_cons_comu\" value=\"$id_cons_comu\">";
200 echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">";
201 echo "<input type=\"hidden\" name=\"desc\" value=\"$descr_cons\">";
202 echo "<input type=\"hidden\" name=\"preferenze\" value=\"$preferenze2\">";
203 echo "<input type=\"hidden\" name=\"chiusa\" value=\"$chiusa\">";
204 echo "<table width=\"100%\"><tr align=\"center\" bgcolor=\"$bgcolor1\">";
205 echo "<td width=\"27%\"><b>$descr_cons</b></td>";
206 echo "<td width=\"27%\"><b>$descr_comu</b></td>";
207 echo "<td width=\"12%\"><b>$preferenze2</b></td>";
208 $stato['0']=_ATTIVA;
209 $stato['1']=_CHIUSA;
210 $stato['2']=_NULLA;
211 echo "<td width=\"11%\"><b>".$stato[$chiusa]."</b></td>";
212 if($tipo_cons==3)
213 echo "<td width=\"25%\"><input type=\"hidden\" name=\"id_conf\" value=\"$id_conf\"><b>".$descr_conf."</b></td>";
214 echo "<td width=\"10\"><input type=\"hidden\" name=\"ok\" value=0><input type=\"submit\" name=\"edit$i\" value=\""._EDIT."\">"
215 ."</td></tr></table></form></td></tr>\n";
216 }
217 echo "</table></td></tr>";
218 echo "</table></td></tr>";
219 CloseTable();
220# echo "</div>";
221 }
222
223function associazioni($ok, $do,$descr_comu,$id_cons_comu,$id_collegio,$id_comune,$chiusa,$id_conf,$preferenze) {
224 global $admin, $bgcolor1, $bgcolor2, $prefix, $dbi, $descr_cons,$genere,$id_cons_gen,$idcomunenew,$pwd4;
225 $delcons=0;
226 if ($do !="" and $id_cons_gen>0 and $idcomunenew>0) {
227 $rescomu = mysql_query("SELECT id_cons from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' and id_comune='$idcomunenew'", $dbi);
228 $max = mysql_num_rows($rescomu); //esiste autorizzazione?
229 list($delcons)=mysql_fetch_row($rescomu);
230 if (!$max){ //se no la inserisce
231 $result = mysql_query("insert into ".$prefix."_ele_cons_comune (chiusa,id_comune,id_cons_gen,id_conf,preferenze) values ('0','$idcomunenew','$id_cons_gen','$id_conf','$preferenze')", $dbi) || die("<br><br>Errore di inserimento: ".mysql_error());
232 $rescomu = mysql_query("SELECT id_cons from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' and id_comune='$idcomunenew'", $dbi);
233 list($id_cons_comu)=mysql_fetch_row($rescomu);
234 $res = mysql_query("SELECT id_cons FROM ".$prefix."_ele_comuni where id_comune='$idcomunenew' ", $dbi);
235 list($id_cons_pred)=mysql_fetch_row($res);
236 if (!$id_cons_pred)
237 $res = mysql_query("update ".$prefix."_ele_comuni set id_cons='$id_cons_comu' where id_comune='$idcomunenew' ", $dbi);
238
239 }
240 if ($do == "update") {
241 if ($idcomunenew>0) $newid=", id_comune = $idcomunenew ";
242 else $newid='';
243 $result = mysql_query("update ".$prefix."_ele_comu_collegi set id_collegio= '$id_collegio' $newid where id_comune='$id_comune' and id_cons_gen='$id_cons_gen'", $dbi) || die(mysql_error());
244 if (!$result) return;
245 $result = mysql_query("update ".$prefix."_ele_cons_comune set id_conf='$id_conf', chiusa= '$chiusa', preferenze='$preferenze' where id_comune='$id_comune' and id_cons_gen='$id_cons_gen'", $dbi)|| die(mysql_error());
246 Header("Location: admin.php?op=associazioni&id_cons_gen=$id_cons_gen");
247 }elseif ($do == "add") {
248 if ($id_collegio){
249 $result = mysql_query("insert into ".$prefix."_ele_comu_collegi (id_collegio,id_cons,id_comune,id_cons_gen) values ('$id_collegio','$id_cons_comu','$idcomunenew','$id_cons_gen')", $dbi) || die("<br><br>Errore di inserimento: ".mysql_error());
250 }
251 Header("Location: admin.php?op=associazioni&id_cons_gen=$id_cons_gen");
252 }elseif ($do == "delete" and $delcons>0) {
253 $idcns=$delcons;
254 $res_del = mysql_query("delete from ".$prefix."_ele_voti_ref where id_cons=$idcns" ,$dbi);
255 $res_del = mysql_query("delete from ".$prefix."_ele_voti_candidati where id_cons=$idcns" ,$dbi);
256 $res_del = mysql_query("delete from ".$prefix."_ele_voti_lista where id_cons=$idcns" ,$dbi);
257 $res_del = mysql_query("delete from ".$prefix."_ele_voti_gruppo where id_cons=$idcns" ,$dbi);
258 $res_del = mysql_query("delete from ".$prefix."_ele_voti_parziale where id_cons=$idcns" ,$dbi);
259 if ($pwd4==1){
260 $res_del = mysql_query("delete from ".$prefix."_ele_candidati where id_cons=$idcns" ,$dbi);
261 $res_del = mysql_query("delete from ".$prefix."_ele_lista where id_cons=$idcns" ,$dbi);
262 $res_del = mysql_query("delete from ".$prefix."_ele_gruppo where id_cons=$idcns" ,$dbi);
263 $res_del = mysql_query("delete from ".$prefix."_ele_sezioni where id_cons=$idcns" ,$dbi);
264 $res_del = mysql_query("delete from ".$prefix."_ele_cons_comune where id_cons=$idcns" ,$dbi);
265 $res = mysql_query("SELECT id_cons FROM ".$prefix."_ele_comuni where id_comune='$id_comune' ", $dbi);
266 list($id_cons_pred)=mysql_fetch_row($res);
267 if ($idcns==$id_cons_pred) {
268 $res = mysql_query("select id_cons from ".$prefix."_ele_cons_comune where id_comune=$id_comune order by id_cons desc limit 0,1" ,$dbi);
269 list($id_cons_pred)=mysql_fetch_row($res);
270 $res = mysql_query("update ".$prefix."_ele_comuni set id_cons='$id_cons_pred' where id_comune='$id_comune' ", $dbi);
271 }
272 }else{
273 $res_del = mysql_query("update ".$prefix."_ele_sezioni set validi='0', nulli='0', bianchi='0', contestati='0', solo_gruppo='0', autorizzati_m='0', autorizzati_f='0', voti_nulli='0', validi_lista='0', contestati_lista='0', voti_nulli_lista='0' where id_cons=$idcns" ,$dbi);
274
275 }
276 Header("Location: admin.php?op=associazioni&id_cons_gen=$id_cons_gen");
277 }
278 }
279}
280
281
282
283
284# die ("do:$do - id_cons:$id_cons_comu - idcomune:$id_comune - new: $idcomunenew");
285
286//****************************
287// switch
288//****************************
289 if ($op=="associazioni"){
290 associazioni($ok, $do,$descr_comu,$id_cons_comu,$id_collegio,$idcomune,$chiusa,$id_conf,$preferenze);
291 }
292 ele();
293 if (isset($_GET['id_cons_gen'])) $id_cons_gen=intval($_GET['id_cons_gen']); else $id_cons_gen='0';
294 all();
295 include("footer.php");
296
297?>
298
299
Note: See TracBrowser for help on using the repository browser.