<?php

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

	$cd_dealer = $_REQUEST["cd_dealer_p"];
?>
<? include("../inc/inc_top.php") ?>
<? include("../inc/inc_header.php") ?>
<section id="contents">
	<h2>딜러 회원관리</h2>

<? include("../inc/inc_header_dealer.php") ?>

<?
	$cd_dealer = $_REQUEST["cd_dealer"];

	$ds_type = "D1";

	$sql ="SELECT
				*
				FROM dealer_master
				WHERE cd_dealer='$cd_dealer' AND ds_delind='N'";

	$mode = "AddManager";

	$col=mysql_fetch_array(mysql_query($sql));
	if (!empty($col['cd_dealer'])){
		$cd_dealer = $col['cd_dealer'];
		$cd_dealerid = $col['cd_dealerid'];
		$cd_dealer_p = $col['cd_dealer_p'];
		$nm_pass = $col['nm_pass'];
		$ds_type = $col['ds_type'];
		$ds_usertype = $col['ds_usertype'];
		$ds_level = $col['ds_level'];
		$nm_company = $col['nm_company'];
		$nm_name = $col['nm_name'];
		$nm_birth = $col['nm_birth'];
		$nm_tel_01 = $col['nm_tel_01'];
		$nm_tel_02 = $col['nm_tel_02'];
		$nm_tel_03 = $col['nm_tel_03'];
		$nm_hp_01 = $col['nm_hp_01'];
		$nm_hp_02 = $col['nm_hp_02'];
		$nm_hp_03 = $col['nm_hp_03'];
		$nm_fax_01 = $col['nm_fax_01'];
		$nm_fax_02 = $col['nm_fax_02'];
		$nm_fax_03 = $col['nm_fax_03'];
		$nm_email = $col['nm_email'];
		$nm_zip = $col['nm_zip'];
		$nm_addr = $col['nm_addr'];
		$nm_addr_sub = $col['nm_addr_sub'];
		$nm_etc_01 = $col['nm_etc_01'];
		$nm_etc_02 = $col['nm_etc_02'];
		$nm_etc_03 = $col['nm_etc_03'];
		$ds_status = $col['ds_status'];
		$nm_company_biz = $col['nm_company_biz'];
		$nm_name_biz = $col['nm_name_biz'];
		$nm_no_biz = $col['nm_no_biz'];
		$nm_date_biz = $col['nm_date_biz'];
		$nm_type_biz = $col['nm_type_biz'];
		$nm_condition_biz = $col['nm_condition_biz'];
		$nm_tel_biz_01 = $col['nm_tel_biz_01'];
		$nm_tel_biz_02 = $col['nm_tel_biz_02'];
		$nm_tel_biz_03 = $col['nm_tel_biz_03'];
		$nm_hp_biz_01 = $col['nm_hp_biz_01'];
		$nm_hp_biz_02 = $col['nm_hp_biz_02'];
		$nm_hp_biz_03 = $col['nm_hp_biz_03'];
		$nm_fax_biz_01 = $col['nm_fax_biz_01'];
		$nm_fax_biz_02 = $col['nm_fax_biz_02'];
		$nm_fax_biz_03 = $col['nm_fax_biz_03'];
		$nm_email_biz = $col['nm_email_biz'];
		$nm_zip_biz = $col['nm_zip_biz'];
		$nm_addr_biz = $col['nm_addr_biz'];
		$nm_addr_sub_biz = $col['nm_addr_sub_biz'];
		$ds_company_bp1 = $col['ds_company_bp1'];
		$ds_branch1 = $col['ds_branch1'];
		$ds_company_bp2 = $col['ds_company_bp2'];
		$ds_branch2 = $col['ds_branch2'];
		$ds_company_bp3 = $col['ds_company_bp3'];
		$ds_branch3 = $col['ds_branch3'];
		$nm_area = $col['nm_area'];
		$nm_title = $col['nm_title'];
		$nm_file = $col['nm_file'];
		$nm_etc = $col['nm_etc'];
		$nm_deposit = $col['nm_deposit'];
		$dt_insert = $col['dt_insert'];
		$nm_insert = $col['nm_insert'];
		$dt_update = $col['dt_update'];
		$nm_update = $col['nm_update'];
		$ds_delind = $col['ds_delind'];

		$ds_info_contract = $col['ds_info_contract'];
		$ds_info_privacy = $col['ds_info_privacy'];
		$ds_info_service = $col['ds_info_service'];
	/*
		$arr_nm_info1 = explode("-",$nm_info1);
		if(count($arr_nm_info1) == 3){
			$nm_info11 = $arr_nm_info1['0'];
			$nm_info12 = $arr_nm_info1['1'];
			$nm_info13 = $arr_nm_info1['2'];
		}else{
			$nm_info11 = "";
			$nm_info12 = "";
			$nm_info13 = "";
		}

		$arr_nm_info3 = explode("@",$nm_info3);
		if(count($arr_nm_info3) == 2){
			$nm_info31 = $arr_nm_info3['0'];
			$nm_info32 = $arr_nm_info3['1'];
		}else{
			$nm_info31 = "";
			$nm_info32 = "";
		}
		$nm_info3 = $col['nm_info3'];
	*/
		$mode = "UpdateManager";
	}else{
		$ds_level = "1";
	}

