<?
//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_escape_string($_REQUEST["cat_no"]), 
	$order_by, "best", "Y", 
	"4", "", "Y");

//$arrList = getGoodListBaseNFileFromCat(mysql_escape_string($_REQUEST["cat_no"]), " A.sort_num DESC, A.idx DESC ", "", "", "4", "", "Y");

$scale = "8";
//상품 리스트
$arrList = getGoodListBaseNFileFromCat(
	mysql_escape_string($_REQUEST["cat_no"]), 
	$order_by, 
	mysql_escape_string($_REQUEST[sw]), 
	mysql_escape_string($_REQUEST[sk]), 
	$scale, $_REQUEST[offset],"Y");

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


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

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

$arrCategoryImg = getCategoryAllimage();

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

//SetDisConn($dblink);
?>
	<div class="md-rec mgb20">
		<div class="contain">
			<div class="md-title">
				<h2>추천제품 소개 <span>각 카테고리에서 추천드리는 상품입니다.</span></h2>
				<div class="path">Home &gt; <?=$arrAllCategory[$CateCode[0]]!=""?$arrAllCategory[$CateCode[0]]:"상품안내"?></div>
			</div>

			<!-- // 추천제품 -->
			<div class="md-product">
				<ul>
					<?if($arrBestList['list']['total'] > 0){?>
					<?for ($i=0;$i<$arrBestList['list']['total'];$i++) {
						$arrCat[$i] = explode("/", $arrBestList["list"][$i]["cat_code"]);

						// 아이콘표시
						$array_part_icons=explode("|",$arrBestList['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]."'> ";				
								}
							}
						}
						if($i%4==0){echo "</ul><ul>";}
					?>
					<li>
						<?if($arrBestList['list'][$i]['etc_9']!=""){?>
						<div class="label"><img src="/images/shop/label_<?=$arrBestList['list'][$i]['etc_9']?>.png" alt="<?=$arrBestList['list'][$i]['etc_9']?>"></div>
						<?}?>
						<div class="thumb"><a href="/shop.php?goPage=GoodDetail&g_code=<?=$arrBestList['list'][$i]['g_code']?>&cat_no=<?=$cat_no?>"><img src="/uploaded/shop_good/<?=$arrBestList['list'][$i]['idx']?>/l_<?=$arrBestList['list'][$i]['re_name']?>" width="249" height="165" alt="" /></a></div>
						<?=$temp_part_icons?>
						<div class="title">
							<a href="/shop.php?goPage=GoodDetail&g_code=<?=$arrBestList['list'][$i]['g_code']?>&cat_no=<?=$cat_no?>"><?=stripslashes($arrBestList['list'][$i]['g_name'])?></a>
						</div>
						<div class="price"><?=number_format($arrBestList['list'][$i]['price'])?>원</div>
					</li>
					<?}?>
					<?}else{?>
					<li>등록된 상품이 없습니다.</li>
					<?}?>
				</ul>
			</div>
			<!--  추천제품 // -->
		</div>
	</div>
	<div class="contain">
		<div class="sub-title">
			<h2><?=$arrAllCategory[$CateCode[0]]?></h2>
		</div>
		<div class="real-cont">
			<!--// content -->

			<!--// 리스트 -->
			<div class="sub-menu">
				<?
				if ($categorySubList["total"] > 0) {
					for ($i = 0;$i < $categorySubList["total"];$i++) {
						$arrSubList = getGoodListBaseNFileFromCat($categorySubList["list"][$i]["cat_no"], $order_by, "", "", $scale, $_REQUEST[offset],"Y");
				?>
				<a href="/shop.php?goPage=GoodList&cat_no=<?=$categorySubList["list"][$i]["cat_no"]?>" class="<?=$cat_no==$categorySubList["list"][$i]["cat_no"]?"on":"";?>">
				<?=$categorySubList["list"][$i]["cat_name"]?> (<?=number_format($arrSubList["total"])?>)</a>
				<span class="var">|</span>
				<?}}?>
			</div>
			<div class="goods-sort">
				<div class="total">· 총 <strong><?=number_format($arrList["total"])?>개</strong>의 상품이 진열되어 있습니다.</div>						
			</div>

			
			<div class="goods-list">
				<?if($arrList['list']['total'] > 0){?>
				<ul>
				<?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]."'> ";				
							}
						}
					}
					if($i%4==0){echo "</ul><ul>";}
				?>
				<li>
					<?if($arrList['list'][$i]['etc_9']!=""){?>
					<div class="label"><img src="/images/shop/label_<?=$arrList['list'][$i]['etc_9']?>.png" alt="<?=$arrList['list'][$i]['etc_9']?>"></div>
					<?}?>
					<div class="thumb"><a href="/shop.php?goPage=GoodDetail&g_code=<?=$arrList['list'][$i]['g_code']?>&cat_no=<?=$cat_no?>"><img src="/uploaded/shop_good/<?=$arrList['list'][$i]['idx']?>/l_<?=$arrList['list'][$i]['re_name']?>" width="249" height="165" alt="" /></a></div>
					<?=$temp_part_icons?>
					<div class="title">
						<a href="/shop.php?goPage=GoodDetail&g_code=<?=$arrList['list'][$i]['g_code']?>&cat_no=<?=$cat_no?>"><?=stripslashes($arrList['list'][$i]['g_name'])?></a>
					</div>
					<div class="price"><?=number_format($arrList['list'][$i]['price'])?>원</div>
				</li>
				<?}?>
				</ul>
				<?}else{?>
				<ul>등록된 상품이 없습니다.</ul>
				<?}?>
			</div>

			<div class="paginate">
				<?=pageNavigation($arrList['total'],$scale,$pagescale,$offset,"cat_no=".$_REQUEST["cat_no"]."&sw=".$_REQUEST[sw]."&sk=".$_REQUEST[sk]."&st=".$_REQUEST[st]."&goPage=".$_REQUEST[goPage])?>
			</div>
			<!-- 리스트 //-->
			<!-- content //-->
		</div>
	</div>