<?php
include("connect.php");

function poll() {
global $htmlorphp,$folder,$idpool,$LANGAUGE;

if ($htmlorphp=="1"){
$y = "vote.html";
}else{
$y = "poll.php?action=vote4pool";
}

$sql = @mysql_query("SELECT * FROM pool where id='$idpool'");
$n = mysql_num_rows($sql);

if($n==0){
$s = $LANGAUGE[144];
}else{
$row = @mysql_fetch_array($sql);
$row[answer1] = text(3,$row[answer1]);
$row[answer2] = text(3,$row[answer2]);
$row[answer3] = text(3,$row[answer3]);
$row[answer4] = text(3,$row[answer4]);
$row[answer5] = text(3,$row[answer5]);
$row[answer6] = text(3,$row[answer6]);
$row[question] = text(3,$row[question]);

$total = $row[vote1]+$row[vote2]+$row[vote3]+$row[vote4]+$row[vote5]+$row[vote6];

if($row[vote1]==0){
$v1 = 0;
}else{
$v1 = (($row[vote1]/$total)*100);
$v1 = sprintf("%01.2f", $v1);
}

if($row[vote2]==0){
$v2 = 0;
}else{
$v2 = (($row[vote2]/$total)*100);
$v2 = sprintf("%01.2f", $v2);
}

if($row[vote3]==0){
$v3 = 0;
}else{
$v3 = (($row[vote3]/$total)*100);
$v3 = sprintf("%01.2f", $v3);
}

if($row[vote4]==0){
$v4 = 0;
}else{
$v4 = (($row[vote4]/$total)*100);
$v4 = sprintf("%01.2f", $v4);
}

if($row[vote5]==0){
$v5 = 0;
}else{
$v5 = (($row[vote5]/$total)*100);
$v5 = sprintf("%01.2f", $v5);
}

if($row[vote6]==0){
$v6 = 0;
}else{
$v6 = (($row[vote6]/$total)*100);
$v6 = sprintf("%01.2f", $v6);
}

if($row[answer1] == ""){ $P1 = ""; }else{ $P1 = "<input class='poll' type='radio' value='vote1' name='answers' id='ww1' checked='checked' /> <label for='ww1'>$row[answer1] ".$v1."%</label><br />"; }
if($row[answer2] == ""){ $P2 = ""; }else{ $P2 = "<input class='poll' type='radio' value='vote2' name='answers' id='ww2' /> <label for='ww2'>$row[answer2] ".$v2."%</label><br />"; }
if($row[answer3] == ""){ $P3 = ""; }else{ $P3 = "<input class='poll' type='radio' value='vote3' name='answers' id='ww3' /> <label for='ww3'>$row[answer3] ".$v3."%</label><br />"; }
if($row[answer4] == ""){ $P4 = ""; }else{ $P4 = "<input class='poll' type='radio' value='vote4' name='answers' id='ww4' /> <label for='ww4'>$row[answer4] ".$v4."%</label><br />"; }
if($row[answer5] == ""){ $P5 = ""; }else{ $P5 = "<input class='poll' type='radio' value='vote5' name='answers' id='ww5' /> <label for='ww5'>$row[answer5] ".$v5."%</label><br />"; }
if($row[answer6] == ""){ $P6 = ""; }else{ $P6 = "<input class='poll' type='radio' value='vote6' name='answers' id='ww6' /> <label for='ww6'>$row[answer6] ".$v6."%</label><br />"; }

$s = "<div>$row[question]</div>
<form name='poll' method='POST' action='$y'>";
$s .= $P1.$P2.$P3.$P4.$P5.$P6;
$s .= "<div align='center'><input type='submit' value='".$LANGAUGE[63]."' name='B1' /></div>
</form>";
}

return $s;
}

$action = $_GET['action'];
if(!isset($action)) $action = "home";

IF ($action=="home"){

tpl_header($LANGAUGE[141]);
bar($namelinks1,$LANGAUGE[141],"","");

table($LANGAUGE[141],poll(),1);

tpl_footer();

}ELSEIF ($action=="vote4pool"){
if(isset($_COOKIE['pollsec']) AND $_COOKIE['pollsec'] > time()){
$x = $LANGAUGE[232];
}else{
$answers = $_POST['answers'];
if ($answers == "vote1"){
$update = mysql_query("UPDATE pool SET vote1=vote1+1 where id='$idpool'");
}elseif ($answers == "vote2"){
$update = mysql_query("UPDATE pool SET vote2=vote2+1 where id='$idpool'");
}elseif ($answers == "vote3"){
$update = mysql_query("UPDATE pool SET vote3=vote3+1 where id='$idpool'");
}elseif ($answers == "vote4"){
$update = mysql_query("UPDATE pool SET vote4=vote4+1 where id='$idpool'");
}elseif ($answers == "vote5"){
$update = mysql_query("UPDATE pool SET vote5=vote5+1 where id='$idpool'");
}elseif ($answers == "vote6"){
$update = mysql_query("UPDATE pool SET vote6=vote6+1 where id='$idpool'");
}

if ($update){
setcookie("pollsec",time()+600,time()+600);
$x = $LANGAUGE[142];
if ($htmlorphp=="1"){
$x .= "<meta http-equiv='Refresh' content='1;URL=poll.html' />";
}else{
$x .= "<meta http-equiv='Refresh' content='1;URL=poll.php?action=home' />";
}
}else{
$x = $LANGAUGE[143];
}
}

tpl_header($LANGAUGE[126]);
bar($namelinks1,$LANGAUGE[126],"","");

table($LANGAUGE[126],$x,1);

tpl_footer();
}
?>