<?
include_once ("./static_data/code.php");
$menu_code = '64';
require_once (APPPATH.'views/skin/admin/_content_comm.php');


$arr_display = array();
foreach ($arr_display_count as $val) {
	$arr_display[$val['is_display']] = $val['cnt'];
}
$is_display1 = 0; $is_display2 = 0;
if(isset($arr_display['Y'])==true) 	$is_display1 = $arr_display['Y'];
if(isset($arr_display['N'])==true) 	$is_display2 = $arr_display['N'];



?>



<form name="input_form" id="input_form" method="post" action="/admin/etc_section/media_list/6">
<input type="hidden" id="search_etc_section_type" name="search_etc_section_type" value="<?=$search_etc_section_type?>">
<input type="hidden" id="search_is_display" name="search_is_display" value="<?=$search_is_display?>">
<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_tep clearfix type01">
	<ul class="clearfix">
		<li style="width:100px">PC섹션</li>
		<li><a href="/admin/etc_section/media_list/6?search_etc_section_type=2" <? if($search_etc_section_type=='2') { echo 'class="on"';}?>>인기포토</a></li>
		<li><a href="/admin/etc_section/media_list/6?search_etc_section_type=1" <? if($search_etc_section_type=='1') { echo 'class="on"';}?>>인기영상</a></li>
		<li><a href="/admin/etc_section/media_list/6?search_etc_section_type=4" <? if($search_etc_section_type=='4') { echo 'class="on"';}?>>카드뉴스</a></li>
	</ul>
	<div class="searh_area">
		<select name="search_type" id="search_type">
		 	<option value="" <? if($search_type==''){ echo 'selected';}?>>선택</option>
		 	<option value="a.title" <? if($search_type=='a.title'){ echo 'selected';}?>>제목</option>
			<option value="b.search_name" <? if($search_type=='b.search_name'){ echo 'selected';}?>>작성자</option>
		</select> <input type="text" name="search_keyword" id="search_keyword" value="<?=$search_keyword?>" 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_tep clearfix type01">
	<ul class="clearfix">
		<li style="width:100px">모바일섹션</li>
		<li><a href="/admin/etc_section/media_list/6?search_etc_section_type=3" <? if($search_etc_section_type=='3') { echo 'class="on"';}?>>은혜로운 영상</a></li>
	</ul>
</div>




<div class="common_table" style="margin-top: 30px">
	<span><b>Total:</b> <?=number_format($total_count);?></span>
	<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>
	<span style="margin-left: 10px">
		<a href="javascript:search_is_display('Y');"><span class="text_blue">출력중: <?=number_format($is_display1)?></span></a>&nbsp;&nbsp;&nbsp;
		<a href="javascript:search_is_display('N');"><span class="text_red">예약중: <?=number_format($is_display2)?></span></a>
	</span>
	<div class="searh_area">
		<select name="search_content_type" onchange="check_search();" style="width:100px">
			<option value="">카테고리</option>
	<? 	foreach ($def_arr_content as $key=>$val) {?>
			<option value="<?=$key?>" <? if($search_content_type==$key){ echo 'selected';}?>><?=$val?></option>

	<? 	}?>
		</select>
	</div>
</div>







<div class="common_table">

