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

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

	$RS = inputAdmin();

	if($RS==true){
		jsGo("admin.php","","");
	}else{
		jsMsg("관리자 등록에 실패 하였습니다.");
		jsHistory("-1") ;
	}

	//DB해제
	SetDisConn($dblink);


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

	$idx = mysql_real_escape_string(trim($_POST[idx]));

	$RS = updateAdmin($idx);
	if($RS==true){
		jsGo("admin.php","","");
	}else{
		jsMsg("관리자 수정에 실패 하였습니다.");
		jsHistory("-1") ;
	}

	//DB해제
	SetDisConn($dblink);

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

	$idx = mysql_real_escape_string(trim($_POST[idx]));

	$RS = updateAdminAuth();
	if($RS==true){
		jsGo("config.php","","");
	}else{
		jsMsg("관리자 수정에 실패 하였습니다.");
		jsHistory("-1") ;
	}

	//DB해제
	SetDisConn($dblink);


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

	$idx = mysql_real_escape_string(trim($_REQUEST[idx]));

	$RS = deleteAdmin($idx);

	if($RS==true){
		jsGo("admin.php","","");
	}else{
		jsMsg("관리자 삭제에 실패 하였습니다.");
		jsHistory("-1") ;
	}

	//DB해제
	SetDisConn($dblink);

}else if($_POST[evnMode]=="setAdmin"){

	//DB연결
	$dblink = SetConn($_conf_db["main_db"]);

	$RS = updateShopSet($idx);

	//DB해제
	SetDisConn($dblink);

	if($RS==true){
		jsGo("admin_set.php","","");
	}else{
		jsMsg("기본정보설정 수정에 실패 하였습니다.");
		jsHistory("-1") ;
	}
	
}else if($_POST[evnMode]=="updateOpen"){
	//DB연결
	$dblink = SetConn($_conf_db["main_db"]);

	$RS = updateShopSetOpen($idx);

	//DB해제
	SetDisConn($dblink);

	if($RS==true){
		jsGo("config.php","","");
	}else{
		jsMsg("오픈시 클릭에 실패 하였습니다.");
		jsHistory("-1") ;
	}

}else if($_POST[evnMode]=="addBoardAddTest"){
	//게시판 테스트 게시글 등록

	//DB연결
	$dblink = SetConn($_conf_db["main_db"]);
	$scale = "999";
	$arrList = getArticleList($_conf_tbl["board_info"], $scale, $_REQUEST[offset], "");
	
	if($arrList['list']['total'] > 0){
		for ($i=0;$i<$arrList['list']['total'];$i++) {
			//게시물 등록
			$arrBoardInfo = getBoardInfo($_conf_tbl[board_info], $arrList['list'][$i]['boardid']);
			$_POST[usehtml] = "Y";
			$_POST[subject] = $arrList['list'][$i]['boardname']." 테스트 게시글 제목입니다.";
			$_POST[contents] = $arrList['list'][$i]['boardname']." 테스트 게시글 내용입니다.";
			$_POST[name] = "관리자";
			$RS = insertBoardArticle($arrList['list'][$i]['boardid'],$arrBoardInfo["list"][0]["thumwidth"]);
			//$RS = addBoardAddTest();
		}
	}

	//DB해제
	SetDisConn($dblink);

	if($RS==true){
		if($_REQUEST[rt_url]!=""){
			jsGo($_REQUEST[rt_url],"","");	
		}else{
			jsGo("config.php","","");
		}
	}else{
		jsMsg("테스트 게시글 등록에 실패 하였습니다.");
		jsHistory("-1") ;
	}

}else if($_POST[evnMode]=="initBoard"){
	//게시판 테스트 게시글 등록

	//DB연결
	$dblink = SetConn($_conf_db["main_db"]);
	$scale = "999";
	$arrList = getArticleList($_conf_tbl["board_info"], $scale, $_REQUEST[offset], "");
	
	if($arrList['list']['total'] > 0){
		for ($i=0;$i<$arrList['list']['total'];$i++) {
			$sql_up = "delete from tbl_board_".$arrList['list'][$i]['boardid'];
			$RS=mysql_query($sql_up);

			$sql_up = "ALTER TABLE tbl_board_".$arrList['list'][$i]['boardid']." convert to charset utf8"; 
			$RS=mysql_query($sql_up);
			
			$sql_up = "ALTER TABLE tbl_board_".$arrList['list'][$i]['boardid']." auto_increment = 1"; 
			$RS=mysql_query($sql_up);
		}
	}
	
	$sql_up = "delete from tbl_board_files";
	$RS=mysql_query($sql_up);

	$sql_up = "ALTER TABLE tbl_board_files convert to charset utf8"; 
	$RS=mysql_query($sql_up);
	
	$sql_up = "ALTER TABLE tbl_board_files auto_increment = 1"; 
	$RS=mysql_query($sql_up);

	//DB해제
	SetDisConn($dblink);

	if($RS==true){
		jsGo("config.php","","");
	}else{
		jsMsg("게시판 초기화에 실패 하였습니다.");
		jsHistory("-1") ;
	}

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

	$RS = updateLog();

	//DB해제
	SetDisConn($dblink);

	if($RS==true){
		jsGo("config.php","","");
	}else{
		jsMsg("로그초기화에 실패 하였습니다.");
		jsHistory("-1") ;
	}
}else if($_POST[evnMode]=="addEnMode"){
	//DB연결
	$dblink = SetConn($_conf_db["main_db"]);

	$RS = addEnMode();

	//DB해제
	SetDisConn($dblink);

	if($RS==true){
		jsGo("config.php","","");
	}else{
		jsMsg("영문추가에 실패 하였습니다.");
		jsHistory("-1") ;
	}

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

	$RS = addCnMode();

	//DB해제
	SetDisConn($dblink);

	if($RS==true){
		jsGo("config.php","","");
	}else{
		jsMsg("중문추가에 실패 하였습니다.");
		jsHistory("-1") ;
	}

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

	$RS = addJpMode();

	//DB해제
	SetDisConn($dblink);

	if($RS==true){
		jsGo("config.php","","");
	}else{
		jsMsg("중문추가에 실패 하였습니다.");
		jsHistory("-1") ;
	}
}
?>