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

Last change on this file since 404 was 383, checked in by roby, 2 years ago
  • Admin:
  • aggiornamento del campo num_gruppo nella tabella ele_lista
  • modifica della funzione di aggiornamento
  • Client
  • Aggiunta la funzione di calcolo dell'assegnazione dei seggi secondo la legge regionale siciliana (da completare, non gestisce tutti i casi particolari)
File size: 5.0 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'])) $datafile=addslashes($param['datafile']); else $datafile='';
20$id_cons_gen=intval($param['id_cons_gen']);
21include("modules/Elezioni/ele.php");
22ele();
23if (isset($_FILES['datafile']['tmp_name'])) $updfile=$_FILES['datafile']['tmp_name']; else $updfile='';
24 if (!is_uploaded_file($updfile))
25# if (!is_uploaded_file($_FILES['datafile']['tmp_name']))
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////////////////////////////
35}else{$datafile=$_FILES['datafile']['tmp_name'];
36$arrFile = file($datafile);
37$handle = fopen($datafile, "r");
38$test=array();
39$errore=0;
40
41// Set counters
42 $currentLine = 0;
43 $cntFile = count($arrFile);
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();
49while( $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
90 if(isset($arrFile[$currentLine]))
91 $test=explode(':',$arrFile[$currentLine]); if(!is_array($test)) {die("errore di import<br>");}
92 $valori='';
93 foreach($test as $key=>$val)
94 if($key==0){
95 $valori.= "'".base64_decode($val)."'";
96 if ($y==0) {$idcns=$valori;$y++;
97 foreach($tabs as $tbs){
98 $sql="delete from $tbs where id_cons=$idcns";
99 $res_del = $dbi->prepare("$sql");
100 $res_del->execute();
101 }
102 }
103 # if(!$res_del->rowCount()) die ("delete $tbs where id_cons=$idcns--- errore di cancellazione");
104 }else $valori.= ",'".addslashes(base64_decode($val))."'";
105# else $valori.= ",''"; if($key!=9 and $tab!='soraldo_ele_gruppo')
106# if($tab=='soraldo_ele_cons_comune') $valori.=",'0'";
107 $sql="insert into $tab values($valori)";
108 try {
109 $res_comune = $dbi->prepare("$sql");
110 $res_comune->execute();
111 }
112 catch(PDOException $e)
113 {
114 echo $sql . "<br>" . $e->getMessage();
115 }
116
117#echo "TAB: $tbs -- $sql<br>";
118 $currentLine++;
119 }
120 }
121
122 }
123} else $errore=1;
124fclose($handle);
125die("finito");
126}
127if (isset($errore))
128 if ($errore) die( _MEX_RESTORE_FAILED);
129 else die( _MEX_RESTORE_OK );
130echo"</td></tr></table>";
131include("footer.php");
132
133?>
Note: See TracBrowser for help on using the repository browser.