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 Inserimento dati */
|
---|
9 | /* Amministrazione */
|
---|
10 | /************************************************************************/
|
---|
11 |
|
---|
12 | if (!defined('ADMIN_FILE')) {
|
---|
13 | die ("You can't access this file directly...");
|
---|
14 | }
|
---|
15 | $perms=ChiSei(0);
|
---|
16 | if ($perms<32) die("Non hai i permessi per effettuare questa operazione!");
|
---|
17 |
|
---|
18 | $param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ? $_GET : $_POST;
|
---|
19 | $id_cons_gen=intval($param['id_cons_gen']);
|
---|
20 | if (isset($param['datafile'])) get_magic_quotes_gpc() ? $datafile=$param['datafile']:$datafile=addslashes($param['datafile']); else $datafile='';
|
---|
21 | include("modules/Elezioni/ele.php");
|
---|
22 |
|
---|
23 |
|
---|
24 | function insgruppo()
|
---|
25 | {
|
---|
26 | global $prefix, $dbi;
|
---|
27 | global $ar_gruppo,$ar_lista,$ar_candi,$idcns;
|
---|
28 |
|
---|
29 | foreach ($ar_gruppo as $rigagruppo){
|
---|
30 | $newidg=0;
|
---|
31 | $oldidg=0;
|
---|
32 | foreach($rigagruppo as $key=>$campo){
|
---|
33 | if ($key==0) $valori="'$idcns',";
|
---|
34 | elseif ($key==1) {$valori.= "null"; $oldidg=$campo;}
|
---|
35 | elseif ($key==6) $valori.= ",0";
|
---|
36 | else $valori.= ",'$campo'";
|
---|
37 | if ($key==2) $numgruppo= $campo;
|
---|
38 | }
|
---|
39 | if(isset($valori)){
|
---|
40 | $res_gruppo = mysql_query("insert into ".$prefix."_ele_gruppo values($valori)" ,$dbi)||die("(1104) Non e' stato possibile inserire i gruppi nel database! contattare l'amministratore".mysql_error());
|
---|
41 | $resnew = mysql_query("select id_gruppo from ".$prefix."_ele_gruppo where num_gruppo='$numgruppo' and id_cons='$idcns'" ,$dbi);
|
---|
42 | list ($newidg) = mysql_fetch_row($resnew);
|
---|
43 | unset($valori);
|
---|
44 | if($oldidg)
|
---|
45 | $_SESSION['gruppi']['idg_'.$oldidg]=$newidg;
|
---|
46 | # inslista($oldidg,$newidg);
|
---|
47 | }
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | function inslista()#$oldidg,$newidg
|
---|
52 | {
|
---|
53 | global $prefix, $dbi;
|
---|
54 | global $ar_lista,$ar_candi,$idcns;
|
---|
55 |
|
---|
56 | foreach ($ar_lista as $rigalista){
|
---|
57 | if(!isset($rigalista[3])) continue;
|
---|
58 | $oldidl=0;
|
---|
59 | $okl=0;
|
---|
60 | $oldidg=$rigalista[3];
|
---|
61 | $newidg=$_SESSION['gruppi']['idg_'.$oldidg];
|
---|
62 | foreach($rigalista as $key=>$campo){
|
---|
63 | if ($key==0) $valori="'$idcns',";
|
---|
64 | elseif ($key==1) {$valori.= "null";$oldidl=$campo;}
|
---|
65 | elseif ($key==3) {$valori.= ",'$newidg'"; if ($campo!=$oldidg) $okl=1;}
|
---|
66 | elseif ($key==4) $valori.= ",0";
|
---|
67 | else $valori.= ",'$campo'";
|
---|
68 | if ($key==2) $numlista= $campo;
|
---|
69 | }
|
---|
70 | if(isset($valori)){
|
---|
71 | if ($okl) {$okl=0;continue;}
|
---|
72 | $res_lista = mysql_query("insert into ".$prefix."_ele_lista values($valori)" ,$dbi)||die("(1104) Non e' stato possibile inserire le liste nel database! contattare l'amministratore".mysql_error());
|
---|
73 | $reslnew = mysql_query("select id_lista from ".$prefix."_ele_lista where num_lista='$numlista' and id_cons='$idcns'" ,$dbi);
|
---|
74 | list ($newidl) = mysql_fetch_row($reslnew);
|
---|
75 | unset($valori);
|
---|
76 | if($oldidl)
|
---|
77 | $_SESSION['liste']['idl_'.$oldidl]=$newidl;
|
---|
78 |
|
---|
79 | # inscandi($oldidl,$newidl);
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | function inscandi()#$oldidl,$newidl
|
---|
85 | {
|
---|
86 | global $prefix, $dbi;
|
---|
87 | global $ar_candi,$idcns;
|
---|
88 |
|
---|
89 | foreach ($ar_candi as $rigacandi){
|
---|
90 | if(!isset($rigacandi[2])) continue;
|
---|
91 | $okc=0;
|
---|
92 | $oldidl=$rigacandi[2];
|
---|
93 | $newidl=$_SESSION['liste']['idl_'.$oldidl];
|
---|
94 | foreach($rigacandi as $key=>$campo){#echo "$key -- $campo<br>";
|
---|
95 | if (count($rigacandi)!=8) {unset($valori);continue;}
|
---|
96 | if ($key==0) $valori= "null,";
|
---|
97 | elseif ($key==1) $valori.="'$idcns',";
|
---|
98 | elseif ($key==2) {$valori.= "'$newidl'"; if ($campo!=$oldidl) $okc=1;}
|
---|
99 | else $valori.= ",'$campo'";
|
---|
100 | }
|
---|
101 | if(isset($valori)){
|
---|
102 | if ($okc) {$okc=0;continue;}
|
---|
103 | $res_lista = mysql_query("insert into ".$prefix."_ele_candidati values($valori)" ,$dbi)||die("(1104) Non e' stato possibile inserire i candidati nel database! contattare l'amministratore".mysql_error());
|
---|
104 | }
|
---|
105 | }
|
---|
106 | #foreach($_SESSION['liste'] as $key=>$val) echo "$key -- $val<br>";
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 |
|
---|
111 |
|
---|
112 |
|
---|
113 | $res = mysql_query("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' and t2.id_cons_gen='$id_cons_gen'" , $dbi);
|
---|
114 | list($id_cons,$descrizione) = mysql_fetch_row($res);
|
---|
115 | if (!isset($_FILES['datafile']['tmp_name']) or !is_uploaded_file($_FILES['datafile']['tmp_name']))
|
---|
116 | {
|
---|
117 | ele();
|
---|
118 | echo "<form name=\"importa\" enctype=\"multipart/form-data\" method=\"post\" action=\"admin.php\" >"
|
---|
119 | ."<input type=\"hidden\" name=\"op\" value=\"importa\">";
|
---|
120 | echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">";
|
---|
121 | echo "<input type=\"hidden\" name=\"id_comune\" value=\"$id_comune\">";
|
---|
122 | echo "<table cellspacing=\"0\" cellpadding=\"2\" border=\"1\"><tr class=\"bggray\"><td colspan=\"2\" align=\"center\">"._SEL_DATA_FILE2."</td></tr><tr><td><input name=\"datafile\" type=\"file\"></td>";
|
---|
123 | echo "<td align=\"center\"><input type=\"submit\" name=\"add\" value=\""._OK."\"></td></tr></table></form>";
|
---|
124 | ////////////////////////////
|
---|
125 | }else{
|
---|
126 | $idcns=$id_cons;
|
---|
127 | $res_del = mysql_query("delete from ".$prefix."_ele_voti_ref where id_cons=$idcns" ,$dbi);
|
---|
128 | $res_del = mysql_query("delete from ".$prefix."_ele_voti_candidati where id_cons=$idcns" ,$dbi);
|
---|
129 | $res_del = mysql_query("delete from ".$prefix."_ele_voti_lista where id_cons=$idcns" ,$dbi);
|
---|
130 | $res_del = mysql_query("delete from ".$prefix."_ele_voti_gruppo where id_cons=$idcns" ,$dbi);
|
---|
131 | $res_del = mysql_query("update ".$prefix."_ele_sezioni set validi='0', contestati='0', validi_lista='0', nulli='0',bianchi='0',contestati_lista='0', voti_nulli_lista='0' where id_cons=$idcns" ,$dbi);
|
---|
132 | $res_del = mysql_query("delete from ".$prefix."_ele_voti_parziale where id_cons=$idcns" ,$dbi);
|
---|
133 | $res_del = mysql_query("delete from ".$prefix."_ele_candidati where id_cons=$idcns" ,$dbi);
|
---|
134 | $res_del = mysql_query("delete from ".$prefix."_ele_lista where id_cons=$idcns" ,$dbi);
|
---|
135 | $res_del = mysql_query("delete from ".$prefix."_ele_gruppo where id_cons=$idcns" ,$dbi);
|
---|
136 | $datafile=$_FILES['datafile']['tmp_name'];
|
---|
137 | $arrFile = file($datafile);
|
---|
138 | $handle = fopen($datafile, "r");
|
---|
139 | $test=array();
|
---|
140 | $errore=0;
|
---|
141 | $fine=0;
|
---|
142 | // Set counters
|
---|
143 | $currentLine = 0;
|
---|
144 | $cntFile = count($arrFile);
|
---|
145 | $tabs=array($prefix."_ele_gruppo",$prefix."_ele_lista",$prefix."_ele_candidati",$prefix."_ele_circoscrizione");
|
---|
146 | $x=0;$k=0;
|
---|
147 | $scarto=0;
|
---|
148 | $primog=0;
|
---|
149 | $primol=0;
|
---|
150 | $conta=array();
|
---|
151 | $currentLine = 0;
|
---|
152 | $x=0;$k=0;
|
---|
153 | $y=0;
|
---|
154 | $ar_gruppo=array(array());
|
---|
155 | $ar_lista=array(array());
|
---|
156 | $ar_candi=array(array());
|
---|
157 | $z=0;
|
---|
158 | $tab=substr($arrFile[$currentLine],1,-2);
|
---|
159 | $conf=$tabs[$x];
|
---|
160 | if($k==0) {while (substr($arrFile[$currentLine],1,-2)!=$conf and $currentLine <= $cntFile) $currentLine++; $k++;}
|
---|
161 | $currentLine++;
|
---|
162 | while($currentLine <= $cntFile and $fine==0){
|
---|
163 | # $appo=substr($arrFile[$currentLine],1,-2);
|
---|
164 | if(isset($arrFile[$currentLine]))
|
---|
165 | $appo=substr($arrFile[$currentLine],1,-2);
|
---|
166 | else $appo='';
|
---|
167 | if (isset($tabs[($x+1)]) and $appo==$tabs[($x+1)]){ $x++;$conf=$tabs[$x];$currentLine++; continue;}
|
---|
168 | $test=explode(':',$appo); if(!is_array($test)) {die("errore di import<br>");}
|
---|
169 | foreach($test as $key=>$val)
|
---|
170 | if ($conf==$prefix."_ele_gruppo")
|
---|
171 | $ar_gruppo[$z][$key]=addslashes(base64_decode($val));
|
---|
172 | elseif ($conf==$prefix."_ele_lista"){
|
---|
173 | if($primog==0){
|
---|
174 | $gruppofil= array_filter($ar_gruppo);
|
---|
175 | $numgruppo=count($gruppofil);
|
---|
176 | insgruppo();
|
---|
177 | $primog=1;
|
---|
178 | unset($ar_gruppo);
|
---|
179 | }
|
---|
180 | $ar_lista[$z][$key]=addslashes(base64_decode($val));}
|
---|
181 | elseif ($conf==$prefix."_ele_candidati"){
|
---|
182 | if($primol==0){
|
---|
183 | $listafil= array_filter($ar_lista);
|
---|
184 | $numlista=count($listafil);
|
---|
185 | inslista();
|
---|
186 | $primol=1;
|
---|
187 | unset($ar_lista);
|
---|
188 | }
|
---|
189 | $ar_candi[$z][$key]=addslashes(base64_decode($val));
|
---|
190 | }
|
---|
191 | elseif ($conf==$prefix."_ele_circoscrizione"){
|
---|
192 | inscandi();
|
---|
193 | unset($ar_candi);
|
---|
194 | $fine=1;
|
---|
195 | break;
|
---|
196 | }
|
---|
197 | $currentLine++;
|
---|
198 | $z++;
|
---|
199 | }
|
---|
200 | fclose($handle);
|
---|
201 |
|
---|
202 |
|
---|
203 |
|
---|
204 | if ($numgruppo){
|
---|
205 | # insgruppo();
|
---|
206 | Header("Location: admin.php?op=gruppo&id_cons_gen=$id_cons_gen");
|
---|
207 | }
|
---|
208 | elseif ($numlista) {
|
---|
209 | inslista(0,0);
|
---|
210 | Header("Location: admin.php?op=lista&id_cons_gen=$id_cons_gen");
|
---|
211 | }
|
---|
212 | else Header("Location: admin.php?op=lista&id_cons_gen=$id_cons_gen");
|
---|
213 |
|
---|
214 | }
|
---|
215 |
|
---|
216 | echo"</td></tr></table>";
|
---|
217 | include("footer.php");
|
---|
218 |
|
---|
219 |
|
---|
220 |
|
---|
221 |
|
---|
222 |
|
---|
223 |
|
---|
224 |
|
---|
225 |
|
---|
226 |
|
---|
227 |
|
---|
228 |
|
---|
229 | /*
|
---|
230 | foreach ($ar_gruppo as $rigagruppo){
|
---|
231 | $newidg=0;
|
---|
232 | $oldidg=0;
|
---|
233 | foreach($rigagruppo as $key=>$campo){
|
---|
234 | if ($key==0) $valori="'$idcns',";
|
---|
235 | elseif ($key==1) {$valori.= "null"; $oldidg=$campo;}
|
---|
236 | elseif ($key==6) $valori.= ",0";
|
---|
237 | else $valori.= ",'$campo'";
|
---|
238 | if ($key==2) $numgruppo= $campo;
|
---|
239 | }
|
---|
240 | if(isset($valori)){
|
---|
241 | $res_gruppo = mysql_query("insert into ".$prefix."_ele_gruppo values($valori)" ,$dbi)||die("(1104) Non e' stato possibile inserire i gruppi nel database! contattare l'amministratore".mysql_error());
|
---|
242 | $resnew = mysql_query("select id_gruppo from ".$prefix."_ele_gruppo where num_gruppo='$numgruppo' and id_cons='$idcns'" ,$dbi);
|
---|
243 | list ($newidg) = mysql_fetch_row($resnew);
|
---|
244 | unset($valori);
|
---|
245 | foreach ($ar_lista as $rigalista){
|
---|
246 | $oldidl=0;
|
---|
247 | foreach($rigalista as $key=>$campo){
|
---|
248 | if ($key==0) $valori="'$idcns',";
|
---|
249 | elseif ($key==1) {$valori.= "null";$oldidl=$campo;}
|
---|
250 | elseif ($key==3) {$valori.= ",'$newidg'"; if ($campo!=$oldidg) $okl=1;}
|
---|
251 | elseif ($key==4) $valori.= ",0";
|
---|
252 | else $valori.= ",'$campo'";
|
---|
253 | if ($key==2) $numlista= $campo;
|
---|
254 | }
|
---|
255 | if(isset($valori)){
|
---|
256 | if ($okl) {$okl=0;continue;}
|
---|
257 | $res_lista = mysql_query("insert into ".$prefix."_ele_lista values($valori)" ,$dbi)||die("(1104) Non e' stato possibile inserire le liste nel database! contattare l'amministratore".mysql_error());
|
---|
258 | $reslnew = mysql_query("select id_lista from ".$prefix."_ele_lista where num_lista='$numlista' and id_cons='$idcns'" ,$dbi);
|
---|
259 | list ($newidl) = mysql_fetch_row($reslnew);
|
---|
260 | unset($valori);
|
---|
261 | foreach ($ar_candi as $rigacandi){
|
---|
262 | foreach($rigacandi as $key=>$campo){if (count($rigacandi)!=8) {unset($valori);continue;}
|
---|
263 | if ($key==0) $valori= "null,";
|
---|
264 | elseif ($key==1) $valori.="'$idcns',";
|
---|
265 | elseif ($key==2) {$valori.= "'$newidl'"; if ($campo!=$oldidl) $okc=1;}
|
---|
266 | else $valori.= ",'$campo'";
|
---|
267 | }
|
---|
268 | if(isset($valori)){
|
---|
269 | if ($okc) {$okc=0;continue;}
|
---|
270 | $res_lista = mysql_query("insert into ".$prefix."_ele_candidati values($valori)" ,$dbi)||die("(1104) Non e' stato possibile inserire i candidati nel database! contattare l'amministratore".mysql_error());
|
---|
271 | }
|
---|
272 | }
|
---|
273 | }
|
---|
274 | }
|
---|
275 | }
|
---|
276 | }
|
---|
277 | */
|
---|
278 |
|
---|
279 | ?>
|
---|