<?
// $request_uri = $_SERVER['REQUEST_URI'];
// $request_category = $_GET['category'];
// $reqeust_arr = array(
//     '/front/nsurgery/n_dns.php',
//     '/front/nsurgery/n_congestion1.php',
//     '/front/nsurgery/nsurgery4.php',
//     '/front/nsurgery/nsurgery5.php',
//     '/front/nsurgery/nsurgery6.php',
//     '/front/nplastic/n_band.php',
//     '/front/nplastic/n_updown.php',
//     '/front/nplastic/nplastic3.php',
//     '/front/nplastic/nplastic4.php',
//     '/front/nplastic/n_flat_nose.php',
//     '/front/nplastic/nplastic6.php',
//     '/front/nplastic/n_fracture.php',
//     '/front/nplastic/nplastic8.php'
// );
// $request_sub_arr = array(
//     'A1' => '/front/nsurgery/n_dns.php',
//     'A2' => '/front/nsurgery/n_congestion1.php',
//     'A3' => '/front/nsurgery/nsurgery4.php',
//     'A4' => '/front/nsurgery/nsurgery5.php',
//     'A5' => '/front/nsurgery/nsurgery6.php',
//     'B1' => '/front/nplastic/n_band.php',
//     'B2' => '/front/nplastic/n_updown.php',
//     'B3' => '/front/nplastic/nplastic3.php',
//     'B4' => '/front/nplastic/nplastic4.php',
//     'B5' => '/front/nplastic/n_flat_nose.php',
//     'B6' => '/front/nplastic/nplastic6.php',
//     'B7' => '/front/nplastic/n_fracture.php',
//     'B8' => '/front/nplastic/nplastic8.php'
// );

// if($request_category){
//     if(in_array($request_uri, $reqeust_arr) == FALSE){
//         echo "<script>\n";
//         echo "location.href=\"$request_sub_arr[$request_category]\";\n";
//         echo "</script>\n";
//         exit;
//     }
// }
include_once $_SERVER['DOCUMENT_ROOT']."/front/include/dehead.php";

//========================================
// Class Connect
//========================================
$Db = new Db(); // 데이터 베이스 클래스

//========================================
// Data Process
//========================================

if(!$type){
	$type = 'A';
}

$rowCount = $pageInfo['post']['rowCount']; // 한 페이지에 보여질 게시물 수
$startNum = ($page - 1) * $rowCount; // limit 시작 위치
//$param = array('no' => PARAMETER_NO, 'show' => PARAMETER_Y, 'del' => PARAMETER_N, 'disease' => $disease, 'category' => $Db->likeify($category));
$param = array('no' => PARAMETER_NO, 'show' => PARAMETER_Y, 'del' => PARAMETER_N, 'category' => $Db->likeify($category));

//$addPath = "&category=$category&disease=$disease#tab";
$addPath = "&no=$no&category=$category&type=$type";


//========================================
// Data Load
//========================================
//$totalCount = $Db->single("SELECT COUNT(*) FROM $TABLE_POST WHERE no > :no AND d_show = :show AND del = :del AND disease = :disease AND category LIKE :category", $param);
$totalCount = $Db->single("SELECT COUNT(*) FROM $TABLE_POST WHERE no > :no AND d_show = :show AND del = :del AND category LIKE :category AND type='".$type."'", $param);
$totalPages = ceil($totalCount / $rowCount);

$param = array_merge($param, array('startNum' => $startNum, 'rowCount' => $rowCount, 'code' => "post", 'seq' => PARAMETER_ONE));