<table>
	<thead>
	<tr>
		<th><input type="checkbox" name="allcheck" id="allcheck"></th>
		<th>번호</th>
		<th>썸네일</th>
		<th>카테고리</th>
		<th>구분</th>
		<th>제목</th>
		<th>작성자</th>
		<th>등록일시</br>(예약일시)</th>
		<th>순위</th>
		<th>조회수</th>
		<th>좋아요수</th>
		<th>댓글수</th>
		<th>관리</th>
	</tr>
	</thead>
	<tbody>


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

	} else {
		$now_date = date("Y-m-d");
	    $dataNumber = ($total_count + $limit)-($page*$limit);
		foreach($list as $val) {
            $idx            	= $val['idx'];
			$title 				= $val['title'];
			$main_img       	= $val['main_img'];
			$content_idx		= $val['content_idx'];
			$content_type		= $val['content_type'];
			$etc_section_type	= $val['etc_section_type'];
			$search_name 		= $val['search_name'];
			$reg_date 	    	= $val['reg_date'];
            $hit_count 	    	= $val['hit_count'];
            $like_count 		= $val['like_count'];
            $comment_count 		= $val['comment_count'];
            $rank 	        	= $val['rank'];
			$is_display			= $val['is_display'];
            $display_date 		= $val['display_date'];

			$display_date_txt = '';
			if($is_display == 'N') {
				$display_date_txt = '</br><span class="text_green">('.$display_date.')</span>';
			}

            $content_txt  		= $def_arr_content[$content_type];
            $etc_section_txt  	= $def_arr_etc_section[$etc_section_type]['name'];

			$new = '';
            if($reg_date == $now_date)	$new = '<img src="/img/admin/board/icon_new.gif" style="vertical-align:middle;margin-top:-3px;" border="0"> ';

			switch ($content_type) {
				case '1':
					$view_url 	= '/admin/news/news_reg/2?mode=edit&idx='.$content_idx;
					$search_url = '/admin/news/news_list/3?search_type=reporter_name&search_keyword='.$search_name;
					break;
				case '2':
					$view_url 	= '/admin/column/column_reg/3?mode=edit&idx='.$content_idx;
					$search_url = '/admin/column/column_list/3?search_type=column_name&search_keyword='.$search_name;
					break;
				case '3':
					$view_url 	= '/admin/life/life_reg/5?mode=edit&idx='.$content_idx;
					$search_url = '/admin/life/life_list/3?search_type=editor_name&search_keyword='.$search_name;
					break;

			}
			
?>

			<tr>
				<td><input type="checkbox" name="is_del[]" value="<?=$idx?>"></td>
				<td><?=$dataNumber?></td>
				<td><img src="<?=$main_img?>" width="35"></td>
				<td><?=$content_txt?></td>
				<td><?=$etc_section_txt?></td>
				<td class="title" style="text-align:left;">
					<a href="javascript:media_edit('<?=$idx?>')"><?=$new?><?=$title?></a>
					<button type="button" class="btn_s_blue" style="width:80px" onclick="location.href='<?=$view_url?>'" style="cursor: pointer;"><?=$content_txt?>보기</button>
				</td>
				<td><a href="<?=$search_url?>"><?=$search_name?></a></td>
				<td><?=$reg_date?><?=$display_date_txt?></td>
				<td><?=$rank?></td>
				<td><?=number_format($hit_count)?></td>
				<td><?=number_format($like_count)?></td>
				<td><?=number_format($comment_count)?></td>
				<td class="tool_btn">
					<a href="javascript:media_edit('<?=$idx?>')"><i class="fa fa-pencil"></i>수정</a>
					<a href="javascript:media_del_proc('<?=$idx?>')"><i class="fa fa-close"></i>삭제</a>
				</td>

			</tr>

<?
		    $dataNumber--;
		}
	}
?>
</tbody>
</table>
<div class="write_btn">
	<a href="javascript:media_arr_del_proc()">삭제</a>
	<a href="javascript:media_list_reg()">송출관리</a>
</div>

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



</form>


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

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


function search_is_display(type){
	$("#search_is_display").val(type);
	$("#input_form").submit();
}

function media_list_reg(){
	$("#mode").val('add');
	$("#input_form").attr("action", "/admin/etc_section/media_list_reg/6");
	$("#input_form").submit();
}


// edit
function media_edit(idx){
	$("#idx").val(idx);
	$("#input_form").attr("action", "/admin/etc_section/media_edit/6");
	$("#input_form").submit();
}

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

// 복수 삭제
function media_arr_del_proc() {
	if($("input:checkbox[name='is_del[]']").is(":checked") == false) {
		alert("삭제할 내용이 없습니다.");
		return false;
	}
	if(confirm("글이 삭제됩니다. 삭제하시겠습니까?") == true) {    //확인
		$("#input_form").attr("action", "/admin/etc_section/media_reg_arr_del_proc");
		$("#input_form").submit();
	} else {   //취소
		return;
	}
}


// checkbox all checked/unchecked
$(function(){
	$("#allcheck").click(function(){
    	if($("#allcheck").prop("checked")) {
    		$("input:checkbox[name='is_del[]']").prop('checked', true); // 전체선택하기
		} else {
      		$("input:checkbox[name='is_del[]']").prop("checked", false);
    	}
  	})
})




</script>