<?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";
include "crypt.php";
$stringa="";
$x=1;
for ($i=0; $i<count($_POST); $i++) {
$id_="id_".$i;
$nome_band_check_="nome_band_check_".$i;
$nome_band_="nome_band_".$i;
if (isset($_POST[$nome_band_check_])&&$_POST[$nome_band_check_]=="on") {
$stringa.="id".$x."=".$_POST[$id_]."&";
$x++;
}
}
$test_domini = true;
if ($domini_esclusi[0]!="") {
foreach ($domini_esclusi as $key => $value) {
if (stristr ($_POST['email'], $value)) {
$test_domini=true;
break;
}
else {
$test_domini=false;
}
}
}
else {
$test_domini=false;
}
if (!$test_domini) {
$ip_attuale = explode(".", $_SERVER['REMOTE_ADDR']);
// 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.";";
//print $query_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)) {
$ip_registrato = explode(".", $dati_voti['ip']);
if ($ip_attuale[0]<=191) {
if (($ip_attuale[0]==$ip_registrato[0])&&($ip_attuale[1]==$ip_registrato[1])) {
if ($dati_voti['timestamp']<$tempo_margine) {
$test_ip_tempo_margine = true;
}
else {
$test_ip_tempo_margine = false;
break;
}
}
else {
$test_ip_tempo_margine = true;
}
}
else if ($ip_attuale[0]>191) {
if (($ip_attuale[0]==$ip_registrato[0])&&($ip_attuale[1]==$ip_registrato[1])&&($ip_attuale[2]==$ip_registrato[2])) {
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 ($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;
}
if ($test_ip_tempo_margine) {
// QUERY per MySQL
$query_voti2 = "SELECT votato, email, id FROM ".$tab_voti.";";
$estrai_voti2 = mysql_query($query_voti2, $phpoll_db)
or die ("Errore nella connessione per estrazione voti dal database ".$phpoll_database);
while ($dati_voti2=mysql_fetch_assoc ($estrai_voti2)) {
if ($dati_voti2['email']==$_POST['email']) {
if ($dati_voti2['votato']=="1") {
$test_vota = false;
break;
}
}
}
if (!isset($test_vota)) {
$test_vota = true;
}
if ($test_vota) {
$var_ip = $_SERVER['REMOTE_ADDR'];
$post_email = mysql_real_escape_string ($_POST['email']);
$query_inserisci_ip = "INSERT INTO `".$tab_voti."` ( `id` , `ip` , `timestamp`, `browser`, `email`) VALUES ('', '".$var_ip."', '".time()."', '".$_SERVER['HTTP_USER_AGENT']."', '".$post_email."');";
$inserisci_ip = mysql_query($query_inserisci_ip, $phpoll_db)
or die ("Errore nella connessione per inserimento ip al database ".$database);
$plain_text = $_POST['email'];
$password = $password_crypt;
$email_encrypted = md5_encrypt($plain_text, $password);
$intestazioni = "MIME-Version: 1.0\r\n";
$intestazioni .= "Content-type: text/html; charset=iso-8859-1\r\n";
mail ($_POST['email'], $oggetto_email, "<html><head><title></title></head><body>".$testo_email."<br /><br /><a href=\"".$percorso_link."cookies/elabora_voto_new.php?".$stringa."email=".$email_encrypted."\">".$percorso_link."cookies/elabora_voto_new.php?".$stringa."email=".$email_encrypted."</a></body></html>", $intestazioni);
print "<script type=\"text/javascript\">alert(\"".$messaggio_conferma_mail."\");</script>";
print "<script type=\"text/javascript\">window.location=\"../risultati.php\";</script>";
print "mail sent";
}
else {
print "<script type=\"text/javascript\">alert(\"".$messaggio_giavotato."\");</script>";
print "<script type=\"text/javascript\">window.location=\"../risultati.php\";</script>";
die ("already voted");
}
mysql_close ($phpoll_db);
}
else {
print "<script type=\"text/javascript\">alert(\"".$messaggio_ip."\");</script>";
print "<script type=\"text/javascript\">window.location=\"../risultati.php\";</script>";
die ("ip not allowed");
}
}
else {
print "<script type=\"text/javascript\">alert(\"".$messaggio_domini."\");</script>";
print "<script type=\"text/javascript\">window.location=\"../risultati.php\";</script>";
die ("domain not allowed");
}
?>