<?php
require_once __DIR__ . '/../../db.php';
require_once __DIR__ . '/../../auth.php';
requireLogin();

$user        = getCurrentUser();
$currentDate = getCurrentDate();
$currentPage = 'main';
$menuArea    = '';
$fullPage    = '';

$tpl = __DIR__ . '/../templates/';
?>
<!doctype html>
<html lang="en">
<head>
  <?php include $tpl . 'backend_head.php'; ?>
</head>
<body class="layout-fixed sidebar-expand-lg sidebar-open bg-body-tertiary">
  <div class="app-wrapper">
    <?php include $tpl . 'backend_header.php'; ?>
    <?php include $tpl . 'backend_menu.php'; ?>
    <main class="app-main">
      <div class="app-content-header">
        <div class="container-fluid">
          <div class="row">
            <div class="col-sm-6"><h3 class="mb-0">Dashboard</h3></div>
            <div class="col-sm-6">
              <ol class="breadcrumb float-sm-end">
                <li class="breadcrumb-item"><a href="/projects/kkv1/ehongmd/ehongmd/main.php">หน้าหลัก</a></li>
                <li class="breadcrumb-item active" aria-current="page">Dashboard</li>
              </ol>
            </div>
          </div>
        </div>
      </div>
      <div class="app-content">
        <div class="container-fluid">
          <div class="row">
            <div class="col-12 col-sm-6 col-md-3">
              <div class="info-box">
                <span class="info-box-icon text-bg-primary shadow-sm"><i class="bi bi-geo-alt-fill"></i></span>
                <div class="info-box-content">
                  <span class="info-box-text">สถานที่ทั้งหมด</span>
                  <span class="info-box-number">
                    <?php
                      try {
                        $cnt = getDB()->query("SELECT COUNT(*) FROM CONFIG.dbo.LOCATION_RAP")->fetchColumn();
                        echo (int)$cnt;
                      } catch(Exception $e) { echo 0; }
                    ?>
                  </span>
                </div>
              </div>
            </div>
            <div class="col-12 col-sm-6 col-md-3">
              <div class="info-box">
                <span class="info-box-icon text-bg-success shadow-sm"><i class="bi bi-cash-stack"></i></span>
                <div class="info-box-content">
                  <span class="info-box-text">รายการจ่ายค่าเช่า (ปีนี้)</span>
                  <span class="info-box-number">
                    <?php
                      try {
                        $y = date('Y');
                        $cnt = getDB()->prepare("SELECT COUNT(*) FROM CONFIG.dbo.LOCATION_RF WHERE RF_Y=?");
                        $cnt->execute([$y]);
                        echo (int)$cnt->fetchColumn();
                      } catch(Exception $e) { echo 0; }
                    ?>
                  </span>
                </div>
              </div>
            </div>
          </div>

          <div class="card mt-3">
            <div class="card-header">
              <h3 class="card-title">สรุปภาพรวมระบบ (Dashboard)</h3>
            </div>
            <div class="card-body">
              ยินดีต้อนรับสู่ระบบงาน EHONG MD — ใช้เมนูด้านซ้ายเพื่อเข้าใช้งานระบบเช่าสถานที่
            </div>
          </div>
        </div>
      </div>
    </main>
    <footer class="app-footer">
      <?php include $tpl . 'backend_footer.php'; ?>
    </footer>
  </div>
  <?php include $tpl . 'backend_js.php'; ?>
</body>
</html>
