source: trunk/admin/modules/Elezioni/ele_gruppo.php@ 320

Last change on this file since 320 was 257, checked in by roby, 6 years ago
File size: 15.3 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 gruppo */
9/* Amministrazione */
10/************************************************************************/
11if (!defined('ADMIN_FILE')) {
12 die ("You can't access this file directly...");
13}
14
15// Offset - visualizza il numero di elementi per pagina
16$offset=5;
17global $dbi;
18$aid=$_SESSION['aid'];
19$prefix=$_SESSION['prefix'];
20$currentlang=$_SESSION['lang'];
21$param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ? $_GET : $_POST;
22$id_cons_gen=intval($param['id_cons_gen']);
23$perms=ChiSei($id_cons_gen);
24if ($perms<32 or !$id_cons_gen) die("Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
25$id_comune=$_SESSION['id_comune'];
26$sql="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' ";
27$res = $dbi->prepare("$sql");
28$res->execute();
29list($tipo_cons,$id_cons) = $res->fetch(PDO::FETCH_NUM);
30
31include("modules/Elezioni/funzionidata.php");
32include("modules/Elezioni/ele.php");
33
34if (isset($param['do'])) get_magic_quotes_gpc() ? $do=$param['do']:$do=addslashes($param['do']); else $do='';
35if (isset($param['min'])) $min=intval($param['min']); else $min=0;
36if (isset($param['id_sede'])) $id_sede=intval($param['id_sede']); else $id_sede='';
37if (isset($param['ok'])) get_magic_quotes_gpc() ? $ok=$param['ok']:$ok=addslashes($param['ok']); else $ok='';
38if (isset($param['id_circ'])) {$id_circ=intval($param['id_circ']); $_SESSION['id_circ']=$id_circ;} else
39if (isset($_SESSION['id_circ'])) $id_circ=intval($_SESSION['id_circ']); else $id_circ='';
40if (isset($param['id_gruppo'])) $id_gruppo=intval($param['id_gruppo']); else $id_gruppo='';
41if (isset($param['num_gruppo'])) $num_gruppo=intval($param['num_gruppo']); else $num_gruppo='';
42if (isset($param['descr_gruppo'])) get_magic_quotes_gpc() ? $descr_gruppo=$param['descr_gruppo']:$descr_gruppo=addslashes($param['descr_gruppo']); else $descr_gruppo='';
43if (isset($param['simbolo'])) get_magic_quotes_gpc() ? $simbolo=$param['simbolo']:$simbolo=addslashes($param['simbolo']); else $simbolo='';
44if (isset($param['delsimb'])) get_magic_quotes_gpc() ? $delsimb=$param['delsimb']:$delsimb=addslashes($param['delsimb']);
45if (isset($param['delprog'])) get_magic_quotes_gpc() ? $delprog=$param['delprog']:$delprog=addslashes($param['delprog']);
46/******************************************************/
47/*Funzione di visualizzazione globale */
48/*****************************************************/
49 function all() {
50 global $delsimb,$delprog,$tipo_cons,$param,$currentlang, $bgcolor1, $bgcolor2, $prefix, $dbi, $offset, $min, $id_cons,$id_cons_gen,$id_comune,$id_circ,$do,$id_gruppo;
51 $sql="SELECT circo FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' and lingua='$currentlang'";
52 $res = $dbi->prepare("$sql");
53 $res->execute();
54 list($cons_circ)= $res->fetch(PDO::FETCH_NUM);
55 if($cons_circ)
56 {
57 echo "<form name=\"circo\" action=\"admin.php\" method=\"post\">";
58 echo "<br><table border=\"1\" width=\"50%\" ><tr bgcolor=\"$bgcolor1\"><td>"._SCEGLI_CIRCO.": </td>";
59 $sql="SELECT * FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons'";
60 $res = $dbi->prepare("$sql");
61 $res->execute();
62 echo "<input type=\"hidden\" name=\"pag\" value=\"admin.php?op=gruppo&amp;id_cons_gen=$id_cons_gen&amp;id_circ=\">";
63 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\">";
64 echo "<option value=\"\">";
65 while($arr=$res->fetch(PDO::FETCH_BOTH)){
66 if (!$id_circ) $id_circ=$arr['id_circ'];
67 $sel= ($arr['id_circ'] == $id_circ) ? "selected":"";
68 echo "<option value=\"".$arr['id_circ']."\" $sel>".$arr['descrizione'];
69 }
70 echo "</select></td></tr></table></form>";
71 }
72 echo "<center><font class=\"title\"><b>"._GRUPPO."</b></font><br>";
73
74 echo "<table border=\"0\" width=\"100%\"><tr bgcolor=\"$bgcolor1\"><td colspan=\"5\">";
75 echo "<form name=\"gruppo2\" enctype=\"multipart/form-data\" action=\"admin.php\" method=\"post\">"
76 ."<input type=\"hidden\" name=\"op\" value=\"gruppo\">";
77 echo "<table><tr>"
78 ."<td align=\"center\"width=\"5%\"><b>"._NUM."</b></td>"
79 ."<td align=\"center\"><b>"._DESCR."</b></td>"
80 ."<td align=\"center\"width=\"5%\"><b>"._SIMBOLO."</b>";
81 if ($do=='modify')
82 echo "<br><input type=\"checkbox\" name=\"delsimb\" value=\"false\"> "._DELETE;
83 echo "</td>";
84
85 if ($tipo_cons!=2) {
86 echo "<td align=\"center\"width=\"5%\"><b>"._PROGRAM."</b>";
87 if ($do=='modify')
88 echo "<br><input type=\"checkbox\" name=\"delprog\" value=\"false\"> "._DELETE;
89 echo "</td>";
90 }
91 echo "<td align=\"center\"><b>"._FUNZIONI."</b></td></tr>";
92 //-----------------------visualizza riga superiore per inserimento -
93 $circo= $cons_circ==1 ? "and id_circ='$id_circ'":"";
94 $sql="SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ";
95 $res = $dbi->prepare("$sql");
96 $res->execute();
97 $max = $res->rowCount();
98 $nuovo_gruppo=$max+1;
99 echo "<tr><td>";
100 if ($do=='modify') {
101 $sql="SELECT * FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
102 $resl = $dbi->prepare("$sql");
103 $resl->execute();
104 $gru=$resl->fetch(PDO::FETCH_BOTH);
105 $nuovo_gruppo=$gru['num_gruppo'];
106 echo "<input type=\"hidden\" name=\"do\" value=\"update\">";
107 }else{
108 $gru['id_gruppo']='';$gru['descrizione']='';
109 echo "<input type=\"hidden\" name=\"do\" value=\"add\">";
110 }
111
112 //-----------------------fine visualizza riga superiore per inserimento -
113 echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">"
114 ."<input type=\"hidden\" name=\"id_gruppo\" value=\"".$gru['id_gruppo']."\">"
115 ."<input type=\"text\" name=\"num_gruppo\" value=\"$nuovo_gruppo\" size=\"3\"></td>";
116 #referendum modif 15 aprile 2016 luc
117 if($tipo_cons==2) echo "<td><textarea rows=\"7\" cols=\"50\" name=\"descr_gruppo\"> ".$gru['descrizione']."</textarea></td>";
118 else echo "<td><input type=\"text\" name=\"descr_gruppo\" value=\"".$gru['descrizione']."\"></td>";
119
120 echo "<td><input type=\"file\" name=\"stemma\" size=\"5\"></td>"; //file=$gru[simbolo]
121 if ($tipo_cons!=2)
122 echo "<td><input type=\"file\" name=\"programma\" size=\"5\">";
123 echo "<input type=\"hidden\" name=\"min\" value=\"$min\">";
124 echo "<input type=\"hidden\" name=\"id_comune\" value=\"$id_comune\">";
125 echo "<input type=\"hidden\" name=\"id_circ\" value=\"$id_circ\">";
126 echo "<input type=\"hidden\" name=\"id_cons\" value=\"$id_cons\">"
127 ."<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">"
128 ."<input type=\"hidden\" name=\"min\" value=\"$min\"></td>";
129 if ($do=='modify')
130 echo "<td><input type=\"submit\" name=\"add\" value=\""._MODIFY."\"></td>";
131 else
132 echo "<td><input type=\"submit\" name=\"add\" value=\""._ADD."\"></td>";
133 echo "</tr></table></form>";
134 echo "</td></tr>";
135
136
137 $sql="SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ";
138 $res = $dbi->prepare("$sql");
139 $res->execute();
140 $max = $res->rowCount();
141 $sql="select * from ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ORDER BY num_gruppo LIMIT $min,$offset";
142 $result = $dbi->prepare("$sql");
143 $result->execute();
144 while(list($id_cons2,$id_gruppo,$num_gruppo, $descr_gruppo, $simbolo,,, $prognome) = $result->fetch(PDO::FETCH_NUM)) {
145 $sql="select count(0) from ".$prefix."_ele_lista where id_gruppo='$id_gruppo'";
146 $restemp = $dbi->prepare("$sql");
147 $restemp->execute();
148 list($numtemp)=$restemp->fetch(PDO::FETCH_NUM);
149 $bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
150 if (!$simbolo) $simbolo="nulla.jpg";
151 echo "<tr bgcolor=\"$bgcolor1\"><td align=\"center\"><b>$num_gruppo</b></td>"
152 ."<td align=\"left\"><b>$descr_gruppo</b></td>";
153 echo "<td align=\"center\"><b>
154 <img src=\"admin.php?op=foto&amp;id_gruppo=$id_gruppo\" width=\"50\" height=\"50\" alt=\"foto\"></b></td>";
155 if ($tipo_cons!=2)
156 echo "<td>$prognome</td>";
157 echo "<td align=\"center\" nowrap>";
158 echo "[<a
159 href=\"admin.php?op=gruppo&amp;do=modify&amp;id_gruppo=$id_gruppo&amp;id_cons_gen=$id_cons_gen&amp;id_circ=$id_circ&amp;min=$min\"><img src=\"modules/Elezioni/images/edit.gif\"
160 border=\"0\" align=\"middle\" alt=\"edit\"> "._EDIT."</a>]";
161 if (!$numtemp)
162 echo "[<a href=\"admin.php?op=gruppo&amp;do=delete&amp;id_gruppo=$id_gruppo&amp;id_cons_gen=$id_cons_gen&amp;id_circ=$id_circ&amp;descr_gruppo=$descr_gruppo&amp;min=$min\">"._DELETE." <img src=\"modules/Elezioni/images/delete.gif\" border=\"0\" align=\"middle\" alt=\"delete\"></a>]";
163 else
164 echo " ["._DELETE." <img src=\"modules/Elezioni/images/delete.gif\" border=\"0\" align=\"middle\" alt=\"delete\">]";
165 echo "</td></tr>";
166 }
167 echo "</table></center>";
168
169// #'Pagina precedente' e 'Pagina Successiva'
170
171 echo"<table align=\"center\" width=\"100%\" ><tr>";
172 $prev=$min-$offset;
173 if ($prev>=0) {
174 echo "<td colspan=\"5\" align=\"center\" bgcolor=\"$bgcolor1\"><a href=\"admin.php?op=gruppo&amp;id_gruppo=$id_gruppo&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;min=$prev\">";
175 echo "<b>$offset "._PREV_MATCH."</b></a></td>";
176 }
177
178 $next=$min+$offset;
179 if ($next>=($offset-1)) {
180 if($next>=$max) $next = $max;
181 else {
182 echo "<td colspan=\"5\" align=\"center\" bgcolor=\"$bgcolor1\"><a href=\"admin.php?op=gruppo&amp;id_gruppo=$id_gruppo&amp;id_cons_gen=$id_cons_gen&amp;min=$next\">";
183 echo "<b>$offset "._NEXT_MATCH."</b></a></td>";
184 }
185 }
186 echo "</tr></table><br>";
187
188 }
189
190//***********************************************************
191//Funzione di inserimento e gestione dei gruppi
192//************************************************************
193
194function gruppo($ok, $do,$id_gruppo,$num_gruppo,$descr_gruppo, $simbolo,$id_circ) {
195 global $delsimb,$delprog,$prefix, $dbi, $id_cons,$simbolo2,$genere,$id_cons_gen,$id_comune,$min;
196 $aid=$_SESSION['aid'];
197 $perms=ChiSei($id_cons_gen);
198 if ($perms >16) {
199 if ($do == "delete") {
200 if ($ok !="1") {
201 ele();
202 echo "<center><br><br>"._DOMCANCELLA." "._GRUPPO." $descr_gruppo ?<br>";
203 echo "[ <a href=\"admin.php?op=gruppo&amp;id_cons_gen=$id_cons_gen&amp;id_circ=$id_circ\">"._NO."</a> ] - [<a href=\"admin.php?op=gruppo&amp;do=delete&amp;id_gruppo=$id_gruppo&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;min=$min&amp;ok=1\">"._YES."</a> ]";exit;
204 }else{
205 $sql="select id_lista from ".$prefix."_ele_lista where id_gruppo='$id_gruppo'";
206 $reslis = $dbi->prepare("$sql");
207 $reslis->execute();
208 while (list($idlst)=$reslis->fetch(PDO::FETCH_NUM)){
209 $sql="select id_cand from ".$prefix."_ele_candidato where id_lista='$idlst'";
210 $rescan = $dbi->prepare("$sql");
211 $rescan->execute();
212 while (list($idcnd)=$rescan->fetch(PDO::FETCH_NUM)){
213 $sql="delete from ".$prefix."_ele_voti_candidati where id_cand='$idcnd'";
214 $res = $dbi->prepare("$sql");
215 $res->execute();
216 $sql="delete from ".$prefix."_ele_candidati where id_cand='$idcnd'";
217 $res = $dbi->prepare("$sql");
218 $res->execute();
219 }
220 $sql="delete from ".$prefix."_ele_voti_lista where id_lista='$idlst'";
221 $res = $dbi->prepare("$sql");
222 $res->execute();
223 $sql="delete from ".$prefix."_ele_lista where id_lista='$idlst'";
224 $res = $dbi->prepare("$sql");
225 $res->execute();
226 }
227 $sql="delete from ".$prefix."_ele_voti_gruppo where id_gruppo='$id_gruppo'";
228 $res = $dbi->prepare("$sql");
229 $res->execute();
230 $sql="delete from ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
231 $res = $dbi->prepare("$sql");
232 $res->execute();
233 if (!$result) return;
234 Header("Location: admin.php?op=gruppo&id_cons_gen=$id_cons_gen&id_circ=$id_circ&min=$min");
235 }
236 } elseif ($do == "add") {
237 if ($descr_gruppo) {
238 $stemmablob='';
239 $stemmanome='';
240 $STEMM=$_FILES['stemma'];
241 $filestemma=$STEMM['tmp_name'];
242 $nomestemma=$STEMM['name'];
243 if ($filestemma){
244 $fdstemma = fopen ("$filestemma", "rb");
245 $stemmacontents = fread ($fdstemma, filesize ("$filestemma"));
246 fclose ($fdstemma);
247 $stemmablob=addslashes($stemmacontents);
248 $stemmanome=addslashes($nomestemma);
249 }
250
251 $progblob='';
252 $prognome='';
253 $PROG=$_FILES['programma'];
254 $fileprog=$PROG['tmp_name'];
255 $nomeprog=$PROG['name'];
256 if ($fileprog){
257 $fdprog = fopen ("$fileprog", "rb");
258 $progcontents = fread ($fdprog, filesize ("$fileprog"));
259 fclose ($fdprog);
260 $progblob=addslashes($progcontents);
261 $prognome=addslashes($nomeprog );
262 }
263 $sql="insert into ".$prefix."_ele_gruppo (id_cons,id_gruppo,num_gruppo,descrizione,simbolo,stemma,id_circ,prognome,programma) values ('$id_cons','$id_gruppo','$num_gruppo','$descr_gruppo','$stemmanome','$stemmablob','$id_circ','$prognome','$progblob')";
264 $result = $dbi->prepare("$sql");
265 $result->execute();
266 if (!$result->rowCount()) return;
267 Header("Location: admin.php?op=gruppo&id_cons_gen=$id_cons_gen&id_circ=$id_circ&min=$min");
268 } else {
269 ele();
270 OpenTable();
271 echo "<center>"._GESTIONE." "._GRUPPO." ";
272 echo "<br><br><a href=\"admin.php?op=gruppo&amp;id_cons_gen=$id_cons_gen&amp;min=$min\">"._IMM." "._GRUPPO."</a></center>";
273 CloseTable();
274 }
275 } elseif ($do == "update") {
276 $progblob='';
277 $prognome='';
278 $PROG=$_FILES['programma'];
279 $fileprog=$PROG['tmp_name'];
280 $nomeprog=$PROG['name'];
281 if ($fileprog){
282 $fdprog = fopen ("$fileprog", "rb");
283 $progcontents = fread ($fdprog, filesize ("$fileprog"));
284 fclose ($fdprog);
285 $progblob=addslashes($progcontents);
286 $prognome=addslashes($nomeprog );
287 $cond=", prognome='$prognome', programma='$progblob'";
288 } else {
289 if ( $delprog=='false') $cond=", prognome='', programma=''";
290 else $cond='';
291 }
292
293
294
295 $stemmablob='';
296 $stemmanome='';
297 $STEMM=$_FILES['stemma'];
298 $filestemma=$STEMM['tmp_name'];
299 $nomestemma=$STEMM['name'];
300 if ($filestemma){
301 $fdstemma = fopen ("$filestemma", "rb");
302 $stemmacontents = fread ($fdstemma, filesize ("$filestemma"));
303 fclose ($fdstemma);
304 $stemmablob=addslashes($stemmacontents);
305 $stemmanome=addslashes($nomestemma);
306 $cond2=", simbolo='$stemmanome', stemma='$stemmablob'";
307 } else {
308 if ( $delsimb=='false') $cond2=", simbolo='', stemma=''";
309 else $cond2='';
310 }
311 $sql="update ".$prefix."_ele_gruppo set num_gruppo='$num_gruppo' , descrizione='$descr_gruppo' $cond $cond2 where id_gruppo='$id_gruppo' ";
312 $result = $dbi->prepare("$sql");
313 $result->execute();
314 Header("Location: admin.php?op=gruppo&id_cons_gen=$id_cons_gen&id_circ=$id_circ&min=$min");
315 }
316
317 }
318}
319
320if ($do and $do!="modify")
321 gruppo($ok, $do,$id_gruppo,$num_gruppo,$descr_gruppo,$simbolo, $id_circ);
322ele();
323all();
324echo"</td></tr></table>";
325include("footer.php");
326
327
328
329
330?>
Note: See TracBrowser for help on using the repository browser.