source: trunk/admin/modules/Elezioni/importa.php@ 404

Last change on this file since 404 was 362, checked in by roby, 3 years ago

Ritocchi e sistemazioni varie di completamento delle mofifiche precedenti

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