[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!=256) die("Non hai i permessi per effettuare questa operazione!");
|
---|
[424] | 17 | global $LINK,$fileback;
|
---|
[2] | 18 | $param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ? $_GET : $_POST;
|
---|
[344] | 19 | if (isset($param['datafile'])) $datafile=addslashes($param['datafile']); else $datafile='';
|
---|
[362] | 20 | $id_cons_gen=intval($param['id_cons_gen']);
|
---|
[2] | 21 | include("modules/Elezioni/ele.php");
|
---|
| 22 | ele();
|
---|
[31] | 23 | if (isset($_FILES['datafile']['tmp_name'])) $updfile=$_FILES['datafile']['tmp_name']; else $updfile='';
|
---|
[424] | 24 | if (!is_uploaded_file($updfile) and $LINK=='')
|
---|
[31] | 25 | # if (!is_uploaded_file($_FILES['datafile']['tmp_name']))
|
---|
[2] | 26 | # if (file_exists($datafile))
|
---|
| 27 | {
|
---|
| 28 | echo "<form name=\"restore\" enctype=\"multipart/form-data\" method=\"post\" action=\"admin.php\" >"
|
---|
| 29 | ."<input type=\"hidden\" name=\"op\" value=\"restore\">";
|
---|
| 30 | echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">";
|
---|
| 31 | echo "<input type=\"hidden\" name=\"id_comune\" value=\"$id_comune\">";
|
---|
| 32 | echo "<table cellspacing=\"0\" cellpadding=\"2\" border=\"1\"><tr class=\"bggray\"><td colspan=\"2\" align=\"center\">"._SEL_DATA_FILE."</td></tr><tr><td><input name=\"datafile\" type=\"file\"></td>";
|
---|
| 33 | echo "<td align=\"center\"><input type=\"submit\" name=\"add\" value=\""._OK."\"></td></tr></table></form>";
|
---|
| 34 | ////////////////////////////
|
---|
[424] | 35 | }else{
|
---|
| 36 | if($LINK=='')
|
---|
| 37 | $datafile=$_FILES['datafile']['tmp_name'];
|
---|
| 38 | else
|
---|
| 39 | $datafile=$fileback;
|
---|
[2] | 40 | $arrFile = file($datafile);
|
---|
| 41 | $handle = fopen($datafile, "r");
|
---|
| 42 | $test=array();
|
---|
| 43 | $errore=0;
|
---|
| 44 |
|
---|
| 45 | // Set counters
|
---|
| 46 | $currentLine = 0;
|
---|
| 47 | $cntFile = count($arrFile);
|
---|
| 48 | // Write contents, inserting $item as first item
|
---|
| 49 | $tabs=array($prefix."_ele_cons_comune",$prefix."_ele_gruppo",$prefix."_ele_lista",$prefix."_ele_candidati",$prefix."_ele_circoscrizione",$prefix."_ele_sede",$prefix."_ele_sezioni",$prefix."_ele_link",$prefix."_ele_come",$prefix."_ele_numeri",$prefix."_ele_servizi",$prefix."_ele_voti_candidati",$prefix."_ele_voti_gruppo",$prefix."_ele_voti_lista",$prefix."_ele_voti_parziale",$prefix."_ele_voti_ref");
|
---|
| 50 | $x=0;
|
---|
| 51 | $scarto=0;
|
---|
| 52 | $conta=array();
|
---|
[362] | 53 | while( $currentLine <= $cntFile ){
|
---|
[2] | 54 | $appo=substr($arrFile[$currentLine],1,-2);
|
---|
| 55 | $conta[$x]=0;
|
---|
| 56 | $conf=$tabs[$x];
|
---|
| 57 | if ($appo==$conf){
|
---|
| 58 | $currentLine++;
|
---|
| 59 | while($currentLine <= $cntFile ){
|
---|
[31] | 60 | if(isset($arrFile[$currentLine]))
|
---|
| 61 | $appo=substr($arrFile[$currentLine],1,-2);
|
---|
| 62 | else $appo='';
|
---|
| 63 | if(isset($tabs[($x+1)]))
|
---|
| 64 | if ($appo==$tabs[($x+1)]){ $x++; break;}
|
---|
| 65 | elseif($appo=='') { $x++; break;}
|
---|
[2] | 66 | $conta[$x]++;
|
---|
| 67 | $currentLine++;
|
---|
| 68 | }
|
---|
| 69 | }else {$scarto++;$currentLine++;}
|
---|
[362] | 70 | }
|
---|
[2] | 71 | if ($scarto==0){
|
---|
| 72 | $currentLine = 0;
|
---|
| 73 | $x=0;
|
---|
| 74 | $y=0;
|
---|
| 75 | while( $currentLine <= $cntFile ){
|
---|
[31] | 76 | if(isset($arrFile[$currentLine]))
|
---|
| 77 | $tab=substr($arrFile[$currentLine],1,-2);
|
---|
| 78 | else $tab='';
|
---|
| 79 | if(isset($tabs[$x]))
|
---|
| 80 | $conf=$tabs[$x];
|
---|
| 81 | else $conf='';
|
---|
[2] | 82 | if ($tab==$conf){
|
---|
| 83 | $currentLine++;
|
---|
| 84 | while($currentLine <= $cntFile ){
|
---|
[31] | 85 | # $appo=substr($arrFile[$currentLine],1,-2);
|
---|
| 86 | # if ($appo==$tabs[($x+1)]){ $x++; break;}
|
---|
| 87 | if(isset($arrFile[$currentLine]))
|
---|
| 88 | $appo=substr($arrFile[$currentLine],1,-2);
|
---|
| 89 | else $appo='';
|
---|
[362] | 90 | if(isset($tabs[($x+1)])){
|
---|
| 91 | if ($appo==$tabs[($x+1)]){ $x++; break;}}
|
---|
| 92 | elseif($appo=='') { $x++; break;}
|
---|
| 93 |
|
---|
[31] | 94 | if(isset($arrFile[$currentLine]))
|
---|
[2] | 95 | $test=explode(':',$arrFile[$currentLine]); if(!is_array($test)) {die("errore di import<br>");}
|
---|
| 96 | $valori='';
|
---|
| 97 | foreach($test as $key=>$val)
|
---|
| 98 | if($key==0){
|
---|
| 99 | $valori.= "'".base64_decode($val)."'";
|
---|
| 100 | if ($y==0) {$idcns=$valori;$y++;
|
---|
| 101 | foreach($tabs as $tbs){
|
---|
[257] | 102 | $sql="delete from $tbs where id_cons=$idcns";
|
---|
| 103 | $res_del = $dbi->prepare("$sql");
|
---|
| 104 | $res_del->execute();
|
---|
[2] | 105 | }
|
---|
| 106 | }
|
---|
[362] | 107 | # if(!$res_del->rowCount()) die ("delete $tbs where id_cons=$idcns--- errore di cancellazione");
|
---|
[2] | 108 | }else $valori.= ",'".addslashes(base64_decode($val))."'";
|
---|
[383] | 109 | # else $valori.= ",''"; if($key!=9 and $tab!='soraldo_ele_gruppo')
|
---|
| 110 | # if($tab=='soraldo_ele_cons_comune') $valori.=",'0'";
|
---|
[362] | 111 | $sql="insert into $tab values($valori)";
|
---|
| 112 | try {
|
---|
[257] | 113 | $res_comune = $dbi->prepare("$sql");
|
---|
| 114 | $res_comune->execute();
|
---|
[362] | 115 | }
|
---|
| 116 | catch(PDOException $e)
|
---|
| 117 | {
|
---|
| 118 | echo $sql . "<br>" . $e->getMessage();
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | #echo "TAB: $tbs -- $sql<br>";
|
---|
[2] | 122 | $currentLine++;
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | }
|
---|
| 127 | } else $errore=1;
|
---|
| 128 | fclose($handle);
|
---|
[424] | 129 | echo "<center><h2>Aggiornamento del ".date('d/m/Y H:i')." terminato</h2></center>";
|
---|
[2] | 130 | }
|
---|
[424] | 131 | if (isset($errore) and $errore) echo _MEX_RESTORE_FAILED;
|
---|
| 132 |
|
---|
[2] | 133 | echo"</td></tr></table>";
|
---|
| 134 | include("footer.php");
|
---|
| 135 |
|
---|
| 136 | ?>
|
---|