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

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

ATTENZIONE: con questa rev viene cambiato il charset che da ora viene impostato su utf8. Fate tutte le vostre verifiche prima di installarla.
Seconda fase di rivisitazione e completamento delle funzioni necessarie per l'accesso al servizio tramite cellulare.
Effettuate alcune sistemazioni per gli avvisi di incongruenza.

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