<link rel="stylesheet" href="<?=DIR_CSS?>/jquery-ui.min.css" />
<script src="<?=DIR_JS?>/jquery-ui.min.js"></script>

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


<form name="input_form" id="input_form" method="post">



 <div class="big_search clearfix common_table">
		<ul class="tl moth">
			<a href="javascript:;" onclick="setting_date(this,'0');" id="s_btn_date1" class="on">1일</a>
			<a href="javascript:;" onclick="setting_date(this,'7');" id="s_btn_date2">7일</a>
			<a href="javascript:;" onclick="setting_date(this,'1');" id="s_btn_date3">1개월</a>
			<a href="javascript:;" onclick="setting_date(this,'3');" id="s_btn_date4">3개월</a>
			<a href="javascript:;" onclick="setting_date(this,'6');" id="s_btn_date5">6개월</a>
			<a href="javascript:;" onclick="setting_date(this,'12');" id="s_btn_date6">1년</a>
			<input type="text" name="start_date" id="start_date" class="type02" value="<?=$start_date?>" /> ~ <input type="text" name="end_date" id="end_date" class="type02" value="<?=$end_date?>" />
			<button type="button" class="btn_black" style="width:80px" onclick="check_search();" style="cursor: pointer;">검색</button> <button type="button" class="btn_green" style="width:80px" onclick="excel_downlaod();" style="cursor: pointer;">엑셀다운</button>
		</ul>
 </div>


<!-- 테이블 시작-->
<div class="common_table">
	<span style="font-weight:bold">Total:</span> <?=number_format($total_count);?>
	<table>
		<thead>
			<th>순위</th>
			<th>순위변동</th>
			<th>날짜</th>
			<th>검색어</th>
			<th>검색횟수</th>

		</thead>
		<tbody>

<?
	if(count($list)==0) {
?>
		<tr>
			<td colspan="5">등록된 내용이 없습니다.</td>
		</tr>
<?
	} else {
		foreach($list as $val) {
			$idx 			= $val['idx'];
			$rank 			= $val['rank'];
			$last_rank 		= $val['last_rank'];
			$keyword		= $val['keyword'];
			$search_count	= $val['search_count'];
			$reg_date		= $val['reg_date'];
			$rank_diff 		= $last_rank - $rank;

			$rank_diff_txt = '';
			if($last_rank == 0) {
				$rank_diff_txt = '<span class="txt_red">new</span>';
			} else {
				if($rank_diff == 0) {
					$rank_diff_txt = '-';
				} else if($rank_diff > 0) {
					$rank_diff_txt = "▲ ".$rank_diff;
				} else {
					$rank_diff_txt = "▼ ".abs($rank_diff);
				}
			}
	?>

			<input type="hidden" name="idx[]" value="<?=$idx?>">
			<tr>
				<td><?=$rank?></td>
				<td><?=$rank_diff_txt?></td>
				<td><?=$reg_date?></td>
				<td><?=$keyword?></td>
				<td><?=$search_count?></td>
			</tr>

<? 		}
	}
?>
	</tbody>
</table>

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


</form>


<script type="text/javascript">
// 검색
function check_search(){
	$("#input_form").attr("action", "/admin/setting/realtime_keyword_log_list/1");
	$("#input_form").submit();
}

// 일자 계산
function setting_date(t, termVal){

	$(t).parent().children("a").removeClass("on");
	$(t).addClass("on");

	var nowDate = new Date();
	if(termVal == '') {
		$("#start_date").val('');
		$("#end_date").val('');
	} else {
		if(termVal!='0') {
			if(termVal=='7') {
				nowDate.setDate(nowDate.getDate() - 7);
			} else {
				nowDate.setMonth(nowDate.getMonth() - parseInt(termVal));
			}
		}
		var newDate = new Date(nowDate);
		var sDate = newDate.format("yyyy-MM-dd");
		var eDate = new Date().format("yyyy-MM-dd");

		$("#start_date").val(sDate);
		$("#end_date").val(eDate);



	}
}

// 엑셀다운로드
function excel_downlaod(){
	if($("#start_date").val()==''){
		alert('일자를 선택해주세요.');
		return false;
	}
	if($("#end_date").val()==''){
		alert('일자를 선택해주세요.');
		return false;
	}
	$("#input_form").attr("action", "/admin/setting/realtime_keyword_excel_download_proc");
	$("#input_form").submit();
}


// jquery datepicker
$("#start_date").datepicker({
	inline: true,
	dateFormat: 'yy-mm-dd',
	buttonImage:"/img/btn_date.png",
	showOn: "both",
	buttonImageOnly: true

});
$("#end_date").datepicker({
	inline: true,
	dateFormat: 'yy-mm-dd',
	buttonImage:"/img/btn_date.png",
	showOn: "both",
	buttonImageOnly: true
});


</script>