[2] | 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<32) die("Non hai i permessi per effettuare questa operazione!");
|
---|
| 17 |
|
---|
| 18 | $param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ? $_GET : $_POST;
|
---|
| 19 | $id_cons_gen=intval($param['id_cons_gen']);
|
---|
| 20 | if (isset($param['datafile'])) get_magic_quotes_gpc() ? $datafile=$param['datafile']:$datafile=addslashes($param['datafile']); else $datafile='';
|
---|
| 21 | include("modules/Elezioni/ele.php");
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 | function insgruppo()
|
---|
| 25 | {
|
---|
| 26 | global $prefix, $dbi;
|
---|
| 27 | global $ar_gruppo,$ar_lista,$ar_candi,$idcns;
|
---|
| 28 |
|
---|
| 29 | foreach ($ar_gruppo as $rigagruppo){
|
---|
| 30 | $newidg=0;
|
---|
| 31 | $oldidg=0;
|
---|
| 32 | foreach($rigagruppo as $key=>$campo){
|
---|
| 33 | if ($key==0) $valori="'$idcns',";
|
---|
| 34 | elseif ($key==1) {$valori.= "null"; $oldidg=$campo;}
|
---|
| 35 | elseif ($key==6) $valori.= ",0";
|
---|
| 36 | else $valori.= ",'$campo'";
|
---|
| 37 | if ($key==2) $numgruppo= $campo;
|
---|
| 38 | }
|
---|
| 39 | if(isset($valori)){
|
---|
| 40 | $res_gruppo = mysql_query("insert into ".$prefix."_ele_gruppo values($valori)" ,$dbi)||die("(1104) Non e' stato possibile inserire i gruppi nel database! contattare l'amministratore".mysql_error());
|
---|
| 41 | $resnew = mysql_query("select id_gruppo from ".$prefix."_ele_gruppo where num_gruppo='$numgruppo' and id_cons='$idcns'" ,$dbi);
|
---|
[77] | 42 | $resnew = mysql_query("select id_gruppo from ".$prefix."_ele_gruppo where num_gruppo='$numgruppo' and id_cons='$idcns'");
|
---|
[2] | 43 | list ($newidg) = mysql_fetch_row($resnew);
|
---|
[80] | 44 | unset($valori);
|
---|
| 45 | if($oldidg)
|
---|
[36] | 46 | $_SESSION['gruppi']['idg_'.$oldidg]=$newidg;
|
---|
| 47 | # inslista($oldidg,$newidg);
|
---|
[2] | 48 | }
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[36] | 52 | function inslista()#$oldidg,$newidg
|
---|
[2] | 53 | {
|
---|
| 54 | global $prefix, $dbi;
|
---|
| 55 | global $ar_lista,$ar_candi,$idcns;
|
---|
| 56 |
|
---|
[80] | 57 | foreach ($ar_lista as $rigalista){
|
---|
[36] | 58 | if(!isset($rigalista[3])) continue;
|
---|
[80] | 59 | $oldidl=0;
|
---|
| 60 | $okl=0;
|
---|
| 61 | $oldidg=$rigalista[3];
|
---|
[36] | 62 | $newidg=$_SESSION['gruppi']['idg_'.$oldidg];
|
---|
[2] | 63 | foreach($rigalista as $key=>$campo){
|
---|
| 64 | if ($key==0) $valori="'$idcns',";
|
---|
| 65 | elseif ($key==1) {$valori.= "null";$oldidl=$campo;}
|
---|
| 66 | elseif ($key==3) {$valori.= ",'$newidg'"; if ($campo!=$oldidg) $okl=1;}
|
---|
| 67 | elseif ($key==4) $valori.= ",0";
|
---|
| 68 | else $valori.= ",'$campo'";
|
---|
| 69 | if ($key==2) $numlista= $campo;
|
---|
| 70 | }
|
---|
| 71 | if(isset($valori)){
|
---|
| 72 | if ($okl) {$okl=0;continue;}
|
---|
| 73 | $res_lista = mysql_query("insert into ".$prefix."_ele_lista values($valori)" ,$dbi)||die("(1104) Non e' stato possibile inserire le liste nel database! contattare l'amministratore".mysql_error());
|
---|
| 74 | $reslnew = mysql_query("select id_lista from ".$prefix."_ele_lista where num_lista='$numlista' and id_cons='$idcns'" ,$dbi);
|
---|
| 75 | list ($newidl) = mysql_fetch_row($reslnew);
|
---|
| 76 | unset($valori);
|
---|
[80] | 77 | if($oldidl)
|
---|
[36] | 78 | $_SESSION['liste']['idl_'.$oldidl]=$newidl;
|
---|
[80] | 79 |
|
---|
[36] | 80 | # inscandi($oldidl,$newidl);
|
---|
[2] | 81 | }
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[36] | 85 | function inscandi()#$oldidl,$newidl
|
---|
[2] | 86 | {
|
---|
| 87 | global $prefix, $dbi;
|
---|
| 88 | global $ar_candi,$idcns;
|
---|
| 89 |
|
---|
[80] | 90 | foreach ($ar_candi as $rigacandi){
|
---|
[36] | 91 | if(!isset($rigacandi[2])) continue;
|
---|
[35] | 92 | $okc=0;
|
---|
[80] | 93 | $oldidl=$rigacandi[2];
|
---|
[36] | 94 | $newidl=$_SESSION['liste']['idl_'.$oldidl];
|
---|
| 95 | foreach($rigacandi as $key=>$campo){#echo "$key -- $campo<br>";
|
---|
[2] | 96 | if (count($rigacandi)!=8) {unset($valori);continue;}
|
---|
| 97 | if ($key==0) $valori= "null,";
|
---|
| 98 | elseif ($key==1) $valori.="'$idcns',";
|
---|
| 99 | elseif ($key==2) {$valori.= "'$newidl'"; if ($campo!=$oldidl) $okc=1;}
|
---|
| 100 | else $valori.= ",'$campo'";
|
---|
| 101 | }
|
---|
| 102 | if(isset($valori)){
|
---|
| 103 | if ($okc) {$okc=0;continue;}
|
---|
| 104 | $res_lista = mysql_query("insert into ".$prefix."_ele_candidati values($valori)" ,$dbi)||die("(1104) Non e' stato possibile inserire i candidati nel database! contattare l'amministratore".mysql_error());
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
[36] | 107 | #foreach($_SESSION['liste'] as $key=>$val) echo "$key -- $val<br>";
|
---|
[2] | 108 | }
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 | $res = mysql_query("SELECT t1.id_cons, t2.descrizione FROM ".$prefix."_ele_cons_comune as t1 left join ".$prefix."_ele_consultazione as t2 on t1.id_cons_gen=t2.id_cons_gen where t1.id_comune='$id_comune' and t2.id_cons_gen='$id_cons_gen'" , $dbi);
|
---|
| 115 | list($id_cons,$descrizione) = mysql_fetch_row($res);
|
---|
| 116 | if (!isset($_FILES['datafile']['tmp_name']) or !is_uploaded_file($_FILES['datafile']['tmp_name']))
|
---|
| 117 | {
|
---|
| 118 | ele();
|
---|
[80] | 119 | if (isset($_GET['help'])) $help=intval($_GET['help']);
|
---|
| 120 | global $help,$language;
|
---|
| 121 | if (isset($help)) include("language/$language/ele_importa.html");
|
---|
[2] | 122 | echo "<form name=\"importa\" enctype=\"multipart/form-data\" method=\"post\" action=\"admin.php\" >"
|
---|
| 123 | ."<input type=\"hidden\" name=\"op\" value=\"importa\">";
|
---|
| 124 | echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">";
|
---|
| 125 | echo "<input type=\"hidden\" name=\"id_comune\" value=\"$id_comune\">";
|
---|
| 126 | echo "<table cellspacing=\"0\" cellpadding=\"2\" border=\"1\"><tr class=\"bggray\"><td colspan=\"2\" align=\"center\">"._SEL_DATA_FILE2."</td></tr><tr><td><input name=\"datafile\" type=\"file\"></td>";
|
---|
| 127 | echo "<td align=\"center\"><input type=\"submit\" name=\"add\" value=\""._OK."\"></td></tr></table></form>";
|
---|
| 128 | ////////////////////////////
|
---|
[80] | 129 | }else{
|
---|
[36] | 130 | $idcns=$id_cons;
|
---|
| 131 | $res_del = mysql_query("delete from ".$prefix."_ele_voti_ref where id_cons=$idcns" ,$dbi);
|
---|
| 132 | $res_del = mysql_query("delete from ".$prefix."_ele_voti_candidati where id_cons=$idcns" ,$dbi);
|
---|
| 133 | $res_del = mysql_query("delete from ".$prefix."_ele_voti_lista where id_cons=$idcns" ,$dbi);
|
---|
| 134 | $res_del = mysql_query("delete from ".$prefix."_ele_voti_gruppo where id_cons=$idcns" ,$dbi);
|
---|
| 135 | $res_del = mysql_query("update ".$prefix."_ele_sezioni set validi='0', contestati='0', validi_lista='0', nulli='0',bianchi='0',contestati_lista='0', voti_nulli_lista='0' where id_cons=$idcns" ,$dbi);
|
---|
| 136 | $res_del = mysql_query("delete from ".$prefix."_ele_voti_parziale where id_cons=$idcns" ,$dbi);
|
---|
| 137 | $res_del = mysql_query("delete from ".$prefix."_ele_candidati where id_cons=$idcns" ,$dbi);
|
---|
| 138 | $res_del = mysql_query("delete from ".$prefix."_ele_lista where id_cons=$idcns" ,$dbi);
|
---|
[80] | 139 | $res_del = mysql_query("delete from ".$prefix."_ele_gruppo where id_cons=$idcns" ,$dbi);
|
---|
[36] | 140 | $datafile=$_FILES['datafile']['tmp_name'];
|
---|
[2] | 141 | $arrFile = file($datafile);
|
---|
| 142 | $handle = fopen($datafile, "r");
|
---|
| 143 | $test=array();
|
---|
| 144 | $errore=0;
|
---|
[80] | 145 | $fine=0;
|
---|
| 146 | $numgruppo=0;
|
---|
[77] | 147 | $numlista=0;
|
---|
[2] | 148 | // Set counters
|
---|
| 149 | $currentLine = 0;
|
---|
| 150 | $cntFile = count($arrFile);
|
---|
[36] | 151 | $tabs=array($prefix."_ele_gruppo",$prefix."_ele_lista",$prefix."_ele_candidati",$prefix."_ele_circoscrizione");
|
---|
[2] | 152 | $x=0;$k=0;
|
---|
[80] | 153 | $scarto=0;
|
---|
| 154 | $primog=0;
|
---|
[36] | 155 | $primol=0;
|
---|
[2] | 156 | $conta=array();
|
---|
| 157 | $currentLine = 0;
|
---|
| 158 | $x=0;$k=0;
|
---|
| 159 | $y=0;
|
---|
| 160 | $ar_gruppo=array(array());
|
---|
| 161 | $ar_lista=array(array());
|
---|
| 162 | $ar_candi=array(array());
|
---|
| 163 | $z=0;
|
---|
| 164 | $tab=substr($arrFile[$currentLine],1,-2);
|
---|
| 165 | $conf=$tabs[$x];
|
---|
| 166 | if($k==0) {while (substr($arrFile[$currentLine],1,-2)!=$conf and $currentLine <= $cntFile) $currentLine++; $k++;}
|
---|
| 167 | $currentLine++;
|
---|
[36] | 168 | while($currentLine <= $cntFile and $fine==0){
|
---|
[35] | 169 | # $appo=substr($arrFile[$currentLine],1,-2);
|
---|
[80] | 170 | if(isset($arrFile[$currentLine]))
|
---|
| 171 | $appo=substr($arrFile[$currentLine],1,-2);
|
---|
| 172 | else $appo='';
|
---|
[2] | 173 | if (isset($tabs[($x+1)]) and $appo==$tabs[($x+1)]){ $x++;$conf=$tabs[$x];$currentLine++; continue;}
|
---|
[35] | 174 | $test=explode(':',$appo); if(!is_array($test)) {die("errore di import<br>");}
|
---|
[36] | 175 | foreach($test as $key=>$val)
|
---|
[77] | 176 | if ($conf==$prefix."_ele_gruppo"){
|
---|
| 177 | $ar_gruppo[$z][$key]=addslashes(base64_decode($val));}
|
---|
[80] | 178 | elseif ($conf==$prefix."_ele_lista"){
|
---|
| 179 | if($primog==0){
|
---|
| 180 | $gruppofil= array_filter($ar_gruppo);
|
---|
| 181 | $numgruppo=count($gruppofil);
|
---|
| 182 | insgruppo();
|
---|
| 183 | $primog=1;
|
---|
| 184 | unset($ar_gruppo);
|
---|
[36] | 185 | }
|
---|
[2] | 186 | $ar_lista[$z][$key]=addslashes(base64_decode($val));}
|
---|
[36] | 187 | elseif ($conf==$prefix."_ele_candidati"){
|
---|
[80] | 188 | if($primog==0){
|
---|
| 189 | $gruppofil= array_filter($ar_gruppo);
|
---|
| 190 | $numgruppo=count($gruppofil);
|
---|
| 191 | insgruppo();
|
---|
| 192 | $primog=1;
|
---|
| 193 | unset($ar_gruppo);
|
---|
[77] | 194 | }
|
---|
[80] | 195 | elseif($primol==0){
|
---|
[36] | 196 | $listafil= array_filter($ar_lista);
|
---|
| 197 | $numlista=count($listafil);
|
---|
[80] | 198 | inslista();
|
---|
| 199 | $primol=1;
|
---|
| 200 | unset($ar_lista);
|
---|
[77] | 201 | }
|
---|
[80] | 202 | $ar_candi[$z][$key]=addslashes(base64_decode($val));
|
---|
| 203 | }
|
---|
| 204 | elseif ($conf==$prefix."_ele_circoscrizione"){
|
---|
| 205 | if($primog==0){
|
---|
| 206 | $gruppofil= array_filter($ar_gruppo);
|
---|
| 207 | $numgruppo=count($gruppofil);
|
---|
| 208 | insgruppo();
|
---|
| 209 | $primog=1;
|
---|
| 210 | unset($ar_gruppo);
|
---|
| 211 | }
|
---|
| 212 | elseif($primol==0){
|
---|
[77] | 213 | $listafil= array_filter($ar_lista);
|
---|
| 214 | $numlista=count($listafil);
|
---|
[80] | 215 | inslista();
|
---|
| 216 | $primol=1;
|
---|
| 217 | unset($ar_lista);
|
---|
| 218 | }else{
|
---|
| 219 | inscandi();
|
---|
[77] | 220 | unset($ar_candi);
|
---|
[80] | 221 | $fine=1;
|
---|
| 222 | break;
|
---|
| 223 | }
|
---|
[36] | 224 | }
|
---|
| 225 | $currentLine++;
|
---|
[2] | 226 | $z++;
|
---|
| 227 | }
|
---|
| 228 | fclose($handle);
|
---|
[36] | 229 |
|
---|
| 230 |
|
---|
| 231 |
|
---|
[2] | 232 | if ($numgruppo){
|
---|
[80] | 233 | # insgruppo();
|
---|
[2] | 234 | Header("Location: admin.php?op=gruppo&id_cons_gen=$id_cons_gen");
|
---|
| 235 | }
|
---|
| 236 | elseif ($numlista) {
|
---|
| 237 | inslista(0,0);
|
---|
| 238 | Header("Location: admin.php?op=lista&id_cons_gen=$id_cons_gen");
|
---|
| 239 | }
|
---|
| 240 | else Header("Location: admin.php?op=lista&id_cons_gen=$id_cons_gen");
|
---|
| 241 |
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | echo"</td></tr></table>";
|
---|
| 245 | include("footer.php");
|
---|
| 246 |
|
---|
| 247 |
|
---|
| 248 |
|
---|
| 249 |
|
---|
| 250 |
|
---|
| 251 |
|
---|
| 252 |
|
---|
| 253 |
|
---|
| 254 |
|
---|
| 255 |
|
---|
| 256 |
|
---|
| 257 | /*
|
---|
| 258 | foreach ($ar_gruppo as $rigagruppo){
|
---|
| 259 | $newidg=0;
|
---|
| 260 | $oldidg=0;
|
---|
| 261 | foreach($rigagruppo as $key=>$campo){
|
---|
| 262 | if ($key==0) $valori="'$idcns',";
|
---|
| 263 | elseif ($key==1) {$valori.= "null"; $oldidg=$campo;}
|
---|
| 264 | elseif ($key==6) $valori.= ",0";
|
---|
| 265 | else $valori.= ",'$campo'";
|
---|
| 266 | if ($key==2) $numgruppo= $campo;
|
---|
| 267 | }
|
---|
| 268 | if(isset($valori)){
|
---|
| 269 | $res_gruppo = mysql_query("insert into ".$prefix."_ele_gruppo values($valori)" ,$dbi)||die("(1104) Non e' stato possibile inserire i gruppi nel database! contattare l'amministratore".mysql_error());
|
---|
| 270 | $resnew = mysql_query("select id_gruppo from ".$prefix."_ele_gruppo where num_gruppo='$numgruppo' and id_cons='$idcns'" ,$dbi);
|
---|
| 271 | list ($newidg) = mysql_fetch_row($resnew);
|
---|
| 272 | unset($valori);
|
---|
| 273 | foreach ($ar_lista as $rigalista){
|
---|
| 274 | $oldidl=0;
|
---|
| 275 | foreach($rigalista as $key=>$campo){
|
---|
| 276 | if ($key==0) $valori="'$idcns',";
|
---|
| 277 | elseif ($key==1) {$valori.= "null";$oldidl=$campo;}
|
---|
| 278 | elseif ($key==3) {$valori.= ",'$newidg'"; if ($campo!=$oldidg) $okl=1;}
|
---|
| 279 | elseif ($key==4) $valori.= ",0";
|
---|
| 280 | else $valori.= ",'$campo'";
|
---|
| 281 | if ($key==2) $numlista= $campo;
|
---|
| 282 | }
|
---|
| 283 | if(isset($valori)){
|
---|
| 284 | if ($okl) {$okl=0;continue;}
|
---|
| 285 | $res_lista = mysql_query("insert into ".$prefix."_ele_lista values($valori)" ,$dbi)||die("(1104) Non e' stato possibile inserire le liste nel database! contattare l'amministratore".mysql_error());
|
---|
| 286 | $reslnew = mysql_query("select id_lista from ".$prefix."_ele_lista where num_lista='$numlista' and id_cons='$idcns'" ,$dbi);
|
---|
| 287 | list ($newidl) = mysql_fetch_row($reslnew);
|
---|
| 288 | unset($valori);
|
---|
| 289 | foreach ($ar_candi as $rigacandi){
|
---|
| 290 | foreach($rigacandi as $key=>$campo){if (count($rigacandi)!=8) {unset($valori);continue;}
|
---|
| 291 | if ($key==0) $valori= "null,";
|
---|
| 292 | elseif ($key==1) $valori.="'$idcns',";
|
---|
| 293 | elseif ($key==2) {$valori.= "'$newidl'"; if ($campo!=$oldidl) $okc=1;}
|
---|
| 294 | else $valori.= ",'$campo'";
|
---|
| 295 | }
|
---|
| 296 | if(isset($valori)){
|
---|
| 297 | if ($okc) {$okc=0;continue;}
|
---|
| 298 | $res_lista = mysql_query("insert into ".$prefix."_ele_candidati values($valori)" ,$dbi)||die("(1104) Non e' stato possibile inserire i candidati nel database! contattare l'amministratore".mysql_error());
|
---|
| 299 | }
|
---|
| 300 | }
|
---|
| 301 | }
|
---|
| 302 | }
|
---|
| 303 | }
|
---|
| 304 | }
|
---|
| 305 | */
|
---|
| 306 |
|
---|
| 307 | ?>
|
---|