<?
#########################################################
# Simple Poll                                           #
#########################################################
#                                                       #
# Author: CodeMunkyX                                    #
#                                                       #
# This script and all included functions, images,       #
# and documentation are copyright 2003                  #
# free-php.net (http://free-php.net) unless             #
# otherwise stated in the module.                       #
#                                                       #
# Any copying, distribution, modification with          #
# intent to distribute as new code will result          #
# in immediate loss of your rights to use this          #
# program as well as possible legal action.             #
#                                                       #
#########################################################

include("admin/config.inc.php");
include("admin/functions.inc.php");

$pollid      = $_REQUEST['pollid'];
$aid         = $_REQUEST['aid'];

if ($_COOKIE[simplepoll.$pollid] == '') {
 // This cookie is good for an hour
 setcookie("simplepoll$pollid", "$pollid", time() + 3600);
 // setcookie("simplepoll$pollid", "$pollid");
 }
  else {
	 header("Location: results.php?pollid=$pollid");
	 exit;
}

connect();

$sql_result = query("SELECT * FROM poll WHERE id = '$pollid'");


if (isset($sql_result)) {

 $numpolls = num_rows($sql_result);

 for ($i=0; $i<$numpolls; $i++) {

	 $row=fetch($sql_result);

	 $numpollvotes = $row[votes] + 1;
    $pollquestion = $row[question];
    $pollname     = $row[name];
 }
}

$sql_result = query("SELECT * FROM choices WHERE (id='$aid' AND pollid='$pollid')");


if (isset($sql_result)) {

 $numpolls = num_rows($sql_result);

 for ($i=0; $i<$numpolls; $i++) {

	 $row=fetch($sql_result);

	 $numchoicevotes = $row[votes] + 1;

 }
}

$pollvote   = query("UPDATE poll SET votes='$numpollvotes' WHERE id='$pollid'");
$choicevote = query("UPDATE choices SET votes='$numchoicevotes' WHERE (id='$aid' AND pollid='$pollid')");

close();

eval("dooutput(\"".gettemplate(templatedir,"poll_vote")."\");");

?>