<?
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";
include $_SERVER[DOCUMENT_ROOT] . "/module/shop/shop.lib.php";
include $_SERVER[DOCUMENT_ROOT] . "/module/mail/mail.lib.php";
include $_SERVER[DOCUMENT_ROOT] . "/module/point/point.lib.php";


if(!in_array("shop_order_manage",$_SESSION[$_SITE["DOMAIN"]]["ADMIN"]["AUTH"]) && $_SESSION[$_SITE["DOMAIN"]]["ADMIN"]["GRADE"]!="ROOT"):
	jsMsg("권한이 없습니다.");
	jsHistory("-1");
endif;

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

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

	$RS = setOrderInfoAdmin($order_no);
	if($RS==true){
		//주문자에게 메일발송
		if(mysql_real_escape_string($_REQUEST[send_mail])=="Y"){
			$arrInfo = getOrderInfoAdmin($order_no);
			$arrMailInfo = getMailConfig(mysql_real_escape_string($_REQUEST[order_state]));
			sendMailShopInfo($arrInfo, $arrMailInfo);

			/*
			// 메시지발송
			function SendMesg($url) {
				$fp = fsockopen("211.233.20.184", 80, $errno, $errstr, 10);
				if(!$fp) echo "$errno : $errstr";

				fwrite($fp, "GET $url HTTP/1.0\r\nHost: 211.233.20.184\r\n\r\n"); 
				$flag = 0; 
				
				while(!feof($fp)){
					$row = fgets($fp, 1024);

					if($flag) $out .= $row;
					if($row=="\r\n") $flag = 1;
				}
				fclose($fp);
				return $out;
			}
			*/
		}
		//주문자에게 메일발송
		jsGo($_REQUEST[rt_url],"","");
//		jsGo("order_detail.php?order_no=".$order_no."&listURL=".$_REQUEST[listURL],"","");
	}else{
		jsMsg("주문정보 수정에 실패 하였습니다.");
		jsHistory("-1") ;
	}

	//DB해제
	SetDisConn($dblink);


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

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

	$RS = delOrderInfoAdmin($order_no);

	if($RS==true){
		jsGo("order.php?"."&listURL=".$_REQUEST[listURL],"","");
	}else{
		jsMsg("주문정보 삭제에 실패 하였습니다.");
		jsHistory("-1") ;
	}

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