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