//2017-08-03 
if($category=='A1'){
//	$addOrderQry = '(A.no = 19 or A.no = 28 or A.no = 39 or A.no = 47) DESC,';
$addOrderQry = 'CASE A.no
                WHEN 47 THEN 0
                WHEN 39 THEN 1
                WHEN 28 THEN 2
                WHEN 19 THEN 3
		WHEN 206 THEN 100
                ELSE 10 END,
                A.no DESC,';
}else if($category == 'B1'){
    $addOrderQry = 'CASE A.no
                WHEN 184 THEN 0
                WHEN 10 THEN 1
                WHEN 12 THEN 2
                WHEN 29 THEN 3
                ELSE 10 END,
                A.no DESC,';
/*
	$addOrderQry = 'CASE A.no 
				WHEN 10 THEN 0
				WHEN 12 THEN 1
				WHEN 29 THEN 2
				WHEN 52 THEN 3
				ELSE 10 END,
				A.no DESC,';*/
}else if($category == 'B2'){
	$addOrderQry = 'CASE A.no
                WHEN 13 THEN 0
                WHEN 26 THEN 1
                WHEN 54 THEN 2
                WHEN 65 THEN 3
                ELSE 10 END,
                A.no DESC,';
}else if($category == 'A2'){
	$addOrderQry = 'CASE A.no
                WHEN 4 THEN 0
                WHEN 23 THEN 1
                WHEN 46 THEN 2
                WHEN 68 THEN 3
                ELSE 10 END,
                A.no DESC,';

}else if($category == 'A3'){
	$addOrderQry = 'CASE A.no
				WHEN 197 THEN 0
                WHEN 9 THEN 1
                WHEN 18 THEN 2
                WHEN 61 THEN 3
                WHEN 51 THEN 4
                ELSE 10 END,
                A.no DESC,';

}else if ($category == 'A7'){
	$addOrderQry = 'CASE A.no
                WHEN 196 THEN 0
                WHEN 185 THEN 1
                ELSE 10 END,
                A.no DESC,';
}


//========================================
// landing Include
//========================================
switch ($category) {
    case 'A1':
        $landing_key = "n_dns";
        $origin_path = "nsurgery/".$landing_key;
		//$landing_title = "비중격만곡증 수술";
        break;
    case 'A2':
	if(!$tab){ $tab = 1;}
        $landing_key = "n_congestion".$tab;
        $origin_path = "nsurgery/".$landing_key;
		//if($tab == 1){	$landing_title = "비염수술";	}else if($tab == 2){ $landing_title = "코막힘/비염"; }
        break;
    case 'A3':
	//if(!$tab){ $tab = 1;}
        $landing_key = "nsurgery4".$tab;
        $origin_path = "nsurgery/".$landing_key;
		//if($tab == 1){	$landing_title = "축농증 수술";	}else if($tab == 2){ $landing_title = "축농증"; }
        break;
    case 'A4':
        $landing_key = "nsurgery5";
        $origin_path = "nsurgery/".$landing_key;
		//$landing_title = "코골이/수면무호흡증";
        break;
    case 'A5':
        $landing_key = "nsurgery6";
        $origin_path = "nsurgery/".$landing_key;
        break;
	case 'A7':
        $landing_key = "nsurgery7";
        $origin_path = "nsurgery/".$landing_key;
        break;
    case 'B1':
        $landing_key = "n_band";
        $origin_path = "nplastic/".$landing_key;
        break;
    case 'B2':
        $landing_key = "n_updown";
        $origin_path = "nplastic/".$landing_key;
        break;
    case 'B3':
        $landing_key = "nplastic3";
        $origin_path = "nplastic/".$landing_key;
        break;
    case 'B4':
        $landing_key = "nplastic4";
        $origin_path = "nplastic/".$landing_key;
        break;
    case 'B5':
        $landing_key = "n_flat_nose";
        $origin_path = "nplastic/".$landing_key;
        break;
    case 'B6':
        $landing_key = "nplastic6";
        $origin_path = "nplastic/".$landing_key;
        break;
    case 'B7':
        $landing_key = "n_fracture";
        $origin_path = "nplastic/".$landing_key;
        break;
    case 'B8':
        $landing_key = "nplastic8";
        $origin_path = "nplastic/".$landing_key;
        break;
    default:
	$landing_key = "n_dns";
	$origin_path = "nsurgery/".$landing_key;
    break;
}
$metaNav = $metaInfo[$landing_key]['nav'];


//$list = $Db->query("SELECT A.no, A.category, A.title, A.content, A.hit, A.reg_date, B.no AS fno, B.attach, B.attach_ori, B.mod_date FROM $TABLE_POST A LEFT JOIN $TABLE_ATTACH B ON A.no = B.wno AND B.code = :code AND B.seq = :seq WHERE A.no > :no AND A.d_show = :show AND A.del = :del AND A.disease = :disease AND A.category LIKE :category ORDER BY A.reg_date DESC LIMIT :startNum, :rowCount", $param);
$list = $Db->query("SELECT A.no, A.category, A.title, A.content, A.hit, A.reg_date,A.youtube, B.no AS fno, B.attach, B.attach_ori, B.mod_date FROM $TABLE_POST A LEFT JOIN $TABLE_ATTACH B ON A.no = B.wno AND B.code = :code AND B.seq = :seq WHERE A.no > :no AND A.d_show = :show AND A.del = :del AND A.category LIKE :category AND type = '".$type."' ORDER BY $addOrderQry A.reg_date DESC LIMIT :startNum, :rowCount", $param);


