<?
session_start();
include $_SERVER[DOCUMENT_ROOT] . "/common/conf/config.inc.php";
include $_SERVER[DOCUMENT_ROOT] . "/backoffice/auth/auth.php";
include $_SERVER[DOCUMENT_ROOT] . "/module/category/category.lib.php";
if(!in_array("product_manage",$_SESSION[$_SITE["DOMAIN"]]["ADMIN"]["AUTH"]) && $_SESSION[$_SITE["DOMAIN"]]["ADMIN"]["GRADE"]!="ROOT"):
	jsMsg("권한이 없습니다.");
	jsHistory("-1");
endif;

if($_POST[evnMode]=="createCategory"){
	//DB연결
	$dblink = SetConn($_conf_db["main_db"]);

	$makeRS = addCategory(mysql_real_escape_string($_POST["s_category"]), mysql_real_escape_string($_POST["s_depth"]), mysql_real_escape_string($_POST["new_name"]));

	if($makeRS==true){
		jsGo("category.php?cat_no=".$_POST["s_cat_no"],"","");
	}else{
		jsMsg("카테고리 생성에 실패 하였습니다.");
		jsHistory("-1") ;
	}

	//DB해제
	SetDisConn($dblink);

}else if($_REQUEST[evnMode]=="sort_up"){
	//DB연결
	$dblink = SetConn($_conf_db["main_db"]);

	$editRS = sortupCategory(mysql_real_escape_string($_REQUEST[cat_no]));
	
	if($editRS==true){
		jsGo("category.php?cat_no=".$_REQUEST["s_cat_no"],"","");
	}else{
		jsMsg("정렬순서 변경에 실패 하였습니다.");
		jsHistory("-1") ;
	}

	//DB해제
	SetDisConn($dblink);

}else if($_REQUEST[evnMode]=="sort_down"){
	//DB연결
	$dblink = SetConn($_conf_db["main_db"]);

	$editRS = sortdownCategory(mysql_real_escape_string($_REQUEST[cat_no]));
	
	if($editRS==true){
		jsGo("category.php?cat_no=".$_REQUEST["s_cat_no"],"","");
	}else{
		jsMsg("정렬순서 변경에 실패 하였습니다.");
		jsHistory("-1") ;
	}

	//DB해제
	SetDisConn($dblink);

}else if($_POST[evnMode]=="editCategory"){
	//DB연결
	$dblink = SetConn($_conf_db["main_db"]);

	$editRS = editCategory (mysql_real_escape_string($_POST[cat_no]), mysql_real_escape_string($_POST[cat_name]), mysql_real_escape_string($_POST[cat_content]));
	
	if($editRS==true){
		jsGo("category_info.php?cat_no=".$_POST[cat_no],"","");
	}else{
		jsMsg("정보수정에 실패 하였습니다.");
		jsHistory("-1") ;
	}

	//DB해제
	SetDisConn($dblink);

}else if($_REQUEST[evnMode]=="deleteCategory"){
	//DB연결
	$dblink = SetConn($_conf_db["main_db"]);
	
	$editRS = deleteCategory(mysql_real_escape_string($_REQUEST[cat_no]));
	
	if($editRS==true){
		jsGo("category.php?cat_no=".$_REQUEST["s_cat_no"],"","");
	}else{
		jsMsg("카테고리 삭제에 실패 하였습니다.");
		jsHistory("-1") ;
	}

	//DB해제
	SetDisConn($dblink);
}
?>