[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 |
|
---|
| 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 | ele();
|
---|
| 23 | $res = mysql_query("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' " , $dbi);
|
---|
| 24 | list($id_cons,$descrizione) = mysql_fetch_row($res);
|
---|
| 25 | if (!is_uploaded_file($_FILES['datafile']['tmp_name']))
|
---|
| 26 | {
|
---|
| 27 | echo "<form name=\"importa\" enctype=\"multipart/form-data\" method=\"post\" action=\"admin.php\" >"
|
---|
| 28 | ."<input type=\"hidden\" name=\"op\" value=\"importa\">";
|
---|
| 29 | echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">";
|
---|
| 30 | echo "<input type=\"hidden\" name=\"id_comune\" value=\"$id_comune\">";
|
---|
| 31 | 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>";
|
---|
| 32 | echo "<td align=\"center\"><input type=\"submit\" name=\"add\" value=\""._OK."\"></td></tr></table></form>";
|
---|
| 33 | ////////////////////////////
|
---|
| 34 | }else{$datafile=$_FILES['datafile']['tmp_name'];
|
---|
| 35 | $arrFile = file($datafile);
|
---|
| 36 | $handle = fopen($datafile, "r");
|
---|
| 37 | $test=array();
|
---|
| 38 | $errore=0;
|
---|
| 39 |
|
---|
| 40 | // Set counters
|
---|
| 41 | $currentLine = 0;
|
---|
| 42 | $cntFile = count($arrFile);
|
---|
| 43 | // $res_comune = mysql_query("delete from ".$prefix."_ele_lista where id_cons='10'" ,$dbi); if(!$res_comune) echo "delete ".$prefix."_ele_lista where id_cons='10'--- errore di cancellazione".mysql_error();
|
---|
| 44 | // Write contents, inserting $item as first item
|
---|
| 45 | $tabs=array($prefix."_ele_gruppo",$prefix."_ele_lista",$prefix."_ele_candidati");
|
---|
| 46 | $x=0;$k=0;
|
---|
| 47 | $scarto=0;
|
---|
| 48 | $conta=array();
|
---|
| 49 | /* while( $currentLine <= $cntFile ){
|
---|
| 50 | $appo=substr($arrFile[$currentLine],1,-2);
|
---|
| 51 | $conta[$x]=0;
|
---|
| 52 | $conf=$tabs[$x];
|
---|
| 53 | # die(substr($arrFile[$currentLine],1,-2)."==$conf and $currentLine <= $cntFile");
|
---|
| 54 | if($k==0) {while (substr($arrFile[$currentLine],1,-2)!=$conf and $currentLine <= $cntFile) $currentLine++; $k++;}
|
---|
| 55 | if ($appo==$conf){
|
---|
| 56 | $currentLine++;
|
---|
| 57 | while($currentLine <= $cntFile ){
|
---|
| 58 | $appo=substr($arrFile[$currentLine],1,-2);
|
---|
| 59 | if ($appo==$tabs[($x+1)]){ $x++; break;}
|
---|
| 60 | $conta[$x]++;
|
---|
| 61 | $currentLine++;
|
---|
| 62 | }
|
---|
| 63 | }else {$scarto++;$currentLine++;}
|
---|
| 64 | }
|
---|
| 65 | #if ($scarto==0){ */
|
---|
| 66 | $currentLine = 0;
|
---|
| 67 | $x=0;$k=0;
|
---|
| 68 | $y=0;
|
---|
| 69 | $ar_gruppo=array(array());
|
---|
| 70 | $ar_lista=array(array());
|
---|
| 71 | $ar_candi=array(array());
|
---|
| 72 | # while( $currentLine <= $cntFile ){
|
---|
| 73 | $z=0;
|
---|
| 74 | $tab=substr($arrFile[$currentLine],1,-2);
|
---|
| 75 | $conf=$tabs[$x];
|
---|
| 76 | if($k==0) {while (substr($arrFile[$currentLine],1,-2)!=$conf and $currentLine <= $cntFile) $currentLine++; $k++;}
|
---|
| 77 | # die("qui arriva $currentLine <= $cntFile $conf=".$tabs[$x]);
|
---|
| 78 | # if ($tab==$conf){
|
---|
| 79 | $currentLine++;
|
---|
| 80 | while($currentLine <= $cntFile ){
|
---|
| 81 | $appo=substr($arrFile[$currentLine],1,-2);
|
---|
| 82 | # if ($appo==$prefix."_ele_circoscrizione"){ break;}
|
---|
| 83 | if ($appo==$tabs[($x+1)]){ $x++;$conf=$tabs[$x];$currentLine++; continue;}
|
---|
| 84 | $test=explode(':',$arrFile[$currentLine]); if(!is_array($test)) {die("errore di import<br>");}
|
---|
| 85 | # $valori='';
|
---|
| 86 | foreach($test as $key=>$val) #echo "$key : $campo ($conf==$prefix._ele_gruppo)"; die();
|
---|
| 87 | if ($conf==$prefix."_ele_gruppo")
|
---|
| 88 | $ar_gruppo[$z][$key]=addslashes(base64_decode($val));
|
---|
| 89 | elseif ($conf==$prefix."_ele_lista"){
|
---|
| 90 | $ar_lista[$z][$key]=addslashes(base64_decode($val));}
|
---|
| 91 | elseif ($conf==$prefix."_ele_candidati")
|
---|
| 92 | $ar_candi[$z][$key]=addslashes(base64_decode($val));
|
---|
| 93 | elseif ($appo==$prefix."_ele_circoscrizione")
|
---|
| 94 | {$fine=0;break;}
|
---|
| 95 | $currentLine++;
|
---|
| 96 | $z++;
|
---|
| 97 | }
|
---|
| 98 | # }
|
---|
| 99 |
|
---|
| 100 | # }
|
---|
| 101 | #} else $errore=1;
|
---|
| 102 | fclose($handle);
|
---|
| 103 | $idcns=$id_cons; #$ar_gruppo[0][0];
|
---|
| 104 | $res_del = mysql_query("delete from ".$prefix."_ele_voti_candidati where id_cons=$idcns" ,$dbi);
|
---|
| 105 | $res_del = mysql_query("delete from ".$prefix."_ele_voti_lista where id_cons=$idcns" ,$dbi);
|
---|
| 106 | $res_del = mysql_query("delete from ".$prefix."_ele_voti_gruppo where id_cons=$idcns" ,$dbi);
|
---|
| 107 | $res_del = mysql_query("delete from ".$prefix."_ele_candidati where id_cons=$idcns" ,$dbi);
|
---|
| 108 | $res_del = mysql_query("delete from ".$prefix."_ele_lista where id_cons=$idcns" ,$dbi);
|
---|
| 109 | $res_del = mysql_query("delete from ".$prefix."_ele_gruppo where id_cons=$idcns" ,$dbi);
|
---|
| 110 | #unset($valori);
|
---|
| 111 | $sigruppo=count($ar_gruppo);die("sigru:$sigruppo");
|
---|
| 112 | foreach ($ar_gruppo as $rigagruppo){
|
---|
| 113 | $newidg=0;
|
---|
| 114 | $oldidg=0;
|
---|
| 115 | foreach($rigagruppo as $key=>$campo){
|
---|
| 116 | if ($key==0) $valori="'$idcns',";
|
---|
| 117 | elseif ($key==1) {$valori.= "null"; $oldidg=$campo;}
|
---|
| 118 | elseif ($key==6) $valori.= ",0";
|
---|
| 119 | else $valori.= ",'$campo'";
|
---|
| 120 | if ($key==2) $numgruppo= $campo;
|
---|
| 121 | }
|
---|
| 122 | if(isset($valori)){
|
---|
| 123 | $res_gruppo = mysql_query("insert into ".$prefix."_ele_gruppo values($valori)" ,$dbi)||die("(1104) Non e' stato possibile inserire i gruppi nel database! contattare l'amministratore".mysql_error());
|
---|
| 124 | $resnew = mysql_query("select id_gruppo from ".$prefix."_ele_gruppo where num_gruppo='$numgruppo' and id_cons='$idcns'" ,$dbi);
|
---|
| 125 | list ($newidg) = mysql_fetch_row($resnew);
|
---|
| 126 | unset($valori);
|
---|
| 127 | foreach ($ar_lista as $rigalista){
|
---|
| 128 | $oldidl=0;
|
---|
| 129 | foreach($rigalista as $key=>$campo){
|
---|
| 130 | if ($key==0) $valori="'$idcns',";
|
---|
| 131 | elseif ($key==1) {$valori.= "null";$oldidl=$campo;}
|
---|
| 132 | elseif ($key==3) {$valori.= ",'$newidg'"; if ($campo!=$oldidg) $okl=1;}
|
---|
| 133 | elseif ($key==4) $valori.= ",0";
|
---|
| 134 | else $valori.= ",'$campo'";
|
---|
| 135 | if ($key==2) $numlista= $campo;
|
---|
| 136 | }
|
---|
| 137 | if(isset($valori)){
|
---|
| 138 | if ($okl) {$okl=0;continue;}
|
---|
| 139 | $res_lista = mysql_query("insert into ".$prefix."_ele_lista values($valori)" ,$dbi)||die("(1104) Non e' stato possibile inserire le liste nel database! contattare l'amministratore".mysql_error());
|
---|
| 140 | $reslnew = mysql_query("select id_lista from ".$prefix."_ele_lista where num_lista='$numlista' and id_cons='$idcns'" ,$dbi);
|
---|
| 141 | list ($newidl) = mysql_fetch_row($reslnew);
|
---|
| 142 | unset($valori);
|
---|
| 143 | foreach ($ar_candi as $rigacandi){
|
---|
| 144 | foreach($rigacandi as $key=>$campo){if (count($rigacandi)!=8) {unset($valori);continue;}
|
---|
| 145 | if ($key==0) $valori= "null,";
|
---|
| 146 | elseif ($key==1) $valori.="'$idcns',";
|
---|
| 147 | elseif ($key==2) {$valori.= "'$newidl'"; if ($campo!=$oldidl) $okc=1;}
|
---|
| 148 | else $valori.= ",'$campo'";
|
---|
| 149 | }
|
---|
| 150 | if(isset($valori)){
|
---|
| 151 | if ($okc) {$okc=0;continue;}
|
---|
| 152 | $res_lista = mysql_query("insert into ".$prefix."_ele_candidati values($valori)" ,$dbi)||die("(1104) Non e' stato possibile inserire i candidati nel database! contattare l'amministratore".mysql_error());
|
---|
| 153 | }
|
---|
| 154 | }
|
---|
| 155 | }
|
---|
| 156 | }
|
---|
| 157 | }
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | /*
|
---|
| 161 | foreach ($ar_gruppo as $rigagruppo){
|
---|
| 162 | foreach($rigagruppo as $key=>$campo) {
|
---|
| 163 | if ($key==0) echo "$valori=\"'$idcns',";
|
---|
| 164 | elseif ($key==1) $valori.= "null";
|
---|
| 165 | else $valori.= ",'$campo'";
|
---|
| 166 | if ($key==2) $numgruppo= $campo;
|
---|
| 167 | #
|
---|
| 168 | }
|
---|
| 169 | die("$res_gruppo = mysql_query(\"insert into ".$prefix."_ele_gruppo values($valori)\" ,$dbi");
|
---|
| 170 | $resnew = mysql_query("select id_gruppo from ".$prefix."_ele_gruppo where num_gruppo='$numgruppo' and id_cons='$idcns'" ,$dbi);
|
---|
| 171 | list ($newidg) = mysql_fetch_row($resnew);
|
---|
| 172 | */
|
---|
| 173 | ########continuare da qui
|
---|
| 174 | #}
|
---|
| 175 |
|
---|
| 176 | Header("Location: admin.php?op=gruppo&id_cons_gen=$id_cons_gen");
|
---|
| 177 |
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | if (isset($errore))
|
---|
| 181 | if ($errore) die( _MEX_IMPORT_FAILED);
|
---|
| 182 | else echo _MEX_IMPORT_OK;
|
---|
| 183 | echo"</td></tr></table>";
|
---|
| 184 | include("footer.php");
|
---|
| 185 | # $valori.= ",'".addslashes(base64_decode($val))."'";
|
---|
| 186 | # }
|
---|
| 187 |
|
---|
| 188 | # $res_comune = mysql_query("insert into $tab values($valori)" ,$dbi);
|
---|
| 189 | /* if($key==0){
|
---|
| 190 | #
|
---|
| 191 | $valori.= "'".base64_decode($val)."'";
|
---|
| 192 | if ($y==0) {$idcns=$valori;$y++;
|
---|
| 193 | foreach($tabs as $tbs){
|
---|
| 194 | $res_del = mysql_query("delete from $tbs where id_cons=$idcns" ,$dbi);
|
---|
| 195 | }
|
---|
| 196 | $ar_da[$z][$key]=
|
---|
| 197 | }
|
---|
| 198 | if(!$res_del) die ("delete $tbs where id_cons=$idcns--- errore di cancellazione").mysql_error();
|
---|
| 199 | }else{
|
---|
| 200 | #se gruppo
|
---|
| 201 | */
|
---|
| 202 | ?>
|
---|