Changeset 362 for trunk/admin/modules/Elezioni/importa.php
- Timestamp:
- Mar 27, 2022, 7:51:34 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/modules/Elezioni/importa.php
r360 r362 21 21 include("modules/Elezioni/ele.php"); 22 22 23 24 23 function insgruppo() 25 24 { 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 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 67 function inslista() #$oldidg,$newidg25 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 66 function inslista() 68 67 { 69 68 global $prefix, $dbi; … … 78 77 foreach($rigalista as $key=>$campo){ 79 78 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 79 elseif ($key==1) {$valori.= "null,";$oldidl=$campo;} 89 80 elseif ($key==2) {$valori.="'$campo',";$numlista= $campo;} … … 91 82 elseif ($key==4) $valori.= "0,"; 92 83 elseif ($key==9 ) $valori.= "'$campo'"; 93 # else $valori.= "'$campo',"; # htmlentities(stripslashes(utf8_decode($_POST['parola'])));94 84 else $valori.="'".utf8_encode($campo)."',"; 95 # else $valori.= "'".htmlentities($campo, ENT_QUOTES, "UTF-8")."',"; htmlspecialchars($str, ENT_QUOTES)96 85 } 97 86 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; 118 echo "id_lista:$oldidl:$newidl<br>"; 119 } 120 # inscandi($oldidl,$newidl); 121 } 122 } 123 } 124 125 function inscandi()#$oldidl,$newidl 126 { 127 global $prefix, $dbi; 128 global $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>"; 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 110 function 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 } 159 140 } 160 141 … … 167 148 $res->execute(); 168 149 list($id_cons,$descrizione) = $res->fetch(PDO::FETCH_NUM); 169 170 150 if (!isset($_FILES['datafile']['tmp_name']) or !is_uploaded_file($_FILES['datafile']['tmp_name'])) 151 { 171 152 ele(); 172 if (isset($_GET['help'])) $help=intval($_GET['help']);153 if (isset($_GET['help'])) $help=intval($_GET['help']); 173 154 global $help,$language; 174 155 if (isset($help)) include("language/$language/ele_importa.html"); … … 179 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>"; 180 161 echo "<td align=\"center\"><input type=\"submit\" name=\"add\" value=\""._OK."\"></td></tr></table></form>"; 181 ////////////////////////////182 162 }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;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; 219 199 // Set counters 220 200 $currentLine = 0; 221 201 $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 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; 229 209 $x=0;$k=0; 230 210 $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]; 237 if($k==0) {while (substr($arrFile[$currentLine],1,-2)!=$conf and $currentLine <= $cntFile) $currentLine++; $k++;} 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 } 238 278 $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 } 299 fclose($handle); 300 301 302 303 if ($numgruppo){ 304 # insgruppo(); 305 Header("Location: admin.php?op=gruppo&id_cons_gen=$id_cons_gen"); 306 } 307 elseif ($numlista) { 308 # inslista(); 309 Header("Location: admin.php?op=lista&id_cons_gen=$id_cons_gen"); 310 } 311 else Header("Location: admin.php?op=lista&id_cons_gen=$id_cons_gen"); 312 313 } 314 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 } 315 291 echo"</td></tr></table>"; 316 292 include("footer.php"); 317 293 318 319 320 294 ?>
Note:
See TracChangeset
for help on using the changeset viewer.