source: trunk/admin/modules/Elezioni/restore.php@ 2

Last change on this file since 2 was 2, checked in by root, 15 years ago

importo il progetto

File size: 4.2 KB
Line 
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
12if (!defined('ADMIN_FILE')) {
13 die ("You can't access this file directly...");
14}
15$perms=ChiSei(0);
16if ($perms!=256) die("Non hai i permessi per effettuare questa operazione!");
17
18$param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ? $_GET : $_POST;
19if (isset($param['datafile'])) get_magic_quotes_gpc() ? $datafile=$param['datafile']:$datafile=addslashes($param['datafile']); else $datafile='';
20include("modules/Elezioni/ele.php");
21ele();
22 if (!is_uploaded_file($_FILES['datafile']['tmp_name']))
23# if (file_exists($datafile))
24 {
25 echo "<form name=\"restore\" enctype=\"multipart/form-data\" method=\"post\" action=\"admin.php\" >"
26 ."<input type=\"hidden\" name=\"op\" value=\"restore\">";
27 echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">";
28 echo "<input type=\"hidden\" name=\"id_comune\" value=\"$id_comune\">";
29 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>";
30 echo "<td align=\"center\"><input type=\"submit\" name=\"add\" value=\""._OK."\"></td></tr></table></form>";
31////////////////////////////
32}else{$datafile=$_FILES['datafile']['tmp_name'];
33$arrFile = file($datafile);
34$handle = fopen($datafile, "r");
35$test=array();
36$errore=0;
37
38// Set counters
39 $currentLine = 0;
40 $cntFile = count($arrFile);
41// $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();
42// Write contents, inserting $item as first item
43$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");
44$x=0;
45$scarto=0;
46$conta=array();
47 while( $currentLine <= $cntFile ){
48 $appo=substr($arrFile[$currentLine],1,-2);
49 $conta[$x]=0;
50 $conf=$tabs[$x];
51 if ($appo==$conf){
52 $currentLine++;
53 while($currentLine <= $cntFile ){
54 $appo=substr($arrFile[$currentLine],1,-2);
55 if ($appo==$tabs[($x+1)]){ $x++; break;}
56 $conta[$x]++;
57 $currentLine++;
58 }
59 }else {$scarto++;$currentLine++;}
60 }
61if ($scarto==0){
62 $currentLine = 0;
63 $x=0;
64 $y=0;
65 while( $currentLine <= $cntFile ){
66 $tab=substr($arrFile[$currentLine],1,-2);
67 $conf=$tabs[$x];
68 if ($tab==$conf){
69 $currentLine++;
70 while($currentLine <= $cntFile ){
71 $appo=substr($arrFile[$currentLine],1,-2);
72 if ($appo==$tabs[($x+1)]){ $x++; break;}
73 $test=explode(':',$arrFile[$currentLine]); if(!is_array($test)) {die("errore di import<br>");}
74 $valori='';
75 foreach($test as $key=>$val)
76 if($key==0){
77 $valori.= "'".base64_decode($val)."'";
78 if ($y==0) {$idcns=$valori;$y++;
79 foreach($tabs as $tbs){
80 $res_del = mysql_query("delete from $tbs where id_cons=$idcns" ,$dbi);
81 }
82 }
83 if(!$res_del) die ("delete $tbs where id_cons=$idcns--- errore di cancellazione").mysql_error();
84 }else $valori.= ",'".addslashes(base64_decode($val))."'";
85 $res_comune = mysql_query("insert into $tab values($valori)" ,$dbi);
86 $currentLine++;
87 }
88 }
89
90 }
91} else $errore=1;
92fclose($handle);
93}
94if (isset($errore))
95 if ($errore) die( _MEX_RESTORE_FAILED);
96 else echo _MEX_RESTORE_OK;
97echo"</td></tr></table>";
98include("footer.php");
99
100?>
Note: See TracBrowser for help on using the repository browser.