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

?>


<form name="input_form" id="input_form" method="post" action="/admin/life/life_channel_list/5" enctype="multipart/form-data">
<input type="hidden" id="search_type" name="search_type" value="channel_name">
<input type="hidden" id="page" name="page" value="<?=$page?>">
<input type="hidden" id="idx" name="idx">
<input type="hidden" id="mode" name="mode">


<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"  style="margin-top: 30px">
	<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>
	<div class="searh_area">
		<select name="search_category" onchange="check_search();">
							<option value="">전체</option>
					<?	foreach($category_list as $val) {?>
							<option value="<?=$val['idx']?>" <? if($search_category==$val['idx']) { echo 'selected'; }?>><?=$val['category_name']?></option>
					<?	}?>
						</select>
	</div>

</div>
	
<div class="common_table">
<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_idx 	= $val['category_idx'];
			$category_name 	= $val['category_name'];
			$channel_icon 	= $val['channel_icon'];
			$channel_name 	= $val['channel_name'];
			$editor_count 	= $val['editor_count'];
			$article_count 	= $val['article_count'];
			$hit_count      = $val['hit_count'];
			$reg_date 	    = $val['reg_date'];
            $reg_date 	    = substr($reg_date, 0, 10);


?>

		<tr>
			<td><?=$dataNumber?></td>
			<td><a href="/admin/life/life_category_list/5?search_type=category_name&search_keyword=<?=$category_name?>"><?=$category_name?></a></td>
			<td><img src="<?=$channel_icon?>" width="40px"></td>
			<td><a href="/admin/member/editor_list/4?$search_category_code1=<?=$category_idx?>&search_category_code2=<?=$idx?>"><?=$channel_name?></a></td>
			<td><?=number_format($editor_count)?></td>
			<td><?=number_format($article_count)?></td>
			<td><?=number_format($hit_count)?></td>
			<td><?=$reg_date?></td>
			<td class="tool_btn">
				<a href="javascript:channel_edit('<?=$idx?>')"><i class="fa fa-pencil"></i>수정</a>
				<a href="javascript:channel_del_proc('<?=$idx?>')"><i class="fa fa-close"></i>삭제</a>
			</td>

		</tr>

<?
		    $dataNumber--;
		}
	}
?>

</table>
</div>
<div class="write_btn">
	<a href="javascript:channel_icon_add();">채널아이콘등록</a>
	<a href="/admin/life/life_channel_reg/5">채널등록</a>
</div>


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





<div id="icon_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('icon_reg_layer')" class="pop_close">x</a>
	<h2>채널아이콘</h2>
	<table>
		<tr style="height:50px">
			<th>아이콘리스트</th>
			<td class="tl">
				<div class="icon_list" style="overflow-y: scroll; height:150px;">
		<?	foreach ($channel_icon_list as $val) {?>
			  <a href="javascript:;" class="por">
				  <img src="<?=$val['channel_icon']?>"  alt=""/>
			  </a>
		<?	}?>
				</div>
			</td>
		</tr>
		<tr>
			<th>아이콘첨부</th>
			<td class="tl">
				<input type="file" name="channel_icon" id="channel_icon" class="input00" size="30" >
			</td>
		</tr>

	</table>
	<div class="write_btn tc">
		<a href="javascript:channel_icon_add_proc()">신규등록</a>
		<a href="javascript:commonLayerClose('icon_reg_layer')">취소하기</a>
	</div>
</div>
</div>


</form>


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

// edit
function channel_edit(idx){
	$("#idx").val(idx);
	$("#mode").val('edit');
	$("#input_form").attr("action", "/admin/life/life_channel_reg/5");
	$("#input_form").submit();
}



// 채널아이콘등록
function channel_icon_add(){
	commonLayerOpen('icon_reg_layer');
}

function channel_icon_add_proc(){
    var channel_icon 	= $("#channel_icon").val();
    if(channel_icon=='') {
        alert("아이콘을 등록해주세요.");
        return false;
    }
    $("#input_form").attr("action", "/admin/life/life_channel_icon_add_proc");
	$("#input_form").submit();

}

// 삭제
function channel_del_proc(idx) {
	$("#idx").val(idx);
	if(confirm("채널을 삭제하면 하위글도 모두 삭제됩니다. 삭제하시겠습니까?") == true) {    //확인
		$("#category_idx").val(idx);
		$("#input_form").attr("action", "/admin/life/life_channel_del_proc");
		$("#input_form").submit();
	} else {   //취소
		return;
	}
}

</script>