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 | // Write contents, inserting $item as first item
|
---|
44 | $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");
|
---|
45 | $x=0;
|
---|
46 | $scarto=0;
|
---|
47 | $conta=array();
|
---|
48 | while( $currentLine <= $cntFile ){
|
---|
49 | $appo=substr($arrFile[$currentLine],1,-2);
|
---|
50 | $conta[$x]=0;
|
---|
51 | $conf=$tabs[$x];
|
---|
52 | if ($appo==$conf){
|
---|
53 | $currentLine++;
|
---|
54 | while($currentLine <= $cntFile ){
|
---|
55 | if(isset($arrFile[$currentLine]))
|
---|
56 | $appo=substr($arrFile[$currentLine],1,-2);
|
---|
57 | else $appo='';
|
---|
58 | if(isset($tabs[($x+1)]))
|
---|
59 | if ($appo==$tabs[($x+1)]){ $x++; break;}
|
---|
60 | elseif($appo=='') { $x++; break;}
|
---|
61 | $conta[$x]++;
|
---|
62 | $currentLine++;
|
---|
63 | }
|
---|
64 | }else {$scarto++;$currentLine++;}
|
---|
65 | }
|
---|
66 | if ($scarto==0){
|
---|
67 | $currentLine = 0;
|
---|
68 | $x=0;
|
---|
69 | $y=0;
|
---|
70 | while( $currentLine <= $cntFile ){
|
---|
71 | if(isset($arrFile[$currentLine]))
|
---|
72 | $tab=substr($arrFile[$currentLine],1,-2);
|
---|
73 | else $tab='';
|
---|
74 | if(isset($tabs[$x]))
|
---|
75 | $conf=$tabs[$x];
|
---|
76 | else $conf='';
|
---|
77 | if ($tab==$conf){
|
---|
78 | $currentLine++;
|
---|
79 | while($currentLine <= $cntFile ){
|
---|
80 | # $appo=substr($arrFile[$currentLine],1,-2);
|
---|
81 | # if ($appo==$tabs[($x+1)]){ $x++; break;}
|
---|
82 | if(isset($arrFile[$currentLine]))
|
---|
83 | $appo=substr($arrFile[$currentLine],1,-2);
|
---|
84 | else $appo='';
|
---|
85 | if(isset($tabs[($x+1)]))
|
---|
86 | if ($appo==$tabs[($x+1)]){ $x++; break;}
|
---|
87 | elseif($appo=='') { $x++; break;}
|
---|
88 | if(isset($arrFile[$currentLine]))
|
---|
89 | $test=explode(':',$arrFile[$currentLine]); if(!is_array($test)) {die("errore di import<br>");}
|
---|
90 | $valori='';
|
---|
91 | foreach($test as $key=>$val)
|
---|
92 | if($key==0){
|
---|
93 | $valori.= "'".base64_decode($val)."'";
|
---|
94 | if ($y==0) {$idcns=$valori;$y++;
|
---|
95 | foreach($tabs as $tbs){
|
---|
96 | $sql="delete from $tbs where id_cons=$idcns";
|
---|
97 | $res_del = $dbi->prepare("$sql");
|
---|
98 | $res_del->execute();
|
---|
99 | }
|
---|
100 | }
|
---|
101 | if(!$res_del->rowCount()) die ("delete $tbs where id_cons=$idcns--- errore di cancellazione");
|
---|
102 | }else $valori.= ",'".addslashes(base64_decode($val))."'";
|
---|
103 | $sql="insert into $tab values($valori)";
|
---|
104 | $res_comune = $dbi->prepare("$sql");
|
---|
105 | $res_comune->execute();
|
---|
106 | $currentLine++;
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | }
|
---|
111 | } else $errore=1;
|
---|
112 | fclose($handle);
|
---|
113 | }
|
---|
114 | if (isset($errore))
|
---|
115 | if ($errore) die( _MEX_RESTORE_FAILED);
|
---|
116 | else echo _MEX_RESTORE_OK;
|
---|
117 | echo"</td></tr></table>";
|
---|
118 | include("footer.php");
|
---|
119 |
|
---|
120 | ?>
|
---|