<?php
$sub_menu = "200100";
include_once("./_common.php");

auth_check($auth[$sub_menu], "w");

$token = get_token();

if ($w == "") {
    $required_mb_id = "required minlength=3 alphanumericunderline itemname='회원아이디'";
    $required_mb_password = "required itemname='패스워드'";

    $mb['mb_mailling'] = 1;
    $mb['mb_open'] = 1;
    $mb['mb_level'] = $config['cf_register_level'];
    $html_title = "등록";
} else if ($w == "u") {
    $mb = get_member($mb_id);
    if (!$mb['mb_id'])
        alert("존재하지 않는 회원자료입니다.");

    if ($is_admin != 'super' && $mb['mb_level'] >= $member['mb_level'])
        alert("자신보다 권한이 높거나 같은 회원은 수정할 수 없습니다.");

    $required_mb_id = "readonly style='background-color:#dddddd;'";
    $required_mb_password = "";
    $html_title = "수정";

    $mb['mb_email'] = get_text($mb['mb_email']);
    $mb['mb_homepage'] = get_text($mb['mb_homepage']);
    $mb['mb_password_q'] = get_text($mb['mb_password_q']);
    $mb['mb_password_a'] = get_text($mb['mb_password_a']);
    $mb['mb_birth'] = get_text($mb['mb_birth']);
    $mb['mb_tel'] = get_text($mb['mb_tel']);
    $mb['mb_hp'] = get_text($mb['mb_hp']);
    $mb['mb_addr1'] = get_text($mb['mb_addr1']);
    $mb['mb_addr2'] = get_text($mb['mb_addr2']);
    $mb['mb_signature'] = get_text($mb['mb_signature']);
    $mb['mb_recommend'] = get_text($mb['mb_recommend']);
    $mb['mb_profile'] = get_text($mb['mb_profile']);
    $mb['mb_1'] = get_text($mb['mb_1']);
    $mb['mb_2'] = get_text($mb['mb_2']);
    $mb['mb_3'] = get_text($mb['mb_3']);
    $mb['mb_4'] = get_text($mb['mb_4']);
    $mb['mb_5'] = get_text($mb['mb_5']);
    $mb['mb_6'] = get_text($mb['mb_6']);
    $mb['mb_7'] = get_text($mb['mb_7']);
    $mb['mb_8'] = get_text($mb['mb_8']);
    $mb['mb_9'] = get_text($mb['mb_9']);
    $mb['mb_10'] = get_text($mb['mb_10']);
} else {
    alert("제대로 된 값이 넘어오지 않았습니다.");
}
if ($mb['mb_mailling']) {
    $mailling_checked = "checked"; // 메일 수신
}
if ($mb['mb_sms']) {
    $sms_checked = "checked"; // SMS 수신
}
if ($mb['mb_open']) {
    $open_checked = "checked"; // 정보 공개
}
$g4['title'] = "회원정보 " . $html_title;
include_once("./admin.head.php");
?>
<h3><?php echo $g4['title'] ?></h3>
<div class="row">
    <div class="round-box ad_config">
        <div class="col-sm-12">
            <form name='fmember' method='post' onsubmit="return fmember_submit(this);" enctype="multipart/form-data" autocomplete="off" class='form-horizontal' role='form'>
                <input type='hidden' name='w'     value='<?php echo $w ?>'/>
                <input type='hidden' name='sfl'   value='<?php echo $sfl ?>'/>
                <input type='hidden' name='stx'   value='<?php echo $stx ?>'/>
                <input type='hidden' name='sst'   value='<?php echo $sst ?>'/>
                <input type='hidden' name='sod'   value='<?php echo $sod ?>'/>
                <input type='hidden' name='page'  value='<?php echo $page ?>'/>
                <input type='hidden' name='token' value='<?php echo $token ?>'/>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        아이디
                    </label>
                    <div class='col-sm-9'>
                        <input type='text' class='form-control' name='mb_id' size='20' maxlength='20' minlength='2' <?php echo $required_mb_id ?> itemname='아이디' value='<? echo $mb['mb_id'] ?>'>
                        <? if ($w == "u") { ?><a href='./boardgroupmember_form.php?mb_id=<?php echo $mb['mb_id'] ?>'>접근가능그룹보기</a><? } ?>
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        패스워드
                    </label>
                    <div class='col-sm-9'>
                        <input type='password' class='form-control' name='mb_password' size='20' maxlength='20' <?php echo $required_mb_password ?> itemname='암호'>
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        이름(실명)
                    </label>
                    <div class='col-sm-9'>
                        <input type='text' class='form-control' name='mb_name' maxlength='20' minlength='2' required itemname='이름(실명)' value='<? echo $mb['mb_name'] ?>'>
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        별명
                    </label>
                    <div class='col-sm-9'>
                        <input type='text' class='form-control' name='mb_nick' maxlength='20' minlength='2' required itemname='별명' value='<? echo $mb['mb_nick'] ?>'>
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        회원 권한
                    </label>
                    <div class='col-sm-9'>
                        <?php echo get_member_level_select("mb_level", 1, $member['mb_level'], $mb['mb_level']) ?>
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        포인트
                    </label>
                    <div class='col-sm-9'>
                        <a href='./point_list.php?sfl=mb_id&stx=<?php echo $mb['mb_id'] ?>' class='bold'><?php echo number_format($mb['mb_point']) ?></a> 점
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        E-mail
                    </label>
                    <div class='col-sm-9'>
                        <input type='text' class='form-control' name='mb_email' size=40 maxlength=100 required email itemname='e-mail' value='<? echo $mb['mb_email'] ?>'>
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        홈페이지
                    </label>
                    <div class='col-sm-9'>
                        <input type='text' class='form-control' name='mb_homepage' size=40 maxlength=255 itemname='홈페이지' value='<? echo $mb['mb_homepage'] ?>'>
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        전화번호
                    </label>
                    <div class='col-sm-9'>
                        <input type='text' class='form-control' name='mb_tel' maxlength='20' itemname='전화번호' value='<? echo $mb['mb_tel'] ?>'>
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        핸드폰번호
                    </label>
                    <div class='col-sm-9'>
                        <input type='text' class='form-control' name='mb_hp' maxlength='20' itemname='핸드폰번호' value='<? echo $mb['mb_hp'] ?>'>
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        주소
                    </label>
                    <div class='col-sm-9'>
                        <input type='text' class='form-inline' name='mb_zip1' size='4' maxlength='3' readonly itemname='우편번호 앞자리' value='<? echo $mb[mb_zip1] ?>'> - 
                        <input type='text' class='form-inline' name='mb_zip2' size='4' maxlength='3' readonly itemname='우편번호 뒷자리' value='<? echo $mb[mb_zip2] ?>'>
                        <a href="javascript:;" onclick="win_zip('fmember', 'mb_zip1', 'mb_zip2', 'mb_addr1', 'mb_addr2');" class="btn btn-default btn-sm">우편번호찾기</a>
                        <br><input type='text' class='form-control' name='mb_addr1' size=40 readonly value='<? echo $mb[mb_addr1] ?>'>
                        <br><input type='text' class='form-control' name='mb_addr2' size=25 itemname='상세주소' value='<? echo $mb[mb_addr2] ?>'> 상세주소 입력
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        회원아이콘
                    </label>
                    <div class='col-sm-9'>
                        <input type=file name='mb_icon' class='form-control'><br>이미지 크기는 <?php echo $config[cf_member_icon_width] ?>x<?php echo $config[cf_member_icon_height] ?>으로 해주세요.
                        <?
                        $mb_dir = substr($mb[mb_id], 0, 2);
                        $icon_file = "{$g4['path']}/data/member/{$mb_dir}/{$mb['mb_id']}.gif";
                        if (file_exists($icon_file)) {
                            echo "<br><img src='$icon_file' align=absmiddle>";
                            echo " <input type=checkbox name='del_mb_icon' value='1' class='csscheck'>삭제";
                        }
                        ?>
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        생년월일
                    </label>
                    <div class='col-sm-9'>
                        <input type='text' class='form-control' name=mb_birth size=9 maxlength=8 value='<? echo $mb['mb_birth'] ?>'>
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        남녀
                    </label>
                    <div class='col-sm-9'>
                        <select name='mb_sex' class="form-control">
                            <option value=''>----</option>
                            <option value='F'>여자</option>
                            <option value='M'>남자</option>
                        </select>
                        <script type="text/javascript"> document.fmember.mb_sex.value = "<?php echo $mb[mb_sex] ?>";</script>
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        메일 수신
                    </label>
                    <div class='col-sm-9'>
                        <label><input type=checkbox name=mb_mailling value='1' <?php echo $mailling_checked ?>> 정보 메일을 받음</label>
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        SMS 수신
                    </label>
                    <div class='col-sm-9'>
                        <label><input type=checkbox name=mb_sms value='1' <?php echo $sms_checked ?>> 문자메세지를 받음</label>
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        정보 공개
                    </label>
                    <div class='col-sm-9'>
                        <label><input type=checkbox name=mb_open value='1' <?php echo $open_checked ?>> 타인에게 자신의 정보를 공개</label>
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        서명
                    </label>
                    <div class='col-sm-9'>
                        <textarea class='form-control' name=mb_signature rows=5 ><? echo $mb[mb_signature] ?></textarea>
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        자기 소개
                    </label>
                    <div class='col-sm-9'>
                        <textarea class='form-control' name=mb_profile rows=5 ><? echo $mb[mb_profile] ?></textarea>
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        메모
                    </label>
                    <div class='col-sm-9'>
                        <textarea class='form-control' name=mb_memo rows=5 ><? echo $mb[mb_memo] ?></textarea>
                    </div>
                </div>
                <?php if ($w == "u") { ?>
                    <div class='form-group'>
                        <label class="col-sm-3 control-label">
                            회원가입일
                        </label>
                        <div class='col-sm-9'>
                            <?php echo $mb['mb_datetime'] ?>
                        </div>
                    </div>
                    <div class='form-group'>
                        <label class="col-sm-3 control-label">
                            최근접속일
                        </label>
                        <div class='col-sm-9'>
                            <?php echo $mb['mb_today_login'] ?>
                        </div>
                    </div>
                    <div class='form-group'>
                        <label class="col-sm-3 control-label">
                            IP
                        </label>
                        <div class='col-sm-9'>
                            <?php echo $mb[mb_ip] ?>
                        </div>
                    </div>
                    <? if ($config[cf_use_email_certify]) { ?>
                        <div class='form-group'>
                            <label class="col-sm-3 control-label">
                                인증일시
                            </label>
                            <div class='col-sm-9'>
                                <?php echo $mb['mb_email_certify'] ?> 
                                <?php
                                if ($mb['mb_email_certify'] == "0000-00-00 00:00:00") {
                                    echo "<input type=checkbox name=passive_certify>수동인증";
                                }
                                ?>
                            </div>
                        </div>
                    <?php } ?>
                <?php } ?>
                <?php if ($config['cf_use_recommend']) { // 추천인 사용  ?>
                    <div class='form-group'>
                        <label class="col-sm-3 control-label">
                            추천인
                        </label>
                        <div class='col-sm-9'>
                            <?php echo ($mb['mb_recommend'] ? get_text($mb['mb_recommend']) : "없음"); // 081022 : CSRF 보안 결함으로 인한 코드 수정   ?>
                        </div>
                    </div>
                <?php } ?>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        탈퇴일자
                    </label>
                    <div class='col-sm-9'>
                        <input type='text' class='form-control' name=mb_leave_date size=9 maxlength=8 value='<? echo $mb[mb_leave_date] ?>'>
                    </div>
                </div>
                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        접근차단일자
                    </label>
                    <div class='col-sm-9'>
                        <input type='text' class='form-control' name=mb_intercept_date size=9 maxlength=8 value='<? echo $mb[mb_intercept_date] ?>'> 
                        <input type=checkbox value='<? echo date("Ymd"); ?>' onclick='if (this.form.mb_intercept_date.value == this.form.mb_intercept_date.defaultValue) {
                                    this.form.mb_intercept_date.value = this.value;
                                } else {
                                    this.form.mb_intercept_date.value = this.form.mb_intercept_date.defaultValue;
                                }'>오늘
                    </div>
                </div>
                <?php for ($i = 1; $i <= 10; $i++) { ?>
                    <div class='form-group'>
                        <label class="col-sm-3 control-label">
                            여분필드 <?php echo $i ?>
                        </label>
                        <div class='col-sm-9'>
                            <input type='text' class='form-control'  name='mb_<?php echo $i ?>' maxlength=255 value='<?php echo $mb["mb_$i"] ?>'>
                        </div>
                    </div>
                <?php } ?>
                <?php echo subtitle("XSS / CSRF 방지") ?>

                <div class='form-group'>
                    <label class="col-sm-3 control-label">
                        관리자 패스워드
                    </label>
                    <div class='col-sm-9'>
                        <input class='form-control' type='password' name='admin_password' itemname="관리자 패스워드" required>
                        <?php echo help("관리자 권한을 빼앗길 것에 대비하여 로그인한 관리자의 패스워드를 한번 더 묻는것 입니다."); ?>
                    </div>
                </div>
                <div class='form-group form-action '>
                    <div class="col-sm-4" style="text-align: center">
                        <button type='submit' class="btn btn-primary">확인</button>
                    </div>
                    <div class='col-sm-4' style="text-align: center">
                        <input type='button' class='btn btn-default' value='  목  록  ' onclick="document.location.href = './member_list.php?<?php echo $qstr ?>';"/>
                    </div>
                    <div class='col-sm-4' style="text-align: center">
                        <?php if ($w != '') { ?>
                            <input type='button' class='btn btn-danger' value='  삭  제  ' onclick="del('./member_delete.php?<?php echo $qstr ?>&w=d&mb_id=<?php echo $mb[mb_id] ?>&url=<?php echo $_SERVER[PHP_SELF] ?>');"/>
                        <?php } ?>
                    </div>
                </div>
                
            </form>
        </div>
    </div>
</div>
<script type='text/javascript'>
    if (document.fmember.w.value == "")
        document.fmember.mb_id.focus();
    else if (document.fmember.w.value == "u")
        document.fmember.mb_password.focus();

    if (typeof (document.fmember.mb_level) != "undefined")
        document.fmember.mb_level.value = "<?php echo $mb[mb_level] ?>";

    function fmember_submit(f)
    {
        if (!f.mb_icon.value.match(/\.(gif|jp[e]g|png)$/i) && f.mb_icon.value) {
            alert('아이콘이 이미지 파일이 아닙니다. (bmp 제외)');
            return false;
        }

        f.action = './member_form_update.php';
        return true;
    }
</script>

<?
include_once("./admin.tail.php");
?>
