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

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

<section class="sc-basic temha_board">
  <div class="contents-container container-md">
 <div class="contents-form"> 
    <div class="bo_list_total">
       총 <strong><?php echo number_format($total_count) ?>건</strong> 의 게시물
   </div>	 
  <!-- 실제 검색 폼 -->
  <form name="fsearch" method="get"class="form-box">
    <input type="hidden" name="bo_table" value="<?php echo $bo_table; ?>">
    <input type="hidden" name="sca" value="<?php echo $sca; ?>">
    <input type="hidden" name="sop" value="and">
    <div class="inputset inputset-icon icon-right"> <span class="icon"> <i class="ff-ico ti-search"> <span class="blind">검색</span> </i> </span>
      <label for="basic-N22-inputset-a-1" class="form-tit h6 blind">검색어</label>
      <!-- 검색어 필드는 반드시 name="stx" 로 사용 -->
      <input id="basic-N22-inputset-a-1" type="text" name="stx" class="inputset-input form-control icon-left"  placeholder="내용을 입력하세요."  required>
    </div>
  </form>
</div>
<form name="fboardlist"  id="fboardlist" action="<?php echo G5_BBS_URL; ?>/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="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="sw" value="">  
    <div class="tableset tableset-fract">
      <table class="tableset-table table">    
        <thead class="thead-light thead-border-top">
          <tr>
			  <?php if ($is_checkbox) { ?>
			  <th scope="col" class="all_chk chk_box">
			  <div class="form-box">
			  <div class="checkset checkset-line">		
			<input type="checkbox" id="chkall" onclick="if (this.checked) all_checked(true); else all_checked(false);" class="checkset-input">
                <label for="chkall" class="checkset-label">          
                	<b class="sound_only">현재 페이지 게시물  전체선택</b>
				</label>
			 </div>
			</div>	
			  </th>		
			  <?php } ?>
            <th scope="col" class="number">No.</th>
            <th scope="col">제목</th>
            <th scope="col">등록일</th>
          </tr>
        </thead>
        <tbody>
          <?php for ($i = 0; $i < count($list); $i++) { ?>
            <tr>
			 <?php if ($is_checkbox) { ?>
				<td>
				  <div class="form-box">
				<div class="checkset checkset-line">
				  <input class="checkset-input" type="checkbox" name="chk_wr_id[]" value="<?php echo $list[$i]['wr_id'] ?>" id="chk_wr_id_<?php echo $i ?>" >
				<label for="chk_wr_id_<?php echo $i ?>" class="checkset-label"> <b class="sound_only"><?php echo $list[$i]['subject'] ?></b></label> 
				</div>
			  </div>
				</td>
			  <?php } ?>
              <td class="tableset-mobile">     <?php
            if ($list[$i]['is_notice']) // 공지사항
                echo '<strong class="notice_icon">공지</strong>';
            else if ($wr_id == $list[$i]['wr_id'])
                echo "<span class=\"bo_current\">열람중</span>";
            else
                echo $list[$i]['num'];
             ?></td>
              <td class="text-left tableset tableset-tit-ellipsis tableset-tit">
                <a href="<?php echo $list[$i]['href']; ?>"><span><?php echo $list[$i]['subject']; ?></span></a>
              </td>
              <td class="date"><?php echo $list[$i]['datetime']; ?></td>
            </tr>
          <?php } ?>
        </tbody>
      </table>
    </div>
	<!-- 페이징 -->
      <?php echo get_paging_new(G5_IS_MOBILE ? $config['cf_mobile_pages'] : $config['cf_write_pages'], $page, $total_page, get_pretty_url($bo_table, '', $qstr . '&amp;page=')); ?>
      <!-- // 페이징 -->
	<div class="btn_bo_user">
  <ul>	  
    <?php if ($admin_href) { ?>
    <li><a href="<?php echo $admin_href ?>" class="btnset btnset-line-primary btnset-icon ff-ico ti-gear-rect" title="관리자"> 관리자</a></li>
    <?php } ?>
    <?php if ($write_href) { ?>
    <li><a href="<?php echo $write_href ?>" class="btnset btnset-primary" title="글쓰기">글쓰기</a></li>
    <?php } ?>
	   <?php if ($is_admin == 'super' || $is_auth) { ?>
	  <li>
	 <button type="button" class="btn_more_opt btnset btnset-line-dark ff-ico ti-dots" title="게시판 리스트 옵션"><span class="sound_only">게시판 리스트 옵션</span></button>
    <?php if ($is_checkbox) { ?>
	 <div class="more_opt is_list_btn">
	 <ul>
    <li>
      <button type="submit" class="btnset btnset-line-dark" name="btn_submit" value="선택삭제" onclick="document.pressed='선택삭제'"><i class="fa fa-trash-o" aria-hidden="true"></i> 선택삭제</button>
    </li>
    <li>
      <button type="submit" class="btnset btnset-line-dark" name="btn_submit" value="선택복사" onclick="document.pressed='선택복사'"><i class="fa fa-files-o" aria-hidden="true"></i> 선택복사</button>
    </li>
    <li>
      <button type="submit" class="btnset btnset-line-dark" name="btn_submit" value="선택이동" onclick="document.pressed='선택이동'"><i class="fa fa-arrows" aria-hidden="true"></i> 선택이동</button>
    </li>
	 </ul>
   </div>
	 </li>
    <?php } ?>  
<?php }  ?>
  </ul>
</div>
 </form> 
	</div>
</div>
</section>
</main>


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

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

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

    if(document.pressed == "선택삭제") {
        if (!confirm("선택한 게시물을 정말 삭제하시겠습니까?\n\n한번 삭제한 자료는 복구할 수 없습니다\n\n답변글이 있는 게시글을 선택하신 경우\n답변글도 선택하셔야 게시글이 삭제됩니다."))
            return false;

        f.removeAttribute("target");
        f.action = g5_bbs_url+"/board_list_update.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 = g5_bbs_url+"/move.php";
    f.submit();
}

// 게시판 리스트 관리자 옵션
jQuery(function($){
    $(".btn_more_opt").on("click", function(e) {
        e.stopPropagation();
        $(".more_opt.is_list_btn").toggle();
    });
    $(document).on("click", function (e) {
        if(!$(e.target).closest('.is_list_btn').length) {
            $(".more_opt.is_list_btn").hide();
        }
    });
});
</script>
<?php } ?>
<!-- } 게시판 목록 끝 -->