source: trunk/admin/modules/Elezioni/ele_cons_comuni.php@ 340

Last change on this file since 340 was 304, checked in by roby, 6 years ago
File size: 12.6 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 definiione consultazione */
9/* Amministrazione */
10/************************************************************************/
11if (!defined('ADMIN_FILE')) {
12 die ("You can't access this file directly...");
13}
14
15$aid=$_SESSION['aid'];
16global $dbi;
17$prefix=$_SESSION['prefix'];
18if($param)
19$param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ? $_GET : $_POST;
20$vari= implode(',',$param);
21$id_cons_gen=$_GET['id_cons_gen'];
22$id_comune=$_SESSION['id_comune'];
23$perms=ChiSei(0);
24if ($perms<64 or !$id_cons_gen) die("Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
25$sql="SELECT tipo_cons,descrizione FROM ".$prefix."_ele_consultazione where id_cons_gen='$id_cons_gen' ";
26$res = $dbi->prepare("$sql");
27$res->execute();
28list($tipo_cons,$descr_cons) = $res->fetch(PDO::FETCH_NUM);
29include("modules/Elezioni/funzionidata.php");
30include("modules/Elezioni/ele.php");
31if (isset($param['do'])) get_magic_quotes_gpc() ? $do=$param['do']:$do=addslashes($param['do']); else $do='';
32if (isset($param['ok'])) get_magic_quotes_gpc() ? $ok=$param['ok']:$ok=addslashes($param['ok']); else $ok='';
33if (isset($param['id_cons2'])) $id_cons2=intval($param['id_cons2']); else $id_cons2='';
34if (isset($param['min'])) $min=intval($param['min']); else $min=0;
35if (isset($param['duplica'])) $duplica=intval($param['duplica']); else $duplica='';
36if (isset($param['elettori'])) get_magic_quotes_gpc() ? $elettori=$param['elettori']:$elettori=addslashes($param['elettori']); else $elettori='';
37if (isset($param['predefinita'])) $predefinita=intval($param['predefinita']); else $predefinita='';
38if (isset($param['help'])) $help=intval($param['help']);
39
40$offset=10;
41$hiddenInfo = "<input type=\"hidden\" name=\"min\" value=\"$min\">";
42
43
44/******************************************************/
45/*Funzione di visualizzazione globale */
46/*****************************************************/
47
48function all() {
49global $bgcolor1, $bgcolor2, $bgcolor6, $prefix, $dbi, $offset, $min, $id_cons,$id_cons2, $id_comune,$descr_cons,$id_cons_gen,$perms,$language,$help;
50
51 if (isset($help)) include("language/$language/ele_cons_comuni.html");
52
53 $sql="SELECT id_cons FROM ".$prefix."_ele_comuni where id_comune=$id_comune";
54 $res = $dbi->prepare("$sql");
55 $res->execute();
56 if ($res->rowCount()) list($idpred) = $res->fetch(PDO::FETCH_NUM); else $idpred='';
57 $sql="SELECT t1.id_cons, t2.descrizione FROM ".$prefix."_ele_cons_comune as t1 left join ".$prefix."_ele_consultazione as t2 on t1.id_cons_gen=t2.id_cons_gen where t1.id_comune='$id_comune' ";
58 $res = $dbi->prepare("$sql");
59 $res->execute();
60 $max = $res->rowCount();
61 echo "<table border=\"0\" width=\"100%\" align=\"left\"><tr><td>";
62 echo "<form name=\"imppred\" action=\"admin.php\">";
63 echo "<table style=\"color: #000000;\"><tr><td bgcolor=\"$bgcolor1\">"
64 ."&nbsp;<b>"._CONSPRED."</b>&nbsp;</td><td><select name=\"predefinita\">";
65 echo "<option value=\"\">";
66 while($arr=$res->fetch(PDO::FETCH_BOTH)){
67 $sel='';
68 if (($idpred))
69 $sel= ($arr['id_cons'] == $idpred) ? "selected":"";
70 echo "<option value=\"".$arr['id_cons']."\" $sel>".$arr['descrizione'];
71 }
72 echo "</select></td><td>";
73 echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">";
74 echo "<input type=\"hidden\" name=\"op\" value=\"cons_comuni\">";
75 echo "<input type=\"hidden\" name=\"do\" value=\"update\">";
76 echo "<input type=\"submit\" name=\"add\" value=\""._OK."\"></td>";
77 echo "</tr></table></form></td></tr></table><hr>";
78
79 echo "<center><font class=\"title\"><b><BR>"._COPIA." "._LA." "._STRUTTURA." "._DA." $descr_cons</b></font><br><br><table border=\"0\" width=\"100%\">"
80 ."<tr><td bgcolor=\"$bgcolor1\" align=\"center\">&nbsp;<b>"._DESCR."</b>&nbsp;</td>"
81 ."<td bgcolor=\"$bgcolor1\" align=\"center\">&nbsp;<b>"._DATAIN."</b>&nbsp;</td>"
82 ."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._DATAFINE."</b></td>"
83 ."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._COPIA." "._NUM." "._ELETTORI."</b></td>"
84 ."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._FUNZIONI."</b></td></tr>";
85 $sql="select t2.chiusa,t2.id_cons,t1.* from ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2, ".$prefix."_ele_tipo as t3 where t1.tipo_cons=t3.tipo_cons and t2.id_comune='$id_comune' and t1.id_cons_gen=t2.id_cons_gen and t2.id_cons!=$id_cons ORDER BY data_fine desc LIMIT $min,$offset";
86 $res = $dbi->prepare("$sql");
87 $res->execute();
88 $i=0;
89 while(list($chiusa,$id_cons2,$idconsgen2, $descr_cons, $data_inizio, $data_fine,$tipo) = $res->fetch(PDO::FETCH_NUM)) {
90 $bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
91 $sql="select count(id_cons) from ".$prefix."_ele_sezioni where id_cons='$id_cons2'";
92 $ressez = $dbi->prepare("$sql");
93 $ressez->execute();
94 list($somma)=$ressez->fetch(PDO::FETCH_NUM);
95 $data_inizio=form_data($data_inizio);$data_fine=form_data($data_fine);
96 echo "<tr bgcolor=\"$bgcolor1\" align=\"center\" ><td align=\"left\" ><a href=\"admin.php?op=cons_comuni&amp;id_cons_gen=$idconsgen2\"><b>$descr_cons</b></a></td>"
97 ."<td>$data_inizio</td>"
98 ."<td>$data_fine</td>";
99 if ($somma==0){
100 $i++;
101 echo "<form name=\"scelta$i\" action=\"admin.php\">";
102 echo "<td align=\"center\"><select name=\"elettori\">";
103 echo "<option value=\"false\">"._NO."</option>";
104 echo "<option value=\"true\">"._SI."</option>";
105 echo "</select></td>";
106 echo "<input type=\"hidden\" name=\"op\" value=\"cons_comuni\">";
107 echo "<input type=\"hidden\" name=\"do\" value=\"add\">";
108 echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">";
109 echo "<input type=\"hidden\" name=\"id_cons2\" value=\"$id_cons2\">";
110 echo "<td align=\"center\"><input type=\"submit\" value=\""._POPOLA."\"></td>";
111 echo "</form>";
112 }elseif($perms==256){
113 $i++;
114 echo "<form name=\"scelta$i\" action=\"admin.php\">";
115 echo "<td align=\"center\">Aggiorna il numero elettori</td>";
116 echo "<input type=\"hidden\" name=\"op\" value=\"cons_comuni\">";
117 echo "<input type=\"hidden\" name=\"do\" value=\"elettori\">";
118 echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">";
119 echo "<input type=\"hidden\" name=\"id_cons2\" value=\"$id_cons2\">";
120 echo "<td align=\"center\"><input type=\"submit\" value=\""._UPDATE."\"></td>";
121 echo "</form>";
122
123 }
124 echo "</tr>";
125 }
126 echo "</table></center>";
127 #'Pagina precedente' e 'Pagina Successiva'
128 echo "<table align=\"center\" width=\"100%\" bgcolor=\"$bgcolor1\"><tr>";
129 $prev=$min-$offset;
130 if ($prev>=0) {
131 echo "<td colspan=\"5\" align=\"center\" bgcolor=\"$bgcolor2\"><a href=\"admin.php?op=cons_comuni&amp;id_cons_gen=$id_cons_gen&amp;min=$prev\">";
132 echo "<b>$offset "._PREV_MATCH."</b></a></td>";
133 }
134
135 $next=$min+$offset;
136 if ($next>=($offset-1)) {
137 if($next>=$max) $next = $max;
138 else {
139 echo "<td colspan=\"5\" align=\"center\" bgcolor=\"$bgcolor2\"><a href=\"admin.php?op=cons_comuni&amp;id_cons_gen=$id_cons_gen&amp;min=$next\">";
140 echo "<b>$offset "._NEXT_MATCH."</b></a></td>";
141 }
142 }
143 echo "</tr></table><br>";
144}
145
146
147
148function cons_comuni($ok, $id_cons2,$do, $duplica,$elettori)
149{
150 global $prefix, $dbi,$id_comune,$id_cons_gen,$perms,$predefinita;
151if ($perms>32) {
152 $sql="select id_cons from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' and id_comune=$id_comune";
153 $res = $dbi->prepare("$sql");
154 $res->execute();
155 list($id_consulta)=$res->fetch(PDO::FETCH_NUM);
156 $sql="select t1.descrizione from ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t2.id_cons='$id_cons2' and t1.id_cons_gen=t2.id_cons_gen";
157 $res = $dbi->prepare("$sql");
158 $res->execute();
159 list($descr_cons2)=$res->fetch(PDO::FETCH_NUM);
160 if ($do == "add") {
161 if ($id_cons2) {
162 // copia circoscrizione
163 $sql="select * from ".$prefix."_ele_circoscrizione where id_cons='$id_consulta'";
164 $res = $dbi->prepare("$sql");
165 $res->execute();
166 while (list($id,$idcirc,$num,$des2)=$res->fetch(PDO::FETCH_NUM)){
167 $des=addslashes($des2);
168 $sql="select count(0) from ".$prefix."_ele_circoscrizione where id_cons='$id_cons2' and num_circ='$num'";
169 $resconnew = $dbi->prepare("$sql");
170 $resconnew->execute();
171 list($contr_circ)=$resconnew->fetch(PDO::FETCH_NUM);
172 if (! $contr_circ){
173 $sql="insert into ".$prefix."_ele_circoscrizione (id_cons,num_circ,descrizione) values ('$id_cons2',$num,'$des')";
174 $res5 = $dbi->prepare("$sql");
175 $res5->execute();
176}
177 $sql="select id_circ from ".$prefix."_ele_circoscrizione where id_cons=$id_cons2 and num_circ=$num";
178 $res0 = $dbi->prepare("$sql");
179 $res0->execute();
180 list($id_circ)=$res0->fetch(PDO::FETCH_NUM);
181 // copia sede
182 $sql="select * from ".$prefix."_ele_sede where id_cons='$id_consulta' and id_circ='$idcirc'";
183 $res1 = $dbi->prepare("$sql");
184 $res1->execute();
185 while(list($id1,$idsede1,$idcirc1,$ind2,$tel,$tel2,$fax,$resp,$mappa2,$filemappa2)=$res1->fetch(PDO::FETCH_NUM)){
186 $filemappa=addslashes($filemappa2);
187 $mappa=addslashes($mappa2);
188 $ind=addslashes($ind2);
189 $sql="select count(0) from ".$prefix."_ele_sede where id_cons='$id_cons2' and indirizzo='$ind'";
190 $ressednew = $dbi->prepare("$sql");
191 $ressednew->execute();
192 list($contr_sed)=$ressednew->fetch(PDO::FETCH_NUM);
193 if (! $contr_sed){
194 $sql="insert into ".$prefix."_ele_sede (id_cons,id_circ,indirizzo,telefono1,telefono2,fax,responsabile,mappa,filemappa) values ('$id_cons2','$id_circ','$ind','$tel','$tel2','$fax','$resp','$mappa','$filemappa')";
195 $res0 = $dbi->prepare("$sql");
196 $res0->execute();
197}
198 $sql="select id_sede from ".$prefix."_ele_sede where id_cons=$id_cons2 and id_circ=$id_circ and indirizzo='$ind'";
199 $res2 = $dbi->prepare("$sql");
200 $res2->execute();
201 list($id_sede)=$res2->fetch(PDO::FETCH_NUM);
202 //copia sezione
203 $sql="select * from ".$prefix."_ele_sezioni where id_cons=$id_consulta and id_sede=$idsede1";
204 $res3 = $dbi->prepare("$sql");
205 $res3->execute();
206 while (list($id3,$idsez3,$idsede3,$numero,$maschi3,$femmine3,$validi3,$nulli3,
207 $bianchi3,$contest3,$sg3,$aut_m,$aut_f)=$res3->fetch(PDO::FETCH_NUM)){
208 if ($elettori=='true') $sql="insert into ".$prefix."_ele_sezioni (id_cons,id_sede,num_sez,maschi,femmine) values ('$id_cons2','$id_sede','$numero','$maschi3','$femmine3')";
209 else $sql="insert into ".$prefix."_ele_sezioni (id_cons,id_sede,num_sez) values ('$id_cons2','$id_sede','$numero')";
210 $res4 = $dbi->prepare("$sql");
211 $res4->execute();
212 }
213 }
214 }
215 # Header("Location: admin.php?op=cons_comuni&id_cons_gen=$id_cons_gen");
216 }
217 }
218 if ($do == "elettori") {
219 if ($ok !="1") {
220 ele();
221 echo "<center><br><br>"._DOMAGGIORNA." Consultazione $descr_cons2 ?<br>";
222 echo "[ <a href=\"admin.php?op=cons_comuni&amp;id_cons_gen=$id_cons_gen\">"._NO."</a> ] - [<a href=\"admin.php?op=cons_comuni&amp;do=elettori&amp;id_cons_gen=$id_cons_gen&amp;id_cons2=$id_cons2&amp;ok=1\">"._YES."</a> ]";exit;
223 }else{
224 $sql="update ".$prefix."_ele_sezioni as t1, ".$prefix."_ele_sezioni as t2 set t1.maschi=t2.maschi, t1.femmine=t2.femmine WHERE t1.id_cons=$id_cons2 and t2.id_cons=$id_consulta and t1.num_sez=t2.num_sez";
225 $result = $dbi->prepare("$sql");
226 $result->execute();
227 if (!$result->rowCount()) return;
228 Header("Location: admin.php?op=cons_comuni&id_cons_gen=$id_cons_gen");
229 }
230 }
231 if ($do == "update") {
232 if ($predefinita) {
233 $sql="update ".$prefix."_ele_comuni set id_cons='$predefinita' WHERE id_comune='$id_comune'";
234 $result = $dbi->prepare("$sql");
235 $result->execute();
236 }else{
237 $sql="update ".$prefix."_ele_cons_comune set chiusa='$chiusa' WHERE id_cons2='$id_cons2'";
238 $result = $dbi->prepare("$sql");
239 $result->execute();
240 }
241 if (!$result->rowCount()) return;
242 Header("Location: admin.php?op=cons_comuni&id_cons_gen=$id_cons_gen");
243 }
244}
245}
246
247function help_cons()
248{
249//da mettere
250}
251
252if ($do) {
253 cons_comuni($ok, $id_cons2,$do, $duplica, $elettori);
254}
255ele();
256//OpenTable();
257all();
258CloseTable();
259include("footer.php");
260?>
261
Note: See TracBrowser for help on using the repository browser.