include('Include/header.inc');
$strTitle = "$cfgCompany Weekly Poll";
?>
=$strTitle?>
if($poll = mysql_fetch_assoc(mysql_query("select *, date_format(datePollStart, '%D %M %Y') as datePollStart, date_format(datePollEnd, '%D %M %Y') as datePollEnd, (select count(*) from votes where votes.iPollId = polls.iPollId) as iTotalVotes from polls where now() between datePollStart and datePollEnd order by datePollEnd limit 1")))
{
$show_form = true;
$answers = preg_split('/[\r\n\|]+/', $poll[lstPollAnswers], null, PREG_SPLIT_NO_EMPTY);
if($_POST[action] == 'Cast Vote')
{
if($vote = mysql_fetch_assoc(mysql_query("select * from votes where iPollId = '$poll[iPollId]' and ipVoteIp = '" . mysql_escape_string($_SERVER[REMOTE_ADDR]) . "'")))
{
$show_form = false;
?>
Sorry, our records indicate that you have already voted "=$vote[strVoteAnswer]?>" on this poll from IP =$vote[ipVoteIp]?>. You cannot vote more than once on the same poll.
}
elseif(!in_array($_POST[answer], $answers))
{
?>
Please select a valid answer to cast your vote.
}
elseif(mysql_query("insert into votes set iPollId = '$poll[iPollId]', strVoteAnswer = '" . mysql_escape_string($_POST[answer]) . "', ipVoteIp = '" . mysql_escape_string($_SERVER[REMOTE_ADDR]) . "'") && !mysql_errno())
{
$show_form = false;
?>
Thanks for voting "=$_POST[answer]?>" on this poll.
}
else
{
?>
An unknown error occurred while trying to record your vote. Please try again.
}
}
?>
=$poll[strPollQuestion]?>
=$poll[datePollStart]?> - =$poll[datePollEnd]?>
if($show_form)
{
?>
}
if($poll = mysql_fetch_assoc(mysql_query("select *, date_format(datePollStart, '%D %M %Y') as datePollStart, date_format(datePollEnd, '%D %M %Y') as datePollEnd, (select count(*) from votes where votes.iPollId = polls.iPollId) as iTotalVotes from polls where now() between datePollStart and datePollEnd order by datePollEnd limit 1")))
{
?>
Current Result
$colors = array( "#ADD8E6","#E6D7AE","#E6AEBC","#AEE6BB","#BBAEE6"); shuffle($colors);
for($i = 0; $i < count($answers); $i++)
{
$answer = array('answer' => $answers[$i]);
$result = mysql_query("select count(*) as iVoteCount from votes where iPollId ='$poll[iPollId]' and strVoteAnswer = '" . mysql_escape_string($answer[answer]) . "' group by iPollId");
if($item = mysql_fetch_assoc($result))
foreach($item as $k=>$v)
$answer[$k] = $v;
$answer[iVoteCount] = intval($answer[iVoteCount]);
$answer[iVotePercentage] = $poll[iTotalVotes] ? round($answer[iVoteCount] / $poll[iTotalVotes] * 100, 0) : 0;
?>
=$answer[answer]?>
=$answer[iVotePercentage]?>%
}
?>
}
}
else
{
?>
No active poll was found.
}
?>
Poll Archive
include('Include/footer.inc');
?>