<?php

	include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';
	include $_SERVER['DOCUMENT_ROOT'].ADMIN_PATH.'common/auth_chk.php';

	$mp = "00";	//set top nav

	$mode = "Add";

?>
<? include("../inc/inc_top.php") ?>
<? include("../inc/inc_header.php") ?>

<section id="contents">
	<h2>관리자 관리</h2>
	<h3><em>▶</em> 관리자 등록</h3>

<form id="frmMember" name="frmMember" method="post" action="<?=ADMIN_PATH?>admin/admin_proc.php">
<input type="hidden" name="mode" id="mode" value="Add"/>
<input type="hidden" name="validate" id="validate" value=""/>
<input type="hidden" name="ds_level" id="ds_level" value="1"/>
<input type="hidden" name="ds_open" id="ds_open" value="Y"/>
<input type="hidden" name="nm_info1" id="nm_info1" value=""/>
<input type="hidden" name="nm_info3" id="nm_info3" value=""/>
	<div class="tbl_wrap">
		<table class="tbl_list2">
			<colgroup>
				<col width="13%">
				<col width="*">
			</colgroup>
			<tr>
				<th>아이디</th>
				<td>
					<input type="text" class="inp_txt" style="width:40%;" name="cd_userid" id="cd_userid" maxlength="20" value="">
					<p id="id_chk_info" class="hide"></p>
				</td>
			</tr>
			<tr>
				<th>비밀번호</th>
				<td><input type="password" class="inp_txt" style="width:40%;" name="nm_pass" id="nm_pass" maxlength="20"></td>
			</tr>
			<tr>
				<th>이름</th>
				<td><input type="text" class="inp_txt" style="width:40%;" name="nm_name" id="nm_name" maxlength="20" value=""></td>
			</tr>
			<tr>
				<th>연락처</th>
				<td>
					<span class="select2" style="margin-right:5px;width:12%;">
						<select name="nm_info11" id="nm_info11"></select>
					</span>
					<input type="text" class="inp_txt" style="width:12%;" name="nm_info12" id="nm_info12" maxlength="4" value="<?=$nm_info12?>">
					 -
					 <input type="text" class="inp_txt" style="width:12%;" name="nm_info13" id="nm_info13" maxlength="4" value="<?=$nm_info13?>">

					 <span class="check_wrap" style='vertical-align: middle;'><input type="checkbox" name="ds_alimtalk" id="ds_alimtalk" value="Y"><i></i><label for="ds_alimtalk">카톡알림</label></span>

				</td>
			</tr>
			<tr>
				<th>이메일</th>
				<td>
					<input type="text" class="inp_txt" style="margin-right:5px;width:25%;" name="nm_info31" id="nm_info31"> @
					<input type="text" class="inp_txt" style="margin-right:5px;width:25%;" name="nm_info32" id="nm_info32">
					<span class="select2" style="margin-left:5px;min-width:12%;">
						<select name="nm_info33" id="nm_info33" onChange="sel_1(this.value)"></select>
					</span>
				</td>
			</tr>

			<!-- <tr>
				<th>관계사</th>
				<td>
					<span class="select2" style="margin-right:5px;width:12%;">
						<select name="ds_company_bp" id="ds_company_bp" onchange="chg_ds_branch(this.value)"></select>
					</span>
				</td>
			</tr>
			<tr>
				<th>지점</th>
				<td>
					<span class="select2" style="margin-right:5px;width:12%;">
						<select name="ds_branch" id="ds_branch"></select>
					</span>
				</td>
			</tr> -->

		</table>
	</div>

	<h3><em>▶</em> 권한 설정</h3>
	<div class="box_check">
		<span class="check_wrap"><input type="checkbox" name="btn_authall" id="btn_authall"><i></i><label for="btn_authall">전체 관리</label></span>
		<span class="check_wrap"><input type="checkbox" name="auth1" id="auth1" value="Y"><i></i><label for="auth1">관리자 관리</label></span>
		<span class="check_wrap"><input type="checkbox" name="auth2" id="auth2" value="Y"><i></i><label for="auth2">차량관리</label></span>
		<span class="check_wrap"><input type="checkbox" name="auth3" id="auth3" value="Y"><i></i><label for="auth3">회원관리</label></span>
		<span class="check_wrap"><input type="checkbox" name="auth4" id="auth4" value="Y"><i></i><label for="auth4">매입관리</label></span>
		<span class="check_wrap"><input type="checkbox" name="auth5" id="auth5" value="Y"><i></i><label for="auth5">정산관리</label></span>
		<span class="check_wrap"><input type="checkbox" name="auth6" id="auth6" value="Y"><i></i><label for="auth6">커뮤니티</label></span>
		<span class="check_wrap"><input type="checkbox" name="auth9" id="auth9" value="Y"><i></i><label for="auth9">사고정보조회</label></span>
	</div>
