<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
// 연락처
$wr_2 = explode("-",$write['wr_2']);
$cotel1 = $wr_2[0];
$cotel2 = $wr_2[1];
$cotel3 = $wr_2[2];
?>
<link rel="stylesheet" href="<?php echo $board_skin_url;?>/style.css">
<link rel="stylesheet" media="all" type="text/css" href="http://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" href="<?php echo $board_skin_url;?>/jquery-ui-timepicker-addon.css">
<script type="text/javascript" src="http://code.jquery.com/ui/1.11.0/jquery-ui.min.js"></script>
<script src="<?php echo $board_skin_url;?>/jquery-ui-timepicker-addon.js"></script>
<script src="<?php echo $board_skin_url;?>/jquery-ui-timepicker.js"></script>
<section id="bo_w">
    <h2 class="sr-only"><?php echo $g5['title'] ?></h2>

    <!-- 게시물 작성/수정 시작 { -->
    <form name="fwrite" id="fwrite" action="<?php echo $action_url ?>" onsubmit="return fwrite_submit(this);" method="post" enctype="multipart/form-data" autocomplete="off" class="form">
    <input type="hidden" name="uid" value="<?php echo get_uniqid(); ?>">
    <input type="hidden" name="w" value="<?php echo $w ?>">
    <input type="hidden" name="bo_table" value="<?php echo $bo_table ?>">
    <input type="hidden" name="wr_id" value="<?php echo $wr_id ?>">
    <input type="hidden" name="sca" value="<?php echo $sca ?>">
    <input type="hidden" name="sfl" value="<?php echo $sfl ?>">
    <input type="hidden" name="stx" value="<?php echo $stx ?>">
    <input type="hidden" name="spt" value="<?php echo $spt ?>">
    <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 ?>">
    <?php
    $option = '';
    $option_hidden = '';
    if ($is_notice || $is_html || $is_secret || $is_mail) {
        $option = '';
        if ($is_notice) {
            $option .= "\n".'<input type="checkbox" id="notice" name="notice" value="1" '.$notice_checked.'>'."\n".'<label for="notice">공지</label>';
        }

        if ($is_html) {
            if ($is_dhtml_editor) {
                $option_hidden .= '<input type="hidden" value="html1" name="html">';
            } else {
                $option .= "\n".'<input type="checkbox" id="html" name="html" onclick="html_auto_br(this);" value="'.$html_value.'" '.$html_checked.'>'."\n".'<label for="html">HTML</label>';
            }
        }

        if ($is_secret) {
            if ($is_admin || $is_secret==1) {
                $option .= "\n".'<input type="checkbox" id="secret" name="secret" value="secret" '.$secret_checked.'>'."\n".'<label for="secret">비밀글</label>';
            } else {
                $option_hidden .= '<input type="hidden" name="secret" value="secret">';
            }
        }

        if ($is_mail) {
            $option .= "\n".'<input type="checkbox" id="mail" name="mail" value="mail" '.$recv_email_checked.'>'."\n".'<label for="mail">답변메일받기</label>';
        }
    }

    echo $option_hidden;
    ?>

    <?php if ($is_category) { ?>
    <div class="bo_w_select write_div">
        <label for="ca_name"  class="sr-only">분류<strong>필수</strong></label>
        <select name="ca_name" id="ca_name" required class="form-control">
            <option value="">분류를 선택하세요</option>
            <?php echo $category_option ?>
        </select>
    </div>
    <?php } ?>

    <?php if ($is_admin == 'super') { ?>
      <div class="form-group row">
        <label for="wr_10" class="col-2 col-form-label font-weight-bold">예약상태</label>
        <div class="col-10">
          <div class="form-check form-check-inline">
            <input class="form-check-input" type="radio" name="wr_10" id="inlineRadio1" value="접수" <?php echo ($write['wr_10']=='접수')?'checked':'';?> >
            <label class="form-check-label" for="inlineRadio1">접수</label>
          </div>
          <div class="form-check form-check-inline">
            <input class="form-check-input" type="radio" name="wr_10" id="inlineRadio2" value="완료" <?php echo ($write['wr_10']=='완료')?'checked':'';?> >
            <label class="form-check-label" for="inlineRadio2">완료</label>
          </div>
          <div class="form-check form-check-inline">
            <input class="form-check-input" type="radio" name="wr_10" id="inlineRadio3" value="취소" <?php echo ($write['wr_10']=='취소')?'checked':'';?> >
            <label class="form-check-label" for="inlineRadio3">취소</label>
          </div>
        </div>
      </div>

    <?php } ?>
    <?php if($w == ''){?>
                <input type="hidden" name="wr_10" value="접수">
    <?php }?>

    <div class="form-group row">
        <label for="wr_name" class="col-2 col-form-label font-weight-bold">예약인</label>
        <div class="col-10">
        <input type="text" name="wr_name" required class="form-control" value="<?php echo $member['mb_name'] ?>" id="wr_name" aria-describedby="nameHelp" placeholder="">
        </div>
        <small id="nameHelp" class="form-text text-muted">예약하시는 분의 성함을 입력해 주세요.</small>
    </div>

    <?php if ($is_password) { ?>
      <div class="form-group row">
        <label for="wr_password" class="col-2 col-form-label font-weight-bold">비밀번호</label>
        <div class="col-10">
        <input type="password" name="wr_password" id="wr_password" <?php echo $password_required ?> class="form-control" placeholder="비밀번호">
        </div>
      </div>
    <?php } ?>

    <div class="form-group row">
          <label for="wr_1" class="col-2 col-form-label font-weight-bold">인원</label>
          <div  class="col-10">
          <input type="number" name="wr_1" required class="form-control" id="wr_1" aria-describedby="numberHelp" value="<?php echo $write['wr_1'];?>" placeholder="">
          </div>
          <small id="numberHelp" class="form-text text-muted">예약인을 포함하는 참석 인원을 숫자로 입력해 주세요.</small>
    </div>

    <div class="form-group row">
            <label for="wr_2" class="col-2 col-form-label font-weight-bold">연락처</label>
              <div class="col-2">
                <select name="tel1" id="tel1" class="form-control" required>
                <option value="" >선택</option>
                <option value="010" <?php echo ($cotel1 == "010")?'selected':'';?>>010</option>
                <option value="011" <?php echo ($cotel1 == "011")?'selected':'';?>>011</option>
                <option value="016" <?php echo ($cotel1 == "016")?'selected':'';?>>016</option>
                <option value="017" <?php echo ($cotel1 == "017")?'selected':'';?>>017</option>
                <option value="018" <?php echo ($cotel1 == "018")?'selected':'';?>>018</option>
                <option value="019" <?php echo ($cotel1 == "019")?'selected':'';?>>019</option>
                </select>
              </div>
              <div class="col-4">
                <input type="text" name="tel2" value="<?php echo $cotel2;?>" class="form-control" maxlength=4 required placeholder="">
              </div>
              <div class="col-4">
                <input type="text" name="tel3" value="<?php echo $cotel3;?>" class="form-control" maxlength=4 required aria-describedby="telHelp" placeholder="">
              </div>
              <small id="telHelp" class="form-text text-muted">예약하시는 분의 연락처를 입력해 주세요.</small>
          </div>

    <div class="bo_w_tit write_div form-group row">
        <label for="wr_subject" class="col-2 col-form-label font-weight-bold">예약일시</label>

        <div class="col-10" id="autosave_wrapper write_div">
            <input type="text" name="wr_subject" value="<?php echo $subject ?>" required class="form-control" id="reserv" value="" maxlength="255">
            <?php if ($is_member) { // 임시 저장된 글 기능 ?>
            <script src="<?php echo G5_JS_URL; ?>/autosave.js"></script>
            <?php if($editor_content_js) echo $editor_content_js; ?>
            <button type="button" id="btn_autosave" class="btn_frmline">임시 저장된 글 (<span id="autosave_count"><?php echo $autosave_count; ?></span>)</button>
            <div id="autosave_pop">
                <strong>임시 저장된 글 목록</strong>
                <ul></ul>
                <div><button type="button" class="autosave_close">닫기</button></div>
            </div>
            <?php } ?>
        </div>

    </div>

    <div class="form-group row">
        <label for="wr_content" class="col-2 col-form-label font-weight-bold">요청사항 및 사연</label>
        <div class="wr_content col-10 <?php echo $is_dhtml_editor ? $config['cf_editor'] : ''; ?>">
            <?php if($write_min || $write_max) { ?>
            <!-- 최소/최대 글자 수 사용 시 -->
            <p id="char_count_desc">이 게시판은 최소 <strong><?php echo $write_min; ?></strong>글자 이상, 최대 <strong><?php echo $write_max; ?></strong>글자 이하까지 글을 쓰실 수 있습니다.</p>
            <?php } ?>
            <?php echo $editor_html; // 에디터 사용시는 에디터로, 아니면 textarea 로 노출 ?>
            <?php if($write_min || $write_max) { ?>
            <!-- 최소/최대 글자 수 사용 시 -->
            <div id="char_count_wrap"><span id="char_count"></span>글자</div>
            <?php } ?>
        </div>
    </div>

    <?php if ($is_use_captcha) { //자동등록방지  ?>
    <div class="write_div">
        <?php echo $captcha_html ?>
    </div>
    <?php } ?>


    <div class="text-right m-3">
        <a href="./board.php?bo_table=<?php echo $bo_table ?>" class="btn btn-default border btn-sm">취소</a>
        <input type="submit" value="예약신청" id="btn_submit" accesskey="s" class="btn btn-primary btn-sm">
    </div>
    </form>

    <script>
    <?php if($write_min || $write_max) { ?>
    // 글자수 제한
    var char_min = parseInt(<?php echo $write_min; ?>); // 최소
    var char_max = parseInt(<?php echo $write_max; ?>); // 최대
    check_byte("wr_content", "char_count");

    $(function() {
        $("#wr_content").on("keyup", function() {
            check_byte("wr_content", "char_count");
        });
    });

    <?php } ?>
    function html_auto_br(obj)
    {
        if (obj.checked) {
            result = confirm("자동 줄바꿈을 하시겠습니까?\n\n자동 줄바꿈은 게시물 내용중 줄바뀐 곳을<br>태그로 변환하는 기능입니다.");
            if (result)
                obj.value = "html2";
            else
                obj.value = "html1";
        }
        else
            obj.value = "";
    }

    function fwrite_submit(f)
    {
        <?php echo $editor_js; // 에디터 사용시 자바스크립트에서 내용을 폼필드로 넣어주며 내용이 입력되었는지 검사함   ?>

        var subject = "";
        var content = "";
        $.ajax({
            url: g5_bbs_url+"/ajax.filter.php",
            type: "POST",
            data: {
                "subject": f.wr_subject.value,
                "content": f.wr_content.value
            },
            dataType: "json",
            async: false,
            cache: false,
            success: function(data, textStatus) {
                subject = data.subject;
                content = data.content;
            }
        });

        if (content) {
            alert("내용에 금지단어('"+content+"')가 포함되어있습니다");
            if (typeof(ed_wr_content) != "undefined")
                ed_wr_content.returnFalse();
            else
                f.wr_content.focus();
            return false;
        }

        if (document.getElementById("char_count")) {
            if (char_min > 0 || char_max > 0) {
                var cnt = parseInt(check_byte("wr_content", "char_count"));
                if (char_min > 0 && char_min > cnt) {
                    alert("내용은 "+char_min+"글자 이상 쓰셔야 합니다.");
                    return false;
                }
                else if (char_max > 0 && char_max < cnt) {
                    alert("내용은 "+char_max+"글자 이하로 쓰셔야 합니다.");
                    return false;
                }
            }
        }

        <?php echo $captcha_js; // 캡챠 사용시 자바스크립트에서 입력된 캡챠를 검사함  ?>

        document.getElementById("btn_submit").disabled = "disabled";

        return true;
    }
    </script>

    <script>
    var now = new Date();

      $('#reserv').datetimepicker({
        minDate: now
      });
    </script>
</section>
<!-- } 게시물 작성/수정 끝 -->
