Location: PHPKode > scripts > Simple PHP Poll > poll_admin.php
<?php
extract($HTTP_GET_VARS);
extract($HTTP_POST_VARS);
$RESULT_FILE_NAME = "poll_data.txt";
$password = "administrator"; //Login Password
$cookie = $HTTP_COOKIE_VARS["login_cookie"];
if($action!="logout"){
$pass_info=explode(";",$cookie);
$s=$pass_info[0];
}
if ($action==""){
?><center><table align=middle><td align=left width=20%>
<tr><td height="27" colspan="2"><FONT SIZE="4" COLOR="#000000">:: SIMPLE PHP POLL ::</FONT></td><tr><td>Password Required (Default is: administrator)</td></tr><tr><form method=post action="?action=login"><td>Password:</td><td><input type=password name=pass>&nbsp;<input type=submit value=Submit></td></tr></form></table></center>
<?php
}
function pmenu(){
?>
<table align=center width=100%><tr><td><A HREF="?action=edit&filename=question.txt">Edit Poll Question</A></td><td><A HREF="?action=edit&filename=ans.txt">Edit Poll Answers</A></td><td><A HREF="?action=cip_log">Clear IP Logs</A></td><td><A HREF="poll_admin.php?action=logout">Logout</A></td></tr></table>
<?php
}
if ($action=="login"){
if ($pass==$password){
$cookie_set=setCookie("login_cookie","$password;",time() + 850);
echo "Successfully Loged In<br><hr>";
pmenu();
}else {echo "Invalid Passsword";}
}
if ($action=="edit" && $s==$password){
$fd = fopen ($filename, "r"); 
$stuff = fread ($fd, filesize ($filename)); 
fclose ($fd);
if($filename == "ans.txt" ){
$text="<div align=center><FONT COLOR=red>Note: Poll result will be set to zero votes</FONT></div>";
}
?>
<center>
<form method="post" action="?action=temp2&fil=<?php echo $filename ?>">
<table width="" border="1" bordercolor="#00000" cellpadding="0" cellspacing="0">
<tr> 
<td width="86%" align=middle> 
<textarea name="cont" cols="45" rows="8"><?php echo $stuff ?></textarea>
</td>
</tr>
<td><?php echo "$text"; ?></td>
<tr> 
<td width="86%" align=middle>&nbsp; 
<input type="submit" name="Submit" value="Save">&nbsp;<input type="button" name="Cancel" value="Cancel" onclick="javascript: history.back(1)">
</td>
</tr>
<tr> 
</tr>
</table></center>
</form>
<?php
}elseif($action=="edit" && $s!=$password){
echo "Please Login";
}
if ($action=="temp2" && $s==$password) {
$cont=stripslashes($cont);
$fp = fopen($fil, "w");
fputs($fp, $cont);
fclose($fp);
if ($fil=="ans.txt"){
$fp = fopen($RESULT_FILE_NAME, "w");
$mplsr = file("ans.txt");
for($x=0;$x<sizeof($mplsr);$x++) {
fputs($fp, "0");
fputs($fp, "\n");
}
fclose($fp);
}
?>
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tr>
<td align=middle><font size="2">Changes saved<hr><?php pmenu(); ?></font></td>
</tr>
</table>
<?php
}elseif($action=="temp2" && $s!=$password){
echo "Please Login";
}
if ($action=="cip_log" && $s==$password) {
$fp = fopen("poll_data.txt", "w");
fputs($fp, "");
fclose($fp);
echo "<font color=blue face=arial>IP Logs have been cleared.</font><hr>";
pmenu();
}elseif($action=="cip_log" && $s!=$password){
echo "Please Login";
}
if($action=="logout"){
$cookie_set=setCookie("login_cookie","0;",time() - 850);
$pass_info=explode(";",$cookie);
$s=$pass_info[0];
echo "You are loged out.";
}
echo "<HR><CENTER><font face=arial>Powered By: <a href='http://www.scriptsez.net' target='_new'>Simple PHP Poll</a></font></CENTER>";
?>
Return current item: Simple PHP Poll