<?
$menu_code = '521';
require_once (APPPATH.'views/skin/admin/_content_comm.php');

?>



<form name="input_form" id="input_form" method="post" action="/admin/life/life_category_list/5">
<input type="hidden" id="category_idx" name="category_idx">
<input type="hidden" id="search_type" name="search_type" value="category_name">

<div class="common_table clearfix type01">

	<div class="searh_area">
		<input type="text" name="search_keyword" id="search_keyword" value="<?=$search_keyword?>" placeholder="카테고리명" onkeypress="if( event.keyCode==13 ){check_search();}">
		<a href="javascript:check_search();" class="btn"><i class="fa moving_all fa-search" style="margin-left:8px;"></i></a>
	</div>
</div>






<div class="common_table">
<span style="font-weight:bold">Total:</span> <?=number_format($total_count);?>
<span style="margin-left: 5px"><input type="radio" name="sort" value="1" <? if($sort=='1') { echo 'checked';}?> onclick="check_search();"> 채널순</span>
<span style="margin-left: 5px"><input type="radio" name="sort" value="2" <? if($sort=='2') { echo 'checked';}?> onclick="check_search();"> 에디터순</span>
<span style="margin-left: 5px"><input type="radio" name="sort" value="3" <? if($sort=='3') { echo 'checked';}?> onclick="check_search();"> 등록글순</span>
<span style="margin-left: 5px"><input type="radio" name="sort" value="4" <? if($sort=='4') { echo 'checked';}?> onclick="check_search();"> 조회수순</span>
<table>
<tr>
	<th>번호</th>
	<th>카테고리</th>
	<th>등록채널 수</th>
	<th>등록에디터 수</th>
	<th>등록 글 수</th>
	<th>조회수</th>
	<th>노출순서</th>
	<th>생성일자</th>
	<th>관리</th>
</tr>

<?
	if(count($list)==0) {
?>
		<tr>
			<td colspan="9">등록된 내용이 없습니다.</td>
		</tr>
<?
	} else {

	    $dataNumber = ($total_count + $limit)-($page*$limit);
		foreach($list as $val) {
            $idx            = $val['idx'];
			$category_name 	= $val['category_name'];
			$channel_count 	= $val['channel_count'];
			$editor_count 	= $val['editor_count'];
			$article_count 	= $val['article_count'];
			$hit_count      = $val['hit_count'];
			$display_sort  	= $val['display_sort'];
			$reg_date 	    = $val['reg_date'];


?>

		<tr>
			<td><?=$dataNumber?></td>
			<td><?=$category_name?></td>
			<td><?=number_format($channel_count, 0)?></td>
			<td><?=number_format($editor_count, 0)?></td>
			<td><?=number_format($article_count, 0)?></td>
			<td><?=number_format($hit_count, 0)?></td>
			<td><?=number_format($display_sort, 0)?></td>
			<td><?=$reg_date?></td>
			<td class="tool_btn">
				<a href="javascript:category_del_proc('<?=$idx?>')"><i class="fa fa-close"></i>삭제</a>
			</td>

		</tr>

<?
		    $dataNumber--;
		}
	}
?>

</table>
</div>

<div class="write_btn">

	<a href="javascript:commonLayerOpen('category_reg_layer');">카테고리등록</a>
</div>


<div class="pasing_wrap">
	<?=$pagination?>
</div>
</form>



<div id="category_reg_layer" style="display:none">
<div class="black_board" style="display:block"></div>
<div class="pop_con common_table moving_all" style="display:block;top:100px;">
   <a href="javascript:commonLayerClose('category_reg_layer')" class="pop_close">x</a>
	<h2>카테고리등록</h2>
	<table>
		<tr>
			<th>카테고리명</th>
			<td><input type="text" name="category_name" id="category_name"></td>
		</tr>
		<tr>
			<th>출력순서</th>
			<td><input type="text" name="display_sort" id="display_sort"></td>
		</tr>
	</table>
	<div class="write_btn tc">
		<a href="javascript:category_add_proc('add')">신규등록</a>
		<a href="javascript:commonLayerClose('category_reg_layer')">취소하기</a>
	</div>
</div>
</div>





<script type="text/javascript">
function check_search(){
    if($("#search_type").val()=="" && $("#search_keyword").val()!=""){
        alert("검색할 항목을 선택해주세요.");
        return false;
    }

    $("#input_form").submit();
}



// 카테고리 등록
function category_add_proc(){
    var category_name 	= $("#category_name").val();
    var display_sort 	= $("#display_sort").val();
    if(category_name=='') {
        alert("카테고리명을 입력해주세요.");
        return false;
    }

	var form_data = {
		"category_name"			: category_name,
		"display_sort"			: display_sort
    };
    $.ajax({
        url: '/admin/life/life_category_add_proc',
        sync: false,
        type: 'POST',
        dataType: 'html',
        data: form_data,
        success: function (rtnHtml) {
			if(rtnHtml.trim()=='0000') {
                alert("저장되었습니다.");
                window.location.reload(true);

			} else {
				alert("등록에 실패했습니다.");
				commonLayerClose('category_reg_layer');
				return false;
			}
        },
        error: function (rtnHtml) {
            return false;
        }
    });
}

// 삭제
function category_del_proc(idx) {
	if(confirm("회원이 삭제됩니다. 삭제하시겠습니까?") == true) {    //확인
		$("#category_idx").val(idx);
		$("#input_form").attr("action", "/admin/life/life_category_del_proc");
		$("#input_form").submit();
	} else {   //취소
		return;
	}
}

</script>