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

Last change on this file since 45 was 31, checked in by roby, 15 years ago

Eliminati ulteriori messaggi notice di php

File size: 4.8 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();
22if (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 }
67if ($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 $res_del = mysql_query("delete from $tbs where id_cons=$idcns" ,$dbi);
98 }
99 }
100 if(!$res_del) die ("delete $tbs where id_cons=$idcns--- errore di cancellazione").mysql_error();
101 }else $valori.= ",'".addslashes(base64_decode($val))."'";
102 $res_comune = mysql_query("insert into $tab values($valori)" ,$dbi);
103 $currentLine++;
104 }
105 }
106
107 }
108} else $errore=1;
109fclose($handle);
110}
111if (isset($errore))
112 if ($errore) die( _MEX_RESTORE_FAILED);
113 else echo _MEX_RESTORE_OK;
114echo"</td></tr></table>";
115include("footer.php");
116
117?>
Note: See TracBrowser for help on using the repository browser.