<?php 

//禁止直接访问
!defined('IN_SYSTEM') && exit('Access Denied');

if(isset($_GET['id'])){
	$DelMid = $_GET['id'];	//接收留言参数
	//过滤处理
	$DelMid = ToUtf8($DelMid);	//转换为UTF8编码
	$DelMid = DeleteHtml($DelMid);	//去除HTML标签
	$DelMid = strip_tags($DelMid);	//第二道过滤去除标签
	$DelMid = trimall($DelMid);		//去除空格
	//安全验证
	if(check_zzs($DelMid) == true){
		//来路判断，如果是回收站过来的请求，则直接删除
		if($AdminLogin->CheckHttpReferer(WEB_URL.'/admin/index.php?location=recycle') == true){
			$DELETEMODE = 1;
		}
		else{
			$DELETEMODE = DELETEMODE;
		}
		//连接到MYSQL并打开系统数据库
		$DataBase->open_db();
		//判断是否有权限进行此操作
		if($_SESSION['Power'] !== 'Administrator'){
			$UserPower = explode('-', $_SESSION['Power']);
			$DataBase->sel('message', "WHERE `id` = '$DelMid'");
			if(count($DataBase->Result) == 1){
				if($DataBase->Result[0]['check'] == 0){
					if($UserPower[3] == 0){
						exit('Access Denied');	//无审核权限
					}
				}
				elseif($DataBase->Result[0]['check'] == 2){
					if($UserPower[4] == 0){
						exit('Access Denied');	//无回收站权限
					}
				}
			}
			else{
				exit('Access Denied');	//不存在此留言
			}
		}		
		//执行删除操作
		switch($DELETEMODE){
			case 1:
				//直接删除
				if($DataBase->Del('message', "WHERE `id` = '$DelMid'")){
					//删除成功
					$return = 1;
				}
				else{
					//删除失败
					$return = 0;
				}
				break;
			case 0:	
				//放入回收站
				if($DataBase->up('message', "`check` = '2'", "WHERE `id` = '$DelMid'")){
					//删除成功
					$return = 1;
				}
				else{
					//删除失败
					$return = 0;
				}
				break;
		}
		echo $return;
		//如果此留言是置顶留言，则清除置顶留言
		if($DelMid == TOP_MESSAGE){
			$DataBase->up('setting', "`value` = ''", "WHERE `name` = 'TOP_MESSAGE'");
		}
		//关闭数据库连接
		$DataBase->close_dblink();
	}
	else{
		exit('Access Denied');	//留言ID不合法
	}
}	
else{
	exit('Access Denied');	//未传入留言ID
}

	
?>