source: trunk/admin/modules/Elezioni/salva_aff.php@ 305

Last change on this file since 305 was 262, checked in by roby, 6 years ago
File size: 4.4 KB
RevLine 
[258]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
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
26
27if (isset($_GET['id_cons_gen'])) $id_cons_gen=intval($_GET['id_cons_gen']); else $id_cons_gen='0';
28if (isset($_GET['op'])) $op=intval($_GET['op']); else $op='0';
29if (isset($_GET['id_circ'])) $id_circ=intval($_GET['id_circ']); else $id_circ='0';
30if (isset($_GET['id_sez'])) $id_sez=intval($_GET['id_sez']); else $id_sez='';
31if (isset($_GET['id_sede'])) $id_sede=intval($_GET['id_sede']); else $id_sede='0';
32if (isset($_GET['voti_u'])) $voti_u=intval($_GET['voti_u']); else $voti_u='0';
33if (isset($_GET['voti_d'])) $voti_d=intval($_GET['voti_d']); else $voti_d='0';
34if (isset($_GET['voti_t'])) $voti_t=intval($_GET['voti_t']); else $voti_t='0';
35if (isset($_GET['orario'])) get_magic_quotes_gpc() ? $orario=$_GET['orario']:$orario=addslashes($_GET['orario']); else $orario='';
36if (isset($_GET['data'])) get_magic_quotes_gpc() ? $data=$_GET['data']:$data=addslashes($_GET['data']); else $data='01-01-1900';
37if (isset($_GET['id_comune'])) $id_comune=intval($_GET['id_comune']); else $id_comune='0';
38if (isset($_GET['id_gruppo'])) $id_gruppo=intval($_GET['id_gruppo']); else $id_gruppo='0';
[262]39if (isset($_GET['genere'])) $genere=intval($_GET['genere']); else $genere='0';
[258]40if (isset($_GET['delete'])) get_magic_quotes_gpc() ? $delete=$_GET['delete']:$delete=addslashes($_GET['delete']); else $delete='';
41global $prefix,$id_parz,$tempo,$username,$aid,$dbi,$genere;
42
43if (!isset($fileout)) $fileout='';
44if(($voti_u+$voti_d) and !$voti_t) $voti_t=$voti_u+$voti_d;
45
46$salvato=0;
47$query="select id_cons from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' and id_comune='$id_comune'";
48$res = $dbi->prepare("$query");
49$res->execute();
50$BASE=substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['REQUEST_URI'], "/")-16);
51list($id_cons)=$res->fetch(PDO::FETCH_NUM);
52$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'";
53$res = $dbi->prepare("$query");
54$res->execute();
55$righe=$res->rowCount();
56list($id_parz)=$res->fetch(PDO::FETCH_NUM);
57if($righe){ #la riga Ú presente e viene aggiorata
58 $arr=$res->fetch(PDO::FETCH_BOTH);
59 $sql="update ".$prefix."_ele_voti_parziale set voti_uomini='$voti_u',voti_donne='$voti_d',voti_complessivi='$voti_t' where id_parz='$id_parz'";
60 $compl = $dbi->prepare("$sql");
61 $compl->execute();
62 if($compl->rowCount()) $salvato=1;
63 if($delete=="true"){
64 $sql="delete from ".$prefix."_ele_voti_parziale where id_parz='$id_parz'";
65 $res = $dbi->prepare("$sql");
66 $res->execute();
67 if($res->rowCount()) $salvato=1;
68 }
69}else{ # Ú un nuovo inserimento
70 $sql="insert into ".$prefix."_ele_voti_parziale values ('$id_cons', '$id_sez','','$orario','$data','$voti_u','$voti_d','$voti_t','$id_gruppo')";
71 $res = $dbi->prepare("$sql");
72 $res->execute();
73 if($res->rowCount()) $salvato=1;
74}
75if ($fileout) {
76 while (!$fp = fopen($fileout,"a"));
77 fwrite($fp,"$sql;\n");
78 fclose($fp);
79}
80if($salvato){
81 $riga=addslashes($sql);
82 $sqlog="insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$data','$orario','','$riga','".$prefix."_ele_voti_parziale')";
83 $res = $dbi->prepare("$sqlog");
84 $res->execute();
85}
[262]86#controllo_aff($id_cons,$id_sez,$id_parz);
87include("ele_controlli.php");
88controllo_aff($id_cons,$id_sez,$id_parz);
89include("ele_colora_sez.php");
[258]90
91Header("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");
92
93
94?>
Note: See TracBrowser for help on using the repository browser.