<?
	$menu_code = '15';
	require_once (APPPATH.'views/skin/admin/_content_comm.php');
?>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<style>
label, input { display:block; }
input.text { margin-bottom:12px; width:95%; padding: .4em; }
fieldset { padding:0; border:0; margin-top:25px; }
h1 { font-size: 1.2em; margin: .6em 0; }
div#users-contain { width: 350px; margin: 20px 0; }
div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
.ui-dialog .ui-state-error { padding: .3em; }
.validateTips { border: 1px solid transparent; padding: 0.3em; }
</style>

<div class="common_depth3 clearfix">
<ul class="clearfix depth3_tep">
    <li><a href="/admin/advertisement/1">광고 페이지 관리</a></li>
    <li><a href="/admin/advertisement/ad_detail" class="on fw700">개별 광고 관리</a></li>
</ul>
</div>

<div class="write_btn">
	<a href="javascript:fn_ad_detail_arr_del_proc();">삭제</a>
	<a href="ad_register" id="ad_register">등록</a>
</div>

<form name="input_form" id="input_form" action="/admin/setting/setting_comment_reg_proc" method="post">
<input type="hidden" id="idx" name="idx">
<input type="hidden" id="mode" name="mode">
	<div class="common_table news">
	<table>
		<thead>
			<tr>
			<th class="fw500" style="width:50px;"><input type="checkbox" name="allcheck" id="allcheck"></th>
			<th class="fw500" width="100">번호</th>
			<th class="fw500">페이지 이름</th>
			<th class="fw500">광고 위치</th>
			<th class="fw500">광고 코드</th>
			<th class="fw500">광고보기</th>
			<th class="fw500">관리</th>
		</tr></thead>
		<tbody>
	<?php
	$len = count($row);
	foreach($row as $v) {
	?>		
		<tr>
			<td><input type="checkbox" name="is_del[]" value="<?php echo $v['idx'];?>"></td>
			<td><?=$len;?></td>
			<td><?=$v['page_name']?></td>
			<td><?=$v['ad_pos_name']?></td>
			<td><?=$v['ad_code']?></td>
			<td><?
			if(empty(!$v['ad_file'])){
				echo '<img id="image_section" src="'.$v['ad_file'].'" style="max-height: 100%; max-width: 100%;"/>';
			}?></td>
			<td style="width:200px" class="tool_btn">
				<a href="javascript:ad_detail_edit('<?=$v['idx']?>')" class="btn_modify" value="<?php echo $v['idx'];?>"><i class="fa fa-pencil"></i>수정</a>
			</td>
		</tr>
		<?php $len-=1;}?>
		</tbody>
		</table>
	</div>
</form>
<iframe frameborder="1" width="600" height="300" name="ifrm" style="border:2px ccc solid;"></iframe>
<script>

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

// modify data
function ad_detail_edit(idx){
	$("#idx").val(idx);
	$("#mode").val('modify');
	$("#input_form").attr("action", "ad_register");
	$("#input_form").submit();
}

</script>
<?
// 	$(".btn_modify").click(function() {
// 		idx = $(this).attr('value');
// 		if(idx>0) {
// 			$.ajax({
// 				url: '/admin/advertisement/ad_page_edit',
// 				data: {
// 					format: 'json',
// 					idx:idx
// 				},
// 				//dataType: 'jsonp',
// 				type:'get',
// 				success: function(msg) {
// 			        var json = $.parseJSON(msg);
// 			        if(json.result=='success') {
// 			        	$("#popup_mode").val('upt');
// 			        	$("#popup_idx").val(idx);
// 			        	fill_popup_form(json.page_key,json.page_name,json.ad_pos_key,json.ad_pos_name);
// 			        }
// 			    },
// 			      error: function(err) {
// 			        console.log(err);
// 			    }
// 			});
// 		}
// 	});
?>