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

// 선택옵션으로 인해 셀합치기가 가변적으로 변함
$colspan = 5;

if ($is_checkbox) $colspan++;
if ($is_good) $colspan++;
if ($is_nogood) $colspan++;

// 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" />

<!-- 게시판 목록 시작 { -->
<div id="bo_list" style="width:<?php echo $width; ?>">


    <!-- 게시판 페이지 정보 및 버튼 시작 { -->
    <div id="bo_btn_top">
        <!-- <div id="bo_list_total">
            <span>Total <?php echo number_format($total_count) ?>건</span>
            <?php echo $page ?> 페이지
        </div> -->

        <?php if ($rss_href || $write_href) { ?>
        <ul class="btn_bo_user">
            <?php if ($rss_href) { ?><li><a href="<?php echo $rss_href ?>" class="btn_b01 btn"><i class="fa fa-rss" aria-hidden="true"></i> RSS</a></li><?php } ?>
            <?php if ($admin_href) { ?><!-- <li><a href="<?php echo $admin_href ?>" class="btn_admin btn"><i class="fa fa-user-circle" aria-hidden="true"></i> 관리자</a></li> --><?php } ?>
            <!-- <?php if ($write_href) { ?><li><a href="<?php echo G5_BBS_URL ?>/logout.php" class="btn_b02 btn">로그아웃</a></li><?php } ?> -->
        </ul>
        <?php } ?>
    </div>
    <!-- } 게시판 페이지 정보 및 버튼 끝 -->

    <!-- 게시판 카테고리 시작 { -->
    <?php if ($is_category) { ?>
    <nav id="bo_cate">
        <h2><?php echo $board['bo_subject'] ?> 카테고리</h2>
        <ul id="bo_cate_ul">
            <?php echo $category_option ?>
        </ul>
    </nav>
    <?php } ?>

    <?php
        //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; //대기수
    ?>

    <!-- } 게시판 카테고리 끝 -->

    <form name="fboardlist" id="fboardlist" action="./board_list_update.php" onsubmit="return fboardlist_submit(this);" method="post">
    <input type="hidden" name="bo_table" value="<?php echo $bo_table ?>">
    <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="sca" value="<?php echo $sca ?>">
    <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="program_id" value="<?php echo $program_wr_id ?>">
    <input type="hidden" name="sw" value="">

    <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><?=$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>
<br />

    <div class="tbl_head01 tbl_wrap">
        <table>
        <caption><?php echo $board['bo_subject'] ?> 목록</caption>
        <thead>
        <tr>
            <?php if ($is_checkbox) { ?>
            <th scope="col">
                <label for="chkall" class="sound_only">현재 페이지 게시물 전체</label>
                <input type="checkbox" id="chkall" onclick="if (this.checked) all_checked(true); else all_checked(false);">
            </th>
            <?php } ?>
            <th scope="col" class="td_num2">번호</th>
            <th scope="col" class="td_name">성명</th>
            <th scope="col" class="td_content">신청사유</th>
            <th scope="col" class="td_datetime">신청시간</th>
            <th scope="col" class="td_permit">승인내역</th>
        </tr>
        </thead>
        <tbody>

        <?php
        //Data Load
        $cateQuery = "select * from {$write_table} where wr_10='{$program_wr_id}'"; //wr_3이용해서 카테고리 찾고
        $cateResult = sql_query($cateQuery);
        $iCount = 0;
        while($cateRow = sql_fetch_array($cateResult))
        { 
        $iCount++;
         ?>

        <tr>
            <?php if ($is_checkbox) { ?>
            <td class="td_chk">
                <label for="chk_wr_id_<?php echo $iCount ?>" class="sound_only"><?php echo $cateRow['wr_subject'] ?></label>
                <input type="checkbox" name="chk_wr_id[]" value="<?php echo $cateRow['wr_id'] ?>" id="chk_wr_id_<?php echo $iCount ?>">
            </td>
            <?php } ?>
            <td class="td_num2">
            <?php
                echo $iCount;
             ?>
            </td>
            <td class="td_name"><?php echo $cateRow['wr_7'] ?></td>
            <td class="td_content"><?php echo $cateRow['wr_content'] ?></td>
            <td class="td_datetime"><?php echo $cateRow['wr_datetime'] ?></td>
            <td class="td_permit">
                <?php  if($cateRow['wr_8'] == '99')  { ?>
                 <span class="btn_appr">승인됨</span>
                 <?php } else { ?>
                 <span class="btn_wait">대기중</span>
                 <?php }?></td>

        </tr>
        <?php } ?>
        <?php if ($iCount == 0) { echo '<tr><td colspan="'.$colspan.'" class="empty_table">신청자가 없습니다.</td></tr>'; } ?>
        </tbody>
        </table>
    </div>

    <?php if ($is_admin) { ?>
    <div class="bo_fx">
        <ul class="btn_bo_user">
            <li><button type="submit" name="btn_submit" value="선택삭제" onclick="document.pressed=this.value" class="btn btn_admin"><i class="fa fa-trash-o" aria-hidden="true"></i> 선택삭제</button></li>
            <li><button type="submit" name="btn_submit" value="승인" onclick="document.pressed=this.value" class="btn btn_admin"><i class="fa fa-trash-o" aria-hidden="true"></i> 승인</button></li>
        </ul>
    </div>
    <?php } ?>

    </form>
     
</div>


<?php if($is_checkbox) { ?>
<noscript>
<p>자바스크립트를 사용하지 않는 경우<br>별도의 확인 절차 없이 바로 선택삭제 처리하므로 주의하시기 바랍니다.</p>
</noscript>
<?php } ?>



<!-- 페이지 -->
<?php echo $write_pages;  ?>


<?php if ($is_checkbox) { ?>
<script>
function all_checked(sw) {
    var f = document.fboardlist;

    for (var i=0; i<f.length; i++) {
        if (f.elements[i].name == "chk_wr_id[]")
            f.elements[i].checked = sw;
    }
}

function fboardlist_submit(f) {
    var chk_count = 0;

    for (var i=0; i<f.length; i++) {
        if (f.elements[i].name == "chk_wr_id[]" && f.elements[i].checked)
            chk_count++;
    }

    if (!chk_count) {
        alert(document.pressed + "할 게시물을 하나 이상 선택하세요.");
        return false;
    }

    if(document.pressed == "선택복사") {
        select_copy("copy");
        return;
    }

    if(document.pressed == "선택이동") {
        select_copy("move");
        return;
    }

    if(document.pressed == "선택삭제") {
        if (!confirm("선택한 신청 내역을 정말 삭제하시겠습니까?\n\n한번 삭제한 자료는 복구할 수 없습니다."))
            return false;

        f.removeAttribute("target");
        f.action = "./board_list_update_for_edu.php";
    }

      if(document.pressed == "승인") {
        if (!confirm("선택한 신청 내역을 승인하시겠습니까?\n\n추후 승인 취소는 삭제를 이용하시면 됩니다."))
            return false;

        f.removeAttribute("target");
        f.action = "./board_list_update_for_edu.php";
    }

    return true;
}

// 선택한 게시물 복사 및 이동
function select_copy(sw) {
    var f = document.fboardlist;

    if (sw == "copy")
        str = "복사";
    else
        str = "이동";

    var sub_win = window.open("", "move", "left=50, top=50, width=500, height=550, scrollbars=1");

    f.sw.value = sw;
    f.target = "move";
    f.action = "./move.php";
    f.submit();
}
</script>
<?php } ?>
<!-- } 게시판 목록 끝 -->
