<?php
require_once(dirname(__FILE__) . "/../../adbcon.php");
function check_email($str) 
{ 
    //returns 1 if valid email, 0 if not 
    if(preg_match("/^.+@.+\\..+$/", $str) && strlen($str)>6)
        return 1; 
    else 
        return 0; 
}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>E-mail Subscription</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7">
<link href="style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style></head>

<body>
<table width="100%"  border="0" cellspacing="2" cellpadding="2" class="loginTd">
  <tr>
    <td align="center" class="boxHeaderTd">Polls</td>
  </tr>
  <tr>
    <td><? if(isset($a_id) && $a_id>0){
$visitor_ip=$REMOTE_ADDR;
$timeint=mysql_fetch_array(mysql_query("SELECT * FROM  polls_questions,polls_answers WHERE polls_answers.a_id='$a_id' AND polls_questions.q_id=polls_answers.q_id"));
$q_id=$timeint["q_id"];
$query="SELECT * FROM polls_iplog WHERE ip_numb='$visitor_ip' AND q_id='$timeint[q_id]'";
if($timeint["time_interval"]>0){
$hours=$timeint["time_interval"]*24;
$query .= " AND ontime > DATE_SUB(NOW(),INTERVAL $hours HOUR)";
}
//echo $query;
$result=mysql_query($query) or die(mysql_error());
if(mysql_num_rows(mysql_query($query))>0){?>
      <strong>You are not allowed to vote again</strong>.
  <? }else{
$result=mysql_query("UPDATE polls_iplog SET ontime=NOW() WHERE ip_numb='$visitor_ip' AND q_id='$q_id'") or die(mysql_error());
if(mysql_affected_rows()<1){
$result=mysql_query("INSERT INTO polls_iplog VALUES ('', '$visitor_ip', '$q_id', NOW())") or die(mysql_error());
}
$result=mysql_query("UPDATE polls_answers SET votes=votes+1 WHERE a_id='$a_id'") or die(mysql_error());?>
  <strong>You have successfully voted. Thank you</strong>.
<? }
}
$resultpollview = mysql_query ("SELECT * FROM polls_questions WHERE q_id='$q_id'");
$linepollview=mysql_fetch_array($resultpollview);
?>
<table width="90%" border="0" cellpadding="2" cellspacing="1" class="tabele">
  <tr>
    <td class="darkBlueBold">Poll results</td>
  </tr>
  <tr>
    <td class="leftLink">
      <?=$linepollview["q_en"];?>
      (
      <?=date("d M, Y",strtotime($linepollview["start_active"]));?>
      )
      <?		$queryans = "SELECT * FROM  polls_answers WHERE q_id='$linepollview[q_id]' ORDER BY order_seq ASC";
			$resultans = mysql_query ($queryans);
			$NumberOfFieldsans=mysql_num_rows($resultans);
			if ($NumberOfFieldsans <> 0){
			while($lineanst = mysql_fetch_array($resultans)){
			$total=$total+$lineanst["votes"];
			}
			if($total>0){?>
      <table border="0" width="100%">
        <? $resultans = mysql_query ($queryans);
while($lineans = mysql_fetch_array($resultans)){ 
$votes=sprintf("%02.2f", $lineans["votes"]/$total*100);?>
        <tr>
          <td width="100"><?=$lineans["a_en"]; ?>
              <br>
          </td>
          <td><img src="images/navigation/bar.jpg" width="1" alt="<?=$votes;?>%" height="15"></td>
          <td width="149"><? echo $votes?> %</td>
          <td width="149" align="right"><?=$lineans["votes"]; ?>
            votes</td>
        </tr>
        <? }?>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td align="right"> <br />
            Total: <span class="fat">
            <?=$total;?>
            votes</span> </td>
        </tr>
      </table>
      <? }else{?>
      <br>
      <br>
      <strong>No one has voted yet!!</strong>
      <? }}?></td>
  </tr>
</table>
<br />
<table width="90%" border="0" cellpadding="0" cellspacing="1" class="tabele">
  <tr>
    <td class="darkBlueBold">Other polls</td>
  </tr>
  <tr>
    <td class="poll">
      <? $querypolls = "SELECT * FROM polls_questions WHERE active='yes' AND q_id<>'$q_id' ORDER BY start_active DESC";
$resultpolls = mysql_query ($querypolls) or die (mysql_error());
$NumberOfFieldspolls=mysql_num_rows($resultpolls);
if ($NumberOfFieldspolls <> 0){
while($linepolls = mysql_fetch_array($resultpolls)){?>
      <a href="<?=$PHP_SELF;?>?q_id=<?=$linepolls["q_id"];?>"><? echo $linepolls["q_en"];?></a> (<? echo date("d M, Y",strtotime($linepolls["start_active"]));?>)<br />
      <? }}else{?>
      No old polls exist.
      <?}?>
    </td>
  </tr>
</table></td>
  </tr>
</table>

<table width="100%"  border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td align="center"><a href="javascript:top.close()" class="inlink">Close Window</a> </td>
  </tr>
</table>
</body>
</html>