?>

	<div class="tbl_wrap">
	<form id="frmMember" name="frmMember" method="post" action="dealer_proc.php" enctype="multipart/form-data">
	<input type="hidden" name="validate" id="validate" value=""/>
	<input type="hidden" name="ds_type" id="ds_type" value="D1"/>
	<input type="hidden" name="ds_usertype" id="ds_usertype" value="<?=$ds_usertype?>"/>
	<input type="hidden" name="ds_company_bp1" id="ds_company_bp1" value="<?=$ds_company_bp1?>"/>
	<input type="hidden" name="ds_branch1" id="ds_branch1" value="<?=$ds_branch1?>"/>
	<input type="hidden" name="ds_company_bp2" id="ds_company_bp2" value="<?=$ds_company_bp2?>"/>
	<input type="hidden" name="ds_branch2" id="ds_branch2" value="<?=$ds_branch2?>"/>
	<input type="hidden" name="ds_company_bp3" id="ds_company_bp3" value="<?=$ds_company_bp3?>"/>
	<input type="hidden" name="ds_branch3" id="ds_branch3" value="<?=$ds_branch3?>"/>
	<input type="hidden" name="ds_level" id="ds_level" value="<?=$ds_level?>"/>
	<input type="hidden" name="cd_dealer" id="cd_dealer" value="<?=$cd_dealer?>"/>
	<input type="hidden" name="cd_dealer_p" id="cd_dealer_p" value="<?=$cd_dealer_p?>"/>
	<input type="hidden" name="mode" id="mode" value="<?=$mode?>"/>
	<input type="hidden" name="nm_email" id="nm_email" value="<?=$nm_email?>"/>
	<input type="hidden" name="nm_hp_01" id="nm_hp_01" value="<?=$nm_hp_01?>"/>
<? if ($mode == "Add"){ ?>
	<input type="hidden" name="idchkresult" id="idchkresult" value="N"/>
<? }else{ ?>
	<input type="hidden" name="idchkresult" id="idchkresult" value="Y"/>
<? } ?>
		<table class="tbl_list2 ty2">
			<colgroup>
				<col width="16%">
				<col width="*">
			</colgroup>
			<tr>
				<th>아이디</th>
				<td>
<? if ($mode == "Add"){ ?>
					<input type="text" class="inp_txt" style="width:330px;" name="cd_dealerid" id="cd_dealerid">
					<input type="submit" class="td_btn ty2" title="아이디 확인" value="확인" id="btn_idchk">
<? }else{ ?>
					<?=$cd_dealerid?>
<? } ?>
				</td>
			</tr>
			<tr>
				<th>비밀번호</th>
				<td><input type="password" class="inp_txt" style="width:330px;" name="nm_pass" id="nm_pass"> <span class="td_txt">8자~15자 영문, 숫자, 특수문자 조합</span></td>
			</tr>
			<tr>
				<th>이름</th>
				<td><input type="text" class="inp_txt" style="width:330px;" name="nm_name" id="nm_name" value="<?=$nm_name?>"></td>
			</tr>
			<tr>
				<th>휴대번호</th>
				<td>
					<span class="select" style="margin-right:5px;width:22%;" id="sel_nm_hp_01">
						<select>
							<option value="" >선택</option>
							<option value="010" <?if($nm_hp_01=="010"){?>selected="selected"<?}?> >010</option>
							<option value="011" <?if($nm_hp_01=="011"){?>selected="selected"<?}?> >011</option>
							<option value="016" <?if($nm_hp_01=="016"){?>selected="selected"<?}?> >016</option>
							<option value="017" <?if($nm_hp_01=="017"){?>selected="selected"<?}?> >017</option>
							<option value="018" <?if($nm_hp_01=="018"){?>selected="selected"<?}?> >018</option>
							<option value="019" <?if($nm_hp_01=="019"){?>selected="selected"<?}?> >019</option>
							<option value="070" <?if($nm_hp_01=="070"){?>selected="selected"<?}?> >070</option>
						</select>
					</span>
					<input type="text" class="inp_txt" style="width:22%;" name="nm_hp_02" id="nm_hp_02" value="<?=$nm_hp_02?>"> - <input type="text" class="inp_txt" style="width:22%;" name="nm_hp_03" id="nm_hp_03" value="<?=$nm_hp_03?>">
				</td>
			</tr>
			<tr>
				<th>부서</th>
				<td><input type="text" class="inp_txt" style="width:330px;" name="nm_title" id="nm_title" value="<?=$nm_title?>"></td>
			</tr>
			<tr>
				<th>계약 동의</th>
				<td>
					<span class="check_wrap"><input type="checkbox" name="ds_info_contract" id="ds_info_contract" value="Y"<?if($ds_info_contract=="Y"){?> checked="checked"<?}?>><i></i><label for="ds_info_contract">유프로 계약서</label></span>
					<span class="check_wrap"><input type="checkbox" name="ds_info_privacy" id="ds_info_privacy" value="Y"<?if($ds_info_privacy=="Y"){?> checked="checked"<?}?>><i></i><label for="ds_info_privacy">개인정보</label></span>
					<span class="check_wrap"><input type="checkbox" name="ds_info_service" id="ds_info_service" value="Y"<?if($ds_info_service=="Y"){?> checked="checked"<?}?>><i></i><label for="ds_info_service">이용약관</label></span>
				</td>
			</tr>
			<tr>
				<th>사진(필수입력)</th>
				<td>
					<div class="filebox">
						<label for="nm_file">찾아보기</label>
						<input class="upload-name" value="">
						<input type="file" class="upload-hidden" name="nm_file" id="nm_file">
				<? if(!empty($nm_file)){ ?>
					<span class="thumb"><img src="<?=UPLOAD_PATH?>dealer/nm_file/<?=$nm_file?>" alt="" width="100"></span>
				<? } ?>
					</div>
				</td>
			</tr>
		</table>
	</div>
    <div class="btn_right">
		<a href="./dealer_view3.php?cd_dealer=<?=$cd_dealer_p?>" class="rnd_btn ty2 gray">목록</a>
		<a href="#" class="rnd_btn ty2 black" id="btn_write">저장</a>
	</div>
