<?
error_reporting("0");

include_once("../../include/common.php");

session_start();

islogin();

$action=addslashes($_GET["action"]);

if($action=="del")
{
	$id=intval($_GET["id"]);
	if(is_int($id))
	{
	$mysql->query("select * from attachment where id=$id");
	
	$arr=$mysql->fetcharray();
	
	if(file_exists(ROOT.$arr["attach"]))
	{
		unlink(ROOT.$arr["attach"]);
	}
	
	$mysql->query("delete from attachment where id=$id");
	
	redirect();
	}
	else
	{
		die("参数出错");
	}
}

if($action=="dodel")
{
	$attach=$_POST["attach"];
	foreach($attach as $key=>$value)
	{
		$value=intval($value);
		if(is_int($value))
		{
		$mysql->query("select * from attachment where id=$value");
	
		$arr=$mysql->fetcharray();
	
		if(file_exists(ROOT.$arr["attach"]))
		{
			unlink(ROOT.$arr["attach"]);
		}
	
		$mysql->query("delete from attachment where id=$value");
		}
		else
		{
			die("参数出错");
		}

	}
	@header("location:../attach.php");
}

$mysql->close();
?>