<?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 "../config/config.php";
for ($i=1; $i<=count($_GET); $i++) {
$id="id".$i;
print $_GET[$id];
}
// 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 ip, timestamp FROM ".$tab_voti.";";
$estrai_voti = mysql_query($query_voti, $phpoll_db)
or die ("Errore nella connessione per estrazione voti dal database ".$phpoll_database);
$tempo_margine = time()-$intervallo_tempo;
while ($dati_voti=mysql_fetch_assoc ($estrai_voti)) {
if ($dati_voti['ip']==$_SERVER['REMOTE_ADDR']) {
if ($dati_voti['timestamp']<$tempo_margine) {
$test_ip_tempo_margine = true;
}
else {
$test_ip_tempo_margine = false;
break;
}
}
else {
$test_ip_tempo_margine = true;
}
}
if (!isset($test_ip_tempo_margine)) {
$test_ip_tempo_margine = true;
}
$cook="S_S_V_".$prepoll;
if (!$_COOKIE [$cook]&&$test_ip_tempo_margine) {
// 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;
while ($dati_band=mysql_fetch_assoc ($estrai_band)) {
for ($i=0; $i<count($_POST); $i++) {
$id_="id_".$i;
$nome_band_check_="nome_band_check_".$i;
$nome_band_="nome_band_".$i;
$id_int = (int)$_POST[$id_];
if ($_POST[$nome_band_check_]=="on"&&$_POST[$nome_band_]==$dati_band['nome_band']) {
$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) {
$var_ip = $_SERVER['REMOTE_ADDR'];
$query_inserisci_ip = "INSERT INTO `".$tab_voti."` ( `id` , `ip` , `band_votate`, `timestamp`, `browser` ) VALUES ('', '".$var_ip."', '".$stringa_band."', '".time()."', '".$_SERVER['HTTP_USER_AGENT']."');";
$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=\"setta_cookie.php?prepoll=".$prepoll."\";</script>";
die ("");
}
else {
print "<script type=\"text/javascript\">alert(\"NON CI PROVARE!\");</script>";
print "<script type=\"text/javascript\">window.location=\"../risultati.php\";</script>";
}
?>