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

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

if($_REQUEST[st]=="1"){
	$order_by = " A.sort_num DESC, A.idx DESC ";
}else{
	$order_by = " A.idx DESC ";
}

//상품 리스트
$arrList = getGoodListBaseNFile(
	mysql_real_escape_string($_REQUEST[cat_no]), 
	$order_by, 
	mysql_real_escape_string($_REQUEST[sw]), 
	mysql_real_escape_string($_REQUEST[sk]), 
	$scale, $_REQUEST[offset],"");

//전체 카테고리 가져오기
$arrAllCategory = getCategoryAll();

//상품분류 리스트
$arrCategory = getCategoryList(0);//1차카테고리

$arrCategoryInfo = getCategoryInfo(mysql_real_escape_string($_REQUEST[cat_no]));

//카테고리 정보
$arrCatCode = explode("/", $arrCategoryInfo["list"][0][cat_code]);

//DB해제
SetDisConn($dblink);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><?=$_SITE["NAME"]?> 관리자</title>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<style>
body,p,br,table,tr,td,input,select,textarea
{
	font-family : 굴림,돋움,verdana;
	font-size   : 12px;
	line-height : 140%;
        color : #333333;
	
	word-break:break-all;
	word-break:keep-all;
	scrollbar-face-color:#FFFFFF;
	scrollbar-shadow-color:#cccccc;
	scrollbar-highlight-color: #cccccc;
	scrollbar-3dlight-color: #FFFFFF;
	scrollbar-darkshadow-color: #FFFFFF;
	scrollbar-track-color: #FFFFFF;
	scrollbar-arrow-color: #999999;
}
body {margin: 0 0 0 0;}
img {border : 0;}