</form>

	<div class="btn_right">
		<a href="#" class="rnd_btn ty2 gray" onclick="location.replace('<?=ADMIN_PATH?>admin/admin_list.php?PageNo=<?=$PageNo?>');">목록</a>
		<a class="rnd_btn ty2 black" id="btn_write">저장</a>
	</div>
</section>


<script language="javascript" type="text/javascript">


	//ID  체크
	function id_chk() {
		if($("#cd_userid").val() == ""){
			return false;
		}

		$("#id_chk_info").removeClass("txt_red").removeClass("hide");

		var valid_msg = "";
		if(!fnCheckAlphaNumber($("#cd_userid").val())){
			valid_msg = "아이디는 영문/숫자 조합으로 이루어져야 합니다.";
		}else if($("#cd_userid").val().length <4){
			valid_msg = "4글자 이상 아이디를 입력하세요.";
		}

		if($.trim(valid_msg) != "") {
			$("#id_chk_info").text(valid_msg).addClass("txt_red");
			return false;
		}

		$.post("admin_proc.php", { mode: "IdChk", cd_userid: $("#cd_userid").val()},function(res) {
			var id_chk_info = "";

			if(res.CODE == "0000") {
				id_chk_info = "사용할 수 있는 아이디입니다.";
				$("#id_chk_info").removeClass("txt_red").text(id_chk_info);
			}else {
				id_chk_info = "사용불가능한 아이디 입니다.";

				$("#id_chk_info").addClass("txt_red").text(id_chk_info);
			}

		}, "json");
		return false;
	}

	$(document).ready(function() {
		setCodeSelectJqTransForm("listPhone","nm_info11","","","","선택하세요","");
		setCodeSelectJqTransForm("listEmail","nm_info33","","","","직접입력","");
		// setCodeSelectJqTransForm("listcode","ds_company_bp", "member_master","ds_company_bp","<?=$ds_company_bp?>","선택하세요","");
		// setCodeSelectJqTransForm("listcode","ds_branch", "member_master","ds_branch","","선택하세요","-1");	//초기 세팅은 안나오도록 -1로 세팅

		//아이디 체크
		$("#cd_userid").bind("focusout", id_chk);

<? if (!empty($ds_branch)){ ?>
		// setCodeSelectJqTransForm("listcode","ds_branch", "member_master","ds_branch","<?=$ds_branch?>","선택하세요","<?=$ds_company_bp?>");
<? } ?>

		// $("#ds_company_bp").change(function(){
		// 	var val = $(this).val();
		// 	console.log(val)
		// 	if($.trim(val) == "") {
		// 		val = "-1";
		// 	}
		// 	setCodeSelectJqTransForm("listcode","ds_branch", "member_master","ds_branch","<?=$ds_branch?>","선택하세요",val);
		// });

		$("#btn_write").bind("click",function(){
			var custom_opts = {
				title : '',
				btn_close_show : false,
			}

			var fieldlist = [["cd_userid","아이디"],["nm_name","이름"],["nm_info11","연락처"],["nm_info12","연락처"],["nm_info13","연락처"],["nm_info31","이메일"],["nm_info32","이메일"]]
			if (!fnCheckForm(fieldlist)){
				return false;
			}else{
				id_chk();

				/*아이디 관련 처리*/
				if(!fnCheckAlphaNumber($("#cd_userid").val())){
					custom_opts.title = '아이디는 영문/숫자 조합으로 이루어져야 합니다.';

					custom_modal_alert(custom_opts);
					return false;
				}
				if($("#cd_userid").val().length <4){
					custom_opts.title = '4글자 이상 아이디를 입력하세요.';

					custom_modal_alert(custom_opts);
					return false;
				}

				/*이름 체크*/
				if(!isValid($("#nm_name").val(),"regKorean")){
					custom_opts.title = '이름은 한글만 가능합니다.';

					custom_modal_alert(custom_opts);
					return false;
				}

				/*패스워드 처리*/
				/*
				if($("#nm_pass").val().length > 0){
					if($("cd_userid").val()==$("#nm_pass").val()){
						alert("아이디와 변경할 패스워드를 다르게입력하세요");
						$("#nm_pass").focus();
						return false;
					}
					if($("#nm_pass").val()!=$("#nm_pass_2").val()){
						alert("입력하신 변경할 패스워드가 일치하지 않습니다.");
						$("#nm_pass").focus();
						return false;
					}
					if(!fnCheckAlphaNumber($("#nm_pass").val())){
						alert('변경할 패스워드는 영문/숫자 조합으로 이루어져야 합니다.');
						return false
					}
					if($("#nm_pass").val().length <6){
						alert("6글자 이상 변경할 패스워드를 입력하세요");
						$("#nm_pass").focus();
						return false;
					}
				}
				*/

				/*연락처*/
				$("#nm_info1").val($("#nm_info11").val()+"-"+$("#nm_info12").val()+"-"+$("#nm_info13").val());

				/*이메일 체크*/
				$("#nm_info3").val($("#nm_info31").val()+"@"+$("#nm_info32").val());
				if(!isValid($("#nm_info3").val(),"regEmail")){
					custom_opts.title = '정확한 이메일을 입력하세요.';

					custom_modal_alert(custom_opts);
					return false;
				}

				custom_opts.title = '정보를 등록하시겠습니까?';
				custom_modal_confirm(custom_opts, function(confirm) {
					if(confirm) {
						$("#btn_write").hide();
						var data = $("#frmMember").serialize();
						$.ajax({
							url : 'admin_proc.php',
							type: 'POST',
							dataType : 'json',
							data: data,
							success: function(res) {
								custom_modal_confirm_close();

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

								//세션 종료시 로그인 페이지로 이동
								if(res.CODE != "0000") {
									custom_opts.title = res.MSG;

									if(res.CODE == "4444") {
										window.location.href = res.DATAS.URL;
									}
									custom_modal_alert(custom_opts);
									return false;
								}

								custom_opts.title = '관리자 등록이 완료되었습니다.';
								custom_opts.event_esc_key = false;

								custom_modal_alert(custom_opts, function() {
									reload();
								});
							},
							error:function(request,status,error){
								$("#btn_write").show();

								custom_modal_confirm_close();

								alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
							}
						});

					}else {
						$("#btn_write").show();
						return false;
					}
				});

			}
		});


		$("#btn_authall").bind("click",function(){
			var checked = $(this).prop("checked");
			$("#auth1").prop('checked', checked);
			$("#auth2").prop('checked', checked);
			$("#auth3").prop('checked', checked);
			$("#auth4").prop('checked', checked);
			$("#auth5").prop('checked', checked);
			$("#auth6").prop('checked', checked);
			$("#auth9").prop('checked', checked);
		});


	});

</script>
<script language="javascript">
<!--
function chg_ds_branch(val) {
	if($.trim(val) == "") {
		val = "-1";
	}
	setCodeSelectJqTransForm("listcode","ds_branch", "member_master","ds_branch","<?=$ds_branch?>","선택하세요",val);
}
function sel_1(sltObj)
{
    document.getElementById("nm_info32").value = sltObj;
	if (sltObj == "")
	{
		document.getElementById("nm_info32").readOnly = false;
	}else{
		document.getElementById("nm_info32").readOnly = true;
	}

}
//-->
</script>
<? include("../inc/inc_footer.php") ?>
<? include("../inc/inc_bottom.php") ?>
<?
mysql_close($connect);
?>
