<?
#########################################################
# 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.             #
#                                                       #
#########################################################

if( !$conn ) {
include("admin/config.inc.php");
include("admin/functions.inc.php");

eval("dooutput(\"".gettemplate(templatedir,"poll_js")."\");");
}

connect();

 // view polls in admin page

 $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);

		 $pollid = $row[id];

		 $pollquestion   = $row[question];
		 $pollname       = $row[name];

		 $pollbgcolor    = $row[bgcolor];
		 $pollfontsize   = $row[fontsize];
		 $pollfont       = $row[font];
		 $pollfontcolor  = $row[fontcolor];

		 $polltfontsize  = $row[tfontsize];
		 $polltfont      = $row[tfont];
		 $polltfontcolor = $row[tfontcolor];
		 $polltbgcolor   = $row[tbgcolor];


		 $sql_result2 = query("SELECT * FROM choices WHERE pollid = '$row[id]' ORDER BY id");

		 $pollanswers = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">\n";

		 if (isset($sql_result2)) {

			 $numanswers = num_rows($sql_result2);

			 for ($x=0; $x<$numanswers; $x++) {

				 $row2=fetch($sql_result2);

				 if ($x == 0) {
					 $selected = "checked";
					 $dfltval  = $row2[id];
				 } else {
					 $selected = "";
				 }

				 $pollanswers .= "<tr>\n";

				 $pollanswers .= "<td width=\"5\" align=\"center\"><input type=\"radio\" name=\"aid\" value=\"".$row2[id]."\" onClick=\"document.poll".$pollid.".haid".$pollid.".value='".$row2[id]."';\" ".$selected."></td>\n";
				 $pollanswers .= "<td align=\"left\"><font face=\"".$pollfont."\" size=\"".$pollfontsize."\" color=\"".$pollfontcolor."\">".$row2[choice]."</font></td>";

				 $pollanswers .= "</tr>\n";

			 }
		 } else {
			$pollanswers .= "<tr><td align=center>No options have been entered</td></tr>";
		 }

		 $pollanswers .= "</table>\n";

		 if ($numanswers < 1) {
			 $pollanswers = "<font face=\"".$pollfont."\" size=\"".$pollfontsize."\" color=\"".$pollfontcolor."\">You need to add an option.</font>";
		 }

		 eval("dooutput(\"".gettemplate(templatedir,"live_poll")."\");");

	 }

 }

close();

?>
