<?php
include_once ("./static_data/code.php");

$arr_category_add1 = array();
$arr_category_add2 = array();
$arr_category_add3 = array();
foreach ($arr_category as $key=>$val) {
	if($val['depth'] == '1') {
		$arr_category_add1[] = array('category_code'=>$val['category_code'], 'category_name'=>$val['category_name'], 'p_category_code'=> $val['p_category_code']);
	} else if($val['depth'] == '2') {
		$arr_category_add2[$val['p_category_code']][] = array('category_code'=>$val['category_code'], 'category_name'=>$val['category_name'], 'p_category_code'=> $val['p_category_code']);
	} else if($val['depth'] == '3') {
		$arr_category_add3[$val['p_category_code']][] = array('category_code'=>$val['category_code'], 'category_name'=>$val['category_name'], 'p_category_code'=> $val['p_category_code']);
	}
}


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

?>


<form name="input_form" id="input_form" method="post" action="/admin/news/news_ranking_log_list/2">
<input type="hidden" id="search_ranking_type" name="search_ranking_type" value="<?=$search_ranking_type?>">
<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><a href="/admin/news/news_ranking_log_list/2" <? if($search_ranking_type=='') { echo 'class="on"';}?>>전체</a></li>
<?  foreach($def_arr_ranking as $val) {
		$css = '';
		if($search_ranking_type == $val['code']) {
			$css = ' class="on"';
		}
?>
		<li><a href="/admin/news/news_ranking_log_list/2?search_ranking_type=<?=$val['code']?>" <?=$css?>><?=$val['name']?></a></li>
<?  }?>
	</ul>

	<div class="searh_area">
		<select name="search_type" id="search_type">
			<option value="">선택</option>
			<option value="title" <? if($search_type=='title'){ echo 'selected';}?>>제목</option>
					<option value="press_name" <? if($search_type=='press_name'){ echo 'selected';}?>>언론사</option>
					<option value="reporter_name" <? if($search_type=='reporter_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_table clearfix" 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>
	<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: 5px"><input type="radio" name="sort" value="5" <? if($sort=='5') { echo 'checked';}?> onclick="check_search();"> 공유순</span>

	<div class="searh_area">
		<select name="search_category_code1" onchange="category_search()" class="type01">
							<option value="">1차섹션</option>
			<?	if(count($arr_category_add1) > 0) {
			 		foreach ($arr_category_add1 as $val) {?>
							<option value="<?=$val['category_code']?>" <? if($search_category_code1==$val['category_code']) { echo 'selected'; }?>><?=$val['category_name']?></option>
			<?		}
				}	?>
						</select>
						<select name="search_category_code2" onchange="category_search()" class="type01">
							<option value="">2차섹션</option>
			<?	if(isset($arr_category_add2[$search_category_code1])==true) {
			 		foreach ($arr_category_add2[$search_category_code1] as $val) {
			?>
							<option value="<?=$val['category_code']?>" <? if($search_category_code2==$val['category_code']) { echo 'selected'; }?>><?=$val['category_name']?></option>
			<?		}
				}
			?>
						</select>
						<select name="search_category_code3" onchange="category_search()" class="type01">
							<option value="">3차섹션</option>
			<?	if(isset($arr_category_add3[$search_category_code2])==true) {
					foreach ($arr_category_add3[$search_category_code2] as $val) {?>
							<option value="<?=$val['category_code']?>" <? if($search_category_code3==$val['category_code']) { echo 'selected'; }?>><?=$val['category_name']?></option>
			<?		}
				}	?>
		</select>&nbsp;&nbsp;&nbsp;&nbsp;
		<select name="search_year" onchange="check_search()" class="type01">
			<option value="">선택</option>
	<?  for ($i=2018;$i<=date("Y");$i++) {?>
			<option value="<?=$i?>" <? if($search_year==$i) { echo 'selected';}?>><?=$i?></option>
	<?  } ?>
		</select>
		<select name="search_month" onchange="check_search()" class="type01">
			<option value="">선택</option>
	<?  for ($i=1;$i<=12;$i++) {?>
			<option value="<?=sprintf('%02d',$i)?>" <? if($search_month==sprintf('%02d',$i)) { echo 'selected';}?>><?=sprintf('%02d',$i)?></option>
	<?  } ?>
		</select>
		<select name="search_day" onchange="check_search()" class="type01">
			<option value="">선택</option>
	<?
		$end_day = date("t", mktime(0, 0, 0, $search_month, 1, $search_year));
		for ($i=1;$i<=$end_day;$i++) {?>
			<option value="<?=sprintf('%02d',$i)?>" <? if($search_day==sprintf('%02d',$i)) { echo 'selected';}?>><?=sprintf('%02d',$i)?></option>
	<?  } ?>
		</select>
	</div>
</div>



<div class="common_table">
	<table>
	<thead>
		<tr>
			<th>순위</th>
			<th>썸네일</th>
			<th>섹션</th>
			<th>테마</th>
			<th>제목</th>
			<th>언론사</th>
			<th>기자</th>
			<th>등록일시</th>
			<th>조회수</th>
			<th>좋아요</th>
			<th>댓글수</th>
		</tr>
	</thead>
	<tbody>

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

		foreach($list as $val) {
            $idx            = $val['idx'];
			$title 			= $val['title'];
			$main_img       = $val['main_img'];
			$category_name1 = $val['category_name1'];
			$ranking_type 	= $val['ranking_type'];
			$press_name     = $val['press_name'];
			$reporter_name 	= $val['reporter_name'];
			$reg_date 	    = $val['reg_date'];
            $hit_count 	    = $val['hit_count'];
            $like_count 	= $val['like_count'];
            $comment_count 	= $val['comment_count'];
            $share_count 	= $val['share_count'];
            $reg_date 		= $val['reg_date'];
            $rank 	        = $val['rank'];

            $ranking_type_txt = $def_arr_ranking[$ranking_type]['name'];

?>
		<tr>
				<td><?=$rank?></td>
				<td><img src="<?=$main_img?>" width="35"></td>
				<td><?=$category_name1?></td>
				<td><?=$ranking_type_txt?></td>
				<td style="text-align:left;">&nbsp;&nbsp;<?=$title?></td>
				<td><?=$press_name?></td>
				<td><?=$reporter_name?></td>
				<td><?=$reg_date?></td>
				<td><?=$hit_count?></td>
				<td><?=$like_count?></td>
				<td><?=$comment_count?></td>
			</tr>
<?
		   
		}
	}
?>
</tbody>
	</table>
</div>
	

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


</div>
</form>

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

function category_search(){
	$("#input_form").submit();
}


</script>