<?php
$menu_code = '1050';
require_once (APPPATH.'views/skin/admin/_content_comm.php');
?>
<!-- jquery UI -->
<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>
<!-- //jquery UI -->


<div class="common_table"  style="margin-top: 30px">
	<span style="font-weight:bold">Total:</span> <?//=number_format($total_count);?>

	 <span style="margin-left:20px">
    <?/*
        foreach ($arr_default_member_gendar as $val) {
            $member_gender_count = 0;
            if(isset($arr_member_gender[$val['code']])==true) {
                $member_gender_count = $arr_member_gender[$val['code']];
            }
	?>
			<b><?=$val['txt']?>:</b> <a href="javascript:click_search('search_member_gender', '<?=$val['code']?>');"><?=number_format($member_gender_count)?></a>&nbsp;&nbsp;
    <?
        }
    ?>
        </span>
        <span style="margin-left:20px">
    <?
        foreach ($arr_default_member_group as $val) {
            $member_group_count = 0;
            if(isset($arr_member_group[$val['code']])==true) {
                $member_group_count = $arr_member_group[$val['code']];
            }
            echo '<b>'.$val['txt'].':</b> '.number_format($member_group_count).'&nbsp;&nbsp;';
        }
    ?>
        </span>
        <span style="margin-left:20px"><b>오늘신규가입:</b> <a href="javascript:click_search('search_member_new', 'today');"><?=number_format($member_new_count);?></a></span>
	</ul>
    <ul style="text-align:left; padding-top:10px; padding-bottom:10px;">
        <span>
    <?
        foreach ($arr_default_member_age as $val) {
            $member_age_count = 0;
            if(isset($arr_member_age[$val['code']])==true) {
                $member_age_count = $arr_member_age[$val['code']];
            }
	?>
			<b><?=$val['txt']?>:</b> <a href="javascript:click_search('search_member_age', '<?=$val['code']?>');"><?=number_format($member_age_count)?></a>&nbsp;&nbsp;
    <?
        }*/
    ?>
        </span>


</div>

<!-- 테이블 시작-->
<div class="common_table">
<table>
	<thead>
		<th>번호</th>
		<th>맵툰작가</th>
		<th>작가 블로그 & 홈페이지 주소</th>
		<th>관리</th>
	</thead>
	<tbody>
<?php
if(isset($list)==TRUE) {
	if(count($list)==0) {
		echo '<tr><td colspan="4">등록된 내용이 없습니다.</td></tr>';
	} else {
	    //$dataNumber = ($total_rows + $limit)-($page*$limit);
		foreach($list as $val) {
            $idx                = $val['idx'];
			$name 	    = $val['name'];
			$website 	    = $val['website'];
?>
				<tr>
					<td><?php echo $idx?></td>
                    <td><?php echo $name?></td>
                    <td><?php echo $website?></td>
					<td style="width:200px" class="tool_btn">
						<a href="#"  class="btn_modify" value="<?php echo $idx;?>"><i class="fa fa-pencil"></i>수정</a>
						<a href="#" class="btn_delete" value="<?php echo $idx;?>"><i class="fa fa-close"></i>삭제</a>
					</td>
				</tr>
<?php
		    //$dataNumber--;
		}
	}
}
?>
	</tbody>
	</table>
</div>


<div class="write_btn">
	<!--a href="javascript:news_arr_del_proc();">삭제</a-->
	<a href="#" id="btn_reg">등록</a>
</div>

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



<!-- register popup -->
<div id="dialog" title="맵툰 작가 등록/수정" style="display:none;">
  <!--p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p-->
  <form name="popup" action="" target="ifrm" method="post">
  	<input type="hidden" id="popup_mode" name="mode" value="" />
  	<input type="hidden" id="popup_idx" name="idx" value="" />
    <fieldset>
      <label for="name">맵툰 작가명</label>
      <input type="text" id="name" name="name" value="" class="text ui-widget-content ui-corner-all" maxlength="50">
      <label for="website">홈페이지 & 블로그 주소</label>
      <input type="text" id="website" name="website" value="" class="text ui-widget-content ui-corner-all" maxlength="300">

      <input type="button" value=" 등록 " id="btn_register" tabindex="-1" >
    </fieldset>
  </form>
</div>
<!-- //register popup -->

<iframe name="ifrm" frameborder="0" width="0" height="0" style="display:none;"></iframe>

<script type="text/javascript">
$(document).ready(function() {
	$("#btn_reg").click(function() {
		$("#dialog").dialog();
		return false;
	});

	function reset_popup_form() {
		$("#name").val('');
		$("#website").val('');
		$( "#dialog" ).dialog();
	}

	function fill_popup_form(a,b) {
		if(a!='' && b!='') {
			reset_popup_form();
			$("#name, json.website").val(a);
			$("#website").val(b);
			$( "#dialog" ).dialog();
		}
	}

	$(".btn_delete").click(function() {
		idx = $(this).attr('value');
		if(idx>0 && confirm('정말 삭제하시겠습니까?')) {
			frm = $("form[name='popup']");
			frm.attr('target','ifrm');
			$("#popup_idx").val(idx);
			frm.attr('action','/admin/maptoon/cartoonist_del_proc');
			frm.submit();
		}
	});

	$(".btn_modify").click(function() {
		idx = $(this).attr('value');
		if(idx>0) {
			$.ajax({
				url: '/admin/maptoon/cartoonist/?idx='+idx,
				data: {
					format: 'json',
					idx:idx
				},
				//dataType: 'jsonp',
				type:'get',
				success: function(msg) {
			        var json = $.parseJSON(msg);
			        console.log(json);
			        if(json.result=='success') {
			        	$("#popup_mode").val('upt');
			        	$("#popup_idx").val(idx);
			        	fill_popup_form(json.name, json.website);
			        }
			    },
			      error: function(err) {
			        console.log(err);
			    }
			});
		}
	});

	$("#btn_open_popup").click(function() {
		reset_popup_form();
	});

	$("#btn_register").click(function() {
		frm = $("form[name='popup']");
		
		if($("#name").val()=='') {
			alert('이름을 등록해 주십시오.');
			$("#name").focus();
			return false;
		}
		if($("#website").val()=='') {
			alert('홈페이지 혹은 블로그 주소를 등록해 주십시오.');
			$("#website").focus();
			return false;
		}

		frm.attr('target','ifrm');
		frm.attr('action','/admin/maptoon/cartoonist_proc');
		frm.submit();
	});
});
</script>