<?
@header("content-Type:text/html; charset=utf-8");

//error_reporting(0);

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

session_start();

islogin();

$action=$_GET["action"];

//添加产品
if($action=="add")
{
	$title=addslashes($_POST["name"]);
	$category=intval(($_POST["category"]));
	$editor=addslashes($_POST["editor"]);
	$content=$_POST["content"];
	$comment=intval($_POST["comment"]);
	$datetime=$_POST["datetime"];
	
	//echo $datetime;
	
	$rownums=$mysql->rownums("select * from news where title='$title'");
	if($rownums)
	{
		die("sorry,有重复的标题");
	}
	
	
	//插入数据库
	$sql="insert into news (bigclassid,time,content,iscomment,editor,title) value ($category,'$datetime','$content',$comment,'$editor','$title')";
	
	//echo $sql;
	
	$mysql->query($sql);
	
	@header("location:../nmanage.php");
}

if($action=="del")
{
	$id=intval($_GET["id"]);
	if($id)
	{
		$mysql->query("delete from news where id=$id");
		redirect();
	}
	else
	{
		die("错误参数");
	}
}

if($action=="dodel")
{
	$id=$_POST["dodel"];
	foreach($id as $key=>$value)
	{
		$value=intval($value);
		if($value)
		{
			$mysql->query("delete from news where id=$value");
			redirect();
		}
		else
		{
			die("错误参数");
		}
	}
}

if($action=="edit")
{
	$id=intval($_POST["aid"]);
	$title=addslashes($_POST["name"]);
	$category=intval(($_POST["category"]));
	$editor=addslashes($_POST["editor"]);
	$content=$_POST["content"];
	$comment=intval($_POST["comment"]);
	$datetime=$_POST["datetime"];
	
	
	//更新数据库
	$sql="update news set title='$title',time='$datetime',bigclassid=$category,content='$content',iscomment=$comment,editor='$editor' where id=$aid";
	
	//echo $sql;
	
	$mysql->query($sql);
	
	
	//echo $sql;
	@header("location:../nmanage.php");
	
}

//批量移动
if($action=="move")
{
	//echo "ok";
	
	$bigclassid=intval($_POST["category"]);
	$aid=$_POST["dodel"];
	if($bigclassid && is_int($bigclassid))
	{
		foreach($aid as $key=>$value)
		{
			$value=intval($value);
			if(is_int($value))
			{
				$mysql->query("update news set bigclassid=$bigclassid where id=$value");
			}
			else
			{
				die("参数错误");
			}
		}
	}
	redirect();
	
	
}
$mysql->close();
?>