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!");
|
---|
17 |
|
---|
18 | $param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ? $_GET : $_POST;
|
---|
19 | if (isset($param['datafile'])) get_magic_quotes_gpc() ? $datafile=$param['datafile']:$datafile=addslashes($param['datafile']); else $datafile='';
|
---|
20 | include("modules/Elezioni/ele.php");
|
---|
21 | ele();
|
---|
22 | if (isset($_FILES['datafile']['tmp_name'])) $updfile=$_FILES['datafile']['tmp_name']; else $updfile='';
|
---|
23 | if (!is_uploaded_file($updfile))
|
---|
24 | # if (!is_uploaded_file($_FILES['datafile']['tmp_name']))
|
---|
25 | # if (file_exists($datafile))
|
---|
26 | {
|
---|
27 | echo "<form name=\"restore\" enctype=\"multipart/form-data\" method=\"post\" action=\"admin.php\" >"
|
---|
28 | ."<input type=\"hidden\" name=\"op\" value=\"restore\">";
|
---|
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_FILE."</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_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");
|
---|
46 | $x=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 | if ($appo==$conf){
|
---|
54 | $currentLine++;
|
---|
55 | while($currentLine <= $cntFile ){
|
---|
56 | if(isset($arrFile[$currentLine]))
|
---|
57 | $appo=substr($arrFile[$currentLine],1,-2);
|
---|
58 | else $appo='';
|
---|
59 | if(isset($tabs[($x+1)]))
|
---|
60 | if ($appo==$tabs[($x+1)]){ $x++; break;}
|
---|
61 | elseif($appo=='') { $x++; break;}
|
---|
62 | $conta[$x]++;
|
---|
63 | $currentLine++;
|
---|
64 | }
|
---|
65 | }else {$scarto++;$currentLine++;}
|
---|
66 | }
|
---|
67 | if ($scarto==0){
|
---|
68 | $currentLine = 0;
|
---|
69 | $x=0;
|
---|
70 | $y=0;
|
---|
71 | while( $currentLine <= $cntFile ){
|
---|
72 | if(isset($arrFile[$currentLine]))
|
---|
73 | $tab=substr($arrFile[$currentLine],1,-2);
|
---|
74 | else $tab='';
|
---|
75 | if(isset($tabs[$x]))
|
---|
76 | $conf=$tabs[$x];
|
---|
77 | else $conf='';
|
---|
78 | if ($tab==$conf){
|
---|
79 | $currentLine++;
|
---|
80 | while($currentLine <= $cntFile ){
|
---|
81 | # $appo=substr($arrFile[$currentLine],1,-2);
|
---|
82 | # if ($appo==$tabs[($x+1)]){ $x++; break;}
|
---|
83 | if(isset($arrFile[$currentLine]))
|
---|
84 | $appo=substr($arrFile[$currentLine],1,-2);
|
---|
85 | else $appo='';
|
---|
86 | if(isset($tabs[($x+1)]))
|
---|
87 | if ($appo==$tabs[($x+1)]){ $x++; break;}
|
---|
88 | elseif($appo=='') { $x++; break;}
|
---|
89 | if(isset($arrFile[$currentLine]))
|
---|
90 | $test=explode(':',$arrFile[$currentLine]); if(!is_array($test)) {die("errore di import<br>");}
|
---|
91 | $valori='';
|
---|
92 | foreach($test as $key=>$val)
|
---|
93 | if($key==0){
|
---|
94 | $valori.= "'".base64_decode($val)."'";
|
---|
95 | if ($y==0) {$idcns=$valori;$y++;
|
---|
96 | foreach($tabs as $tbs){
|
---|
97 | $sql="delete from $tbs where id_cons=$idcns";
|
---|
98 | $res_del = $dbi->prepare("$sql");
|
---|
99 | $res_del->execute();
|
---|
100 | }
|
---|
101 | }
|
---|
102 | if(!$res_del->rowCount()) die ("delete $tbs where id_cons=$idcns--- errore di cancellazione");
|
---|
103 | }else $valori.= ",'".addslashes(base64_decode($val))."'";
|
---|
104 | $sql="insert into $tab values($valori)";
|
---|
105 | $res_comune = $dbi->prepare("$sql");
|
---|
106 | $res_comune->execute();
|
---|
107 | $currentLine++;
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | }
|
---|
112 | } else $errore=1;
|
---|
113 | fclose($handle);
|
---|
114 | }
|
---|
115 | if (isset($errore))
|
---|
116 | if ($errore) die( _MEX_RESTORE_FAILED);
|
---|
117 | else echo _MEX_RESTORE_OK;
|
---|
118 | echo"</td></tr></table>";
|
---|
119 | include("footer.php");
|
---|
120 |
|
---|
121 | ?>
|
---|