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

<!-- 게시판 목록 시작 -->

<div class="row">
    <!-- 제목 -->
    <form name="fboardlist" method="post" action="" class="form-inline">
        <legend class="hide">List</legend>
        <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='page' value='<?php echo $page ?>'/>
        <input type='hidden' name='sw'   value=''/>
        <div class="col-sm-12">

            <div class="g4board_basic panel panel-primary">
                <div class="panel-heading">
                    <h3 style="margin:0"><?php echo $board['bo_subject'] ?></h3>
                </div>    
                <div class="panel-body">
                    <?php if ($is_category) { ?>
                        <div class="pull-left">
                            <form name="fcategory" method="get" action="" class="form-inline">
                                <div class="form-group">
                                    <legend class="hide">분류</legend>
                                    <select name='sca' class='form-control' onchange="location = '<?php echo $category_location ?>' +<?php echo strtolower($g4[charset]) == 'utf-8' ? "encodeURIComponent(this.value)" : "this.value" ?>;">
                                        <option value=''>전체</option>
                                        <?php echo $category_option ?>
                                    </select>
                                </div>
                            </form>
                        </div>
                    <?php } ?>
                    <div class="pull-right">
                        <span style="color:#888888; font-size: 0.85em;">Total <?php echo number_format($total_count) ?></span>
                        <?php if ($rss_href) { ?><a href='<?php echo $rss_href ?>' class="btn btn-mini" title="rss">RSS</a><?php } ?>
                        <?php if ($admin_href) { ?><a href="<?php echo $g4m_admin_href ?>" class="btn btn-primary" title="관리자">Admin</a><?php } ?>
                    </div>
                </div>
                <ul class="basic_list list-group">
                    <?php
                    $list_count = count($list);
                    for ($i = 0; $i < $list_count; $i++) {
                        $list[$i]['href'] = str_replace('../bbs', './bbs', $list[$i]['href']); //함수 수정 하지 않고 경로 변경
                        if ($list[$i]['is_notice']) {
                            $class_notice = "notice";
                            $notice = "<span class='glyphicon glyphicon-comment'></span>";
                        } else {
                            $class_notice = "";
                            $notice = "";
                        }
                        if ($list[$i]['comment_cnt']) {
                            $cmt_count = "<span class='cmt'>{$list[$i]['comment_cnt']}</span>";
                        } else {
                            $cmt_count = "";
                        }
                        if ($list[$i]['reply']) {
                            $reply = "<span><img src='{$board_skin_path}/img/icon_reply.png'></span>";
                        } else {
                            $reply = "";
                        }
                        if ($is_category && $list[$i]['ca_name']) {
                            $ca_name = "<span>[{$list[$i]['ca_name']}]</span> ";
                        } else {
                            $ca_name = "";
                        }
                        //$bg = $i%2 ? 0 : 1;//배경
                        ?>
                        <li class="list-group-item">
                            <a href='<?php echo $list[$i]['href'] ?>' class="subject <?php echo $class_notice ?>">
                                <?php echo $notice ?><?php echo $ca_name ?> <?php echo $reply ?> <?php echo $list[$i]['subject'] ?> <?php echo $cmt_count ?>
                                <?php
                                if ($list[$i]['icon_new']) {
                                    echo "<span class='icon-leaf'></i>";
                                }
                                if ($list[$i]['icon_file']) {
                                    echo "<span class='icon-file'></i>";
                                }
                                if ($list[$i]['icon_link']) {
                                    echo "<span class='icon-star'></i>";
                                }
                                if ($list[$i]['icon_hot']) {
                                    echo "<span class='glyphicon glyphicon-fire'></i>";
                                }
                                if ($list[$i]['icon_secret']) {
                                    echo "<span class='glyphicon glyphicon-lock'></i>";
                                }
                                ?>
                            </a>
                            <span class="writer">
                                <?php echo $list[$i]['name']; ?>
                            </span>
                            <span class="wr_date"><?php echo $list[$i]['datetime'] ?></span>
                        </li>
                    <?php } //for?>
                    <?php
                    if ($list_count == 0) {
                        echo "<li><p style='padding: 48px; text-align: center'>게시물이 없습니다.</p></li>";
                    }
                    ?>
                </ul>
            </div><!--//.board_search -->

        </div><!--//.g4board_basic -->
</div>
</form>
<div class="form-actions" style="overflow: hidden; min-height: 45px">
    <div class="pull-left">
        <?php if ($list_href) { ?>
            <a href="<?php echo $list_href ?>" class="btn btn-default" title="목록">목록</a>
        <?php } ?>
    </div>

    <div class="pull-right">
        <?php if ($write_href) { ?><a href="<?php echo $write_href ?>" class="btn btn-primary" title="글쓰기">글쓰기</a><?php } ?>
    </div>
</div>
<!-- 페이지 -->
<div class="page">
    <?php
    /*
      $write_pages = str_replace("처음", "&lt;&lt;", $write_pages);
      $write_pages = str_replace("이전", "&lt;", $write_pages);
      $write_pages = str_replace("다음", "&gt;", $write_pages);
      $write_pages = str_replace("맨끝", "&gt;&gt;", $write_pages);
     */
    echo $write_pages
    ?>

</div>
<?php if ($prev_part_href) {?>
<div style="text-align: center;">
    <ul class="pager">
        <?php
        if ($prev_part_href) {
            echo "<li><a href='$prev_part_href' class='btn'>이전검색</a></li>";
        }
        ?>
        <?php
        if ($next_part_href) {
            echo "<li><a href='$next_part_href' class='btn'>다음검색</a></li>";
        }
        ?>
    </ul>
</div>
<?php } ?>
<!-- 검색 -->
<div class="board_search">
    <form name="fsearch" method="get" action="" class="form-inline" role='form'>
        <input type="hidden" name="bo_table" value="<?php echo $bo_table ?>"/>
        <input type="hidden" name="sca"      value="<?php echo $sca ?>"/>
        <input type="hidden" name="sfl"      value="wr_subject||wr_content"/>
        <input type="hidden" name="sop" value="and" checked="checked"/>
        <input type="hidden" name="sop" value="or"/>
        <div class="form-group stx-box">
            <input name="stx" class="form-control" maxlength="30" value='<?php echo stripslashes($stx) ?>' style="padding-right: 40px;"/>
            <button id="searchDelete" class="btn btn-danger" type="button">x</button>
        </div>
        <div class="form-group">

            <button class="btn btn-primary btn-100" type="submit">검색</button>
        </div>
    </form>       

    <script type="text/javascript">
        $(function() {
            $("#searchDelete").click(function() {
                $("input[name='stx']").val('');
            });
        });

        
    <?php if ($is_checkbox) { ?>
            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 check_confirm(str) {
                var f = document.fboardlist;
                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(str + "할 게시물을 하나 이상 선택하세요.");
                    return false;
                }
                return true;
            }

            // 선택한 게시물 삭제
            function select_delete() {
                var f = document.fboardlist;

                str = "삭제";
                if (!check_confirm(str))
                    return;

                if (!confirm("선택한 게시물을 정말 " + str + " 하시겠습니까?\n\n한번 " + str + "한 자료는 복구할 수 없습니다"))
                    return;

                f.action = "./delete_all.php";
                f.submit();
            }
            // 선택한 게시물 복사 및 이동
            function select_copy(sw) {
                var f = document.fboardlist;
                if (sw == "copy")
                    str = "복사";
                else
                    str = "이동";

                if (!check_confirm(str))
                    return;
                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();
            }
<?php } ?>
    </script>
</div>
<!-- 게시판 목록 끝 -->
