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


$arr_status = array();
$arr_status[1] = '0';
$arr_status[2] = '0';
foreach ($status_list as $val) {
	$arr_status[$val['limit_status']] = $val['cnt'];
}

?>




<form name="input_form" id="input_form" method="post" action="/admin/setting/blind_limit_list/1">
<input type="hidden" id="page" name="page" value="<?=$page?>">
<input type="hidden" id="search_type" name="search_type" value="member">
<input type="hidden" id="search_is_today" name="search_is_today" value="<?=$search_is_today?>">
<input type="hidden" id="idx" name="idx">

<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">
	<a href="javascript:search_total();"><span><b>Total:</b> <?=number_format($total_count);?></span></a>
	<a href="javascript:search_today('Y');"><span style="margin-left:10px"><b>오늘신규:</b> <?=number_format($new_count);?></span></a>
    <a href="javascript:search_status(1);"><span style="margin-left:10px" class="text_red"><b>제재진행중:</b> <?=number_format($arr_status[1]);?></span></a>
    <a href="javascript:search_status(2);"><span style="margin-left:10px" class="text_blue"><b>제재완료:</b> <?=number_format($arr_status[2]);?></span></a>

	<div class="searh_area">
		<select name="search_limit_type" id="search_limit_type" onchange="check_search();" style="width:120px">
			<option value="" <? if($search_limit_type==""){ echo 'selected';}?>>제재내용</option>
	<? 	foreach ($def_arr_blind_limit_type as $key1=>$val1) {?>
			<option value="<?=$key1?>" <? if($search_limit_type==(string)$key1){ echo 'selected';}?>><?=$val1?></option>
	<? 	}?>
		</select>
		<select name="search_status" id="search_status" onchange="check_search();" style="width:120px">
			<option value="" <? if($search_status==""){ echo 'selected';}?>>진행상태</option>
	<? 	foreach ($def_arr_blind_limit_status as $key2=>$val2) {?>
			<option value="<?=$key2?>" <? if($search_status==(string)$key2){ echo 'selected';}?>><?=$val2?></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>
	</tr>
	</thead>
	<tbody>


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

	} else {
	    $dataNumber = ($total_count + $limit)-($page*$limit);
		foreach($list as $val) {
            $idx            	= $val['idx'];
			$limit_type 		= $val['limit_type'];
			$limit_status 		= $val['limit_status'];
			$member_id       	= $val['member_id'];
			$member_name	    = $val['member_name'];
			$start_date	        = $val['start_date'];
			$end_date	        = $val['end_date'];
			$limit_sum_count	= $val['limit_sum_count'];

            $limit_type_txt     = $def_arr_blind_limit_type[$limit_type];
            $limit_status_txt  	= $def_arr_blind_limit_status[$limit_status];
?>

			<tr>
				<td><?=$dataNumber?></td>
				<td><?=$member_id?>(<?=$member_name?>)</td>
				<td><?=number_format($limit_sum_count)?>회</td>
				<td><?=$limit_type_txt?></td>
				<td><?=$limit_status_txt?></td>
				<td><?=$start_date?></br><span class="text_blue"><?=$end_date?></span></td>
				<td class="tool_btn">
					<? if($limit_status != '2') {?>
                    <a href="javascript:blind_limit_edit('<?=$idx?>')"><i class="fa fa-close"></i>수정</a>
					<? }?>
				</td>
			</tr>

<?
		    $dataNumber--;
		}
	}
?>
</tbody>
</table>

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




<div id="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('reg_layer')" class="pop_close">x</a>
	<input type="hidden" name="start_date" id="start_date">
	<input type="hidden" name="blind_setting_idx" id="blind_setting_idx">
	<input type="hidden" name="blind_id" id="blind_id">
	<h2>제재 수정</h2>
	<table>
		<tr>
			<th>아이디</th>
			<td class="tl"><div id="layer_member"></div></td>
		</tr>
		<tr>
			<th>제재일</th>
			<td class="tl">
				<input type="text" name="limit_day" id="limit_day" class="type03">일 동안
			</td>
		</tr>
        <tr>
			<th>제재내용</th>
			<td class="tl">
				<select name="limit_type" id="limit_type" style="width:120px">
                    <option value="">선택</option>
            <? 	foreach ($def_arr_blind_limit_type as $key1=>$val1) {?>
                    <option value="<?=$key1?>"><?=$val1?></option>
            <? 	}?>
                </select>
			</td>
		</tr>
        <tr>
			<th>제재상태</th>
			<td class="tl">
				<select name="limit_status" id="limit_status" style="width:120px">
                    <option value="">선택</option>
            <? 	foreach ($def_arr_blind_limit_status as $key2=>$val2) {?>
                    <option value="<?=$key2?>"><?=$val2?></option>
            <? 	}?>
                </select>
			</td>
		</tr>
		<tr>
			<th>마지막수정일</th>
			<td class="tl"><div id="layer_update_date"></div></td>
		</tr>
	</table>
	<div class="write_btn tc">
		<a href="javascript:blind_limit_edit_proc()">수정</a>
		<a href="javascript:commonLayerClose('reg_layer')">취소하기</a>
	</div>
</div>
</div>






</form>


<script type="text/javascript">
function search_status(type) {
	$("#search_status").val(type);
	$("#input_form").submit();
}

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

function search_total() {
	$("#search_status").val('');
	$("#search_is_today").val('');
	$("#input_form").submit();
}


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

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

function reset(){
    $("#idx").val('');
    $("#layer_member").empty();
    $("#limit_day").val('');
    $("#layer_update_date").empty();
    $("#limit_type").val("").prop("selected", true);
    $("#limit_status").val("").prop("selected", true);
}

// 수정 - layer열기
function blind_limit_edit(idx){
    reset();

    $("#idx").val(idx);
	var form_data = {
		"idx"					: idx
    };
    $.ajax({
        url: '/admin/setting/blind_limit_detail',
        sync: false,
        type: 'POST',
        dataType: 'json',
        data: form_data,
        success: function (rtn_json) {
			if(rtn_json.result_code=='0000') {
				var result = rtn_json.result_data;

                var member = result.member_id + "("+result.member_name+")";
                $("#layer_member").html(member);
                $("#blind_id").val(result.member_id);
                $("#limit_day").val(result.limit_day);
                $("#layer_update_date").html(result.update_date);
                $("#limit_type").val(result.limit_type).prop("selected", true);
				$("#start_date").val(result.start_date);
				$("#blind_setting_idx").val(result.blind_setting_idx);
				$("#limit_status").val(result.limit_status).prop("selected", true);



			    commonLayerOpen('reg_layer');
			} else {
				alert("데이터로드에 실패했습니다.");
				return false;
			}
        },
        error: function (rtnHtml) {
            return false;
        }
    });

}


function blind_limit_edit_proc(){
	if($("#limit_day").val()=='') {
		alert("제재일을 입력해주세요.");
		return false;
	}
	if($("#limit_type").val()=='') {
		alert("제재내용을 입력해주세요.");
		return false;
	}
	if($("#limit_status").val()=='') {
		alert("제재상태를 입력해주세요.");
		return false;
	}

	if($("#limit_type").val()=='0') {
		alert("경고메일은 발송할수 없습니다.");
		return false;
	}

	$("#input_form").attr("action", "/admin/setting/blind_limit_edit_proc");
	$("#input_form").submit();

}

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






</script>