source: trunk/admin/modules/Elezioni/salva_voti.php@ 261

Last change on this file since 261 was 261, checked in by roby, 6 years ago
File size: 8.1 KB
Line 
1<?php
2/************************************************************************/
3/* Eleonline - Raccolta e diffusione dei dati elettorali */
4/************************************************************************/
5/* Modulo salva affluenze */
6/* Amministrazione */
7/************************************************************************/
8session_name('sesadmin');
9 // gestione sessione
10$a = session_id();
11if(empty($a)) session_start();
12if(!$_SESSION['aid'])
13 die ("You can't access this file directly...");
14$aid=$_SESSION['aid'];
15include("../../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
26if (isset($_GET['genere'])) get_magic_quotes_gpc() ? $genere=$_GET['genere']:$genere=addslashes($_GET['genere']); else $genere='';
27if (isset($_GET['id_cons_gen'])) get_magic_quotes_gpc() ? $id_cons_gen=$_GET['id_cons_gen']:$id_cons_gen=addslashes($_GET['id_cons_gen']); else $id_cons_gen='';
28if (isset($_GET['id_cons'])) get_magic_quotes_gpc() ? $id_cons=$_GET['id_cons']:$id_cons=addslashes($_GET['id_cons']); else $id_cons='';
29if (isset($_GET['op'])) get_magic_quotes_gpc() ? $op=$_GET['op']:$op=addslashes($_GET['op']); else $op='';
30if (isset($_GET['id_circ'])) get_magic_quotes_gpc() ? $id_circ=$_GET['id_circ']:$id_circ=addslashes($_GET['id_circ']); else $id_circ='';
31if (isset($_GET['id_sez'])) get_magic_quotes_gpc() ? $id_sez=$_GET['id_sez']:$id_sez=addslashes($_GET['id_sez']); else $id_sez='';
32if (isset($_GET['id_sede'])) get_magic_quotes_gpc() ? $id_sede=$_GET['id_sede']:$id_sede=addslashes($_GET['id_sede']); else $id_sede='';
33if (isset($_GET['validi'])) get_magic_quotes_gpc() ? $validi=$_GET['validi']:$validi=addslashes($_GET['validi']); else $validi='';
34if (isset($_GET['nulli'])) get_magic_quotes_gpc() ? $nulli=$_GET['nulli']:$nulli=intval($_GET['nulli']); else $nulli='';
35if (isset($_GET['bianchi'])) get_magic_quotes_gpc() ? $bianchi=$_GET['bianchi']:$bianchi=addslashes($_GET['bianchi']); else $bianchi='';
36if (isset($_GET['contestati'])) get_magic_quotes_gpc() ? $contestati=$_GET['contestati']:$contestati=addslashes($_GET['contestati']); else $contestati='';
37if (isset($_GET['votinulli'])) get_magic_quotes_gpc() ? $votinulli=$_GET['votinulli']:$votinulli=addslashes($_GET['votinulli']); else $votinulli='01-01-1900';
38if (isset($_GET['id_comune'])) get_magic_quotes_gpc() ? $id_comune=$_GET['id_comune']:$id_comune=addslashes($_GET['id_comune']); else $id_comune='';
39if (isset($_GET['ops'])) get_magic_quotes_gpc() ? $ops=$_GET['ops']:$ops=addslashes($_GET['ops']); else $ops='';
40if (isset($_GET['delete'])) get_magic_quotes_gpc() ? $delete=$_GET['delete']:$delete=addslashes($_GET['delete']); else $delete='';
41
42global $prefix,$id_parz,$genere,$fileout,$id_cons;
43if (!isset($fileout)) $fileout='';
44#if(($voti_u+$voti_d) and !$voti_t) $voti_t=$voti_u+$voti_d;
45if ($fileout) while (!$fp = fopen($fileout,"a"));
46
47$salvato=0;
48
49##################
50$sql="select solo_gruppo,disgiunto from ".$prefix."_ele_cons_comune where id_cons='$id_cons' ";
51$result = $dbi->prepare("$sql");
52$result->execute();
53list($flagsg,$disgiunto)=$result->fetch(PDO::FETCH_NUM);
54$sql="select * from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez' ";
55$result = $dbi->prepare("$sql");
56$result->execute();
57$ar=$result->fetch(PDO::FETCH_BOTH);
58$validilista=$validi-$ar['solo_gruppo'];
59$log_data= date("Y/m/d");
60$log_ora=getdate(time());
61$orario=($log_ora['hours'].":".$log_ora['minutes'].":".$log_ora['seconds']);
62
63#if($ops==3 and ($genere==3 or $genere==4 or $genere==5) and ($votog or $genere==4)){
64 $sql="insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$aid','$log_data','$orario','validi_lista:$ar[14] nulli:$ar[7] bianchi:$ar[8] ','validi_lista=$validilista, nulli=$nulli,bianchi=$bianchi','_ele_sezioni')";
65 $res = $dbi->prepare("$sql");
66 $res->execute();
67 $sql="update ".$prefix."_ele_sezioni set validi='$validi', contestati='$contestati', nulli='$nulli',bianchi='$bianchi', voti_nulli='$votinulli' where id_cons='$id_cons' and id_sez='$id_sez' ";
68 $res = $dbi->prepare("$sql");
69 $res->execute();
70 if ($fileout) fwrite($fp,"$sql;\n");
71/*}else{
72 $sql="insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$aid','','','validi:$ar[6] nulli:$ar[7] bianchi:$ar[8] contestati:$ar[9] voti_nulli:$ar[13]','validi=$validi, nulli=$nulli,bianchi=$bianchi,contestati=$contestati, voti_nulli=$votinulli','_ele_sezioni')";
73 $res = $dbi->prepare("$sql");
74 $res->execute();
75 $sql="update ".$prefix."_ele_sezioni set validi='$validi', nulli='$nulli',bianchi='$bianchi',contestati='$contestati',voti_nulli='$votinulli' where id_cons='$id_cons' and id_sez='$id_sez' ";
76 $res = $dbi->prepare("$sql");
77 $res->execute();
78 if ($fileout) fwrite($fp,"$sql;\n"); */
79#}
80controllo_voti($id_cons,$id_sez);
81
82if ($fileout) fclose($fp);
83$BASE=substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['REQUEST_URI'], "/")-16);
84Header("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");
85#################################
86
87
88
89
90
91function controllo_voti($id_cons,$id_sez){
92 global $prefix,$dbi,$id_sede,$id_con_gen,$genere;
93 ##############################
94 $sql="select * from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'";
95 $resc = $dbi->prepare("$sql");
96 $resc->execute();
97 $conta=$resc->rowCount();
98 $err=0; $err2=0;
99 $sql="SELECT id_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons'";
100 $resref = $dbi->prepare("$sql");
101 $resref->execute();
102 if($genere==0){
103 $numscru=$resref->rowCount(); $rifscru=0;
104 while(list($idrefgruppo)=$resref->fetch(PDO::FETCH_NUM)) {
105 $sql="SELECT si,no,validi,nulli,bianchi,contestati FROM ".$prefix."_ele_voti_ref where id_sez='$id_sez' and id_gruppo='$idrefgruppo'";
106 $res2 = $dbi->prepare("$sql");
107 $res2->execute();
108 $refscru=$res2->rowCount();
109 $sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and id_gruppo='$idrefgruppo'";
110 $res3 = $dbi->prepare("$sql");
111 $res3->execute();
112 list($voti)=$res3->fetch(PDO::FETCH_NUM);
113 $rifscru++;
114 list($si,$no,$validi,$nulli,$bianchi,$contestati)=$res2->fetch(PDO::FETCH_NUM);
115 if(($si+$no==$validi) and ($validi+$nulli+$bianchi+$contestati==$voti))
116 continue;
117 else {$err=1; break;}
118 }
119 }else{
120 #per le altre consultazione
121 $sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez'";
122 $res3 = $dbi->prepare("$sql");
123 $res3->execute();
124 list($voti)=$res3->fetch(PDO::FETCH_NUM);
125 $sql="SELECT validi FROM ".$prefix."_ele_sezioni where id_sez='$id_sez' and id_cons='$id_cons' ";
126 $res2 = $dbi->prepare("$sql");
127 $res2->execute();
128 list($validi) = $res2->fetch(PDO::FETCH_NUM);
129 if($validi) {
130 $status=0;
131 $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'";
132 $sql="$query";
133 $res4 = $dbi->prepare("$sql");
134 $res4->execute();
135 list($validi, $nulli, $bianchi,$contestati,$votinulli)=$res4->fetch(PDO::FETCH_NUM);
136 if (($validi+$nulli+$bianchi+$contestati+$votinulli)!=$voti)
137 {$err=1;}
138 }
139 }
140 $tipo='votanti';
141 $sql="select id from ".$prefix."_ele_controlli where tipo='$tipo' and id_sez='$id_sez' ";
142 $res = $dbi->prepare("$sql");
143 $res->execute();
144 $righe=$res->rowCount();
145 if($righe){
146 if(!$err){
147 $sql="delete from ".$prefix."_ele_controlli where tipo='$tipo' and id='$id_sez' ";
148 $res = $dbi->prepare("$sql");
149 $res->execute();
150 }
151 $err=0;
152 }
153 if($err){
154 $sql="insert into ".$prefix."_ele_controlli value('$id_cons','$id_sez','$tipo','$id_sez')";
155 $res = $dbi->prepare("$sql");
156 $res->execute();
157 }
158 include("ele_colora_sez.php");
159}
160
161?>
Note: See TracBrowser for help on using the repository browser.