<?
include "header.php";

//SET PRIVACY SETTINGS
if($is_admin_logged_in == "yes") {
$privacy = "AND (privacy='0' OR privacy='1' OR privacy='2' OR privacy='3')";
} elseif($user_status == "owner" | $user_status == "admin" | $user_status == "member" | $user_status == "site_owner") {
$privacy = "AND (privacy='0' OR privacy='1' OR privacy='2' OR privacy='3')";
} elseif($owner_group_info[allow_friends] == "1" & $is_logged_in == "yes" & $user_status == "guest" & $is_friend == "yes") {
$privacy = "AND (privacy='1' OR privacy='2' OR privacy='3')";
} elseif($is_logged_in == "yes") {
$privacy = "AND (privacy='2' OR privacy='3')";
} else {
$privacy = "AND privacy='3'";
}

// IF PRIVACY FEATURE IS DISABLED BY ADMIN
if($owner_group_info[allow_privacy] != 1) {
$privacy = "AND (privacy='0' OR privacy='1' OR privacy='2' OR privacy='3')";
}

if(isset($_POST['task'])) { $task = $_POST['task']; } elseif(isset($_GET['task'])) { $task = $_GET['task']; } else { $task = "main"; }
if(isset($_POST['e_id'])) { $e_id = $_POST['e_id']; } elseif(isset($_GET['e_id'])) { $e_id = $_GET['e_id']; } else { exit(); }
if(isset($_POST['c_id'])) { $c_id = $_POST['c_id']; } elseif(isset($_GET['c_id'])) { $c_id = $_GET['c_id']; } else { exit(); }
if(mysql_num_rows(mysql_query("SELECT e_id FROM bhost_entries WHERE e_id='$e_id' AND w_id='$weblog_info[w_id]' $privacy")) != 1) { exit(); }
if(mysql_num_rows(mysql_query("SELECT c_id FROM bhost_comments WHERE c_id='$c_id' AND e_id='$e_id' AND w_id='$weblog_info[w_id]'")) != 1) { exit(); }
$entry_info = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_entries WHERE e_id='$e_id' AND w_id='$weblog_info[w_id]' $privacy"));
$comment_info = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_comments WHERE c_id='$c_id' AND e_id='$e_id' AND w_id='$weblog_info[w_id]'"));

$is_error = "no";
$error = "";
if($owner_group_info[allow_friends] == "1" & $weblog_info[show_comments] == "1" & ($user_status != "owner" & $user_status != "admin" & $user_status != "member" & $user_status != "site_owner") & $is_admin_logged_in != "yes" & ($is_logged_in == "no" | ($user_status == "guest" & $is_friend != "yes"))) {
  $is_error = "yes";
  $error = "<b>$delete_comment1</b><br>$delete_comment2 <a href='login.php?w=$weblog_info[weblog]&e_id=$e_id&c_id=$c_id&ref=4'>$delete_comment3</a>.";
  $icon = "./images/key.gif";
} elseif($weblog_info[show_comments] == "2" & $is_logged_in == "no" & $is_admin_logged_in != "yes") {
  $is_error = "yes";
  $error = "<b>$delete_comment1</b><br>$delete_comment4 <a href='login.php?w=$weblog_info[weblog]&e_id=$e_id&c_id=$c_id&ref=4'>$delete_comment3</a>.";
  $icon = "./images/key.gif";
} elseif($entry_info[comments] == "0") {
  $is_error = "yes";
  $error = "<b>$delete_comment5</b><br>$delete_comment6";
  $icon = "./images/error.gif";
} elseif($owner_group_info[allow_comments] == "0" | $weblog_info[show_comments] == "0") { 
  $is_error = "yes"; 
  $error = "<b>$delete_comment5</b><br>$delete_comment7"; 
  $icon = "./images/error.gif";
} elseif(($weblog_info[manage_comments] == "0" | $weblog_info[manage_comments] == "1") & ($user_status != "owner" & $user_status != "admin" & $user_status != "member" & $user_status != "site_owner") & $is_admin_logged_in != "yes") {
  $is_error = "yes"; 
  $error = "<b>$delete_comment8</b><br>$delete_comment9"; 
  $icon = "./images/error.gif";
} elseif($is_logged_in != "yes" & $is_admin_logged_in != "yes") {
  $is_error = "yes";
  $error = "<b>$delete_comment1</b><br>$delete_comment4 <a href='login.php?w=$weblog_info[weblog]&e_id=$e_id&c_id=$c_id&ref=4'>$delete_comment3</a>.";
  $icon = "./images/key.gif";
} elseif(($user_info[username] != $comment_info[username] | $user_info[u_id] != $comment_info[author_u_id]) & ($user_status != "owner" & $user_status != "admin" & $user_status != "member" & $user_status != "site_owner") & $is_admin_logged_in != "yes") {
  $is_error = "yes"; 
  $error = "<b>$delete_comment1</b><br>$delete_comment10 <a href='login.php?w=$weblog_info[weblog]&e_id=$e_id&c_id=$c_id&ref=4'>$delete_comment3</a>"; 
  $icon = "./images/key.gif";
}


if($is_error == "yes") {
echo $head;
echo "
<div class='float' style='padding-right: 2px;'><img src='$icon' border='0'></div>
<div>$error</div>
";
echo $foot;
exit();
}



if($task == "cancel") {
$url = url("entry", "$weblog_info[weblog]", "", "$e_id", "", "", "#c$c_id");
header("Location: $url");
exit();
}


if($task == "dodelete") {
mysql_query("DELETE FROM bhost_comments WHERE c_id='$c_id' AND e_id='$e_id' AND w_id='$weblog_info[w_id]'");
$url = url("entry", "$weblog_info[weblog]", "", "$e_id");
header("Location: $url");
exit();
}




echo $head;
echo "
<h2>$delete_comment11</h2>
$delete_comment12
<br><br>

<table cellpadding='0' cellspacing='0'>
<tr>
<form action='delete_comment.php' method='POST'>
<td>
<input type='submit' class='button' value='$delete_comment13'>&nbsp;
<input type='hidden' name='task' value='dodelete'>
<input type='hidden' name='w' value='$weblog_info[weblog]'>
<input type='hidden' name='e_id' value='$e_id'>
<input type='hidden' name='c_id' value='$c_id'>
</td>
</form>
<form action='delete_comment.php' method='POST'>
<td>
<input type='submit' class='button' value='$delete_comment14'>
<input type='hidden' name='task' value='cancel'>
<input type='hidden' name='w' value='$weblog_info[weblog]'>
<input type='hidden' name='e_id' value='$e_id'>
<input type='hidden' name='c_id' value='$c_id'>
</td>
</form>
</tr>
</table>
";
echo $foot;
?>