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 |
|
---|
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 |
|
---|
27 | if (isset($_GET['id_cons_gen'])) $id_cons_gen=intval($_GET['id_cons_gen']); else $id_cons_gen='0';
|
---|
28 | if (isset($_GET['op'])) $op=intval($_GET['op']); else $op='0';
|
---|
29 | if (isset($_GET['id_circ'])) $id_circ=intval($_GET['id_circ']); else $id_circ='0';
|
---|
30 | if (isset($_GET['id_sez'])) $id_sez=intval($_GET['id_sez']); else $id_sez='';
|
---|
31 | if (isset($_GET['id_sede'])) $id_sede=intval($_GET['id_sede']); else $id_sede='0';
|
---|
32 | if (isset($_GET['voti_u'])) $voti_u=intval($_GET['voti_u']); else $voti_u='0';
|
---|
33 | if (isset($_GET['voti_d'])) $voti_d=intval($_GET['voti_d']); else $voti_d='0';
|
---|
34 | if (isset($_GET['voti_t'])) $voti_t=intval($_GET['voti_t']); else $voti_t='0';
|
---|
35 | if (isset($_GET['orario'])) get_magic_quotes_gpc() ? $orario=$_GET['orario']:$orario=addslashes($_GET['orario']); else $orario='';
|
---|
36 | if (isset($_GET['data'])) get_magic_quotes_gpc() ? $data=$_GET['data']:$data=addslashes($_GET['data']); else $data='01-01-1900';
|
---|
37 | if (isset($_GET['id_comune'])) $id_comune=intval($_GET['id_comune']); else $id_comune='0';
|
---|
38 | if (isset($_GET['id_gruppo'])) $id_gruppo=intval($_GET['id_gruppo']); else $id_gruppo='0';
|
---|
39 | if (isset($_GET['delete'])) get_magic_quotes_gpc() ? $delete=$_GET['delete']:$delete=addslashes($_GET['delete']); else $delete='';
|
---|
40 | global $prefix,$id_parz,$tempo,$username,$aid,$dbi,$genere;
|
---|
41 | /* ############
|
---|
42 | $sql="SELECT orario,data FROM ".$prefix."_ele_rilaff where id_cons_gen=$id_cons_gen order by data,orario ";
|
---|
43 | $res = $dbi->prepare("$sql");
|
---|
44 | $res->execute();
|
---|
45 | $num = $res->rowCount();
|
---|
46 | $y=0;
|
---|
47 | while(list($i,$a)=$result->fetch(PDO::FETCH_BOTH)) {
|
---|
48 | $y++;
|
---|
49 | $sql="SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' ";
|
---|
50 | $res2 = $dbi->prepare("$sql");
|
---|
51 | $res2->execute();
|
---|
52 | for($i=1;$i<=$max;$i++){
|
---|
53 | $idg="id_gruppo$i";$vnp="vnpl$i";$slp="slpl$i";$idlist="id_lista$i";
|
---|
54 | if (isset($_GET[$vnp])) $vnpl[$i]=intval($_GET[$vnp]); else $vnpl[$i]='0';
|
---|
55 | if (isset($_GET[$vot])) $voti[$i]=intval($_GET[$vot]); else $voti[$i]='0';
|
---|
56 | if (isset($_GET[$slp])) $slpl[$i]=intval($_GET[$slp]); else $slpl[$i]='0';
|
---|
57 | if (isset($_GET[$idlist])) $idlista[$i]=intval($_GET[$idlist]); else $idlista[$i]='0';
|
---|
58 | $sololiste+=$slpl[$i];
|
---|
59 | }
|
---|
60 | }
|
---|
61 | #############
|
---|
62 | */
|
---|
63 |
|
---|
64 | if (!isset($fileout)) $fileout='';
|
---|
65 | if(($voti_u+$voti_d) and !$voti_t) $voti_t=$voti_u+$voti_d;
|
---|
66 |
|
---|
67 | $salvato=0;
|
---|
68 | $query="select id_cons from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' and id_comune='$id_comune'";
|
---|
69 | $res = $dbi->prepare("$query");
|
---|
70 | $res->execute();
|
---|
71 | $BASE=substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['REQUEST_URI'], "/")-16);
|
---|
72 | list($id_cons)=$res->fetch(PDO::FETCH_NUM);
|
---|
73 | $query="select id_parz from ".$prefix."_ele_voti_parziale where data='$data' and orario='$orario' and id_sez='$id_sez' and id_gruppo='$id_gruppo'";
|
---|
74 | $res = $dbi->prepare("$query");
|
---|
75 | $res->execute();
|
---|
76 | $righe=$res->rowCount();
|
---|
77 | list($id_parz)=$res->fetch(PDO::FETCH_NUM);
|
---|
78 | if($righe){ #la riga Ú presente e viene aggiorata
|
---|
79 | $arr=$res->fetch(PDO::FETCH_BOTH);
|
---|
80 | $sql="update ".$prefix."_ele_voti_parziale set voti_uomini='$voti_u',voti_donne='$voti_d',voti_complessivi='$voti_t' where id_parz='$id_parz'";
|
---|
81 | $compl = $dbi->prepare("$sql");
|
---|
82 | $compl->execute();
|
---|
83 | if($compl->rowCount()) $salvato=1;
|
---|
84 | if($delete=="true"){
|
---|
85 | $sql="delete from ".$prefix."_ele_voti_parziale where id_parz='$id_parz'";
|
---|
86 | $res = $dbi->prepare("$sql");
|
---|
87 | $res->execute();
|
---|
88 | if($res->rowCount()) $salvato=1;
|
---|
89 | }
|
---|
90 | }else{ # Ú un nuovo inserimento
|
---|
91 | $sql="insert into ".$prefix."_ele_voti_parziale values ('$id_cons', '$id_sez','','$orario','$data','$voti_u','$voti_d','$voti_t','$id_gruppo')";
|
---|
92 | $res = $dbi->prepare("$sql");
|
---|
93 | $res->execute();
|
---|
94 | if($res->rowCount()) $salvato=1;
|
---|
95 | }
|
---|
96 | if ($fileout) {
|
---|
97 | while (!$fp = fopen($fileout,"a"));
|
---|
98 | fwrite($fp,"$sql;\n");
|
---|
99 | fclose($fp);
|
---|
100 | }
|
---|
101 | if($salvato){
|
---|
102 | $riga=addslashes($sql);
|
---|
103 | $sqlog="insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$data','$orario','','$riga','".$prefix."_ele_voti_parziale')";
|
---|
104 | $res = $dbi->prepare("$sqlog");
|
---|
105 | $res->execute();
|
---|
106 | }
|
---|
107 | controllo_aff($id_cons,$id_sez,$id_parz);
|
---|
108 |
|
---|
109 | 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&ops=1&do=spoglio");
|
---|
110 |
|
---|
111 |
|
---|
112 | function controllo_aff($id_cons,$id_sez,$id_parz){
|
---|
113 | global $prefix,$dbi,$id_sede,$id_con_gen;
|
---|
114 | ##############################
|
---|
115 | # $sql="select * from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
116 | # $resc = $dbi->prepare("$sql");
|
---|
117 | # $resc->execute();
|
---|
118 | # $conta=$resc->rowCount();
|
---|
119 | $err=0;
|
---|
120 | # $err2=0;
|
---|
121 | $sql="select maschi,femmine from ".$prefix."_ele_sezioni where id_sez='$id_sez'";
|
---|
122 | $res = $dbi->prepare("$sql");
|
---|
123 | $res->execute();
|
---|
124 | list($maschi,$femmine)=$res->fetch(PDO::FETCH_NUM);
|
---|
125 |
|
---|
126 | $sql="select voti_uomini,voti_donne,voti_complessivi from ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and id_parz='$id_parz'";
|
---|
127 | $res = $dbi->prepare("$sql");
|
---|
128 | $res->execute();
|
---|
129 | while(list($voti_u,$voti_d,$voti_t)=$res->fetch(PDO::FETCH_NUM))
|
---|
130 | if(($voti_u+$voti_d!=$voti_t || $voti_u>$maschi || $voti_d>$femmine) and ($voti_u+$voti_d>0)) {$err=1; break;}
|
---|
131 | /* if($conta){
|
---|
132 | $aff=$resc->fetch(PDO::FETCH_BOTH);
|
---|
133 | if($aff['status'])
|
---|
134 | if ($aff['stato_val'] || $aff['stato_lis'] || $aff['stato_gru'] || $aff['stato_can']) $err2=1;
|
---|
135 | }
|
---|
136 | if($conta && !$err2) {
|
---|
137 | $sql="update ".$prefix."_ele_controllosez set stato_aff='$err',status='$err' where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
138 | $res = $dbi->prepare("$sql");
|
---|
139 | $res->execute();
|
---|
140 | } elseif($conta && !$err){
|
---|
141 | $sql="update ".$prefix."_ele_controllosez set stato_aff='$err' where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
142 | $res = $dbi->prepare("$sql");
|
---|
143 | $res->execute();
|
---|
144 | return;
|
---|
145 | } else {
|
---|
146 | $sql="insert into ".$prefix."_ele_controllosez values ('$id_sez','$id_cons','$err','0','0','0','0','$err')";
|
---|
147 | $res = $dbi->prepare("$sql");
|
---|
148 | $res->execute();
|
---|
149 | }*/
|
---|
150 | #######################
|
---|
151 | $tipo='affluenze';
|
---|
152 | $sql="select id from ".$prefix."_ele_controlli where tipo='$tipo' and id_sez='$id_sez' ";
|
---|
153 | $res = $dbi->prepare("$sql");
|
---|
154 | $res->execute();
|
---|
155 | $righe=$res->rowCount();
|
---|
156 | if($righe){
|
---|
157 | while(list($id)=$res->fetch(PDO::FETCH_NUM)){
|
---|
158 | if($id==$id_parz){
|
---|
159 | if(!$err){
|
---|
160 | $sql="delete from ".$prefix."_ele_controlli where tipo='$tipo' and id='$id_parz' ";
|
---|
161 | $res = $dbi->prepare("$sql");
|
---|
162 | $res->execute();
|
---|
163 |
|
---|
164 | }
|
---|
165 | $err=0;
|
---|
166 | break;
|
---|
167 | }
|
---|
168 | }
|
---|
169 | }
|
---|
170 | if($err){
|
---|
171 | $sql="insert into ".$prefix."_ele_controlli value('$id_cons','$id_sez','$tipo','$id_parz')";
|
---|
172 | $res = $dbi->prepare("$sql");
|
---|
173 | $res->execute();
|
---|
174 | }
|
---|
175 |
|
---|
176 |
|
---|
177 | #######################
|
---|
178 | include("ele_colora_sez.php");
|
---|
179 | }
|
---|
180 |
|
---|
181 | ?>
|
---|