<?php
/**
 * 炎酷CMS - 后台仪表盘
 */
define('YKCMS', 1);
require __DIR__ . '/inc/auth.php';

$page_title = '仪表盘';
$active = 'index';

$stats = array(
    array('文章总数', (int)db_val('SELECT COUNT(*) FROM ' . DB_PREFIX . 'article'), ADMIN_URL . '/article/index.php'),
    array('栏目总数', (int)db_val('SELECT COUNT(*) FROM ' . DB_PREFIX . 'column'), ADMIN_URL . '/column/index.php'),
    array('单页总数', (int)db_val('SELECT COUNT(*) FROM ' . DB_PREFIX . 'page'), ADMIN_URL . '/page/index.php'),
    array('首页区块', (int)db_val('SELECT COUNT(*) FROM ' . DB_PREFIX . 'index_block'), ADMIN_URL . '/block/index.php'),
    array('素材文件', (int)db_val('SELECT COUNT(*) FROM ' . DB_PREFIX . 'upload'), ADMIN_URL . '/upload/index.php'),
    array('管理员',   (int)db_val('SELECT COUNT(*) FROM ' . DB_PREFIX . 'admin'), ADMIN_URL . '/system/admin.php'),
);
$admin = admin_current();
$lastLogs = db_all('SELECT * FROM ' . DB_PREFIX . 'log ORDER BY id DESC LIMIT 8');
$visitCards = stats_overview();

require __DIR__ . '/inc/header.php';
?>
<div class="yk-stats">
  <?php foreach ($stats as $s): ?>
  <div class="yk-stat">
    <div><?php echo e($s[0]); ?></div>
    <div class="num"><a href="<?php echo e($s[2]); ?>"><?php echo $s[1]; ?></a></div>
  </div>
  <?php endforeach; ?>
</div>

<div class="yk-card" style="margin-top:20px">
  <h3>访问概况（IP 数 / 浏览量）</h3>
  <div class="yk-stats">
    <?php foreach ($visitCards as $c): ?>
    <div class="yk-stat">
      <div style="color:#888;font-size:13px"><?php echo e($c['label']); ?></div>
      <div class="num"><?php echo number_format($c['ip']); ?><small style="font-size:13px;color:#999;font-weight:400"> IP</small></div>
      <div style="color:#999;font-size:12px;margin-top:4px">浏览量 <?php echo number_format($c['pv']); ?></div>
    </div>
    <?php endforeach; ?>
  </div>
</div>

<div class="yk-card" style="margin-top:20px">
  <h3>站点信息</h3>
  <table class="yk-table">
    <tr><th width="160">公司名称</th><td><?php echo e(site_config('company_name')); ?></td></tr>
    <tr><th>站点标题</th><td><?php echo e(site_config('seo_title')); ?></td></tr>
    <tr><th>PHP 版本</th><td><?php echo e(PHP_VERSION); ?></td></tr>
    <tr><th>数据库表前缀</th><td><?php echo e(DB_PREFIX); ?></td></tr>
    <tr><th>当前账号</th><td><?php echo e($admin['username']); ?>（<?php echo e($admin['role']); ?>）</td></tr>
    <tr><th>服务器时间</th><td><?php echo e(date('Y-m-d H:i:s')); ?></td></tr>
  </table>
</div>

<div class="yk-card">
  <h3>快捷入口</h3>
  <p>
    <a class="yk-btn" href="<?php echo e(ADMIN_URL); ?>/article/edit.php">发布文章</a>
    <a class="yk-btn gray" href="<?php echo e(ADMIN_URL); ?>/column/index.php?act=add">新增栏目</a>
    <a class="yk-btn gray" href="<?php echo e(ADMIN_URL); ?>/block/index.php?act=add">新增首页区块</a>
    <a class="yk-btn gray" href="<?php echo e(ADMIN_URL); ?>/upload/index.php">上传素材</a>
    <a class="yk-btn gray" href="<?php echo e(ADMIN_URL); ?>/system/backup.php">备份数据库</a>
  </p>
</div>

<div class="yk-card">
  <h3>最近操作日志</h3>
  <table class="yk-table">
    <tr><th>账号</th><th>操作</th><th>详情</th><th>IP</th><th width="150">时间</th></tr>
    <?php foreach ($lastLogs as $l): ?>
    <tr>
      <td><?php echo e($l['admin']); ?></td>
      <td><?php echo e($l['action']); ?></td>
      <td><?php echo e($l['detail']); ?></td>
      <td><?php echo e($l['ip']); ?></td>
      <td><?php echo e(fdate($l['add_time'], 'Y-m-d H:i:s')); ?></td>
    </tr>
    <?php endforeach; ?>
    <?php if (!$lastLogs): ?><tr><td colspan="5" style="text-align:center;color:#999">暂无日志</td></tr><?php endif; ?>
  </table>
</div>
<?php require __DIR__ . '/inc/footer.php'; ?>