/*$param2 = array('no' => PARAMETER_NO, 'show' => PARAMETER_Y, 'del' => PARAMETER_N);
$totalCount2 = $Db->single("SELECT COUNT(*) FROM $TABLE_POST WHERE no > :no AND d_show = :show AND del = :del AND category LIKE :category AND type='B'", $param);
$totalPages2 = ceil($totalCount2 / $rowCount);
 
$param2 = array_merge($param2, array('startNum' => $startNum, 'rowCount' => $rowCount));
//echo $param2[startNum];
$searchINS = "";
$orderINS = "no DESC";
$list2 = $Db->query("SELECT no, best, store, title, content, hit, youtube, likes, tag FROM 2015_post3 WHERE no > :no AND d_show = :show AND del = :del $searchINS ORDER BY $orderINS LIMIT :startNum, :rowCount", $param2);
echo "SELECT no, best, store, title, content, hit, youtube, likes, tag FROM 2015_post3 WHERE no > :no AND d_show = :show AND del = :del $searchINS ORDER BY $orderINS LIMIT :startNum, :rowCount";
echo "<br>";
print_r($param2);
*/
$Db->CloseConnection;


include_once PATH_INCLUDE."header.php";

include_once PATH_LANDING.$landing_key.".php";
?>

<style>
.photo img{
	width:389px;
}
.cover{
	_display:none;
}
.infomation_wraper .gallery_list ul li a .cover img{
	width:50px;
	height:50px;
	display:block;
	margin-left:169px;
	margin-top:88px;
}
.infomation_wraper .gallery_list ul li a .photo img{
	width:389px;
	height:218px;
}
.infomation_wraper .gallery_list ul li a .txt_box .name{
	font-size:16px;
}
.infomation_wraper .gallery_list ul li a .title{
	display: block;
    width: 100%;
    font-size: 16px;
    line-height: 36px;
    font-family: 'ng_b';
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
	
	_background:#33a5fc;
	background:#0053b0;
	color:#fff;
	padding:0 10px;
	-webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
          box-sizing: border-box;
}
.layer_desc1{
	text-align:center;
	line-height:22px;
	margin-bottom:10px;
}
.login_layerpopup .inner_box .layer_conts{
	padding:20px 30px 40px;
}
@media screen and (max-width:1620px){
	.infomation_wraper .gallery_list ul li{
		width:480px;
		margin:0 16px 20px 0;
	}
	.infomation_wraper .gallery_list ul li a .cover img{
		margin-left:215px;
		margin-top:115px;
	}
	.infomation_wraper .gallery_list ul li a .txt_box .name{
		max-width:440px;
		_line-height:46px;
	}
	.infomation_wraper .gallery_list ul li a .photo img{
		width:480px;
		height:270px;
	}
	.infomation_wraper .gallery_list ul li a .title{
		font-size:16px;
		line-height:36px;
		_width:480px;
	}
}
@media screen and (max-width:640px){
	.infomation_wraper .gallery_list{
		margin:0px;
	}
	.text{
		margin-left:0px;
	}
	.infomation_wraper .gallery_list ul .title{
		margin-left:0%;
	}
	.infomation_wraper .gallery_list ul li{
		width:45%;
		margin:0 2.5% 15px 2.5%;
	}
	.infomation_wraper .gallery_list ul li a .cover img{
		margin:auto;
		margin-top:10vw;
		width:6vw;
		height:6vw;
	}
	.infomation_wraper .gallery_list ul li a .txt_box .name{
		
		font-size:11px;
	}
	.infomation_wraper .gallery_list ul li a .photo img{
		width:100%;
		height:25vw;
	}
	.infomation_wraper .gallery_list ul li a .title{
		font-size:12px;
		line-height:20px;
		_width:100%;
	}
}
</style>
	<div id="contents">
	</div>
    <div id="tab" class="tab_wraper2">
        <div class="public_inner">
            <div class="tab_style1 two">
                <ul>
					<li <? if($type == "A"){ ?> class="on" <? } ?>><a href="/front/seo/seo_list2.php?category=<?=$category?>&disease=Y&type=A#tab">수술/질환정보</a></li>
					<li <? if($type == "B"){ ?> class="on" <? } ?>><a href="/front/seo/seo_list2.php?category=<?=$category?>&disease=N&type=B#tab">관련 영상</a></li>
                    <!--li <? if($disease == "Y"){ ?> class="on" <? } ?>><a href="?category=<?=$category?>&disease=Y#tab">수술정보</a></li>
                    <li <? if($disease == "N" || $disease == ""){ ?> class="on" <? } ?>><a href="?category=<?=$category?>&disease=N#tab">질환정보</a></li-->
					<!--li <? if($disease == "N"){ ?> class="on" <? } ?>><a href="#tab">수술/질환정보</a></li-->
                </ul>
            </div>
        </div>
    </div>

    <div class="infomation_wraper">
        <div class="public_inner <? if($type == 'B'){ echo "gallery_list";}?>">
            <ul>
            <?
			if($type == 'A'){
            if($totalCount > 0){
                foreach ($list as $key => $val) {
                    $no = $val['no'];
                    $title = stripslashes($val['title']);
                    $content = stripslashes($val['content']);
                    $imgPath = ($val['attach']) ? $pathInfo['post']['file'].DateConv($val['mod_date'], 3)."/".$val['attach'] : PATH_IMAGES."/common/no_img.png";
                    $content = StrCut(strip_tags($content), 0, 125, "...");
                    $reg_date = DateConv($val['reg_date'], 11);
                    $hit = $val['hit'];
            ?>
                <li>
                    <a href="/front/seo/seo_view2.php?no=<?=$no?>&category=<?=$category?>&disease=<?=$disease?>&page=<?=$page?>&tab=<?=$tab?>&type=<?=$type?>#tab">
                        <img src="<?=$imgPath?>" alt="" />
                        <div class="text">
                            <strong><?=$title?></strong>
                            <p><?=$content?></p>
                            <div class="info">
                                <span class="datestr">등록일 : </span>
                                <span class="date"><?=$reg_date?></span>
                                <span class="hitstr">조회수 : </span>
                                <span class="hit"><?=$hit?></span>
                            </div>
                        </div>
                    </a>
                </li>
            <?
                }
            } else {
            ?>
                <li>내용이 없습니다.</li>
            <? }	}else if($type == 'B'){ ?>
			<?

                    if($totalCount > 0){
                        foreach($list as $key => $val){
                            $no = $val['no'];
                            $best = ($val['best'] === "Y" && $sb === "Y") ? "best" : "";
                            $store = $storeNameArr[$val['store']];
                            $storeColor = StoreColorClass($val['store']);
                            $name = Utf8SubstrReplace(stripslashes($val['name']), "o");
                            $title = stripslashes($val['title']);
                            $content = stripslashes($val['content']);
                            preg_match("/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i", $content, $contImg);
							$imgPath = "https://i.ytimg.com/vi/".$val['youtube']."/mqdefault.jpg";
							$likes = $val['likes'];
                            $hit = $val['hit'];
                            $insert_date = DateConv($val['insert_date'], 7);
							$tag = $val['tag'];
							$tag_arr = explode(',',$tag);
							$mTagMatch = 0;
							foreach($tag_arr as $kw){
								if(in_array($kw, $mTagArr)){
									$mTagMatch = 1;
								}
							}
                    ?>
                        <li class="<?=$bestClass?>">
                            <a href="/front/seo/seo_view2.php?no=<?=$no?>&category=<?=$category?>&disease=<?=$disease?>&page=<?=$page?>&tab=<?=$tab?>&type=<?=$type?>#tab" data-mtag="<?=$mTagMatch?>">
                                <span class="photo"><img src="<?=$imgPath?>" alt="" /></span>
								
                                <span class="cover"><img src="<?=PATH_IMAGES?>/common/video_play3.png" alt="" /></span>
								
								
                                <span class="best"><img src="<?=PATH_IMAGES?>/epilogue/ico_best.png" alt="BEST" /></span>
								<span class="title"><?=$title?></span>
                            </a>
                        </li>
                    <?
                        }
			}else{
			?><li>내용이 없습니다.</li><?
			}	}
                    ?>
            </ul>
			
            <div class="pagination_wrap">
				
				
                <? if($totalPages > 0) Pageing($totalPages, $blockCount, $page, $addPath,'#tab'); ?>
				
            </div>
        </div>
    </div>
</div><!-- end : container -->

<?php
include_once PATH_INCLUDE."footer.php";

?>
