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

if($_REQUEST[st]=="new"){
	$order_by = " A.idx DESC ";
}else if($_REQUEST[st]=="hit"){
	$order_by = " A.hit DESC ";
}else if($_REQUEST[st]=="name"){
	$order_by = " A.g_name ";
}else if($_REQUEST[st]=="hprice"){
	$order_by = " length(A.price) DESC, A.price DESC ";
}else if($_REQUEST[st]=="lprice"){
	$order_by = " length(A.price) ASC, A.price ASC ";
}else{
	$order_by = " A.sort_num DESC, A.idx DESC ";
}

//best상품 리스트
//$arrBestList = getGoodListBaseNFileFromCat(mysql_real_escape_string($_REQUEST["cat_no"]), $order_by, "best", "Y", "4", "", "Y");

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

//현재 카테고리 정보
$arrCategoryInfo = getCategoryInfo(mysql_real_escape_string($_REQUEST["cat_no"]));
$arrCatCode = explode("/", $arrCategoryInfo["list"][0]["cat_code"]);

//서브 카테고리 목록
$categorySubList = getCategoryList(mysql_real_escape_string($arrCatCode[0]));

$arrCategoryImg = getCategoryAllimage();

$scale = "9";
$pages=intval($arrList["total"]/$scale); 
if ($arrList["total"] % $scale) { 
	$pages++; 
} 

//상품 리스트
$arrList = getGoodListBaseNFileFromCat(
	mysql_real_escape_string($_REQUEST["cat_no"]), 
	$order_by, 
	mysql_real_escape_string($_REQUEST[sw]), 
	mysql_real_escape_string($_REQUEST[sk]), 
	$scale, $_REQUEST[offset],"Y");
