[258] | 1 | <?php
|
---|
| 2 | /************************************************************************/
|
---|
| 3 | /* Eleonline - Raccolta e diffusione dei dati elettorali */
|
---|
| 4 | /************************************************************************/
|
---|
| 5 | /* Modulo salva affluenze */
|
---|
| 6 | /* Amministrazione */
|
---|
| 7 | /************************************************************************/
|
---|
| 8 | session_name('sesadmin');
|
---|
| 9 | // gestione sessione
|
---|
| 10 | $a = session_id();
|
---|
| 11 | if(empty($a)) session_start();
|
---|
| 12 | if(!$_SESSION['aid'])
|
---|
| 13 | die ("You can't access this file directly...");
|
---|
| 14 | $aid=$_SESSION['aid'];
|
---|
| 15 | include("../../config.php");
|
---|
| 16 | try{
|
---|
| 17 | $dbi = new PDO("mysql:host=$dbhost;charset=latin1", $dbuname, $dbpass, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
|
---|
| 18 | $sql = "use $dbname";
|
---|
| 19 | $dbi->exec($sql);
|
---|
| 20 | }
|
---|
| 21 | catch(PDOException $e)
|
---|
| 22 | {
|
---|
| 23 | echo $sql . "<br>" . $e->getMessage();
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | if (isset($_GET['genere'])) $genere=intval($_GET['genere']); else $genere='';
|
---|
| 27 | if (isset($_GET['id_cons_gen'])) $id_cons_gen=intval($_GET['id_cons_gen']); else $id_cons_gen='';
|
---|
| 28 | if (isset($_GET['id_cons'])) $id_cons=intval($_GET['id_cons']); else $id_cons='';
|
---|
| 29 | if (isset($_GET['op'])) $op=intval($_GET['op']); else $op='';
|
---|
| 30 | if (isset($_GET['id_circ'])) $id_circ=intval($_GET['id_circ']); else $id_circ='';
|
---|
| 31 | if (isset($_GET['id_sez'])) $id_sez=intval($_GET['id_sez']); else $id_sez='';
|
---|
| 32 | if (isset($_GET['id_sede'])) $id_sede=intval($_GET['id_sede']); else $id_sede='';
|
---|
| 33 | if (isset($_GET['id_lista'])) $id_lista=intval($_GET['id_lista']); else $id_lista='';
|
---|
| 34 | if (isset($_GET['valista'])) $valista=intval($_GET['valista']); else $valista='';
|
---|
| 35 | if (isset($_GET['sg'])) $sg=intval($_GET['sg']); else $sg='';
|
---|
| 36 | if (isset($_GET['votinulli'])) $votinulli=intval($_GET['votinulli']); else $votinulli='';
|
---|
| 37 | if (isset($_GET['contestati'])) $contestati=intval($_GET['contestati']); else $contestati='';
|
---|
| 38 | if (isset($_GET['update'])) $update=intval($_GET['update']); else $update='';
|
---|
| 39 | if (isset($_GET['pwd3'])) $pwd3=intval($_GET['pwd3']); else $pwd3='';
|
---|
| 40 | if (isset($_GET['do'])) $do=intval($_GET['do']); else $do='';
|
---|
| 41 | if (isset($_GET['valista'])) $validi=intval($_GET['valista']); else $validi='0';
|
---|
| 42 | if (isset($_GET['nulli'])) get_magic_quotes_gpc() ? $nulli=$_GET['nulli']:$nulli=intval($_GET['nulli']); else $nulli='';
|
---|
| 43 | if (isset($_GET['bianchi'])) get_magic_quotes_gpc() ? $bianchi=$_GET['bianchi']:$bianchi=addslashes($_GET['bianchi']); else $bianchi='';
|
---|
| 44 | if (isset($_GET['contestati'])) get_magic_quotes_gpc() ? $contestati=$_GET['contestati']:$contestati=addslashes($_GET['contestati']); else $contestati='';
|
---|
| 45 | if (isset($_GET['votinulli'])) get_magic_quotes_gpc() ? $votinulli=$_GET['votinulli']:$votinulli=addslashes($_GET['votinulli']); else $votinulli='01-01-1900';
|
---|
| 46 | if (isset($_GET['id_comune'])) $id_comune=intval($_GET['id_comune']); else $id_comune='';
|
---|
| 47 | if (isset($_GET['ops'])) $ops=intval($_GET['ops']); else $ops='';
|
---|
| 48 | if (isset($_GET['delete'])) $delete=intval($_GET['delete']); else $delete='';
|
---|
| 49 | if (isset($_GET['circo'])) get_magic_quotes_gpc() ? $circo=$_GET['circo']:$circo=addslashes($_GET['circo']); else $circo='';
|
---|
| 50 |
|
---|
| 51 | global $prefix,$id_parz,$fileout;
|
---|
| 52 | if($id_lista){
|
---|
| 53 | $sql="select num_cand from ".$prefix."_ele_candidati where id_cons='$id_cons' and id_lista='$id_lista' ORDER BY num_cand ";
|
---|
| 54 | $result = $dbi->prepare("$sql");
|
---|
| 55 | $result->execute();
|
---|
| 56 | while(list($i)=$result->fetch(PDO::FETCH_BOTH)) {
|
---|
| 57 | $vot="voti$i";$cand="id_cand$i";
|
---|
| 58 | if (isset($_GET[$cand])) $idcand[$i]=intval($_GET[$cand]); else $idcand[$i]='0';
|
---|
| 59 | if (isset($_GET[$vot])) $voti[$i]=intval($_GET[$vot]); else $voti[$i]='0';
|
---|
| 60 | # if (isset($_GET[$solo])) $solog[$i]=intval($_GET[$solo]); else $solog[$i]='0';
|
---|
| 61 |
|
---|
| 62 | }
|
---|
| 63 | }else{
|
---|
| 64 | $sql="select num_lista from ".$prefix."_ele_lista where id_cons='$id_cons' ORDER BY num_lista ";
|
---|
| 65 | $result = $dbi->prepare("$sql");
|
---|
| 66 | $result->execute();
|
---|
| 67 | $sololiste=0;
|
---|
| 68 | while(list($i)=$result->fetch(PDO::FETCH_BOTH)) {
|
---|
| 69 | $vot="voti$i";$vnp="vnpl$i";$slp="slpl$i";$idlist="id_lista$i";
|
---|
| 70 | if (isset($_GET[$vnp])) $vnpl[$i]=intval($_GET[$vnp]); else $vnpl[$i]='0';
|
---|
| 71 | if (isset($_GET[$vot])) $voti[$i]=intval($_GET[$vot]); else $voti[$i]='0';
|
---|
| 72 | if (isset($_GET[$slp])) $slpl[$i]=intval($_GET[$slp]); else $slpl[$i]='0';
|
---|
| 73 | if (isset($_GET[$idlist])) $idlista[$i]=intval($_GET[$idlist]); else $idlista[$i]='0';
|
---|
| 74 | $sololiste+=$slpl[$i];
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 | if (!isset($fileout)) $fileout='';
|
---|
| 78 | #if(($voti_u+$voti_d) and !$voti_t) $voti_t=$voti_u+$voti_d;
|
---|
| 79 | if ($fileout) while (!$fp = fopen($fileout,"a"));
|
---|
| 80 |
|
---|
| 81 | ##################
|
---|
| 82 | # if($id_lista){
|
---|
| 83 | if($pwd3==1) {
|
---|
| 84 | $sql="delete from ".$prefix."_ele_voti_lista where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
| 85 | $res = $dbi->prepare("$sql");
|
---|
| 86 | $res->execute();
|
---|
| 87 | $sql="delete from ".$prefix."_ele_voti_candidati where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
| 88 | $res = $dbi->prepare("$sql");
|
---|
| 89 | $res->execute();
|
---|
| 90 | $sql="update ".$prefix."_ele_sezioni set validi_lista='',contestati_lista='',voti_nulli_lista='',solo_gruppo='',solo_lista='' where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
| 91 | $res = $dbi->prepare("$sql");
|
---|
| 92 | $res->execute();
|
---|
| 93 | }elseif($id_lista){
|
---|
| 94 | $sql="SELECT disgiunto FROM ".$prefix."_ele_cons_comune where id_cons='$id_cons' ";
|
---|
| 95 | $res = $dbi->prepare("$sql");
|
---|
| 96 | $res->execute();
|
---|
| 97 | list($disgiunto)=$res->fetch(PDO::FETCH_NUM);
|
---|
| 98 | if($disgiunto){
|
---|
| 99 | }
|
---|
| 100 | foreach($idcand as $idkey=>$idc){
|
---|
| 101 |
|
---|
| 102 | $sql="select num_cand from ".$prefix."_ele_voti_candidati where id_sez='$id_sez' and id_cand='$idc'";
|
---|
| 103 | $result = $dbi->prepare("$sql");
|
---|
| 104 | $result->execute();
|
---|
| 105 | if($result->rowCount())
|
---|
| 106 | $sql="update ".$prefix."_ele_voti_candidati set voti='".$voti[$idkey]."' where id_sez='$id_sez' and id_cand='$idc'";
|
---|
| 107 | else
|
---|
| 108 | $sql="insert into ".$prefix."_ele_voti_candidati values('$id_cons','$idc','$id_sez','$idkey','".$voti[$idkey]."')";
|
---|
| 109 | $result = $dbi->prepare("$sql");
|
---|
| 110 | $result->execute();
|
---|
| 111 | }
|
---|
| 112 | }else{
|
---|
| 113 | $sql="update ".$prefix."_ele_sezioni set validi_lista='$validi',contestati_lista='$contestati',voti_nulli_lista='$votinulli',solo_gruppo='$sg',solo_lista='' where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
| 114 | $res = $dbi->prepare("$sql");
|
---|
| 115 | $res->execute();
|
---|
| 116 | $sql="select num_lista,id_lista from ".$prefix."_ele_voti_lista where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
| 117 | $result = $dbi->prepare("$sql");
|
---|
| 118 | $result->execute();
|
---|
| 119 | if($result->rowCount()){
|
---|
| 120 | $sql="select num_lista,id_lista from ".$prefix."_ele_lista where id_cons='$id_cons'";
|
---|
| 121 | $result = $dbi->prepare("$sql");
|
---|
| 122 | $result->execute();
|
---|
| 123 | while(list($i,$idl)=$result->fetch(PDO::FETCH_NUM)){
|
---|
| 124 | $sql="update ".$prefix."_ele_voti_lista set num_lista='$i',voti='".$voti[$i]."',nulli_lista='".$vnpl[$i]."',solo_lista='".$slpl[$i]."' where num_lista='$i' and id_sez='$id_sez'";
|
---|
| 125 | $res = $dbi->prepare("$sql");
|
---|
| 126 | $res->execute();
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | }else{
|
---|
| 130 |
|
---|
| 131 | $sql="select num_lista,id_lista from ".$prefix."_ele_lista where id_cons='$id_cons'";
|
---|
| 132 | $result = $dbi->prepare("$sql");
|
---|
| 133 | $result->execute();
|
---|
| 134 | while(list($i,$idl)=$result->fetch(PDO::FETCH_NUM)){
|
---|
| 135 | $sql="insert into ".$prefix."_ele_voti_lista values('$id_cons','$idl','$id_sez','$i','".$voti[$i]."','".$vnpl[$i]."','".$slpl[$i]."')";
|
---|
| 136 | $res = $dbi->prepare("$sql");
|
---|
| 137 | $res->execute();
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 |
|
---|
| 143 |
|
---|
| 144 |
|
---|
| 145 | controllo_votil($id_cons,$id_sez,$id_lista);
|
---|
| 146 |
|
---|
| 147 | if ($fileout) fclose($fp);
|
---|
| 148 | $BASE=substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['REQUEST_URI'], "/")-16);
|
---|
| 149 | Header("Location: ".$BASE."admin.php?op=voti&id_cons_gen=$id_cons_gen&id_circ=$id_circ&id_sede=$id_sede&id_sez=$id_sez&do=spoglio&ops=$ops");
|
---|
| 150 | #################################
|
---|
| 151 |
|
---|
| 152 |
|
---|
| 153 |
|
---|
| 154 |
|
---|
| 155 |
|
---|
| 156 | function controllo_votil($id_cons,$id_sez,$id_lista){
|
---|
| 157 | global $prefix,$dbi,$id_sede,$id_cons_gen;
|
---|
| 158 | ##############################
|
---|
| 159 | $sql="select * from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
| 160 | $resc = $dbi->prepare("$sql");
|
---|
| 161 | $resc->execute();
|
---|
| 162 | $conta=$resc->rowCount();
|
---|
| 163 | $err=0; $err2=0;
|
---|
| 164 | if($id_lista){
|
---|
| 165 | $sql="SELECT preferenze FROM ".$prefix."_ele_cons_comune where id_cons='$id_cons'";
|
---|
| 166 | $res = $dbi->prepare("$sql");
|
---|
| 167 | $res->execute();
|
---|
| 168 | list($prefs)=$res->fetch(PDO::FETCH_NUM);
|
---|
| 169 | $sql="select voti from ".$prefix."_ele_voti_lista where id_lista='$id_lista' and id_sez='$id_sez'";
|
---|
| 170 | $res = $dbi->prepare("$sql");
|
---|
| 171 | $res->execute();
|
---|
| 172 | list($votil)=$res->fetch(PDO::FETCH_NUM);
|
---|
| 173 | $sql="SELECT sum(voti),max(voti) FROM ".$prefix."_ele_voti_candidati where id_sez='$id_sez' and id_cand in (select id_cand from ".$prefix."_ele_candidati where id_lista='$id_lista')";
|
---|
| 174 | $res = $dbi->prepare("$sql");
|
---|
| 175 | $res->execute();
|
---|
| 176 | list($votic,$mvc)=$res->fetch(PDO::FETCH_NUM);
|
---|
| 177 | if(($votic*$prefs)>$votil || $mvc>$votil)
|
---|
| 178 | $err=1;
|
---|
| 179 | }else{
|
---|
| 180 | $sql="select id_gruppo from ".$prefix."_ele_lista where id_lista='$id_lista'";
|
---|
| 181 | $res = $dbi->prepare("$sql");
|
---|
| 182 | $res->execute();
|
---|
| 183 | list($idg)=$res->fetch(PDO::FETCH_NUM);
|
---|
| 184 | $sql="SELECT id_gruppo, voti, solo_gruppo FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez'";
|
---|
| 185 | $resref = $dbi->prepare("$sql");
|
---|
| 186 | $resref->execute();
|
---|
| 187 | while (list($idg,$votig,$svg)=$resref->fetch(PDO::FETCH_NUM)) {
|
---|
| 188 | $sql="SELECT sum(voti), sum(solo_lista) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez' and id_lista in (select id_lista from ".$prefix."_ele_lista where id_gruppo='$idg')";
|
---|
| 189 | $res2 = $dbi->prepare("$sql");
|
---|
| 190 | $res2->execute();
|
---|
| 191 | if($res2->rowCount()){
|
---|
| 192 | list($votil,$svl)=$res2->fetch(PDO::FETCH_NUM);
|
---|
| 193 | if(($votig+$svl)!=($votil+$svg))
|
---|
| 194 | $err=1;include("if(($votig+$svl)!=($votil+$svg))");
|
---|
| 195 | }
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | }
|
---|
| 199 | $sql="select * from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
| 200 | $resc = $dbi->prepare("$sql");
|
---|
| 201 | $resc->execute();
|
---|
| 202 | $aff=$resc->fetch(PDO::FETCH_BOTH);
|
---|
| 203 | if($id_lista) {$cur=$aff['stato_lis']; $campo='stato_can';} else {$curr=$aff['stato_can']; $campo='stato_lis';}
|
---|
| 204 | if($aff['status']) {
|
---|
| 205 | if ($aff['stato_aff'] ||$curr || $aff['stato_gru'] || $aff['stato_val']) {
|
---|
| 206 | $sql="update ".$prefix."_ele_controllosez set $campo='$err' where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
| 207 | $res = $dbi->prepare("$sql");include("$sql");
|
---|
| 208 | $res->execute();
|
---|
| 209 | }else{
|
---|
| 210 | $sql="update ".$prefix."_ele_controllosez set $campo='$err',status='$err' where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
| 211 | $res = $dbi->prepare("$sql");
|
---|
| 212 | $res->execute();
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | }
|
---|
| 216 | if($err || $aff['status'])
|
---|
| 217 | $sql="UPDATE ".$prefix."_ele_sezioni set colore='style=\" background: #FF3300;' where id_cons='$id_cons' and id_sez='$id_sez'"; #ROSSO
|
---|
| 218 | else {
|
---|
| 219 | $col="#F0E68C;";
|
---|
| 220 | $sql="select id_cand from ".$prefix."_ele_voti_candidati where id_sez='$id_sez' group by id_cand";
|
---|
| 221 | $res = $dbi->prepare("$sql");
|
---|
| 222 | $res->execute();
|
---|
| 223 | $vv=$res->rowCount();
|
---|
| 224 | $sql="select id_cand from ".$prefix."_ele_candidati where id_cons='$id_cons'";
|
---|
| 225 | $res = $dbi->prepare("$sql");
|
---|
| 226 | $res->execute();
|
---|
| 227 | $vvt=$res->rowCount();
|
---|
| 228 | if($vvt=$vv) $col="#32CD32;"; #"LIMEGREEN" colore se finito l'inserimento dei voti ai candidati
|
---|
| 229 | else{
|
---|
| 230 | $sql="select id_lista from ".$prefix."_ele_voti_lista where id_sez='$id_sez' group by id_lista";
|
---|
| 231 | $res = $dbi->prepare("$sql");
|
---|
| 232 | $res->execute();
|
---|
| 233 | $vv=$res->rowCount();
|
---|
| 234 | $sql="select id_lista from ".$prefix."_ele_lista where id_cons='id_cons'";
|
---|
| 235 | $res = $dbi->prepare("$sql");
|
---|
| 236 | $res->execute();
|
---|
| 237 | $vvt=$res->rowCount();
|
---|
| 238 | if($vvt=$vv) $col="#F0E68C;"; #"KHAKY" colore se finito l'inserimento dei voti alle liste
|
---|
| 239 | }
|
---|
| 240 | $sql="UPDATE ".$prefix."_ele_sezioni set colore='style=\" background: $col' where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
| 241 | }
|
---|
| 242 | $res = $dbi->prepare("$sql");
|
---|
| 243 | $res->execute();
|
---|
| 244 |
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | ?>
|
---|