<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
// add_stylesheet('<link rel="stylesheet" href="'.$board_skin_url.'/style.css">', 0);
?>
<link rel="stylesheet" type="text/css" href="<?php echo $board_skin_url; ?>/style.css" />

<section id="bo_w">
    <h2 class="sound_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" style="width:<?php echo $width; ?>">
    <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(!isset($program_wr_id))
        {
           alert('프로그램 정보가 넘어오지 않았습니다. 관리자에게 문의해주세요.', G5_HTTP_BBS_URL.'/board.php?bo_table=edu_program'); 
           exit;
        }

        //Data Load
        $programContentQuery = "select * from g5_write_edu_program where wr_id={$program_wr_id}"; //wr_3이용해서 카테고리 찾고
        $programContentResult = sql_fetch($programContentQuery);
        $recruitMember = $programContentResult['wr_4']; //모집인원 총 수
 
        //지원멤버 계산
        $applyContentQuery = "select count(*) as cnt from g5_write_edu_apply where wr_10={$program_wr_id}"; 
        $applyContentResult = sql_fetch($applyContentQuery);
        $recruitMember_now = $applyContentResult['cnt']; //지원한 인원수

        $permitContentQuery = "select count(*) as cnt from g5_write_edu_apply where wr_10={$program_wr_id} and wr_8=99"; 
        $permitContentResult = sql_fetch($permitContentQuery);
        $applyMember = $permitContentResult['cnt']; //승인된 수
        $remainMember = $recruitMember_now - $applyMember; //대기수

        if($programContentResult['ca_name'] != '접수중') {
           alert('해당 프로그램은 접수상태가 아닙니다.', G5_HTTP_BBS_URL.'/board.php?bo_table=edu_program');
           exit;
        }
    ?>  
    
    <input type="hidden" name="wr_10" value="<?php echo $program_wr_id ?>">
    <input type="hidden" name="wr_subject" value="<?php echo $programContentResult['wr_subject'] ?>">
     <div class="tbl_program_intro">
        <table class="edu">
          <tr>
            <th scope="row" class="edu_tit">교 육 명</th>
              <td class="edu_con"><?=$programContentResult['wr_subject']?></td>
            <th scope="row" class="edu_tit">구&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;분</th>
            <td class="edu_con"><?=$programContentResult['ca_name']?> </td>
          </tr>
          <tr>
              <th scope="row" class="edu_tit">신청대상</th>
              <td class="edu_con"><?=$programContentResult['wr_1']?></td>
              <th scope="row" class="edu_tit">진행일시</th>
              <td class="edu_con"><?=$programContentResult['wr_6']?></td>
          </tr>
          <tr>
              <th scope="row" class="edu_tit">장&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;소</th>
              <td class="edu_con"><?=$programContentResult['wr_2']?></td>
              <th scope="row" class="edu_tit">모집인원</th>
              <td class="edu_con"><?=$recruitMember_now?> / <?=$recruitMember ?>명 (승인:<?=$applyMember?>/대기:<?=$remainMember?>)</td>
          </tr>
          <tr>
              <th scope="row" class="edu_tit">비&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;용</th>
              <td class="edu_con"><?=$programContentResult['wr_3']?></td>
              <th scope="row" class="edu_tit">모집기간</th>
              <td class="edu_con"><?=$programContentResult['wr_5']?></td>
          </tr>
      </table>
    </div>

    <div class="tbl_frm01 tbl_wrap">
        <table>
        <caption>회원정보</caption>
        <tbody>
        
        <tr>
            <th scope="row" class="td_tit"><label for="wr_7">성명<strong class="sound_only">필수</strong></label></th>
            <td class="td_auto"><input type="text" name="wr_7" value="<?php echo $wr_7 ?>" id="wr_7" required class="frm_input required"></td>
        </tr>
            <?php if ($is_password) { ?>
        <tr>
            <th scope="row" class="td_tit"><label for="wr_password">비밀번호<strong class="sound_only">필수</strong></label></th>
            <td class="td_auto"><input type="password" name="wr_password" id="wr_password" <?php echo $password_required ?> class="frm_input <?php echo $password_required ?>"></td>
        </tr>
        <?php } ?>
        <tr>
            <th scope="row" class="td_tit"><label for="wr_1">성별<strong class="sound_only">필수</strong></label></th>
            <td class="td_auto"><input type="text" name="wr_1" value="<?php echo $wr_1 ?>" id="wr_1" required class="frm_input required" placeholder="남자/여자"></td>
        </tr>
        <tr>
            <th scope="row" class="td_tit"><label for="wr_2">생년월일<strong class="sound_only">필수</strong></label></th>
            <td class="td_auto"><input type="text" name="wr_2" value="<?php echo $wr_2 ?>" id="wr_2" required class="frm_input required" placeholder="년.월.일 (92.10.27)"></td>
        </tr>
        <tr>
            <th scope="row" class="td_tit"><label for="wr_3">나이<strong class="sound_only">필수</strong></label></th>
            <td class="td_auto"><input type="text" name="wr_3" value="<?php echo $wr_3 ?>" id="wr_3" required class="frm_input required" placeholder="27"></td>
        </tr>
        <tr>
            <th scope="row" class="td_tit"><label for="wr_4">휴대폰번호<strong class="sound_only">필수</strong></label></th>
            <td class="td_auto"><input type="text" name="wr_4" value="<?php echo $wr_4 ?>" id="wr_4" required class="frm_input required" placeholder="010-1234-1234"></td>
        </tr>
        <tr>
            <th scope="row" class="td_tit"><label for="wr_eamil">이메일<strong class="sound_only">필수</strong></label></th>
            <td class="td_auto"><input type="text" name="wr_eamil" value="<?php echo $email ?>" id="wr_eamil" required class="frm_input email" placeholder="이메일"></td>
        </tr>
        <tr>
             <th scope="row" class="td_tit"><label for="wr_content">신청사유<strong class="sound_only">필수</strong></label></th>
            <td class="td_auto">
                <?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 } ?>
            <textarea id="wr_content" name="wr_content" class="" maxlength="65536"></textarea>
            <?php if($write_min || $write_max) { ?>
                <!-- 최소/최대 글자 수 사용 시 -->
                <div id="char_count_wrap"><span id="char_count"></span>글자</div>
                <?php } ?>
            </td>
        </tr>

        <!--
        <?php if ($is_homepage) { ?>
        <tr>
            <th scope="row"><label for="wr_homepage">홈페이지</label></th>
            <td><input type="url" name="wr_homepage" value="<?php echo $homepage ?>" id="wr_homepage" class="frm_input"></td>
        </tr>
        <?php } ?>
        

        <?php if ($option) { ?>
        <tr>
            <th scope="row">옵션</th>
            <td><?php echo $option ?></td>
        </tr>
        <?php } ?>
        -->
        </tbody>
        </table>
    </div>


     <div class="tbl_frm01 fregister_term">
            <h3><i class="fa fa-check-square-o" aria-hidden="true"></i> 개인 정보 처리 방침 안내</h3>
            <h3>교육신청을 하려면 개인정보 제공 및 이용 동의를 해주셔야 가능합니다.</h3>
            <textarea readonly>1. 개인정보 수집·이용목적
