<?
// 删除评论内容
include_once("./_common.php");

if ($is_admin)
{
    if (!($token && get_session("ss_delete_token") == $token)) 
        alert("数据认证错误！禁止操作！");
}

// 4.1
@include_once("$board_skin_path/delete_comment.head.skin.php");

$write = sql_fetch(" select * from $write_table where wr_id = '$comment_id' ");

if (!$write[wr_id] || !$write[wr_is_comment])
    alert("评论已被删除或不存在");

if ($is_admin == "super") // 管理员认证
    ;
else if ($is_admin == "group") { // 版块管理员认证
    $mb = get_member($write[mb_id]);
    if ($member[mb_id] == $group[gr_admin]) { // 检查是否属于自己管理
        if ($member[mb_level] >= $mb[mb_level]) // 检查等级
            ;
        else
            alert("管理权限错误，不能进行管理操作 Code:1000");
    } else
        alert("管理权限错误，不能进行管理操作 Code:1001");
} else if ($is_admin == "board") { // 如果是管理员
    $mb = get_member($write[mb_id]);
    if ($member[mb_id] == $board[bo_admin]) { // 检查权限
        if ($member[mb_level] >= $mb[mb_level]) // 检查等级
            ;
        else
            alert("管理权限错误，不能进行管理操作 Code:1001");
    } else
        alert("管理权限错误，不能进行管理操作 Code:1000");
} else if ($member[mb_id]) {
    if ($member[mb_id] != $write[mb_id])
        alert("不能删除他人文章");
} else {
    if (sql_password($wr_password) != $write[wr_password])
        alert("密码错误，删除失败！");
}

$len = strlen($write[wr_comment_reply]);
if ($len < 0) $len = 0; 
$comment_reply = substr($write[wr_comment_reply], 0, $len);

$sql = " select count(*) as cnt from $write_table
          where wr_comment_reply like '$comment_reply%'
            and wr_id <> '$comment_id'
            and wr_parent = '$write[wr_parent]'
            and wr_comment = '$write[wr_comment]' 
            and wr_is_comment = 1 ";
$row = sql_fetch($sql);
if ($row[cnt] && !$is_admin)
    alert("此内容已有相关引用评论内容，不能被删除");

// 删除评论
if (!delete_point($write[mb_id], $bo_table, $comment_id, '评论'))
    insert_point($write[mb_id], $board[bo_comment_point] * (-1), "$board[bo_subject] {$write[wr_parent]}-{$comment_id} 评论删除");

// 评论删除
sql_query(" delete from $write_table where wr_id = '$comment_id' ");

// 重新获取文章时间.
$sql = " select max(wr_datetime) as wr_last from $write_table where wr_parent = '$write[wr_parent]' ";
$row = sql_fetch($sql);
                                      
// 减少评论计数
sql_query(" update $write_table set wr_comment = wr_comment - 1, wr_last = '$row[wr_last]' where wr_id = '$write[wr_parent]' ");

// 计数
sql_query(" update $g4[board_table] set bo_count_comment = bo_count_comment - 1 where bo_table = '$bo_table' ");

// 新评论数据删除
sql_query(" delete from $g4[board_new_table] where bo_table = '$bo_table' and wr_id = '$comment_id' ");

// 执行用户代码
@include_once("$board_skin_path/delete_comment.skin.php");
// 4.1
@include_once("$board_skin_path/delete_comment.tail.skin.php");

goto_url("./board.php?bo_table=$bo_table&wr_id=$write[wr_parent]&cwin=$cwin&page=$page" . $qstr);
?>
