<?

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



<form name="input_form" id="input_form" method="post" action="/admin/etc_section/press_list/6" enctype="multipart/form-data">
<input type="hidden" id="page" name="page" value="<?=$page?>">
<input type="hidden" id="idx" name="idx">
<input type="hidden" id="mode" name="mode">
<input type="hidden" id="search_type" name="search_type" value="press_name">
<input type="hidden" id="search_click1" name="search_click1" value="<?=$search_click1?>">




<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">
	<span><b>Total:</b> <?=number_format($total_count);?></span>
	<a href="javascript:click_search('1', 'search_click1');"><span style="margin-left:5px"><b>바로가기:</b> <?=number_format($direct_count);?></span></a>
	<span style="margin-left:10px"><input type="radio" name="sort" value="1" <? if($sort=='1') { echo 'checked';}?> onclick="check_search();"> 최신순</span>
	<span style="margin-left:5px"><input type="radio" name="sort" value="2" <? if($sort=='2') { echo 'checked';}?> onclick="check_search();"> 등록기사순</span>
</div>



<div class="common_table">
<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 {
		$now_date = date("Y-m-d");
	    $dataNumber = ($total_count + $limit)-($page*$limit);
		foreach($list as $val) {
            $idx            = $val['idx'];
			$logo_img 		= $val['logo_img'];
			$press_name 	= $val['press_name'];
			$article_count 	= $val['article_count'];
			$homepage 		= $val['homepage'];
			$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="<?=$logo_img?>" width="55"></td>
			<td><?=$press_name?></td>
			<td><?=$article_count?></td>
			<td><a href="<?=$homepage?>" target="_blank"><?=$homepage?></a></td>
			<td><?=$reg_date?></td>
			<td><?=$display_sort?></td>
			<td><?=$is_direct_txt?></td>
			<td class="tool_btn">
				<a href="javascript:press_edit('<?=$idx?>')"><i class="fa fa-pencil"></i>수정</a>
				<a href="javascript:press_del_proc('<?=$idx?>')"><i class="fa fa-close"></i>삭제</a>
			</td>
		</tr>

<?
		    $dataNumber--;
		}
	}
?>
</tbody>
</table>
</div>
<div class="write_btn">
	<a href="javascript:press_arr_del_proc();">삭제</a>
	<a href="javascript:press_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 class="tl">
				<input type="text" name="press_name" id="press_name" class="input00" size="30">
			</td>
		</tr>
		<tr>
			<th>홈페이지</th>
			<td class="tl">
				<input type="text" name="homepage" id="homepage" 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_logo_img" id="org_logo_img">
				<input type="file" name="logo_img" id="logo_img" class="input00">
			</td>
		</tr>
	</table>
	<div class="write_btn tc">
		<a href="javascript:press_reg_proc('add')" id="btn_add" style="display:none;">신규등록</a>
		<a href="javascript:press_reg_proc('edit')" id="bnt_edit" style="display:none;">수정</a>
		<a href="javascript:commonLayerClose('reg_layer')">취소하기</a>
	</div>
</div>
</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();
}


// 등록 - layer 열기
function press_add() {
	form_reset();
    $("#bnt_edit").hide();
    $("#btn_add").show();

    commonLayerOpen('reg_layer');
}

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

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

	var form_data = {
		"idx"					: idx
    };
    $.ajax({
        url: '/admin/etc_section/press_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);
				$("#press_name").val(result.press_name);
				$("#homepage").val(result.homepage);
				$("#display_sort").val(result.display_sort);
				if(result.is_direct=='Y') {
					$("input:checkbox[id='is_direct']").attr("checked", true);
				}
				if(result.logo_img!= '') {
					$("#org_logo_img").val(result.logo_img);
					$('#load_img').html('<img src="' + result.logo_img + '" style="max-width:150px"><br /><input type="checkbox" name="is_del_img" value="Y"> 이미지삭제 ');
				}
				commonLayerOpen('reg_layer');
			} else {
				alert("데이터로드에 실패했습니다.");
				return false;
			}
        },
        error: function (rtnHtml) {
            return false;
        }
    });

}

// 언론사 저장
function press_reg_proc(mode){
	$("#mode").val(mode);
	if($("#press_name").val()=='') {
		alert("언론사명을 입력해주세요.");
		return false;
	}
	$("#input_form").attr("action", "/admin/etc_section/press_reg_proc/6");
	$("#input_form").submit();

}

// form 초기화
function form_reset(){
	$("#idx").val('');
	$("#press_name").val('');
	$("#homepage").val('');
	$("#display_sort").val('');
	$("input:checkbox[id='is_direct']").attr("checked", false);
	$("#org_logo_img").val('');
	$('#load_img').empty();
}

// 삭제
function press_del_proc(idx) {
	if(confirm("언론사가 삭제됩니다. 삭제하시겠습니까?") == true) {    //확인
		$("#idx").val(idx);
		$("#input_form").attr("action", "/admin/etc_section/press_del_proc");
		$("#input_form").submit();
	} else {   //취소
		return;
	}
}

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