<?php
if (!defined("_GNUBOARD_"))
    exit; // 개별 페이지 접근 불가 
//g4m gallery list.skin.php
$width = "80";
$height = "60";
$crop = "1"; // 잘라서 썸네일 생성
$quality = "90"; //품질 1~100
?>

<!-- 게시판 목록 시작 -->
<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 g4board_gallery">

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

                <table class="table table-nohover">
                    <tbody>
                        <tr>
                            <?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]['comment_cnt']) {
                                    $cmt_count = "<span class='cmt'>{$list[$i]['comment_cnt']}</span>";
                                } else {
                                    $cmt_count = "";
                                }

                                if ($is_category && $list[$i]['ca_name']) {
                                    $ca_name = "<span>[{$list[$i]['ca_name']}]</span> ";
                                } else {
                                    $ca_name = "";
                                }
                                //$bg = $i%2 ? 0 : 1;//배경
                                if ($list[$i]['is_notice'])
                                    continue; //공지는 무시하자!


                                    
//썸네일 생성
                                //get_thumb(원본파일명, 목록/내용을구분하기위한구분자, 이미지너비, 이미지높이, 이미지품질=75 생략가능);
                                //기존 코드는 느려서 바꿈!
                                if ($list[$i]['file']['0']['file'] && $list[$i]['file']['0']['image_type'] < 3) {
                                    $img = get_thumb($board['bo_table'], $list[$i]['file']['0']['file'], 'list', 160, 120);
                                } else {
                                    $img = "<img src='{$board_skin_path}/img/noimage.gif' width='100%' alt='no img'/>";
                                }
                                ?>
                                <td style="width: 33.3%">
                                    <a href='<?php echo $list[$i]['href'] ?>' class="gallery_thum">
                                    <?php echo $img ?>
                                        <p class="subject"><?php echo cut_str($list[$i]['subject'], '21') ?> <?php echo $cmt_count ?></p>
                                    </a>
                                    <div class="writer"><?php echo $list[$i]['name'] ?></div>

            <!-- <p class="wr_date"><?php echo $list[$i]['datetime'] ?></p> -->
                                </td>
                                <?php
                                if (($i + 1) % 3 == 0) {
                                    echo "</tr><tr>";
                                }
                            } //for
                            ?>
                            <?php
                            if ($list_count == 0) {
                                echo "<tr><td>게시물이 없습니다.</td></tr>";
                            }
                            ?>
                        </tr>
                    </tbody>
                </table>

                </form>
                <div class="col-sm-12" style="overflow: hidden">
                    <div class="pull-left">
                        <?php if ($list_href) { ?>
                            <a href="<?php echo $list_href ?>" class="btn" 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 id="paging" style="text-align: center">

                    <?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>
                <div style="text-align: center;">
                    <?php
                    if ($prev_part_href) {
                        echo "<a href='$prev_part_href' class='btn'>이전검색</a>";
                    }
                    ?>
                    <?php
                    if ($next_part_href) {
                        echo "<a href='$next_part_href' class='btn'>다음검색</a>";
                    }
                    ?>
                </div>
            </div>
        </div>
<!-- 검색 -->
        <div class="board_search col-sm-12" style="position: relative">
            <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'>
                    <input name="stx" class="form-control" maxlength="15" value='<?php echo stripslashes($stx) ?>'/>
                </div>
                <button class="btn btn-primary btn-100" type="submit">검색</button>
            </form>       
        </div><!--//.board_search -->
</div>

<script type="text/javascript">
    $(function() {
        $("#searchDelete").click(function() {
            $("input.stx").val("");
        });
    });
    if ('<?php echo $sca ?>')
        document.fcategory.sca.value = '<?php echo $sca ?>';
    if ('<?php echo $stx ?>') {
        document.fsearch.sfl.value = '<?php echo $sfl ?>';

        if ('<?php echo $sop ?>' == 'and')
            document.fsearch.sop[0].checked = true;

        if ('<?php echo $sop ?>' == 'or')
            document.fsearch.sop[1].checked = true;
    } else {
        document.fsearch.sop[0].checked = true;
    }
<?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>
<!-- 게시판 목록 끝 -->