<? "html.inc"; ?>
Complete code:
<?
"html.inc";
$poll = "poll.dat";
$data = "";
$cfile = "";
$dfile = "";
global $view;
global $page;
global $results;
global $topic;
global $ans;
global $email;
global $guest;
global $option1;
global $option2;
global $option3;
global $question;
if (! ($view) )
$view = "view";
$afile = file($poll);
if (! ($page) )
$page = 1;
if (! ($results) )
$results = 5;
$Count_back_value1 = $page * $results;
$nxt_page = $page + 1;
$lst_page = $page - 1;
if ($view == "add")
{
if (! ($email && $guest && $option1 && $option2 && $option3 && $question) )
{
$title = "Submit A New Question";
$data = <<<EOT
<form action="poll.php" name="poll" onSubmit="return poll.php">
<table align="center" cellspacing="0" cellpadding="0" border="0">
<tr>
<td align="right" valign="top">Name :</td>
<td valign="top">
<input type="text" name="guest" size="30" class="textbox" id="input">
<input name="view" id="input" type="hidden" value="add">
</td>
</tr>
<tr>
<td align="right" valign="top">Email :</td>
<td valign="top"><input type="text" name="email" size="30" class="textbox" id="input"></td>
</tr>
<tr>
<td align="right" valign="top">Question :</td>
<td valign="top"><input type="text" name="question" size="30" class="textbox" id="input"></td>
</tr>
<tr>
<td align="right" valign="top">Option 1 :</td>
<td valign="top"><input type="text" name="option1" size="30" class="textbox" id="input"></td>
</tr>
<tr>
<td align="right" valign="top">Option 2 :</td>
<td valign="top"><input type="text" name="option2" size="30" class="textbox" id="input"></td>
</tr>
<tr>
<td align="right" valign="top">Option 3 :</td>
<td valign="top"><input type="text" name="option3" size="30" class="textbox" id="input"></td>
</tr>
<tr>
<td align="right" valign="top"></td>
<td valign="top">
<input type="Submit" name="submit" value="Submit" class="button">
<input type="Reset" name="reset" value="Reset" class="button"><br>
<center>
All fields are Required
</center>
</td>
</tr>
</table>
</form>
EOT;
}
else
{
$afile = file($poll);
$title = "Posting Compleat";
$data = "Thank You For Wanting Peoples Oppinions";
$posted_on = date('D F dS Y');
if (file_exists($poll))
{
$pollentry = "\n$guest|$email|$question|$option1|$option2|$option3|$posted_on|0|0|0";
$file = fopen($poll,"a");
fputs($file,$pollentry);
if(flock($file,3))
fclose($file);
else
$data = "Error: couldn't close file";
}
}
}
else if ($view == "view")
{
$title = "Viewing The Questions";
if (file_exists($poll))
{
if ((count($afile)) > $Count_back_value1+1)
{
$Count_back_value2 = $Count_back_value1-$results+1;
$Count_to = count($afile)-$Count_back_value1-1;
for($num = count($afile)-$Count_back_value2; $num > $Count_to; $num--)
{
$pt7 = "0";
$pt8 = "0";
$pt9 = "0";
$bfile = explode("|",$afile[$num]);
$Tmp = $data;
$pt = $bfile[7] + $bfile[8] + $bfile[9];
if ($pt)
{
$pt7 = "100" / $pt $bfile[7];
$pt8 = "100" / $pt $bfile[8];
$pt9 = "100" / $pt $bfile[9];
}
$data = <<<EOT
<table border="0" cellpadding="0" cellspacing="2" width="85%">
<tr>
<td width="10%" align="right" valign="top">
Question :<br>
By :
</td>
<td width="50%" valign="top">
$bfile[2]<br>
$bfile[0]
</td>
</tr>
<tr>
<td width="10%" align="right" valign="top">
$bfile[3] :<br>
$bfile[4] :<br>
$bfile[5] :
</td>
<td width="50%" valign="top">
$bfile[7] votes - $pt7 % - <a href="poll.php?view=vote&topic=$num&ans=7">Vote</a><br>
$bfile[8] votes - $pt8 % - <a href="poll.php?view=vote&topic=$num&ans=8">Vote</a><br>
$bfile[9] votes - $pt9 % - <a href="poll.php?view=vote&topic=$num&ans=9">Vote</a>
</td>
</tr>
</table><br>
EOT;
$Tmp2 = $data;
$data = $Tmp . $Tmp2;
}
$Tmp = $data;
if ($page < 2)
$data = $Tmp . "<br><a>Previous Page</a> - \n<a href='poll.php?view=view&page=$nxt_page&results=5'>Next Page</a>";
else if ($page > 1)
$data = $Tmp . "<br><a href='poll.php?view=view&page=$lst_page&results=5'>Previous Page</a> - \n<a href='poll.php?view=view&page=$nxt_page&results=5'>Next Page</a>";
}
else
{
$Count_to = count($afile) - $Count_back_value1 + $results - 1;
for($num = $Count_to; $num > 0; $num--)
{
$pt7 = "0";
$pt8 = "0";
$pt9 = "0";
$bfile = explode("|",$afile[$num]);
$Tmp = $data;
$pt = $bfile[7] + $bfile[8] + $bfile[9];
if ($pt)
{
$pt7 = "100" / $pt $bfile[7];
$pt8 = "100" / $pt $bfile[8];
$pt9 = "100" / $pt $bfile[9];
}
$data = <<<EOT
<table border="0" cellpadding="0" cellspacing="2" width="85%">
<tr>
<td width="10%" align="right" valign="top">
Question :<br>
By :
</td>
<td width="50%" valign="top">
$bfile[2]<br>
$bfile[0]
</td>
</tr>
<tr>
<td width="10%" align="right" valign="top">
$bfile[3] :<br>
$bfile[4] :<br>
$bfile[5] :
</td>
<td width="50%" valign="top">
$bfile[7] votes - $pt7 % - <a href="poll.php?view=vote&topic=$num&ans=7">Vote</a><br>
$bfile[8] votes - $pt8 % - <a href="poll.php?view=vote&topic=$num&ans=8">Vote</a><br>
$bfile[9] votes - $pt9 % - <a href="poll.php?view=vote&topic=$num&ans=9">Vote</a>
</td>
</tr>
</table><br>
EOT;
$Tmp2 = $data;
$data = $Tmp . $Tmp2;
}
$Tmp = $data;
if ($page < 2)
$data = $Tmp . "<br><a>Previous Page</a> - \n<a>Next Page</a>";
else if ($page > 1)
$data = $Tmp . "<br><a href='poll.php?view=view&page=$lst_page&results=5'>Previous Page</a> - \n<a>Next Page</a>";
}
}
else
{
$data = "Error: blank file";
}
}
else if ($view == "vote")
{
$title = "Voting Compleat";
$data = "Thank You For Voting";
if (file_exists($poll))
{
$afile = file($poll);
$bfile = explode("|",$afile[$topic]);
$bfile[$ans]++;
$pollentry = "$bfile[0]|$bfile[1]|$bfile[2]|$bfile[3]|$bfile[4]|$bfile[5]|$bfile[6]|$bfile[7]|$bfile[8]|$bfile[9]";
for ($i = 0; $i < $topic; $i++)
{
$Tmp = $cfile;
$cfile = $Tmp . $afile[$i];
}
for ($i = $topic+1; $i < count($afile); $i++)
{
$Tmp = $dfile;
$dfile = $Tmp . $afile[$i];
}
$file = fopen($poll,"r+");
fwrite($file,$cfile . $pollentry . $dfile);
if(flock($file,3))
fclose($file);
else
$data = "Error: couldn't close file";
}
}
echo $above_title;
echo "\n<TITLE>" . $title . "</TITLE>\n";
echo $below_title;
echo "\n <div class='end'>" . $title . "</div>\n";
echo "<center>\n<a href='poll.php?view=view&results=5&page=1'>View the polls</a> - <a href='poll.php?view=add'>Add a question</a><br>\n</center>";
echo $data;
echo $base_html;
?>