<?php
$is_reply_y_count = 0;
if(isset($arr_is_reply_count['Y'])==true)	$is_reply_y_count = 	$arr_is_reply_count['Y'];

$is_reply_n_count = 0;
if(isset($arr_is_reply_count['N'])==true)	$is_reply_n_count = 	$arr_is_reply_count['N'];


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


<form name="input_form" id="input_form" method="post" action="/admin/cs/cs_question_list/7">
<input type="hidden" id="page" name="page" value="<?=$page?>">
<input type="hidden" id="idx" name="idx">
<input type="hidden" id="search_click1" name="search_click1" value="<?=$search_click1?>">
<input type="hidden" id="search_click2" name="search_click2" value="<?=$search_click2?>">

<div class="common_table clearfix type01">
	<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="write_name" <? if($search_type=='write_name'){ echo 'selected';}?>>글쓴이</option>
			<option value="mobile_no" <? if($search_type=='mobile_no'){ echo 'selected';}?>>연락처</option>
			<option value="email" <? if($search_type=='email'){ 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">
	<span style="font-weight:bold">Total:</span> <?=number_format($total_count);?>
	<a href="javascript:click_search(1, 'search_click1');"><span style="font-weight:bold">오늘신규:</span> <?=number_format($new_count);?></a>
	<a href="javascript:click_search(1, 'search_click2');"><span style="font-weight:bold" class="text_blue">처리완료:</span> <?=number_format($is_reply_y_count);?></a>
	<a href="javascript:click_search(2, 'search_click2');"><span style="font-weight:bold" class="text_red">미처리:</span> <?=number_format($is_reply_n_count);?></a>
	<table>
		<thead>
			<th><input type="checkbox" name="allcheck" id="allcheck"></th>
			<th>번호</th>
			<th>제목</th>
			<th>글쓴이</th>
			<th>연락처</th>
			<th>이메일</th>
			<th>작성일</th>
			<th>처리상태</th>
			<th>관리</th>
		</thead>
		<tbody>


<?
	if(count($list)==0) {
?>
		<tr>
			<td colspan="9">등록된 내용이 없습니다.</td>
		</tr>
<?
	} else {
		$now_date = date("Y-m-d");
	    $dataNumber = ($total_count + $limit)-($page*$limit);
		foreach($list as $val) {
            $idx            = $val['idx'];
			$s_idx          = $val['s_idx'];
			$title 			= $val['title'];
			$write_id 		= $val['write_id'];
			$write_name 	= $val['write_name'];
			$mobile_no      = $val['mobile_no'];
			$email 	        = $val['email'];
			$reg_date 	    = $val['reg_date'];
			$is_reply 	    = $val['is_reply'];
			$reg_date		= substr($reg_date, 0, 10);


			switch ($is_reply) {
				case 'Y': $is_reply_txt = '<span class="text_blue">처리완료</span>'; break;
				case 'N': $is_reply_txt = '<span class="text_red">미처리</span>'; break;
				default : $is_reply_txt = ''; break;
			}

			if($s_idx > 1) {
				$is_reply_txt = '';
			}


			$reply_icon = ''; $new = '';
			if($s_idx > 1) {
				$reply_icon ='<img src="/img/admin/board/icon_reply.gif"  style="vertical-align:middle;margin-top:-3px;" border="0">&nbsp;&nbsp;';
			} else {
				if($reg_date == $now_date)	$new = '<img src="/img/admin/board/icon_new.gif"  style="vertical-align:middle;margin-top:-3px;" border="0">&nbsp;&nbsp;';
			}


?>

			<tr>
				<td><input type="checkbox" name="is_del[]" value="<?=$idx?>"></td>
				<td><?=$dataNumber?></td>
				<td class="title"><a href="javascript:question_view('<?=$idx?>')"><?=$reply_icon?><?=$new?><?=$title?></a></td>
				<td><?=$write_id?>(<?=$write_name?>)</td>
				<td><?=$mobile_no?></td>
				<td><?=$email?></td>
				<td><?=$reg_date?></td>
				<td><?=$is_reply_txt?></td>
				<td class="tool_btn">
				<? 	if($s_idx==1) {?>
					<a href="javascript:question_reply_add('<?=$idx?>')"><i class="fa fa-pencil"></i>답글쓰기</a>
				<?	} else { ?>
					<a href="javascript:question_reply_del_proc('<?=$idx?>')"><i class="fa fa-close"></i>삭제</a>
				<?	} ?>
				</td>
			</tr>

<?
		    $dataNumber--;
		}
	}
?>

</tbody>
</table>
</div>

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

<div class="write_btn">
	<a href="javascript:popup_arr_del_proc()">삭제</a>
</div>

</form>


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

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

function click_search(type, id){
	$("#"+id).val(type);
	$("#input_form").submit();
}



// 댭글쓰기
function question_reply_add(idx){
	$("#idx").val(idx);
	$("#input_form").attr("action", "/admin/cs/cs_question_reply_add/7");
	$("#input_form").submit();
}

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

// view
function question_view(idx){
	$("#idx").val(idx);
	$("#input_form").attr("action", "/admin/cs/cs_question_view/7");
	$("#input_form").submit();
}


// 복수 삭제
function popup_arr_del_proc() {
	if($("input:checkbox[name='is_del[]']").is(":checked") == false) {
		alert("삭제할 내용이 없습니다.");
		return false;
	}
	if(confirm("답글이 삭제됩니다. 삭제하시겠습니까?") == true) {    //확인
		$("#input_form").attr("action", "/admin/cs/cs_question_reply_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>