<?
include "header.php";

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['tb_id'])) { $tb_id = $_POST['tb_id']; } elseif(isset($_GET['tb_id'])) { $tb_id = $_GET['tb_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]'")) != 1) { exit(); }
if(mysql_num_rows(mysql_query("SELECT tb_id FROM bhost_trackbacks WHERE tb_id='$tb_id' AND e_id='$e_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]'"));
$trackback_info = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_trackbacks WHERE tb_id='$tb_id' AND e_id='$e_id'"));

$is_error = "no";
$error = "";
if($entry_info[trackbacks] == "0") {
  $is_error = "yes";
  $error = "<b>$delete_trackback5</b><br>$delete_trackback6";
  $icon = "./images/error.gif";
} elseif($owner_group_info[allow_trackbacks] == "0") { 
  $is_error = "yes"; 
  $error = "<b>$delete_trackback5</b><br>$delete_trackback7"; 
  $icon = "./images/error.gif";
} elseif(($is_logged_in != "yes" & $is_admin_logged_in != "yes") | (($user_status != "owner" & $user_status != "admin" & $user_status != "member" & $user_status != "site_owner") & $is_admin_logged_in != "yes")) {
  $is_error = "yes"; 
  $error = "<b>$delete_trackback1</b><br>$delete_trackback4"; 
  $icon = "./images/error.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", "", "", "#tb$tb_id");
header("Location: $url");
exit();
}


if($task == "dodelete") {
 if($_POST['blacklist'] == "1") { 
  $trackback_info[tb_url] = eregi_replace("www.", "http://", $trackback_info[tb_url]);
  $trackback_info[tb_url] = eregi_replace("http://http://", "http://", $trackback_info[tb_url]);
  $parsed_tb_url = parse_url($trackback_info[tb_url]);
  $tb_domain = $parsed_tb_url[host];
  $tb_blacklist = trim($weblog_info[tb_blacklist]." ".$tb_domain);
  mysql_query("UPDATE bhost_weblogs SET tb_blacklist='$tb_blacklist' WHERE w_id='$weblog_info[w_id]'");
 }
mysql_query("DELETE FROM bhost_trackbacks WHERE tb_id='$tb_id' AND e_id='$e_id'");
$url = url("entry", "$weblog_info[weblog]", "", "$e_id");
header("Location: $url");
exit();
}




echo $head;
echo "
<h2>$delete_trackback8</h2>
$delete_trackback9<br>
<form action='delete_trackback.php' method='POST'>
";

$is_spam = "no";
$trackback_info[tb_url] = eregi_replace("www.", "http://", $trackback_info[tb_url]);
$trackback_info[tb_url] = eregi_replace("http://http://", "http://", $trackback_info[tb_url]);
$parsed_tb_url = parse_url($trackback_info[tb_url]);
$tb_domain = $parsed_tb_url[host];
if(str_replace(" ", "", $weblog_info[tb_blacklist]) != "") {
$blacklist = explode(" ", trim($weblog_info[tb_blacklist]));
for($s=0;$s<count($blacklist);$s++) {
if(strpos($trackback_info[tb_url], $blacklist[$s]) === FALSE) {
  $is_spam = "no";
} else {
  $is_spam = "yes";
}}}

if($is_spam == "yes") {
echo "$delete_trackback11 <input type='hidden' name='blacklist' value='0'><br><br>";
} else {
echo "
$delete_trackback12<br><br>
<table cellpadding='0' cellspacing='0'>
<tr>
<td><input type='checkbox' name='blacklist' value='1'>&nbsp;</td><td>$tb_domain &nbsp;</td></tr>
</table>
<br><br>
";
}

echo "
<table cellpadding='0' cellspacing='0'>
<tr>
<td>
<input type='submit' class='button' value='$delete_trackback10'>&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='tb_id' value='$tb_id'>
</td>
</form>
<form action='delete_trackback.php' method='POST'>
<td>
<input type='submit' class='button' value='$delete_trackback2'>
<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='tb_id' value='$tb_id'>
</td>
</form>
</tr>
</table>
";
echo $foot;
?>