<?php

function GraphValue($hits,$hitstotal,$colour)
{
   $colourbars = array('blue','pink','yellow','darkgreen','purple','gold','green','brown','orange','aqua','grey','red');

   $colourval = ($colour % count($colourbars));
   $graphvalue = '';
   $percentage = ceil(($hits / $hitstotal) * 100);
   if (($hitstotal > 0) && ($percentage > 0)) {
      $imagelength = $percentage * $GLOBALS["ScreenWidthMultiplier"];
      $graphvalue='<IMG SRC="'.$GLOBALS["rootdp"].$GLOBALS["icon_home"].'graphbar_'.$colourbars[$colourval].'.gif" HEIGHT="10" WIDTH="'.$imagelength.'">';
   }
   return $graphvalue;
} // function GraphValue()


function RegisterVote($poll,$vote)
{
	$sqlString = "INSERT INTO ".$GLOBALS["scTable"]."results (userid,pollid,pollresult) VALUES('".$GLOBALS["PollName"]."', '".$poll."', '".$vote."')";
	$result = dbExecute($sqlString,true);

	$sqlString = "UPDATE ".$GLOBALS["scTable"]."options SET optioncount=optioncount+1 WHERE pollid='".$poll."' AND polloptionid='".$vote."'";
	$result = dbExecute($sqlString,true);
//	dbCommit();
} // function RegisterVote()


function CompleteVote($poll)
{
	$sqlString = "UPDATE ".$GLOBALS["scTable"]." SET pollvotes=pollvotes+1 WHERE pollid='".$poll."'";
	$result = dbExecute($sqlString,true);
//	dbCommit();
} // function CompleteVote()


function GetPollName()
{
   global $HTTP_COOKIE_VARS, $EZ_SESSION_VARS;

   $PollName = $GLOBALS["ezSID"];
//   $PollName = '';
   if ($HTTP_COOKIE_VARS["PollName"] != '') {
      $PollName = $HTTP_COOKIE_VARS["PollName"];
      if (substr($PollName,0,1) != '^') {
         // Somebody is trying to fiddle a cookie
         $PollName = '';
      }
   } elseif ($HTTP_COOKIE_VARS["UserIdCookie"] != '') {
      $strQuery = "SELECT login from ".$GLOBALS["eztbAuthors"]." WHERE login='".$HTTP_COOKIE_VARS["UserIdCookie"]."'";
      $result = dbRetrieve($strQuery,true,0,0);
      $rs     = dbFetch($result);
      if ($rs["login"] == $HTTP_COOKIE_VARS["UserIdCookie"]) { $PollName = $rs["login"]; }
      dbFreeResult($result);
   } elseif (($EZ_SESSION_VARS["UserID"] != '') && ($EZ_SESSION_VARS["UserID"] != 0)) {
      $strQuery = "SELECT authorid,login from ".$GLOBALS["eztbAuthors"]." WHERE authorid='".$EZ_SESSION_VARS["UserID"]."'";
      $result = dbRetrieve($strQuery,true,0,0);
      $rs     = dbFetch($result);
      if ($rs["authorid"] == $EZ_SESSION_VARS["UserID"]) { $PollName = $rs["login"]; }
      dbFreeResult($result);
   }
   if ($PollName == $GLOBALS["ezSID"]) {
      $PollName = substr_replace($PollName,'^',0,1);
      // Timer values for cookies
      // 15 Minutes	= 900;
      // 1 Hour	= 3600;
      // 2 Hours	= 7200;
      // 6 Hours	= 21600;
      // 1 Day	= 86400;
      // 1 Year	= 31622400;
      setcookie ("PollName", $PollName, time()+316224000);
   }
   return $PollName;
} // function GetPollName()


?>
