<?
if ($_GET['cmd'] == 'logout'){
if (strtolower(substr($_SERVER[HTTP_HOST],0,4)) == 'www.'){
$server='.'.substr($_SERVER[HTTP_HOST],4);
} else {
$server='.'.$_SERVER[HTTP_HOST];
}
setcookie('password','',0,'/',$server);
$_COOKIE['password']='';
header("Location: ./");
exit();
}
include dirname(__FILE__).'/../includes/config.php';
if ((strtoupper($_COOKIE['password']) != strtoupper(md5(ADMIN_PASS))) And ( strtoupper(md5($_POST['pwd'])) != strtoupper(md5(ADMIN_PASS)))){
echo "<center>Please Enter Your Password: <p> <form method=post><input type=password name=pwd size=20><p><input type=submit value='Go &raquo;'></center>";
exit();
}
?> [ <a href='?cmd='>View Entries</a> ] <b>|</b> [ <a href='?cmd=banned'>View Banned 
IP's</a> ] <b>|</b> [ <a href='?cmd=template'>Change Template</a> ] <b>|</b> [ 
<a href='?cmd=fields'>Edit Form Fields</a> ] <b>|</b> [ <a href='cadmin.php?cmd=logout'>Logout 
(all)</a> ]
<p>
<?
if ($_GET['cmd'] == 'edit'){
if ($_POST[inpurl] != ''){
$information=explode('[]', $_POST['orig']);
$byte=$information[0];
if ($_POST[dont_show_email] != 'on') $_POST[dont_show_email]='false';
$dat="{$byte}[]{$_POST[name]}{$byte}{$_POST[email]}{$byte}{$_POST[website]}{$byte}{$_POST[title]}{$byte}{$_POST[dont_show_email]}{$byte}".str_replace("\n","[nl]",$_POST[message])."{$byte}{$_POST[timestamp]}{$byte}{$_POST[ip]}{$byte}{$_POST[inpurl]}";
#echo $dat;
$daa=file_get_contents(dirname(__URL__).'/../data/comments.dat');
$h=fopen(dirname(__URL__).'/../data/comments.dat', "w");
$t1=str_replace($_POST[orig],$dat,$daa);
#echo($t1);
echo "<b>Modifications Complete!</b>";
fwrite($h, $t1);
fclose($h);
}
$information=explode('[]', $_GET['p']);
$byte=$information[0];
$temp=explode($byte, $information[1]);

showForm($temp[3], $temp[0], $temp[1], $temp[2], $temp[5], $temp[6], $temp[8], $temp[7],$temp[4]);

exit();
}
if ($_GET['cmd'] == 'template'){
if ($_POST['save'] != ''){
$h=fopen(dirname(__URL__).'/../data/top.dat', "w");
fwrite($h, stripslashes($_POST[top]));
fclose($h);

$h=fopen(dirname(__URL__).'/../data/body.dat', "w");
fwrite($h, stripslashes($_POST[body]));
fclose($h);
echo "<b>Modifications Complete</b>";
}
$tdata=file_get_contents(dirname(__URL__).'/../data/top.dat');
$data=file_get_contents(dirname(__URL__).'/../data/body.dat');
print <<<e
<form method=post action='?cmd=template'>
Top Of The Page Data:<br><textarea name="top" rows="5" cols="90">$tdata</textarea>
<p>
Data For Each Post:<br>
Variables: <font size="3"><pre>[:title:] - Title / Subject of Post
[:ehb:] - Creates The Beginning Of The Email Hyperlink (If Required By Post)
[:ehe:] - Creates The End Of The Email Hyperlink (If Required By Post)
[:name:] - Name Of Poster
[:homepage:] - Homepage Of Poster
[:datetime:] - Date/Time Of Poster
[:body:] - Message Body
[:htitle:] - Hyphen Is Added Here If A Title Is Present
[:hweb:] - Hyphen Is Added Here If a Homepage Address Is Present
</pre></font><p>
<textarea name="body" rows="7" cols="90">$data</textarea>
<p>
<input type=reset value='Reset'> <input type=submit value='Save' name=save>
</form>
e;
exit();
}
if ($_GET['cmd'] == 'fields'){
if ($_POST['action'] == 'mod'){
$u=0;
$t=0;
if ($_POST['url'] == 'on') $u=1;
if ($_POST['title'] == 'on') $t=1;
$h=fopen(dirname(__URL__).'/../data/fields.dat', "w");
fwrite($h, "$u|$t");
fclose($h);
echo "<b>Changes Applied</b><p>";
}
$data=file_get_contents(dirname(__URL__).'/../data/fields.dat');
$a='';
$b='';
list($a,$b)=explode('|', $data);
if ($a == 1) $a='CHECKED';
if ($b == 1) $b='CHECKED';
print <<<e
<form action="?cmd=fields" method=POST><input type=hidden name=action value=mod>
Display URL/Website Field? <input type=checkbox name=url value=on {$a}><br>
Display Title/Subject Field? <input type=checkbox name=title value=on {$b}><br>
<br>
<input type=submit value="Make Changes">
</form>
e;
exit();
}

