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

Last change on this file since 343 was 336, checked in by roby, 4 years ago

Admin: prime modifiche per compatibilità con php 7.4

File size: 9.5 KB
RevLine 
[2]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
18$param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ? $_GET : $_POST;
19$id_cons_gen=intval($param['id_cons_gen']);
20if (isset($param['datafile'])) get_magic_quotes_gpc() ? $datafile=$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;
[88]32 $isnew=0;
[2]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;
[88]39 if ($key==8) $isnew=1;
40 }
[111]41 if (!$isnew and isset($valori)) $valori.=",null,null";
[2]42 if(isset($valori)){
[88]43
[257]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);
[80]51 unset($valori);
52 if($oldidg)
[36]53 $_SESSION['gruppi']['idg_'.$oldidg]=$newidg;
54# inslista($oldidg,$newidg);
[2]55 }
56}
57}
58
[36]59function inslista()#$oldidg,$newidg
[2]60{
61global $prefix, $dbi;
62global $ar_lista,$ar_candi,$idcns;
63
[80]64 foreach ($ar_lista as $rigalista){
[36]65 if(!isset($rigalista[3])) continue;
[80]66 $oldidl=0;
67 $okl=0;
68 $oldidg=$rigalista[3];
[36]69 $newidg=$_SESSION['gruppi']['idg_'.$oldidg];
[2]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;}
[257]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);
[2]87 unset($valori);
[80]88 if($oldidl)
[36]89 $_SESSION['liste']['idl_'.$oldidl]=$newidl;
[80]90
[36]91# inscandi($oldidl,$newidl);
[2]92 }
93}
94}
95
[36]96function inscandi()#$oldidl,$newidl
[2]97{
98global $prefix, $dbi;
99global $ar_candi,$idcns;
100
[80]101 foreach ($ar_candi as $rigacandi){
[36]102 if(!isset($rigacandi[2])) continue;
[35]103 $okc=0;
[80]104 $oldidl=$rigacandi[2];
[36]105 $newidl=$_SESSION['liste']['idl_'.$oldidl];
106 foreach($rigacandi as $key=>$campo){#echo "$key -- $campo<br>";
[334]107 if (count($rigacandi)!=9) {unset($valori);continue;}
[2]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;}
[257]115 $sql="insert into ".$prefix."_ele_candidati values($valori)";
116 $res_lista = $dbi->prepare("$sql");
117 $res_lista->execute();
[2]118 }
119 }
[36]120#foreach($_SESSION['liste'] as $key=>$val) echo "$key -- $val<br>";
[2]121}
122
123
124
125
126
[257]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();
130list($id_cons,$descrizione) = $res->fetch(PDO::FETCH_NUM);
[2]131 if (!isset($_FILES['datafile']['tmp_name']) or !is_uploaded_file($_FILES['datafile']['tmp_name']))
132 {
133 ele();
[80]134if (isset($_GET['help'])) $help=intval($_GET['help']);
135 global $help,$language;
136 if (isset($help)) include("language/$language/ele_importa.html");
[2]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////////////////////////////
[80]144}else{
[36]145$idcns=$id_cons;
[257]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();
[36]173$datafile=$_FILES['datafile']['tmp_name'];
[2]174$arrFile = file($datafile);
175$handle = fopen($datafile, "r");
176$test=array();
177$errore=0;
[80]178$fine=0;
179$numgruppo=0;
[77]180$numlista=0;
[2]181// Set counters
182 $currentLine = 0;
183 $cntFile = count($arrFile);
[36]184$tabs=array($prefix."_ele_gruppo",$prefix."_ele_lista",$prefix."_ele_candidati",$prefix."_ele_circoscrizione");
[2]185$x=0;$k=0;
[80]186$scarto=0;
187$primog=0;
[36]188$primol=0;
[2]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];
199if($k==0) {while (substr($arrFile[$currentLine],1,-2)!=$conf and $currentLine <= $cntFile) $currentLine++; $k++;}
200 $currentLine++;
[36]201 while($currentLine <= $cntFile and $fine==0){
[35]202# $appo=substr($arrFile[$currentLine],1,-2);
[80]203 if(isset($arrFile[$currentLine]))
204 $appo=substr($arrFile[$currentLine],1,-2);
205 else $appo='';
[2]206 if (isset($tabs[($x+1)]) and $appo==$tabs[($x+1)]){ $x++;$conf=$tabs[$x];$currentLine++; continue;}
[35]207 $test=explode(':',$appo); if(!is_array($test)) {die("errore di import<br>");}
[36]208 foreach($test as $key=>$val)
[77]209 if ($conf==$prefix."_ele_gruppo"){
210 $ar_gruppo[$z][$key]=addslashes(base64_decode($val));}
[80]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);
[36]218 }
[2]219 $ar_lista[$z][$key]=addslashes(base64_decode($val));}
[36]220 elseif ($conf==$prefix."_ele_candidati"){
[80]221 if($primog==0){
222 $gruppofil= array_filter($ar_gruppo);
223 $numgruppo=count($gruppofil);
224 insgruppo();
225 $primog=1;
226 unset($ar_gruppo);
[77]227 }
[80]228 elseif($primol==0){
[36]229 $listafil= array_filter($ar_lista);
230 $numlista=count($listafil);
[80]231 inslista();
232 $primol=1;
233 unset($ar_lista);
[77]234 }
[80]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){
[77]246 $listafil= array_filter($ar_lista);
247 $numlista=count($listafil);
[80]248 inslista();
249 $primol=1;
250 unset($ar_lista);
251 }else{
252 inscandi();
[77]253 unset($ar_candi);
[80]254 $fine=1;
255 break;
256 }
[36]257 }
258 $currentLine++;
[2]259 $z++;
260 }
261fclose($handle);
[36]262
263
264
[2]265if ($numgruppo){
[80]266# insgruppo();
[2]267 Header("Location: admin.php?op=gruppo&id_cons_gen=$id_cons_gen");
268 }
269elseif ($numlista) {
270 inslista(0,0);
271 Header("Location: admin.php?op=lista&id_cons_gen=$id_cons_gen");
272 }
273else Header("Location: admin.php?op=lista&id_cons_gen=$id_cons_gen");
274
275}
276
277echo"</td></tr></table>";
278include("footer.php");
279
[336]280
[2]281
282?>
Note: See TracBrowser for help on using the repository browser.