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