<?php
/*
 *  꾸미기 전체 목록 보기
 */
include_once './_common.php';
include_once './index.php';

if (!defined('_GNUBOARD_')) {
    exit;
}

include_once G5_PLUGIN_PATH . "/asktheme/_admin/head.php";
add_stylesheet('<link rel="stylesheet" href="' . G5_PLUGIN_URL . '/asktheme/plugin/' . $plugin['id'] . '/plugin_style.css">', 0);
$banner_config = get_plugin_config($plugin['id']);
?>
<script type="text/javascript">
    $(function () {
        /*
         $('.view-detail').toggle(function () {
         $('.' + $(this).attr('id')).slideDown();
         $(this).text('상세보기 - 닫기');
         }, function () {
         $('.' + $(this).attr('id')).slideUp();
         $(this).text('상세보기 - 열기');
         });
         */
    });
</script>
<div id="container">
    <div class="row">
        <div class="small-12 medium-12 large-12 columns">
            <?php
            if ($banner_config['pc_use'] == 0) {
                echo "<div class='alert alert-default'>플러그인이 사용 중지상태입니다. 설정 메뉴에서 변경 가능합니다.</div>";
            }
            ?>
            <div class="panel panel-default">
                <div class="panel-header">
                    <h1><?php echo $plugin['name'], $plugin['version']; ?> 목록</h1>
                </div>
                <div class="panel-body">

                    <!-- PC LIST ###################################################################################  -->
                    <div class="responsetable tb-even">
                        <div class="caption">
                            PC 꾸미기 목록
                        </div>
                        <div class="tb-header">
                            <div class="tb-row show-for-medium">
                                <div class="tb-cell" style="width: 140px">
                                    Group
                                </div>
                                <div class="tb-cell">
                                    LIST
                                </div>
                            </div>
                        </div>
                        <div class="tb-body">
                            <?php
                            $sql = "select * from ask_plugin_indexgroup where not aig_area like 'mobile%' group by aig_area order by aig_area, aig_sort";
                            $result = sql_query($sql);
                            for ($i = 0; $rows = sql_fetch_array($result); $i++) {
                                ?>
                                <div class="tb-row">
                                    <div class="tb-cell show-for-medium">
                                        <?php
                                        echo "(" . $rows['aig_area'] . ")";
                                        ?>
                                    </div>
                                    <div class="tb-cell">
                                        <?php
                                        $sql_sub = "select * from ask_plugin_indexgroup where aig_area = '{$rows['aig_area']}' order by aig_area, aig_sort";
                                        $result_sub = sql_query($sql_sub);
                                        for ($j = 0, $a = 1; $data = sql_fetch_array($result_sub); $j++, $a++) {
                                            $gr_id = get_group($data['aig_area']);
                                            ?>

                                            <div class="responsetable">
                                                <div class="tb-body">
                                                    <div class="tb-row">
                                                        <div class="tb-cell">
                                                            <div class="button-group">
                                                                <a href="./indexgroup_add.php?w=u&idx=<?php echo $data['aig_idx'] ?>" class="button primary button-sm">
                                                                    <?php
                                                                    //없으면 모바일
                                                                    if (!$gr_id) {
                                                                        $gr_id_mobile = get_group(str_replace('mobile-', '', $data['aig_area']));
                                                                        if ($gr_id_mobile) {
                                                                            $mobile_subject = '<i class="fa fa-mobile" aria-hidden="true"></i> ' . $gr_id_mobile['gr_subject'];
                                                                            echo $mobile_subject;
                                                                        }
                                                                    } elseif ($gr_id) {
                                                                        echo $gr_id['gr_subject'];
                                                                    }

                                                                    if ($data['aig_area'] == 'index') {
                                                                        echo "메인";
                                                                    }
                                                                    if ($data['aig_area'] == 'index-aside') {
                                                                        echo "메인ASIDE";
                                                                    }
                                                                    if ($data['aig_area'] == 'mobile-index') {
                                                                        echo "모바일 메인";
                                                                    }
                                                                    echo $a . '행 레이아웃';
                                                                    ?>
                                                                    <i class="fa fa-pencil"></i> 수정
                                                                </a>

                                                            </div>

                                                            <?php
                                                            $sql_child = "select * from ask_plugin_indexgroup_child where aic_parent_idx = '{$data['aig_idx']}' order by aic_sort";
                                                            $result_child = sql_query($sql_child);
                                                            $child_rows = sql_num_rows($result_child);
                                                            ?>
                                                            <table class="ask-table ask-table-bordered">
                                                                <caption>
                                                                    등록된 최신글 / 탭 / HTML 컨텐츠 목록
                                                                </caption>
                                                                <thead>
                                                                    <tr>
                                                                        <th>레이아웃</th>
                                                                        <th>게시판</th>
                                                                        <th>줄수</th>
                                                                        <th class='show-for-medium'>스킨</th>
                                                                        <th>상태</th>
                                                                        <th>관리</th>
                                                                    </tr>
                                                                </thead>
                                                                <tbody>
                                                                    <?php for ($x = 0; $childs = sql_fetch_array($result_child); $x++) { ?>
                                                                        <tr>
                                                                            <?php
                                                                            if ($x == 0) {
                                                                                echo "<td rowspan='{$child_rows}' style='vertical-align:baseline;'><img src='./image/" . $data['aig_column'] . ".png'></td>";
                                                                            }
                                                                            ?>
                                                                            <td>
                                                                                <?php
                                                                                if ($childs['aic_bo_table'] && !$childs['aic_tab']) {
                                                                                    $bo_name = ask_get_board($childs['aic_bo_table']);
                                                                                    echo "<a href='" . G5_BBS_URL . "/board.php?bo_table={$bo_name['bo_table']}' target='_blank'><i class='fa fa-link'></i> " . $bo_name['bo_subject'] . "</a>";
                                                                                } else if ($childs['aic_tab']) {
                                                                                    $array = explode(',', trim($childs['aic_bo_table']));
                                                                                    $tables = array_filter($array);
                                                                                    echo "TAB : ";
                                                                                    foreach ($tables as $val) {
                                                                                        $tabs = preg_replace("/\(.*?\)/", "", $val);
                                                                                        $bo_subject = ask_get_board($tabs);
                                                                                        echo "<a href='" . G5_BBS_URL . "/board.php?bo_table={$bo_name['bo_table']}' target='_blank'><i class='fa fa-link'></i> " . $bo_subject['bo_subject'] . "</a> ";
                                                                                    }
                                                                                }
                                                                                if ($childs['aic_html']) {
                                                                                    echo cut_str(strip_tags($childs['aic_html']), 30);
                                                                                }
                                                                                ?>
                                                                            </td>
                                                                            <td>
                                                                                <?php echo $childs['aic_rows'] ?>
                                                                            </td>
                                                                            <td class="show-for-medium">
                                                                                <?php echo $childs['aic_type'] ?>
                                                                                <?php
                                                                                if ($childs['aic_html']) {
                                                                                    echo '<i class="fa fa-html5"></i> HTML 컨텐츠';
                                                                                }
                                                                                ?>
                                                                            </td>
                                                                            <td>
                                                                                <?php
                                                                                if ($childs['aic_status']) {
                                                                                    echo '<i class="fa fa-toggle-on"> On</i>';
                                                                                } else {
                                                                                    echo '<i class="fa fa-toggle-off"> Off</i>';
                                                                                }
                                                                                ?>    
                                                                            </td>

                                                                            <td>
                                                                                <div class="button-group nowrap">
                                                                                    <?php
                                                                                    if ($childs['aic_html']) {
                                                                                        $page = 'page_';
                                                                                    } elseif ($childs['aic_tab'] == '1') {
                                                                                        $page = 'tab_';
                                                                                    } else {
                                                                                        $page = '';
                                                                                    }
                                                                                    ?>
                                                                                    <a href="./indexgroup_child_<?php echo $page ?>add.php?w=u&idx=<?php echo $childs['aic_idx'] ?>" class="button primary button-sm"><i class="fa fa-pencil"></i></a>
                                                                                </div>
                                                                            </td>
                                                                        </tr>
                                                                    <?php } ?>
                                                                    <?php if ($x == 0) { ?>
                                                                    <tbody>
                                                                        <tr>
                                                                            <td>
                                                                                등록된 최신글, HTML이 없습니다.
                                                                            </td>
                                                                        </tr>
                                                                    </tbody>
                                                                <?php } ?>
                                                                </tbody>
                                                            </table>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <?php
                                        }//for
                                        ?>
                                    </div>
                                </div>
                            <?php } //for ?>
                            <?php if ($i == 0) { ?>
                                <div class="tb-row-group">
                                    <div class="tb-row">
                                        <div class="tb-cell empty-table">
                                            등록된 꾸미기가 없습니다.
                                        </div>
                                    </div>
                                </div>
                            <?php } ?>
                        </div>
                    </div>

                    <!-- Mobile LIST ###################################################################################  -->
                    <div class="responsetable tb-even">
                        <div class="caption">
                            모바일 꾸미기 목록
                        </div>
                        <div class="tb-header">
                            <div class="tb-row">
                                <div class="tb-cell" style="width: 140px">
                                    Group
                                </div>
                                <div class="tb-cell">
                                    LIST
                                </div>
                            </div>
                        </div>
                        <div class="tb-body">
                            <?php
                            $sql = "select * from ask_plugin_indexgroup where aig_area like 'mobile%' group by aig_area order by aig_area, aig_sort";
                            $result = sql_query($sql);
                            for ($i = 0; $rows = sql_fetch_array($result); $i++) {
                                ?>
                                <div class="tb-row">
                                    <div class="tb-cell">
                                        <?php
                                        echo "(" . $rows['aig_area'] . ")";
                                        ?>
                                    </div>
                                    <div class="tb-cell">
                                        <?php
                                        $sql_sub = "select * from ask_plugin_indexgroup where aig_area = '{$rows['aig_area']}' order by aig_area, aig_sort";
                                        $result_sub = sql_query($sql_sub);
                                        for ($j = 0, $a = 1; $data = sql_fetch_array($result_sub); $j++, $a++) {
                                            $gr_id = get_group($data['aig_area']);
                                            ?>

                                            <div class="responsetable">
                                                <div class="tb-body">
                                                    <div class="tb-row">
                                                        <div class="tb-cell">
                                                            <div class="button-group">
                                                                <a href="./indexgroup_add.php?w=u&idx=<?php echo $data['aig_idx'] ?>" class="button primary button-sm">
                                                                    <?php
                                                                    //없으면 모바일
                                                                    if (!$gr_id) {
                                                                        $gr_id_mobile = get_group(str_replace('mobile-', '', $data['aig_area']));
                                                                        if ($gr_id_mobile) {
                                                                            $mobile_subject = '<i class="fa fa-mobile" aria-hidden="true"></i> ' . $gr_id_mobile['gr_subject'];
                                                                            echo $mobile_subject;
                                                                        }
                                                                    } elseif ($gr_id) {
                                                                        echo $gr_id['gr_subject'];
                                                                    }

                                                                    if ($data['aig_area'] == 'index') {
                                                                        echo "메인";
                                                                    }
                                                                    if ($data['aig_area'] == 'index-aside') {
                                                                        echo "메인ASIDE";
                                                                    }
                                                                    if ($data['aig_area'] == 'mobile-index') {
                                                                        echo "모바일 메인";
                                                                    }
                                                                    echo $a . '행 레이아웃';
                                                                    ?>
                                                                    <i class="fa fa-pencil"></i> 수정
                                                                </a>

                                                            </div>

                                                            <?php
                                                            $sql_child = "select * from ask_plugin_indexgroup_child where aic_parent_idx = '{$data['aig_idx']}' order by aic_sort";
                                                            $result_child = sql_query($sql_child);
                                                            $child_rows = sql_num_rows($result_child);
                                                            ?>
                                                            <table class="ask-table ask-table-bordered">
                                                                <caption>
                                                                    등록된 최신글 / HTML 컨텐츠 목록
                                                                </caption>
                                                                <thead>
                                                                    <tr>
                                                                        <th>레이아웃</th>
                                                                        <th>게시판</th>
                                                                        <th>줄수</th>
                                                                        <th>스킨</th>
                                                                        <th>상태</th>
                                                                        <th>관리</th>
                                                                    </tr>
                                                                </thead>
                                                                <tbody>
                                                                    <?php for ($x = 0; $childs = sql_fetch_array($result_child); $x++) { ?>
                                                                        <tr>
                                                                            <?php
                                                                            if ($x == 0) {
                                                                                echo "<td rowspan='{$child_rows}' style='vertical-align:baseline;'><img src='./image/" . $data['aig_column'] . ".png'></td>";
                                                                            }
                                                                            ?>
                                                                            <td>
                                                                                <?php
                                                                                if ($childs['aic_bo_table'] && !$childs['aic_tab']) {
                                                                                    $bo_name = ask_get_board($childs['aic_bo_table']);
                                                                                    echo "<a href='" . G5_BBS_URL . "/board.php?bo_table={$bo_name['bo_table']}' target='_blank'><i class='fa fa-link'></i> " . $bo_name['bo_subject'] . "</a>";
                                                                                } else if ($childs['aic_tab']) {
                                                                                    $array = explode(',', trim($childs['aic_bo_table']));
                                                                                    $tables = array_filter($array);
                                                                                    echo "TAB : ";
                                                                                    foreach ($tables as $val) {
                                                                                        $tabs = preg_replace("/\(.*?\)/", "", $val);
                                                                                        $bo_subject = ask_get_board($tabs);
                                                                                        echo "<a href='" . G5_BBS_URL . "/board.php?bo_table={$bo_name['bo_table']}' target='_blank'><i class='fa fa-link'></i> " . $bo_subject['bo_subject'] . "</a> ";
                                                                                    }
                                                                                }
                                                                                if ($childs['aic_html']) {
                                                                                    echo cut_str(strip_tags($childs['aic_html']), 30);
                                                                                }
                                                                                ?>
                                                                            </td>
                                                                            <td>
                                                                                <?php echo $childs['aic_rows'] ?>
                                                                            </td>
                                                                            <td>
                                                                                <?php echo $childs['aic_type'] ?>
                                                                                <?php
                                                                                if ($childs['aic_html']) {
                                                                                    echo '<i class="fa fa-html5"></i> HTML 컨텐츠';
                                                                                }
                                                                                ?>
                                                                            </td>
                                                                            <td>
                                                                                <?php
                                                                                if ($childs['aic_status']) {
                                                                                    echo '<i class="fa fa-toggle-on"> On</i>';
                                                                                } else {
                                                                                    echo '<i class="fa fa-toggle-off"> Off</i>';
                                                                                }
                                                                                ?>    
                                                                            </td>

                                                                            <td>
                                                                                <div class="button-group nowrap">
                                                                                    <?php
                                                                                    if ($childs['aic_html']) {
                                                                                        $page = 'page_';
                                                                                    } elseif ($childs['aic_tab'] == '1') {
                                                                                        $page = 'tab_';
                                                                                    } else {
                                                                                        $page = '';
                                                                                    }
                                                                                    ?>
                                                                                    <a href="./indexgroup_child_<?php echo $page ?>add.php?w=u&idx=<?php echo $childs['aic_idx'] ?>" class="button primary button-sm"><i class="fa fa-pencil"></i></a>
                                                                                </div>
                                                                            </td>
                                                                        </tr>
                                                                    <?php } ?>
                                                                    <?php if ($x == 0) { ?>
                                                                    <tbody>
                                                                        <tr>
                                                                            <td>
                                                                                등록된 최신글, HTML이 없습니다.
                                                                            </td>
                                                                        </tr>
                                                                    </tbody>
                                                                <?php } ?>
                                                                </tbody>
                                                            </table>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <?php
                                        }//for
                                        ?>
                                    </div>
                                </div>
                            <?php } //for ?>
                            <?php if ($i == 0) { ?>
                                <div class="tb-row-group">
                                    <div class="tb-row">
                                        <div class="tb-cell empty-table">
                                            등록된 꾸미기가 없습니다.
                                        </div>
                                    </div>
                                </div>
                            <?php } ?>
                        </div>
                    </div>



                    <!-- //LIST-->

                </div>
                <div class="panel-footer">
                    &middot; 페이지 등록은 수정을 클릭후 등록하세요!
                </div>
            </div>
            <div class="alert alert-info">
                &middot; 위치 부분에 index는 메인페이지, index-aside 는 메인 사이드, mobile로 시작하는 위치는 모바일 페이지입니다.
            </div>
        </div>
    </div>
</div>

<?php
include_once G5_PLUGIN_PATH . "/asktheme/_admin/tail.php";

