271 lines
15 KiB
PHP
271 lines
15 KiB
PHP
<?php
|
|
ob_start();
|
|
// index.php (Main Router)
|
|
require_once 'config/config.php';
|
|
require_once 'config/database.php';
|
|
|
|
// Simple routing mechanism
|
|
$page = isset($_GET['page']) ? $_GET['page'] : 'dashboard';
|
|
|
|
// Check if user is logged in for protected pages
|
|
if (!isset($_SESSION['user_id']) && !in_array($page, ['login', 'public_request'])) {
|
|
redirect('?page=login');
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="th" class="antialiased">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
<meta name="theme-color" content="#10b981">
|
|
<title>Smart Patient Transport System - รพ.เกาะสมุย</title>
|
|
|
|
<!-- PWA Manifest -->
|
|
<link rel="manifest" href="manifest.json">
|
|
<link rel="apple-touch-icon" href="assets/img/logo.png">
|
|
|
|
<!-- Favicon -->
|
|
<link rel="icon" type="image/png" href="assets/img/logo.png">
|
|
|
|
<!-- Tailwind CSS (CDN for zero-build setup) -->
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
<script>
|
|
tailwind.config = {
|
|
darkMode: 'class',
|
|
theme: {
|
|
extend: {
|
|
colors: {
|
|
brand: {
|
|
50: '#ecfdf5',
|
|
100: '#d1fae5',
|
|
500: '#10b981',
|
|
600: '#059669',
|
|
700: '#047857',
|
|
900: '#064e3b',
|
|
}
|
|
},
|
|
fontFamily: {
|
|
sans: ['Inter', 'Sarabun', 'sans-serif'],
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<!-- Google Fonts -->
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Sarabun:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
|
|
|
<!-- FontAwesome -->
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
|
|
<!-- SweetAlert2 -->
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">
|
|
|
|
<!-- Custom CSS -->
|
|
<link rel="stylesheet" href="assets/css/style.css">
|
|
|
|
<style type="text/tailwindcss">
|
|
body { font-family: 'Inter', 'Sarabun', sans-serif; }
|
|
|
|
@layer utilities {
|
|
.glass-card {
|
|
@apply backdrop-blur-xl bg-white/70 dark:bg-slate-900/70 border border-white/60 dark:border-white/10 shadow-[var(--glass-shadow)] rounded-2xl;
|
|
}
|
|
|
|
.glass-nav {
|
|
@apply backdrop-blur-lg bg-emerald-800/95 dark:bg-slate-900/95 border-b border-emerald-900/20 dark:border-white/10 shadow-md sticky top-0 z-50;
|
|
}
|
|
|
|
.glass-input {
|
|
@apply backdrop-blur-md bg-white/80 dark:bg-slate-800/80 border border-slate-300 dark:border-slate-600 focus:bg-white dark:focus:bg-slate-900 focus:ring-2 focus:ring-emerald-500 rounded-xl transition-all duration-300;
|
|
}
|
|
|
|
.btn-primary-glass {
|
|
@apply bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-700 hover:to-teal-700 text-white shadow-lg shadow-emerald-500/30 hover:shadow-emerald-500/50 rounded-xl transition-all duration-300 active:scale-95;
|
|
}
|
|
|
|
.btn-secondary-glass {
|
|
@apply bg-white/90 dark:bg-slate-800/90 hover:bg-white dark:hover:bg-slate-700 border border-slate-300 dark:border-slate-600 text-slate-700 dark:text-slate-200 rounded-xl transition-all duration-300 active:scale-95 shadow-sm;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body class="text-slate-800 dark:text-slate-200 transition-colors duration-300 min-h-screen flex flex-col">
|
|
|
|
<!-- Floating Background Orbs -->
|
|
<div class="bg-floating">
|
|
<div class="bg-orb bg-orb-1"></div>
|
|
<div class="bg-orb bg-orb-2"></div>
|
|
<div class="bg-orb bg-orb-3"></div>
|
|
</div>
|
|
|
|
<?php if (isset($_SESSION['user_id'])): ?>
|
|
<nav class="glass-nav mb-6">
|
|
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
|
<div class="flex justify-between h-16">
|
|
<!-- Logo & Brand -->
|
|
<div class="flex items-center">
|
|
<a href="?page=dashboard" class="flex items-center gap-3 shrink-0">
|
|
<div class="w-10 h-10 rounded-full bg-white flex items-center justify-center p-1 shadow-sm">
|
|
<img src="assets/img/logo.png" alt="Logo" class="w-full h-full object-contain">
|
|
</div>
|
|
<span class="font-bold text-white tracking-tight hidden sm:block">PT System<br><span class="text-xs font-normal text-emerald-100">รพ.เกาะสมุย</span></span>
|
|
</a>
|
|
</div>
|
|
|
|
<!-- Desktop Menu -->
|
|
<div class="hidden md:flex md:items-center md:space-x-4">
|
|
<a href="?page=dashboard" class="px-3 py-2 rounded-lg text-sm font-medium <?= $page == 'dashboard' ? 'bg-white/20 text-white' : 'text-emerald-50 hover:bg-white/10' ?> transition-colors">
|
|
<i class="fa-solid fa-chart-pie me-1"></i> Dashboard
|
|
</a>
|
|
<?php if (isset($_SESSION['role']) && ($_SESSION['role'] === 'admin' || $_SESSION['role'] === 'manager')): ?>
|
|
<a href="?page=executive" class="px-3 py-2 rounded-lg text-sm font-medium <?= $page == 'executive' ? 'bg-white/20 text-white' : 'text-emerald-50 hover:bg-white/10' ?> transition-colors">
|
|
<i class="fa-solid fa-chart-line me-1"></i> Executive
|
|
</a>
|
|
<?php endif; ?>
|
|
<a href="?page=request" class="px-3 py-2 rounded-lg text-sm font-medium <?= $page == 'request' ? 'bg-white/20 text-white' : 'text-emerald-50 hover:bg-white/10' ?> transition-colors">
|
|
<i class="fa-solid fa-bell-concierge me-1"></i> ขอเปล
|
|
</a>
|
|
<a href="?page=staff" class="px-3 py-2 rounded-lg text-sm font-medium <?= $page == 'staff' ? 'bg-white/20 text-white' : 'text-emerald-50 hover:bg-white/10' ?> transition-colors">
|
|
<i class="fa-solid fa-mobile-screen me-1"></i> หน้างาน
|
|
</a>
|
|
<?php if (isset($_SESSION['role']) && ($_SESSION['role'] === 'staff' || $_SESSION['role'] === 'admin')): ?>
|
|
<a href="?page=staff_summary" class="px-3 py-2 rounded-lg text-sm font-medium <?= $page == 'staff_summary' ? 'bg-white/20 text-white' : 'text-emerald-50 hover:bg-white/10' ?> transition-colors">
|
|
<i class="fa-solid fa-clipboard-list me-1"></i> ผลงานฉัน
|
|
</a>
|
|
<?php endif; ?>
|
|
<a href="?page=tracking" class="px-3 py-2 rounded-lg text-sm font-medium <?= $page == 'tracking' ? 'bg-white/20 text-white' : 'text-emerald-50 hover:bg-white/10' ?> transition-colors">
|
|
<i class="fa-solid fa-map-location-dot me-1"></i> พิกัด
|
|
</a>
|
|
<?php if ($_SESSION['role'] === 'admin'): ?>
|
|
<div class="h-6 w-px bg-white/20 mx-2 hidden lg:block"></div>
|
|
<a href="?page=users" class="px-3 py-2 rounded-lg text-sm font-medium <?= $page == 'users' ? 'bg-white/20 text-white' : 'text-emerald-50 hover:bg-white/10' ?> transition-colors" title="ทะเบียนบุคลากร">
|
|
<i class="fa-solid fa-users"></i>
|
|
</a>
|
|
<a href="?page=settings" class="px-3 py-2 rounded-lg text-sm font-medium <?= $page == 'settings' ? 'bg-white/20 text-white' : 'text-emerald-50 hover:bg-white/10' ?> transition-colors" title="ตั้งค่าระบบ">
|
|
<i class="fa-solid fa-gear"></i>
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<!-- Right Side (Theme Toggle & Profile) -->
|
|
<div class="flex items-center gap-3">
|
|
<button id="themeToggle" class="p-2 rounded-full text-emerald-50 hover:bg-white/10 transition-colors" aria-label="Toggle Dark Mode">
|
|
<i class="fa-solid fa-moon dark:hidden"></i>
|
|
<i class="fa-solid fa-sun hidden dark:block"></i>
|
|
</button>
|
|
|
|
<div class="relative group">
|
|
<button class="flex items-center gap-2 p-2 rounded-lg text-emerald-50 hover:bg-white/10 transition-colors">
|
|
<img src="api/avatar.php?username=<?= urlencode($_SESSION['username'] ?? '') ?>&name=<?= urlencode($_SESSION['full_name'] ?? 'User') ?>" class="w-8 h-8 rounded-full border border-white/30 object-cover">
|
|
<span class="text-sm font-medium hidden sm:block"><?= escape($_SESSION['full_name'] ?? 'User') ?></span>
|
|
<i class="fa-solid fa-chevron-down text-xs"></i>
|
|
</button>
|
|
<!-- Dropdown -->
|
|
<div class="absolute right-0 mt-2 w-48 glass-card opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 transform origin-top-right">
|
|
<div class="p-1">
|
|
<a href="api/users.php?action=logout" class="block px-4 py-2 text-sm text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/30 rounded-lg transition-colors">
|
|
<i class="fa-solid fa-arrow-right-from-bracket me-2"></i> ออกจากระบบ
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Mobile Menu Button -->
|
|
<button id="mobileMenuBtn" class="md:hidden p-2 rounded-lg text-emerald-50 hover:bg-white/10 transition-colors">
|
|
<i class="fa-solid fa-bars text-xl"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Mobile Menu -->
|
|
<div id="mobileMenu" class="md:hidden hidden border-t border-white/10 bg-emerald-800/95 dark:bg-slate-900/95 backdrop-blur-xl">
|
|
<div class="px-2 pt-2 pb-3 space-y-1">
|
|
<a href="?page=dashboard" class="block px-3 py-2 rounded-lg text-base font-medium <?= $page == 'dashboard' ? 'bg-white/20 text-white' : 'text-emerald-50 hover:bg-white/10' ?>">Dashboard</a>
|
|
<?php if (isset($_SESSION['role']) && ($_SESSION['role'] === 'admin' || $_SESSION['role'] === 'manager')): ?>
|
|
<a href="?page=executive" class="block px-3 py-2 rounded-lg text-base font-medium <?= $page == 'executive' ? 'bg-white/20 text-white' : 'text-emerald-50 hover:bg-white/10' ?>">Executive</a>
|
|
<?php endif; ?>
|
|
<a href="?page=request" class="block px-3 py-2 rounded-lg text-base font-medium <?= $page == 'request' ? 'bg-white/20 text-white' : 'text-emerald-50 hover:bg-white/10' ?>">ขอเปล</a>
|
|
<a href="?page=staff" class="block px-3 py-2 rounded-lg text-base font-medium <?= $page == 'staff' ? 'bg-white/20 text-white' : 'text-emerald-50 hover:bg-white/10' ?>">หน้างานเจ้าหน้าที่</a>
|
|
<a href="?page=tracking" class="block px-3 py-2 rounded-lg text-base font-medium <?= $page == 'tracking' ? 'bg-white/20 text-white' : 'text-emerald-50 hover:bg-white/10' ?>">พิกัด</a>
|
|
<?php if ($_SESSION['role'] === 'admin'): ?>
|
|
<a href="?page=users" class="block px-3 py-2 rounded-lg text-base font-medium <?= $page == 'users' ? 'bg-white/20 text-white' : 'text-emerald-50 hover:bg-white/10' ?>">ทะเบียนบุคลากร</a>
|
|
<a href="?page=settings" class="block px-3 py-2 rounded-lg text-base font-medium <?= $page == 'settings' ? 'bg-white/20 text-white' : 'text-emerald-50 hover:bg-white/10' ?>">ตั้งค่าระบบ</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
<?php endif; ?>
|
|
|
|
<main class="flex-1 w-full max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 pb-10 page-enter">
|
|
<?php
|
|
// Load the requested page view
|
|
$view_path = "";
|
|
switch ($page) {
|
|
case 'login':
|
|
$view_path = 'views/auth/login.php';
|
|
break;
|
|
case 'dashboard':
|
|
$view_path = 'views/dashboard/index.php';
|
|
break;
|
|
case 'executive':
|
|
$view_path = 'views/dashboard/executive.php';
|
|
break;
|
|
case 'request':
|
|
$view_path = 'views/jobs/request.php';
|
|
break;
|
|
case 'staff':
|
|
$view_path = 'views/jobs/staff.php';
|
|
break;
|
|
case 'tracking':
|
|
$view_path = 'views/tracking/map.php';
|
|
break;
|
|
case 'users':
|
|
$view_path = 'views/users/index.php';
|
|
break;
|
|
case 'settings':
|
|
$view_path = 'views/settings/index.php';
|
|
break;
|
|
case 'public_request':
|
|
$view_path = 'views/public/request.php';
|
|
break;
|
|
case 'job_detail':
|
|
$view_path = 'views/jobs/detail.php';
|
|
break;
|
|
case 'staff_summary':
|
|
$view_path = 'views/jobs/staff_summary.php';
|
|
break;
|
|
default:
|
|
$view_path = 'views/dashboard/index.php';
|
|
break;
|
|
}
|
|
|
|
if (file_exists($view_path)) {
|
|
require_once $view_path;
|
|
} else {
|
|
echo '<div class="glass-card p-8 text-center text-red-500">
|
|
<i class="fa-solid fa-triangle-exclamation text-4xl mb-4"></i>
|
|
<h2 class="text-xl font-bold">404 Page Not Found</h2>
|
|
<p>ไม่พบหน้าที่ต้องการ</p>
|
|
</div>';
|
|
}
|
|
?>
|
|
</main>
|
|
|
|
<!-- Scripts -->
|
|
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
<!-- Custom JS -->
|
|
<script src="assets/js/main.js"></script>
|
|
<script src="assets/js/location.js"></script>
|
|
|
|
<script>
|
|
// Mobile Menu Toggle
|
|
document.getElementById('mobileMenuBtn')?.addEventListener('click', function() {
|
|
document.getElementById('mobileMenu').classList.toggle('hidden');
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|