<?php
/**
 * 文章管理
 */

$title = '文章管理';
include "header.php";
$sum = 8; #每页数量
$page = shop::page($sum, $_QET['page']); #取出翻页数据
$article_list = user::article_list($sum, $page['count'], $page['limit']); #获取商品列表
$paging = shop::paging($article_list['count'], $_QET['page']); #取出翻页按钮数据
if (!empty($_QET['unset'])) {
    $a = $DB->query("DELETE FROM `sky_notice` WHERE (`id`='{$_QET['unset']}')"); #删除
    if ($a) {
        show_msg('成功提示', '编号:' . $_QET['unset'] . '删除成功,请点击下方按钮返回', '1');
    } else show_msg('温馨提示', '编号:' . $_QET['unset'] . '删除失败,原因->' . $DB->error(), '2');
}
?>
<!-- third party css -->
<link href="<?= $cdnserver == null ? '../' : $cdnserver ?>assets/css/vendor/dataTables.bootstrap4.css" rel="stylesheet"
      type="text/css"/>
<link href="<?= $cdnserver == null ? '../' : $cdnserver ?>assets/css/vendor/responsive.bootstrap4.css" rel="stylesheet"
      type="text/css"/>
<!-- third party css end -->
<!-- App css -->
<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-body">
                <div class="row mb-2">
                    <div class="col-sm-4">
                        <a href="admin.article.add.php" class="btn btn-danger mb-2"><i
                                    class="layui-icon layui-icon-add-circle-fine mr-2"></i>
                            新增一篇文章
                        </a>
                    </div>
                </div>
                <div class="table-responsive">
                    <table class="table table-centered table-striped dt-responsive nowrap w-100"
                           id="products-datatable">
                        <thead>
                        <tr style="white-space: nowrap">
                            <th>ID</th>
                            <th>标题</th>
                            <th>内容</th>
                            <th>浏览人数</th>
                            <th>发布时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php foreach ($article_list['data'] as $v) {
                            ?>
                            <tr style="white-space: nowrap;font-size: 0.9em">
                                <td>
                                    <a href="admin.article.add.php?id=<?= $v['id'] ?>" class="badge badge-info-lighten">
                                        <?= $v['id'] ?>
                                    </a>
                                </td>
                                <td class="table-user">
                                    <?php
                                    echo mb_strlen($v['title'], 'utf-8') > 8 ? mb_substr($v['title'], 0, 8, 'utf-8') . '...' : $v['title'];
                                    ?>
                                </td>
                                <td>
                                    <a class="badge badge-success-lighten" target="_blank"
                                       href="../?mod=article&id=<?= $v['id'] ?>">查看文章预览</a>
                                </td>
                                <td>
                                    <span class="badge badge-danger-lighten">
                                        <?= count(explode('|', $v['browse'])); ?>
                                    </span>
                                </td>
                                <td>
                                    <?= $v['date'] ?>
                                </td>
                                <td>
                                    <a href="admin.article.add.php?id=<?= $v['id'] ?>" class="action-icon"> <i
                                                class="layui-icon layui-icon-set-fill"></i></a>
                                    <a href="javascript:unset(<?= $v['id'] ?>)" class="action-icon"> <i
                                                class="layui-icon layui-icon-delete"></i></a>
                                </td>
                            </tr>
                        <?php } ?>

                        </tbody>
                    </table>
                </div>
                <nav>
                    <ul class="pagination pagination-rounded" style="overflow: auto">
                        <li class="page-item">
                            <a class="page-link" href="?page=1" aria-label="Previous">
                                <span aria-hidden="true">«</span>
                                <span class="sr-only">Previous</span>
                            </a>
                        </li>
                        <?php foreach ($paging as $v) { ?>
                            <li class="page-item <?= $v['active'] ?>"><a class="page-link"
                                                                         href="?page=<?= $v['number'] ?>"><?= $v['number'] ?></a>
                            </li>
                        <?php } ?>
                        <li class="page-item">
                            <a class="page-link" href="?page=<?= $article_list['count'] ?>" aria-label="Next">
                                <span aria-hidden="true">»</span>
                                <span class="sr-only">Next</span>
                            </a>
                        </li>
                    </ul>
                </nav>
            </div> <!-- end card-body-->
        </div> <!-- end card-->
    </div> <!-- end col -->
</div>


<?php include "bottom.php"; ?>
<script>
    function unset(a) {
        layer.alert('删除后不可撤销，是否确认删除？', {
            icon: 3, title: '温馨提示', btn: ['取消', '确定删除'], btn2: function (layero, index) {
                window.location.href = '?unset=' + a;
            }
        })
    }
</script>