//SetDisConn($dblink);
?>
	<div class="sub-title">			
		<h2><?=$arrAllCategory[$CateCode[1]]?></h2>
		<div class="path"><img src="../images/common/home.png" alt="Home"> <span class="arrow">&gt;</span> 재품소개 <span class="arrow">&gt;</span>  <?=$arrAllCategory[$CateCode[0]]?> <span class="arrow">&gt;</span> <?=$arrAllCategory[$CateCode[1]]?></div>
	</div>
	<div class="real-cont">
		<!--// content -->
		<?$categoryList = getCategoryList($CateCode[1]);?>
		<? if($categoryList["total"]>0): ?>
		<div class="board-category">
			<ul>
				<a href="/shop.php?goPage=GoodList&cat_no=<?=$CateCode[1]?>" class="<?=$CateCode[2]==""?"active":""?>">전체상품보기</a> |
				<?for ($j = 0;$j < $categoryList["total"];$j++) {?>
				<a href="/shop.php?goPage=GoodList&cat_no=<?=$categoryList["list"][$j]["cat_no"]?>" class="<?=$CateCode[2]==$categoryList["list"][$j]["cat_no"]?"active":""?>"><?=$categoryList["list"][$j]["cat_name"]?></a>
				<?
				if($j!=$categoryList["total"]-1){
				echo " |";
				}
				?>
				<?}?>
			</ul>
		</div>
		<? endif ?>

		<div class="board-search"> 
			<div class="total-page">· 총 <strong><?=number_format($arrList['total'])?>개</strong>의 상품이 진열되어 있습니다.</div> 
			<div class="search">
				<form action="/shop.php">
				<input type="hidden" name="goPage" value="GoodList"/>
				<input type="hidden" name="sw" value="a"/>
				<input type="hidden" name="cat_no" value="<?=$_REQUEST[cat_no]?>"/>
					<label for="keyword" class="hide">검색어</label>
					<input type="text" name="sk" id="keyword" class="input"> 
					<button type="submit" class="btn btn-pack">검색</button>
				</form>
			</div>
		</div>
		
		<style type="text/css">  
		   .imgResize { width: expression((this.width > 178)? ((this.height > 178)? ((this.width < this.height)? true : 100) : 178) :true); height: expression((this.height > 178)? ((this.width > 178)? ((this.width > this.height)? true : 178) : 178) :true); max-width: 178px; max-height: 178px;} 
		</style>  
		<script>  
		function setPos(img) {  
			var diff = 133 - img.offsetHeight; // 133은 스타일에서 지정한 이미지 최대 높이  
			if(diff > 0) {  
				img.style.marginTop = Math.floor(diff/2) + 'px';  
			}  
		}  
		</script> 
		
		<div class="goods-sort">
			<ul>
				<li class="<?=$_REQUEST[st]=="lprice"?"on":""?>"><a href="/shop.php?goPage=GoodList&cat_no=<?=$_REQUEST[cat_no]?>&sw=<?=$_REQUEST[sw]?>&sk=<?=$_REQUEST[sk]?>&st=lprice">낮은가격</a></li>
				<li class="<?=$_REQUEST[st]=="hprice"?"on":""?>"><a href="/shop.php?goPage=GoodList&cat_no=<?=$_REQUEST[cat_no]?>&sw=<?=$_REQUEST[sw]?>&sk=<?=$_REQUEST[sk]?>&st=hprice">높은가격</a></li>
				<li class="<?=$_REQUEST[st]=="name"?"on":""?>"><a href="/shop.php?goPage=GoodList&cat_no=<?=$_REQUEST[cat_no]?>&sw=<?=$_REQUEST[sw]?>&sk=<?=$_REQUEST[sk]?>&st=name">상품명</a></li>
				<li class="<?=$_REQUEST[st]=="vendor"?"on":""?>"><a href="/shop.php?goPage=GoodList&cat_no=<?=$_REQUEST[cat_no]?>&sw=<?=$_REQUEST[sw]?>&sk=<?=$_REQUEST[sk]?>&st=vendor">제조사</a></li>
			</ul>
		</div>

		<div class="goods-list">
			<ul>
				<?if($arrList['list']['total'] > 0){?>
				<?for ($i=0;$i<$arrList['list']['total'];$i++) {
					$arrCat[$i] = explode("/", $arrList["list"][$i]["cat_code"]);

					// 아이콘표시
					$array_part_icons=explode("|",$arrList['list'][$i]['icons']);
					// 상품아이콘(히트,뉴,추천....)		
					$temp_part_icons="";
					if (count($array_part_icons)>0){				
						for($k=0;$k<count($array_part_icons);$k++){
							if ($array_part_icons[$k]){
								$temp_part_icons.="<img src='/uploaded/shop_icons/".$array_part_icons[$k]."'> ";				
							}
						}
					}

					//신규글 표시(28일간)
					if(strtotime($arrList["list"][$i][wdate])+(28*86400) > time()){
						$newImage =" <img src='/images/shop/label_new.png' alt='New' />";
					}else{
						$newImage ="";
					}
				?>
				<li>
					<a href="/shop.php?goPage=GoodDetail&g_code=<?=$arrList['list'][$i]['g_code']?>&cat_no=<?=$_REQUEST[cat_no]?>&offset=<?=$_REQUEST[offset]?>">
					<div class="thumb"><img src="/uploaded/shop_good/<?=$arrList['list'][$i]['idx']?>/<?=$arrList['list'][$i]['p_image']?>" class='imgResize' onload="setPos(this);" alt=""></div>
					<div class="tit"><?=stripslashes($arrList['list'][$i]['g_name'])?></div>
					<div class="price"><?=number_format($arrList['list'][$i]['price'])?>원</div>
					</a>
				</li>
				<?}?>
				<?}else{?>
				<li class="none">등록된 상품이 없습니다.</li>
				<?}?>
			</ul>
		</div>
		<div class="paginate">
			<?=pageNavigation($arrList['total'],$scale,$pagescale,$_REQUEST[offset],"cat_no=".$_REQUEST["cat_no"]."&sw=".$_REQUEST[sw]."&sk=".$_REQUEST[sk]."&st=".$_REQUEST[st]."&goPage=".$_REQUEST[goPage])?>
		</div>
	</div>
</div>
