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='0';
|
---|
27 | if (isset($_GET['id_cons_gen'])) $id_cons_gen=intval($_GET['id_cons_gen']); else $id_cons_gen='0';
|
---|
28 | if (isset($_GET['id_cons'])) $id_cons=intval($_GET['id_cons']); else $id_cons='0';
|
---|
29 | if (isset($_GET['op'])) $op=intval($_GET['op']); else $op='0';
|
---|
30 | if (isset($_GET['id_circ'])) $id_circ=intval($_GET['id_circ']); else $id_circ='0';
|
---|
31 | if (isset($_GET['id_sez'])) $id_sez=intval($_GET['id_sez']); else $id_sez='0';
|
---|
32 | if (isset($_GET['id_sede'])) $id_sede=intval($_GET['id_sede']); else $id_sede='0';
|
---|
33 | if (isset($_GET['do'])) $do=intval($_GET['do']); else $do='0';
|
---|
34 | if (isset($_GET['validi'])) $validi=intval($_GET['validi']); else $validi='0';
|
---|
35 | if (isset($_GET['nulli'])) $nulli=intval($_GET['nulli']); else $nulli='0';
|
---|
36 | if (isset($_GET['bianchi'])) $bianchi=intval($_GET['bianchi']); else $bianchi='0';
|
---|
37 | if (isset($_GET['contestati'])) $contestati=intval($_GET['contestati']); else $contestati='0';
|
---|
38 | if (isset($_GET['votinulli'])) $votinulli=intval($_GET['votinulli']); else $votinulli='0';
|
---|
39 | if (isset($_GET['id_comune'])) $id_comune=intval($_GET['id_comune']); else $id_comune='0';
|
---|
40 | if (isset($_GET['ops'])) $ops=intval($_GET['ops']); else $ops='0';
|
---|
41 | if (isset($_GET['delete'])) $delete=intval($_GET['delete']); else $delete='';
|
---|
42 | if (isset($_GET['circo'])) get_magic_quotes_gpc() ? $circo=$_GET['circo']:$circo=addslashes($_GET['circo']); else $circo='';
|
---|
43 |
|
---|
44 | global $prefix,$id_parz,$fileout;
|
---|
45 | $sql="select num_gruppo from ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ORDER BY num_gruppo ";
|
---|
46 | $result = $dbi->prepare("$sql");
|
---|
47 | $result->execute();
|
---|
48 | while(list($i)=$result->fetch(PDO::FETCH_BOTH)) {
|
---|
49 | $vot="voti$i";$solo="solog$i";$grupp="num_gruppo$i";
|
---|
50 | if (isset($_GET[$grupp])) $num_gruppo[$i]=intval($_GET[$grupp]); else $num_gruppo[$i]='0';
|
---|
51 | if (isset($_GET[$vot])) $voti[$i]=intval($_GET[$vot]); else $voti[$i]='0';
|
---|
52 | if (isset($_GET[$solo])) $solog[$i]=intval($_GET[$solo]); else $solog[$i]='0';
|
---|
53 |
|
---|
54 | }
|
---|
55 |
|
---|
56 | if (!isset($fileout)) $fileout='';
|
---|
57 | #if(($voti_u+$voti_d) and !$voti_t) $voti_t=$voti_u+$voti_d;
|
---|
58 | if ($fileout) while (!$fp = fopen($fileout,"a"));
|
---|
59 |
|
---|
60 | ##################
|
---|
61 | if($do==1) {
|
---|
62 | $sql="delete from ".$prefix."_ele_voti_gruppo where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
63 | $res = $dbi->prepare("$sql");
|
---|
64 | $res->execute();
|
---|
65 | $sql="delete from ".$prefix."_ele_voti_lista where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
66 | $res = $dbi->prepare("$sql");
|
---|
67 | $res->execute();
|
---|
68 | $sql="delete from ".$prefix."_ele_voti_candidati where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
69 | $res = $dbi->prepare("$sql");
|
---|
70 | $res->execute();
|
---|
71 | $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'";
|
---|
72 | $res = $dbi->prepare("$sql");
|
---|
73 | $res->execute();
|
---|
74 | }else{
|
---|
75 | $sql="SELECT disgiunto FROM ".$prefix."_ele_cons_comune where id_cons='$id_cons' ";
|
---|
76 | $res = $dbi->prepare("$sql");
|
---|
77 | $res->execute();
|
---|
78 | list($disgiunto)=$res->fetch(PDO::FETCH_NUM);
|
---|
79 | if($disgiunto){
|
---|
80 | }
|
---|
81 | $sql="select num_gruppo from ".$prefix."_ele_voti_gruppo where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
82 | $result = $dbi->prepare("$sql");
|
---|
83 | $result->execute();
|
---|
84 | if($result->rowCount()) {
|
---|
85 | while(list($i)=$result->fetch(PDO::FETCH_NUM)){
|
---|
86 | $sql="update ".$prefix."_ele_voti_gruppo set voti='".$voti[$i]."',solo_gruppo='".$solog[$i]."' where id_cons='$id_cons' and id_sez='$id_sez' and num_gruppo='".$num_gruppo[$i]."'";
|
---|
87 | $res = $dbi->prepare("$sql");
|
---|
88 | $res->execute();
|
---|
89 | }
|
---|
90 | }else{
|
---|
91 | $sql="select num_gruppo,id_gruppo from ".$prefix."_ele_gruppo where id_cons='$id_cons'";
|
---|
92 | $result = $dbi->prepare("$sql");
|
---|
93 | $result->execute();
|
---|
94 | while(list($i,$id_gruppo)=$result->fetch(PDO::FETCH_NUM)){
|
---|
95 | $sql="insert into ".$prefix."_ele_voti_gruppo values('$id_cons','$id_gruppo','$id_sez','$i','".$voti[$i]."','".$solog[$i]."')";
|
---|
96 | $res = $dbi->prepare("$sql");
|
---|
97 | $res->execute();
|
---|
98 | }
|
---|
99 |
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 |
|
---|
104 |
|
---|
105 | controllo_votig($id_cons,$id_sez,$genere,$id_gruppo);
|
---|
106 |
|
---|
107 | if ($fileout) fclose($fp);
|
---|
108 | $BASE=substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['REQUEST_URI'], "/")-16);
|
---|
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&do=spoglio&ops=$ops");
|
---|
110 | #################################
|
---|
111 |
|
---|
112 |
|
---|
113 |
|
---|
114 |
|
---|
115 |
|
---|
116 | function controllo_votig($id_cons,$id_sez,$genere){
|
---|
117 | global $prefix,$dbi,$id_sede,$id_cons_gen;
|
---|
118 | ##############################
|
---|
119 | $sql="select * from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
120 | $resc = $dbi->prepare("$sql");
|
---|
121 | $resc->execute();
|
---|
122 | $conta=$resc->rowCount();
|
---|
123 | $err=0; $err2=0;
|
---|
124 | $sql="SELECT id_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons'";
|
---|
125 | $resref = $dbi->prepare("$sql");
|
---|
126 | $resref->execute();
|
---|
127 | if($genere==0){
|
---|
128 | $numscru=$resref->rowCount(); $rifscru=0;
|
---|
129 | while(list($idrefgruppo)=$resref->fetch(PDO::FETCH_NUM)) {
|
---|
130 | $sql="SELECT si,no,validi,nulli,bianchi,contestati FROM ".$prefix."_ele_voti_ref where id_sez='$id_sez' and id_gruppo='$idrefgruppo'";
|
---|
131 | $res2 = $dbi->prepare("$sql");
|
---|
132 | $res2->execute();
|
---|
133 | $refscru=$res2->rowCount();
|
---|
134 | $sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and id_gruppo='$idrefgruppo'";
|
---|
135 | $res3 = $dbi->prepare("$sql");
|
---|
136 | $res3->execute();
|
---|
137 | list($voti)=$res3->fetch(PDO::FETCH_NUM);
|
---|
138 | $rifscru++;
|
---|
139 | list($si,$no,$validi,$nulli,$bianchi,$contestati)=$res2->fetch(PDO::FETCH_NUM);
|
---|
140 | if(($si+$no==$validi) and ($validi+$nulli+$bianchi+$contestati==$voti))
|
---|
141 | continue;
|
---|
142 | else {$err=1; break;}
|
---|
143 | }
|
---|
144 | }else{
|
---|
145 | #per le altre consultazione
|
---|
146 | $sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez'";
|
---|
147 | $res3 = $dbi->prepare("$sql");
|
---|
148 | $res3->execute();
|
---|
149 | list($voti)=$res3->fetch(PDO::FETCH_NUM);
|
---|
150 | $sql="SELECT validi FROM ".$prefix."_ele_sezioni where id_sez='$id_sez' and id_cons='$id_cons' ";
|
---|
151 | $res2 = $dbi->prepare("$sql");
|
---|
152 | $res2->execute();
|
---|
153 | list($validi) = $res2->fetch(PDO::FETCH_NUM);
|
---|
154 | if($validi) {
|
---|
155 | $status=0;
|
---|
156 | $query="SELECT validi,nulli,bianchi,contestati,voti_nulli,solo_gruppo,validi_lista,contestati_lista,voti_nulli_lista,solo_lista FROM ".$prefix."_ele_sezioni as t1 where t1.id_sez='$id_sez'";
|
---|
157 | $sql="$query";
|
---|
158 | $res4 = $dbi->prepare("$sql");
|
---|
159 | $res4->execute();
|
---|
160 | list($validi, $nulli, $bianchi,$contestati,$votinulli)=$res4->fetch(PDO::FETCH_NUM);
|
---|
161 | if (($validi+$nulli+$bianchi+$contestati+$votinulli)!=$voti)
|
---|
162 | {$err=1;}
|
---|
163 | }
|
---|
164 | }
|
---|
165 |
|
---|
166 | #############
|
---|
167 | $tipo='gruppo';
|
---|
168 | $sql="select id from ".$prefix."_ele_controlli where tipo='$tipo' and id_sez='$id_sez' and id= ";
|
---|
169 | $res = $dbi->prepare("$sql");
|
---|
170 | $res->execute();
|
---|
171 | $righe=$res->rowCount();
|
---|
172 | if($righe){
|
---|
173 | if(!$err){
|
---|
174 | $sql="delete from ".$prefix."_ele_controlli where tipo='$tipo' and id='$id_sez' ";
|
---|
175 | $res = $dbi->prepare("$sql");
|
---|
176 | $res->execute();
|
---|
177 | }
|
---|
178 | $err=0;
|
---|
179 | }
|
---|
180 | if($err){
|
---|
181 | $sql="insert into ".$prefix."_ele_controlli value('$id_cons','$id_sez','$tipo','$id_sez')";
|
---|
182 | $res = $dbi->prepare("$sql");
|
---|
183 | $res->execute();
|
---|
184 | }
|
---|
185 | #############
|
---|
186 | $sql="select * from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
187 | $resc = $dbi->prepare("$sql");
|
---|
188 | $resc->execute();
|
---|
189 | $aff=$resc->fetch(PDO::FETCH_BOTH);
|
---|
190 | if($aff['status']) {
|
---|
191 | if ($aff['stato_aff'] ||$aff['stato_lis'] || $aff['stato_gru'] || $aff['stato_can']) {
|
---|
192 | $sql="update ".$prefix."_ele_controllosez set stato_val='$err' where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
193 | $res = $dbi->prepare("$sql");
|
---|
194 | $res->execute();
|
---|
195 | }else{
|
---|
196 | $sql="update ".$prefix."_ele_controllosez set stato_val='$err',status='$err' where id_cons='$id_cons' and id_sez='$id_sez'";
|
---|
197 | $res = $dbi->prepare("$sql");
|
---|
198 | $res->execute();
|
---|
199 | }
|
---|
200 |
|
---|
201 | }
|
---|
202 | if($err || $aff['status'])
|
---|
203 | $sql="UPDATE ".$prefix."_ele_sezioni set colore='style=\" background: #FF3300;' where id_cons='$id_cons' and id_sez='$id_sez'"; #ROSSO
|
---|
204 | else {
|
---|
205 | $col="#F0E68C;";
|
---|
206 | $sql="select id_cand from ".$prefix."_ele_voti_candidati where id_sez='$id_sez' group by id_cand";
|
---|
207 | $res = $dbi->prepare("$sql");
|
---|
208 | $res->execute();
|
---|
209 | $vv=$res->rowCount();
|
---|
210 | $sql="select id_cand from ".$prefix."_ele_candidati where id_cons='$id_cons'";
|
---|
211 | $res = $dbi->prepare("$sql");
|
---|
212 | $res->execute();
|
---|
213 | $vvt=$res->rowCount();
|
---|
214 | if($vvt=$vv) $col="#F0E68C;"; #colore se finito l'inserimento dei viti ai candidati
|
---|
215 | else{
|
---|
216 | $sql="select id_lista from ".$prefix."_ele_voti_lista where id_sez='$id_sez' group by id_lista";
|
---|
217 | $res = $dbi->prepare("$sql");
|
---|
218 | $res->execute();
|
---|
219 | $vv=$res->rowCount();
|
---|
220 | $sql="select id_lista from ".$prefix."_ele_lista where id_cons='id_cons'";
|
---|
221 | $res = $dbi->prepare("$sql");
|
---|
222 | $res->execute();
|
---|
223 | $vvt=$res->rowCount();
|
---|
224 | if($vvt=$vv) $col="#F0E68C;"; #colore se finito l'inserimento dei voti alle liste
|
---|
225 |
|
---|
226 | }
|
---|
227 | $sql="UPDATE ".$prefix."_ele_sezioni set colore='style=\" background: $col' where id_cons='$id_cons' and id_sez='$id_sez'"; #"#F0E68C" "KHAKY"
|
---|
228 |
|
---|
229 | }
|
---|
230 | $res = $dbi->prepare("$sql");
|
---|
231 | $res->execute();
|
---|
232 |
|
---|
233 | }
|
---|
234 |
|
---|
235 | ?>
|
---|