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



<form name="input_form" id="input_form" method="post" action="/admin/etc_section/recommend_app_list/6" enctype="multipart/form-data">
<input type="hidden" id="idx" name="idx">
<input type="hidden" id="del_key" name="del_key">
<input type="hidden" id="mode" name="mode">
<input type="hidden" id="search_type" name="search_type" value="app_name">



<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">
<span><b>Total:</b> <?=number_format($total_count);?></span>
<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>출력순서</th>
		<th>출력상태</th>
		<th>관리</th>
	</tr>
	</thead>
	<tbody>


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

	} else {

	    $dataNumber = ($total_count + $limit)-($page*$limit);
		foreach($list as $val) {
            $idx            = $val['idx'];
			$app_name 	    = $val['app_name'];
			$icon_img		= $val['icon_img'];
			$market_url		= $val['market_url'];
			$hit_count		= $val['hit_count'];
			$reg_date 	    = $val['reg_date'];
			$display_sort	= $val['display_sort'];
			$is_direct		= $val['is_direct'];

			$reg_date		= substr($reg_date, 0, 10);

			$is_direct_txt = '';
			if($is_direct == 'Y')	$is_direct_txt = '<span class="text_blue">ON</span>';

?>

				<tr>
					<td><input type="checkbox" name="is_del[]" value="<?=$idx?>"></td>
					<td><?=$dataNumber?></td>
					<td><img src="<?=$icon_img?>" width="75"></td>
                    <td><?=$app_name?></td>
                    <td><a href="<?=$market_url?>" target="_blank"><?=$market_url?></a></td>
                    <td><?=$hit_count?></td>
                    <td><?=$reg_date?></td>
                    <td><?=$display_sort?></td>
                    <td><?=$is_direct_txt?></td>

					<td class="tool_btn">
						<a href="javascript:app_edit('<?=$idx?>')"><i class="fa fa-pencil"></i>수정</a>
						<a href="javascript:app_del_proc('<?=$idx?>')"><i class="fa fa-close"></i>삭제</a>
					</td>

				</tr>

<?
		    $dataNumber--;
		}
	}
?>
</tbody>
</table>
<div class="write_btn">
	<a href="javascript:app_arr_del_proc();">삭제</a>
	<a href="javascript:app_add();">어플등록</a>
</div>

<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>
	<h2>추천어플등록</h2>
	<table>
		<tr>
			<th>어플명</th>
			<td>
				<input type="text" name="app_name" id="app_name" class="input00" size="30">
			</td>
		</tr>
		<tr>
			<th>마켓주소</th>
			<td>
				<input type="text" name="market_url" id="market_url" class="input00" size="30">
			</td>
		</tr>
		<tr>
			<th>송출관리</th>
			<td class="tl">
				<input type="checkbox" name="is_direct" id="is_direct" class="input00" value="Y"> 펼침메뉴에 노출
			</td>
		</tr>
		<tr>
			<th>출력순서</th>
			<td class="tl">
				<input type="text" name="display_sort" id="display_sort" class="type03" size="4">
			</td>
		</tr>
		<tr>
			<th>로고첨부</th>
			<td class="tl">
				<span id="load_img"></span>
				<input type="hidden" name="org_icon_img" id="org_icon_img">
				<input type="file" name="icon_img" id="icon_img" class="input00">
			</td>
		</tr>
	</table>
	<div class="write_btn tc">
		<a href="javascript:app_reg_proc('add')" id="btn_add" style="display:none;">신규등록</a>
		<a href="javascript:app_reg_proc('edit')" id="bnt_edit" style="display:none;">수정</a>
		<a href="javascript:commonLayerClose('reg_layer')">취소하기</a>
	</div>
</div>
</div>


<!--// 카테고리 등록/수정 layer -->


</form>


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

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


// 등록 - layer 열기
function app_add() {
	form_reset();
    $("#btn_add").show();
    commonLayerOpen('reg_layer');
}

// form 초기화
function form_reset(){
	$("#bnt_edit").hide();
	$("#btn_add").hide();

	$("#idx").val('');
	$("#app_name").val('');
	$("#marker_url").val('');
	$("#display_sort").val('');
	$("input:checkbox[id='is_direct']").attr("checked", false);
	$("#org_icon_img").val('');
	$('#load_img').empty();
}

// 수정 - layer열기
function app_edit(idx){
	form_reset();

	$("#bnt_edit").show();

	var form_data = {
		"idx"					: idx
    };
    $.ajax({
        url: '/admin/etc_section/recommend_app_detail',
        sync: false,
        type: 'POST',
        dataType: 'json',
        data: form_data,
        success: function (rtn_json) {
        	console.log(rtn_json);
			if(rtn_json.result_code=='0000') {
				var result = rtn_json.result_data;
				$("#idx").val(idx);
				$("#app_name").val(result.app_name);
				$("#market_url").val(result.market_url);
				$("#display_sort").val(result.display_sort);
				if(result.is_direct=='Y') {
					$("input:checkbox[id='is_direct']").attr("checked", true);
				}
				if(result.icon_img!= '') {
					$("#org_icon_img").val(result.icon_img);
					$('#load_img').html('<img src="' + result.icon_img + '" width="250"><br /><input type="checkbox" name="is_del_img" value="Y"> 이미지삭제 ');
				}
				commonLayerOpen('reg_layer');
			} else {
				alert("데이터로드에 실패했습니다.");
				return false;
			}
        },
        error: function (rtnHtml) {
            return false;
        }
    });

}


// 저장
function app_reg_proc(mode){
	if($("#app_name").val()=='') {
		alert("어플명을 입력해주세요.");
		return false;
	}
	if($("#market_url").val()=='') {
		alert("마켓주소를 입력해주세요.");
		return false;
	}
    $("#mode").val(mode);

	$("#input_form").attr("action", "/admin/etc_section/recommend_app_reg_proc");
	$("#input_form").submit();

}

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

// 복수 삭제
function app_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/recommend_app_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>