<?
$page = "delete_entry.php";
include "manager_header.php";

if(isset($_POST['task'])) { $task = $_POST['task']; } else { $task = "none"; }
if(isset($_POST['e_id'])) { $e_id = $_POST['e_id']; } elseif(isset($_GET['e_id'])) { $e_id = $_GET['e_id']; } else { exit(); } 

$entry = mysql_fetch_assoc(mysql_query("SELECT e_id, author_u_id FROM bhost_entries WHERE e_id='$e_id' AND w_id='$weblog_info[w_id]'"));
if(($user_status != "owner" & $user_status != "admin") & ($user_status == "member" & $user_info[u_id] != $entry[author_u_id])) { header("Location: view_entries.php"); exit(); }


if($task == "cancel") {
header("Location: view_entries.php");
exit();
}

if($task == "dodelete") {

mysql_query("DELETE FROM bhost_entries WHERE e_id='$e_id' AND w_id='$weblog_info[w_id]'");
mysql_query("DELETE FROM bhost_comments WHERE e_id='$e_id' AND w_id='$weblog_info[w_id]'");
mysql_query("DELETE FROM bhost_trackbacks WHERE e_id='$e_id' AND w_id='$weblog_info[w_id]'");

// DECREMENT NUM_ENTRIES IN BHOST_USERS
mysql_query("UPDATE bhost_users SET num_entries=num_entries-1 WHERE u_id='$entry[author_u_id]'");
mysql_query("UPDATE bhost_weblogs SET num_entries=num_entries-1 WHERE w_id='$weblog_info[w_id]'");

header("Location: view_entries.php");
exit();
}






if($task == "none") {

// CHECK FOR DUPES
$dupe = mysql_num_rows(mysql_query("SELECT w_id FROM bhost_entries WHERE e_id='$e_id'"));
if($dupe != 1) { exit(); }

echo $head;
echo "
<h2>$delete_entry2</h2>
$delete_entry3
<br><br>

<table cellspacing='0' cellpadding='0'>
<tr>
<form action='delete_entry.php' method='POST'>
<td><input type='submit' class='button' value='$delete_entry1'>&nbsp;</td>
<input type='hidden' name='task' value='dodelete'>
<input type='hidden' name='e_id' value='$e_id'>
</form>
<form action='delete_entry.php' method='POST'>
<td><input type='submit' class='button' value='$delete_entry4'></td>
<input type='hidden' name='task' value='cancel'>
<input type='hidden' name='e_id' value='$e_id'>
</form>
</tr>
</table>
";

echo $foot;
}
?>