if ($_GET['cmd'] == 'delete'){
if ($_GET['p'] != ''){
$filename = dirname(__URL__).'/../data/comments.dat';
$handle = fopen($filename, "r");
$data = fread($handle, filesize($filename));
fclose($handle);
$h=fopen(dirname(__URL__).'/../data/comments.dat', "w");
$t1=str_replace("$_GET[p]\r\n",'',$data);
#$t2=str_replace("\n\n", '', $t1);
fwrite($h, $t1);
fclose($h);
}
}
if ($_GET['cmd'] == 'ban'){
if (!strstr(file_get_contents(dirname(__URL__).'/../data/banned.dat'), $_GET['ip'])){
$h=fopen(dirname(__URL__).'/../data/banned.dat', "a");
fwrite($h, "$_GET[ip]\r\n");
fclose($h);
}
}
if ($_GET['cmd'] == 'banned'){
if ($_GET['cmd2'] == 'unban'){
if ($_GET['ip'] != ''){
$filename = dirname(__URL__).'/../data/banned.dat';
$handle = fopen($filename, "r");
$data = fread($handle, filesize($filename));
fclose($handle);
$h=fopen(dirname(__URL__).'/../data/banned.dat', "w");
$t1=str_replace("$_GET[ip]\r\n",'',$data);
#$t2=str_replace("\n\n", '', $t1);
fwrite($h, $t1);
fclose($h);
}
}

print <<<e
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="361" id="AutoNumber1" height="57">
  <tr>
    <td width="124" height="38">Task</td>
    <td width="237" height="38">IP Address</td>
  </tr>
e;
$banned=file(dirname(__URL__).'/../data/banned.dat');
foreach ($banned as $ban){
print <<<e
  <tr>
    <td width="95" height="19">[<a href='?cmd=banned&cmd2=unban&ip=$ban'>Unban</a>]</td>
    <td width="237" height="19">$ban</td>
  </tr>
e;
}
echo '</table>';
exit();
}

print <<<e
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="1000" id="AutoNumber1" height="57">
  <tr>
 <td>Task?</td>
    <td width="47" height="38">Page</td>
    <td width="193" height="38">Title / Subject</td>
    <td width="133" height="38">Name [email]</td>
    <td width="137" height="38">Homepage</td>
    <td width="136" height="38">Message</td>
    <td width="64" height="100">Date/Time</td>
    <td width="69" height="38">IP Address</td>
  </tr>
e;

$data=file(dirname(__URL__).'/../data/comments.dat');

foreach ($data as $post){
$post=stripslashes($post);
$information=explode('[]', $post);
$byte=$information[0];
$temp=explode($byte, $information[1]);
#print_r($temp); die;
#if ($temp[3] != ''){ $temp[3] .= ' - '; }
$temp[5]=str_replace('[nl]', '<br>', $temp[5]);
unset($esub); unset($eend); unset($webbie);
if ($temp[4] == 'false'){ $esub="<a href=\"mailto:$temp[1]\">"; $eend='</a>'; }
$tstamp=date("j\<\s\u\p\>S\<\/\s\u\p\> F Y - g:ia", $temp[6]);
if ($temp[2] != ''){ if(substr($temp[2],0,4)!='http'){$temp[2]='http://'.$temp[2]; } $webbie=" - <a href='$temp[2]' target='_blank'>Homepage</a>"; }
print <<<eof
  <tr> <Td>[<a href='?cmd=delete&p={$post}'>Delete</A>]<br>
[<a href='?cmd=edit&p={$post}'>Edit</A>]<br>
[<a href='?cmd=ban&ip={$temp[7]}'>Ban IP</A>]</td>
    <td width="47" height="19">{$temp[8]}</td>
    <td width="193" height="19">{$temp[3]}</td>
    <td width="133" height="19">{$temp[0]} [{$temp[1]}]</td>
    <td width="137" height="19">{$temp[2]}</td>
    <td width="136" height="19">{$temp[5]}</td>
    <td width="100" height="19">{$tstamp}</td>
    <td width="69" height="19">{$temp[7]}</td>
  </tr>
eof;
}
function showForm($a,$b, $x, $c,$d,$e,$f,$g,$dse){
if ($dse != 'false'){ $dse=' CHECKED'; } else {$dse='';}
print <<<eee
		<form method=POST action="" onSubmit="get(this.parentNode); return false;" name=f1>
		  <table width="" border="0" cellspacing="1" cellpadding="2" align="center">

		    <tr> 
		      <td width="200" align="right"><font color="red">*</font>Name: 
		        </td>

		      <td width="196" align="left">
		        <input type=text name="name" id="name" value="$b" maxlength=40 size=30>
		        </td>
		    </tr>
		    <tr> 
		      <td width="200" align="right"><font color="red">*</font>Email:</font></td>

		      <td width="196" align="left">
		        <input type="Text" name="email" id="email" size="30" maxlength="70" value="$x">
		        </td>		    <tr> 
		      <td width="200" align="right">Website URL:</font></td>
		      <td width="196" align="left">
		        <input type="Text" name="website" id="website" size="30" maxlength="70" value="$c">
		        </td>
		    </tr>		    <tr> 
		      <td width="200" align="right">Title / Subject:</font></td>

		      <td width="196" align="left">
		        <input type="Text" name="title" id="title" size="30" maxlength="70" value="$a">
		        </td>
</tr>		    <tr> 
		      <td width="200"></td>
		      <td width="196" align="left">
				<input type="checkbox" value="on" name="dont_show_email" id="dont_show_email"{$dse}><font size=2><nobr>Hide my email</nobr></font><br>
		        </td>

		    </tr>
		    <tr> 
		      <td valign="top" width="200" align="right"> 
		        <font color="red">*</font>Comments:
		      </td>
		      <td valign="top" width="196" align="left">
		        <textarea name="message" id="message" cols="40" rows="13" wrap="VIRTUAL">$d</textarea>
		        </td>

		    </tr>
		    <tr> 
		      <td valign="top" width="200" align="right">&nbsp; </td>
		      <td valign="top" width="196">

		        <div align="center"><input type="hidden" name="inpurl" id="inpurl" value="$f"><input type=hidden name=ip value="$g"><input type=hidden name=timestamp value="$e"><input type=hidden name=orig value="$_GET[p]">
		          <input type="submit" name="submit" value="Submit">
		          </div>
		      </td>
		    </tr>

		  </table>
		</form>
eee;
}
?></table>