</section>

<script laguage="javascript" type="text/javascript">
    $(document).ready(function() {

        setCodeSelect("listcode","ds_area", "dealer_master","ds_area","<?=$ds_area?>","선택하세요","");

		$("#sel_nm_hp_01 div.jq_sel ul li a").bind("click",function(){
			$("#nm_hp_01").val($("#sel_nm_hp_01 option:selected").val());
		});

       $("#cd_dealerid").bind("keyup",function(){
            $("#idchkresult").val("N");
        });

        $("#btn_idchk").bind("click",function(){

			if($("#cd_dealerid").val() == ""){
				alert("아이디를 입력하세요.");
				$("#cd_dealerid").focus();
				return false;
			}

            $.post("dealer_proc.php", { mode: "IdChk", cd_dealerid: $("#cd_dealerid").val()},function(data) {
                 if(data=="Y"){
                     if(confirm("이용가능합니다. 아이디를 사용하시겠습니까?")){
                         $("#cd_dealerid").attr("readonly",true).css("background","#d2d3d5");
                         $("#idchkresult").val("Y");
                         return;
                     }
                 }else{
                     alert("사용불가능한 아이디 입니다.");
                     $("#idchkresult").val("N");
                     return;
                 }
            });
            return false;

        });

		$("#btn_write").bind("click",function(){

		<? if ($mode == "Add"){ ?>
            var fieldlist = [["cd_dealerid","아이디"],["nm_pass","비밀번호"],["nm_name","이름"],["nm_hp_01","핸드폰"],["nm_hp_02","핸드폰"],["nm_hp_03","핸드폰"],["nm_title","부서"],["nm_file","사진"]]
		<? }else{ ?>
            var fieldlist = [["nm_name","이름"],["nm_hp_01","핸드폰"],["nm_hp_02","핸드폰"],["nm_hp_03","핸드폰"],["nm_title","부서"]]
		<? } ?>

            if (!fnCheckForm(fieldlist)){
                return false;
            }else{

                /*아이디 관련 처리*/

		<? if ($mode == "Add"){ ?>

				var idReg1 = /[a-z]/g;
				var idReg2 = /[0-9]/g;

//				if( !(idReg1.test( $("#cd_dealerid").val() )) || !(idReg2.test( $("#cd_dealerid").val() )) ) {
//					alert("아이디는 영문/숫자 조합으로 이루어져야 합니다.");
//					$("#cd_dealerid").focus();
//					return false;
//				}
				var idReg = /^[a-z]+[a-z0-9]{5,19}$/g;
				if( !idReg.test( $("#cd_dealerid").val() ) ) {
					alert("아이디는 영문자로 시작하는 6~20자 영문자 또는 숫자이어야 합니다.");
                    $("#cd_dealerid").focus();
                    return false;
				}

				if(!fnCheckAlphaNumber($("#cd_dealerid").val())){
                    alert('아이디는 영문/숫자 조합으로 이루어져야 합니다.');
                    return false;
                }
                if($("#cd_dealerid").val().length <6){
                    alert("6글자 이상 아이디를 입력하세요");
                    $("#cd_dealerid").focus();
                    return false;
                }

				if($("#idchkresult").val() != "Y"){
					alert("아이디 중복확인을 해 주세요.");
					$("#idchkresult").focus();
					return false;
				}

               if($("#nm_pass").val().length > 0){
                    if($("#cd_dealerid").val()==$("#nm_pass").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;
                    }
                }
		<? } ?>

				var c=confirm("정보를 등록하시겠습니까?");
                if(c){
                    $("#btn_write").hide();
                    $("#frmMember").submit();
                }else{
                    $("#btn_write").show();
                    return false;
                }
            }
        });
    });
</script>

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