a:link , a:active , a:visited  { color:#666666; text-decoration: none;}
a:hover { color: #AA3333; text-decoration: underline; }

.input {border: 1px solid #cccccc;}
</style>
<script src="/common/js/common.js" type="text/javascript"></script>
<script src="/common/js/prototype-1.6.0.3-euc-kr.js" type="text/javascript"></script>
<script src="/common/js/scriptaculous/scriptaculous.js" type="text/javascript"></script>
<script src="/common/js/scriptaculous/effects.js" type="text/javascript"></script>
<script src="/common/js/calendar.js" type="text/javascript"></script>
<script src="/common/js/layer.js" type="text/javascript"></script>
<script src="/common/js/shop.js" type="text/javascript"></script>
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<script language="javascript">
<?
for($j=1;$j<$_SITE["PRODUCT"]["CATEGORY_DEPTH"]+1;$j++){ //카테고리 $_SITE["PRODUCT"]["CATEGORY_DEPTH"]차까지 만듬
?>
//카테고리 초기화
function initCat<?=$j?>(){
	for(i=$("cat<?=$j?>").length; i >= 0; i--){
		$("cat<?=$j?>").options[i] = null;
	}
	$("cat<?=$j?>").options[0] = new Option("=====<?=$j?>차분류=====","");
}

//카테고리 가져오기
function getCat<?=$j?>(cat,selected_idx){
	//선택된 값 이후 카테고리는 초기화
	//마지막 $_SITE["PRODUCT"]["CATEGORY_DEPTH"]차 이후는 셀렉트 박스가 없으므로 try 로 씀
	<?for($k=$j;$k<$_SITE["PRODUCT"]["CATEGORY_DEPTH"];$k++){?>
	try{ initCat<?=$k+1?>(); }catch(e){}
	<?}?>

	new Ajax.Request('/module/category/ajax_get_cat.php',
	{
		method: 'get',
		asynchronous: this.asynchronous,
		contentType: 'application/x-www-form-urlencoded',
		encoding: 'euc-kr',
		parameters: {cat_no: cat},

		onSuccess: function(transport){
			var response = transport.responseText; 
			setCat<?=$j?>(response,selected_idx);
			//카테고리 번호 설정
			$("cat_no").value = cat;
		},
		
		onFailure: function(){ 
			alert('Something went wrong...') 
		}   
	});

}

//카테고리 설정하기
function setCat<?=$j?>(txt,selected_idx){
	if(txt !=""){
		var opt = new Array();
		var opt2 = new Array();
		opt = txt.split("||");
		for(i=0; i<opt.length; i++){
			opt2 = opt[i].split("**");
			//마지막 $_SITE["PRODUCT"]["CATEGORY_DEPTH"]차 이후는 셀렉트 박스가 없으므로 try 로 씀
			try{
				if(selected_idx==opt2[0]){
					$("cat<?=$j+1?>").options[i+1] = new Option(opt2[1],opt2[0],true,true);
				}else{
					$("cat<?=$j+1?>").options[i+1] = new Option(opt2[1],opt2[0]);
				}
			}catch(e){}
		}
	}
}
<?
} //카테고리 js 끝
?>
</script>

<script language="javascript">

</script>
<table border="0" width="100%" cellpadding="3" cellspacing="0" align="center">
	<form name="frmSort" method="get" action="<?=$_SERVER[DOCUMENT_URI]?>">
	<tr>
		<td><input type="button" value="선택상품을 관련상품으로 등록" style="color:green" onclick="addRelGoodChecked();"> <input type="button" value="창닫기" style="color:red" onclick="parent.LayerHideRelGood();"></td>
	</tr>
	<tr>
		<td>
			<fieldset>
			<legend>상품검색</legend>
				<input type="hidden" name="cat_no">
				<table border="0" cellpadding="3" cellspacing="2" width="100%">
				<tr><td>
				<select name="cat" onchange="getCat1(this.value);">
				<option value="">==========1차분류==========</option>
				<?for($i=0;$i<$arrCategory["total"];$i++){?>
				<option value="<?=$arrCategory["list"][$i][cat_no]?>"<?=$arrCatCode[0]==$arrCategory["list"][$i][cat_no]?" selected":""?>><?=$arrCategory["list"][$i][cat_name]?></option>
				<?}?>
				</select>

				<?
				for($i=2;$i<$_SITE["PRODUCT"]["CATEGORY_DEPTH"]+1;$i++){ //카테고리 $_SITE["PRODUCT"]["CATEGORY_DEPTH"]차까지 만듬 => 1차 초기화는 따로위에서 함
				?>
				<select name="cat<?=$i?>" onchange="getCat<?=$i?>(this.value);">
				<option value="">==========<?=$i?>차분류==========</option>
				</select>
				<?
				}
				?>
				<input type="text" name="sk" value="<?=$_REQUEST[sk]?>">
				<select name="st">
				<option value="0"<?=$_REQUEST[st]=="0"?" selected":""?>>상품번호 역순</option>
				<option value="1"<?=$_REQUEST[st]=="1"?" selected":""?>>정렬번호 역순</option>
				</select>
				<input type="submit" value="검색">
				</td></tr>
				</table>
			</fieldset>
		</td>
  </tr>
	</form>
</table>

<table border="0" cellpadding="0" cellspacing="1" width="100%">
<form name="frmRelGood" method="get" action="<?=$_SERVER[DOCUMENT_URI]?>">
<tr height="25" align="center" bgcolor="#646464">
  <td width="5%"><font color="#ffffff"><input type="checkbox" onclick="checkboxCheckAll(this.status);"></font></td>
  <!--td width="5%"><font color="#ffffff">사진</font></td-->
  <td width="15%"><font color="#ffffff">상품코드</font></td>
  <td width="20%"><font color="#ffffff">상품분류</font></td>
  <td width="30%"><font color="#ffffff">상품명</font></td>
  <td width="10%"><font color="#ffffff">판매가</font></td>
  <td width="10%"><font color="#ffffff">재고관리</font></td>
  <td width="10%"><font color="#ffffff">등록일</font></td>
</tr>
<?if($arrList['list']['total'] > 0):?>

<?for ($i=0;$i<$arrList['list']['total'];$i++) {
	//카테고리 정보
	$arrThisCatCode = explode("/", $arrList["list"][$i][cat_code]);
?>
<tr height="25" align="center">
	<td><input type="checkbox" id="items[]" name="items[]" value="<?=$arrList['list'][$i]['idx']?>|<?=stripslashes($arrList['list'][$i]['g_name'])?>"></td>
	<!--td><a href="/shop.php?goPage=GoodDetail&idx=<?=$arrList['list'][$i]['idx']?>" target="_blank"><img src="/uploaded/shop_good/<?=$arrList['list'][$i]['idx']?>/<?=$arrList['list'][$i]['image_s']?>" width="60"></a></td-->
	<td align="left"><a href="/shop.php?goPage=GoodDetail&idx=<?=$arrList['list'][$i]['idx']?>" target="_blank"><?=stripslashes($arrList['list'][$i]['g_code'])?></a></td>
	<td align="left">
	<?for($j=0; $j <count($arrThisCatCode)-1;$j++){?>
	<a href="/shop.php?goPage=GoodList&cat_no=<?=$arrThisCatCode[$j]?>" target="_blank"><?=$arrAllCategory[$arrThisCatCode[$j]]?></a>
	<?=($j < count($arrThisCatCode)-2)?">":""?>
	<?}?>
	</td>
	<td align="left"><?=stripslashes($arrList['list'][$i]['g_name'])?></td>
	<td><?=number_format($arrList['list'][$i]['price'])?></td>
	<td align="left">
	<?if($arrList['list'][$i]['stock_type']=="2"):?>
	일반관리 | <?=number_format($arrList['list'][$i]['stock'])?> 개
	<?elseif($arrList['list'][$i]['stock_type']=="3"):?>
	연계관리 | 최소: <?=number_format($arrList['list'][$i]['min_stock'])?>
	<?else:?>
	관리안함
	<?endif;?>
	</td>
	<td><?=$arrList['list'][$i]['wdate']?></td>
</tr>
<tr>
  <td colspan="12" height="1" bgcolor="646464"></td>
</tr>
<?}?>

<?else:?>
<tr height="100" align="center">
  <td width="100%" colspan="12" >등록된 상품이 없습니다.</td>
</tr>
<tr>
  <td colspan="12" height="1" bgcolor="646464"></td>
</tr>
<?endif;?>
</form>
</table>

<br />
<table border="0" cellpadding="0" cellspacing="1" width="100%">
<tr height="25" align="center">
  <td><?=pageNavigation($arrList['total'],$scale,$pagescale,$offset,"cat_no=".$_REQUEST[cat_no]."&sw=".$_REQUEST[sw]."&sk=".$_REQUEST[sk])?></td>
</tr>
</table>

<script language="javascript">
<?
for($i=0;$i<count($arrCatCode)-1;$i++){
?>
getCat<?=$i+1?>('<?=$arrCatCode[$i]?>','<?=$arrCatCode[$i+1]?>');
<?
}
?>
</script>

</body>
</html>
