<?php
/*
This file is part of PHPOLL.
PHPOLL is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
PHPOLL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PHPOLL; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
include "crypt.php";
include "../config/config.php";
$enc_text = $_GET['email'];
$password = $password_crypt;
$email_decrypted = md5_decrypt($enc_text, $password);
// assegno le variabili di connessione
$phpoll_db = mysql_connect ($phpoll_host, $phpoll_user, $phpoll_password)
or die ("Errore nella connessione a MySQL");
// selezione del database
mysql_select_db($phpoll_database, $phpoll_db)
or die ("Errore nella connessione al database ".$phpoll_database);
// QUERY per MySQL
$query_voti = "SELECT votato, email, id FROM ".$tab_voti." WHERE email='".$email_decrypted."';";
$estrai_voti = mysql_query($query_voti, $phpoll_db)
or die ("Errore nella connessione per estrazione voti dal database ".$phpoll_database);
while ($dati_voti=mysql_fetch_assoc ($estrai_voti)) {
if ($dati_voti['email']==$email_decrypted&&$dati_voti['votato']!="1") {
$test_vota = true;
$id_votante = $dati_voti['id'];
}
else {
$test_vota = false;
break;
}
}
if (isset($test_vota)&&$test_vota) {
// QUERY per MySQL
$query_band = "SELECT * FROM ".$tab_band." ORDER BY nome_band;";
$estrai_band = mysql_query($query_band, $phpoll_db)
or die ("Errore nella connessione per estrazione band al database ".$phpoll_database);
// print "<br />";
$test_inserimento = false;
$stringa_band="";
while ($dati_band=mysql_fetch_assoc ($estrai_band)) {
for ($i=1; $i<=(count($_GET)-1); $i++) {
$id="id".$i;
$nome_band_="nome_band_".$i;
$id_int = (int)$_GET[$id];
if ($dati_band['id']==$id_int]) {
$valore_voto=$dati_band['voti']+1;
$query_inserisci_voto = "UPDATE `".$tab_band."` SET `voti` = '".$valore_voto."' WHERE `id` = ".$id_int." LIMIT 1 ;";
// print $query_inserisci_voto."<br />";
$inserisci_voto = mysql_query($query_inserisci_voto, $phpoll_db)
or die ("Errore nella connessione per inserimento voti ".$phpoll_database);
$stringa_band.=$dati_band['nome_band'].", ";
$test_inserimento = true;
}
}
}
if ($test_inserimento) {
$query_inserisci_ip = "UPDATE `".$tab_voti."` SET `band_votate` ='".$stringa_band."', `votato` = '1' WHERE `id` =".$id_votante." LIMIT 1;";
$inserisci_ip = mysql_query($query_inserisci_ip, $phpoll_db)
or die ("Errore nella connessione per inserimento ip al database ".$database);
}
mysql_close ($phpoll_db);
print "<script type=\"text/javascript\">window.location=\"../risultati.php\";</script>";
}
else {
if (isset($test_vota)) { $message = $messaggio_giavotato; } else { $message = $messaggio_sgamo; }
print "<script type=\"text/javascript\">alert(\"".$message."\");</script>";
print "<script type=\"text/javascript\">window.location=\"../risultati.php\";</script>";
}
?>