<?
$page = "admin_entryedit.php";
include "admin_header.php";

if(isset($_POST['task'])) { $task = $_POST['task']; } else { $task = "main"; }
if(isset($_POST['p'])) { $p = (int) $_POST['p']; } elseif(isset($_GET['p'])) { $p = (int) $_GET['p']; } else { $p = 1; }
if(isset($_POST['s'])) { $s = $_POST['s']; } elseif(isset($_GET['s'])) { $s = $_GET['s']; } else { $s = "dd"; }



if($task == "doedit") {
$submit = $_POST['submit'];
$p = $_POST['p'];
$s = $_POST['s'];
$e_id = $_POST['e_id'];
$title = str_replace("<", "&lt;", str_replace(">", "&gt;", str_replace("'", "&#39;", $_POST['title'])));
$contents = $_POST['contents'];
$contents = str_replace("'", "&#39;", $contents);

if($submit == "$admin_entryedit6") {
header("Location: admin_entries.php?p=$p&s=$s");
exit();
}

if($submit == "$admin_entryedit5") {
mysql_query("UPDATE bhost_entries SET title='$title', contents='$contents' WHERE e_id='$e_id'");
header("Location: admin_entries.php?p=$p&s=$s&u=$u");
exit();
}
}




if($task == "main") {
if(isset($_GET['e_id'])) { $e_id = $_GET['e_id']; }
if($e_id == "") { exit(); }

$getentry = mysql_query("SELECT * FROM bhost_entries WHERE e_id='$e_id'");
if(mysql_num_rows($getentry) == 0) { exit(); }
$entry = mysql_fetch_assoc($getentry);
$user_info = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_users WHERE u_id='$entry[u_id]'"));

// GET ORIGINAL ENTRY DATE AND TIME
$thism = cdate("n", $entry[date]);
$thisd = cdate("j", $entry[date]);
$thisy = cdate("Y", $entry[date]);
$thishour = cdate("g", $entry[date]); 
$thismin = cdate("i", $entry[date]); 
$thisampm = cdate("A", $entry[date]);

echo $head;
echo "
<h2>$admin_entryedit1</h2>
$admin_entryedit2
<br><br>
<form action='admin_entryedit.php' method='POST'>
$admin_entryedit3<br>
<input type='text' class='text' size='50' name='title' value='$entry[title]'>
<br><br>
$admin_entryedit4<br>
<textarea name='contents' cols='60' rows='10' style='width: 100%'>$entry[contents]</textarea>
<br>

<table cellpadding='0' cellspacing='0'>
<tr>
<td>
<input type='submit' class='button' name='submit' value='$admin_entryedit5'>
<input type='submit' class='button' name='submit' value='$admin_entryedit6'>
<input type='hidden' name='task' value='doedit'>
<input type='hidden' name='e_id' value='$e_id'>
<input type='hidden' name='p' value='$p'>
<input type='hidden' name='s' value='$s'>
</td>
</form>
</tr>
</table>
";

echo $foot;

}

?>