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

error_reporting(0);

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

session_start();

islogin();

$fenlei=addslashes($_POST["fenlei"]);

$id=intval($_GET["id"]);

$category=$_GET["category"];

$action=$_GET["action"];


if(!strlen($fenlei)>30 && $fenlei=="" && $id=="")
{
	die("填写内容不正确或超过30个字符");
}

//产品分类管理

if($category=="product")

{

//添加操作

if($action=="add")
{
	$mysql->query("select * from pclass where name='$fenlei'");
	if($mysql->fetcharray())
	{
		die("提示信息:貌似重名了吧,最好别重名的了&nbsp;&nbsp;<a href='#' onclick='window.history.go(-1);' >返回</a>");
	}
	$mysql->query("insert into pclass (name) value ('$fenlei')");
	redirect();
}

//删除操作
if($action=="del")
{
	$mysql->query("delete from pclass where id=$id");
	redirect();
}

//编辑操作
if($action=="edit")
{
	$mysql->query("select * from pclass where name='$fenlei'");
	if($mysql->fetcharray())
	{
		die("提示信息:貌似重名了吧,最好别重名的了&nbsp;&nbsp;<a href='#' onclick='window.history.go(-1);' >返回</a>");
	}
	$mysql->query("update pclass set name='$fenlei' where id=$id");
	redirect();
}

//多项删除

if($action=="dodel")
{
	$dodel=$_POST["dodel"];
	//echo $dodel;
	if($dodel=="")
	{
		die("sorry,参数不能为空的!!!");
	}
	foreach($dodel as $id)
	{
		
		$id=intval($id);
		$mysql->query("delete from pclass where id=$id");
	}
	redirect();
}

}
elseif($category=="news")
{
	
	//添加操作
	if($action=="add")
	{
		$mysql->query("select * from nclass where name='$fenlei'");
		if($mysql->fetcharray())
		{
			die("提示信息:貌似重名了吧,最好别重名的了&nbsp;&nbsp;<a href='#' onclick='window.history.go(-1);' >返回</a>");
		}
		$mysql->query("insert into nclass (name) value ('$fenlei')");
		redirect();
	}

	
	//删除操作
	if($action=="del")
	{
		$mysql->query("delete from nclass where id=$id");
		redirect();
	}
	
	//编辑操作
	if($action=="edit")
	{
		$mysql->query("select * from nclass where name='$fenlei'");
		if($mysql->fetcharray())
		{
			die("提示信息:貌似重名了吧,最好别重名的了&nbsp;&nbsp;<a href='#' onclick='window.history.go(-1);' >返回</a>");
		}
		$mysql->query("update nclass set name='$fenlei' where id=$id");
		redirect();
	}
	
	//多项删除
	
	if($action=="dodel")
	{
		$dodel=$_POST["dodel"];
		//echo $dodel;
		if($dodel=="")
		{
			die("sorry,参数不能为空的!!!");
		}
		foreach($dodel as $id)
		{
			
			$id=intval($id);
			$mysql->query("delete from nclass where id=$id");
		}
		redirect();
	}

	

}

else
{
	die("参数错误");
}
unset($id,$fenlei);
$mysql->close();
?>