- 천안시2030청년복지센터 서비스 제공을 위해 필요한 본인확인
- 통계작성 및 학술 연구 등의 목적을 위하여 필요한 경우

2. 개인정보 수집항목
- 수집항목 : 성명, 성별, 생년월일, 나이, 휴대폰번호, 이메일, 주소, 신청사유

3. 개인정보의 보유 및 이용기간
- 본센터 진행하는 사업에만 보유, 이용, 보관됩니다.

4. 동의 거부 및 동의 거부 시 불이익 내용
- 개인정보 수집 동의를 거부하실 수 있습니다. 다만, 동의하지 않을 경우 서비스가 원활하지 못할 수 도 있습니다.
- 개인정보는 본 센터가 제공되는 서비스  이외의 다른 목적으로 사용하지 않습니다.
            </textarea>
            <fieldset class="fregister_agree">
                <label for="agree">개인정보 제공 및 이용 내용에 동의합니다.</label>
                <input type="checkbox" name="wr_6" value="1" id="agree" required class="frm_input required">
            </fieldset>
        </div>

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


    <div class="btn_confirm write_div">
        <a href="./board.php?bo_table=<?php echo $bo_table ?>" class="btn_cancel btn">취소</a>
        <input type="submit" value="작성완료" id="btn_submit" accesskey="s" class="btn_submit btn">
    </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 (subject) {
            alert("제목에 금지단어('"+subject+"')가 포함되어있습니다");
            f.wr_subject.focus();
            return false;
        }

        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;
                }
            }
        }

        if (!f.agree.checked) {
            alert("개인정보처리방침안내에 동의하셔야 교육신청이 가능합니다.");
            f.agree.focus();
            return false;
        }

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

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

        return true;
    }
    </script>
</section>
<!-- } 게시물 작성/수정 끝 -->