134 lines
7.5 KiB
PHP
134 lines
7.5 KiB
PHP
<?php
|
|
session_start();
|
|
require_once '../includes/db.php';
|
|
|
|
if (!isset($_SESSION['admin_logged_in'])) {
|
|
header("Location: login.php");
|
|
exit;
|
|
}
|
|
|
|
// Ensure 2FA is setup
|
|
$stmt_admin = $pdo->prepare("SELECT username, role, google2fa_secret FROM admin_users WHERE id = ?");
|
|
$stmt_admin->execute([$_SESSION['admin_id']]);
|
|
$current_admin = $stmt_admin->fetch();
|
|
|
|
if (empty($current_admin['google2fa_secret'])) {
|
|
header("Location: setup_2fa.php");
|
|
exit;
|
|
}
|
|
|
|
$is_superadmin = ($current_admin['role'] === 'superadmin');
|
|
|
|
// Handle settings update
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['update_settings'])) {
|
|
$require = isset($_POST['require_assessment']) ? '1' : '0';
|
|
$stmt = $pdo->prepare("UPDATE settings SET setting_value = ? WHERE setting_key = 'require_assessment'");
|
|
$stmt->execute([$require]);
|
|
$msg = "บันทึกการตั้งค่าเรียบร้อยแล้ว";
|
|
}
|
|
|
|
$require_assessment = getSetting($pdo, 'require_assessment');
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="th">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Admin Dashboard - KSH-STAFF</title>
|
|
<link rel="icon" type="image/png" href="../assets/img/logo.png">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
|
<script>
|
|
tailwind.config = {
|
|
theme: {
|
|
extend: {
|
|
fontFamily: {
|
|
sans: ['Sarabun', 'sans-serif'],
|
|
},
|
|
animation: {
|
|
shine: 'shine 3s ease-in-out infinite'
|
|
},
|
|
keyframes: {
|
|
shine: {
|
|
'0%': { left: '-150%' },
|
|
'20%': { left: '150%' },
|
|
'100%': { left: '150%' }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
</head>
|
|
<body class="bg-gray-100 font-sans antialiased text-gray-800 flex min-h-screen">
|
|
<!-- Sidebar -->
|
|
<aside class="w-64 bg-gray-800 text-gray-300 flex flex-col fixed top-0 left-0 h-screen shadow-lg z-20">
|
|
<div class="px-6 py-5 bg-gray-900 border-b border-gray-700 text-center">
|
|
<div class="relative inline-block overflow-hidden rounded-full w-20 h-20 mx-auto mb-3 shadow-md bg-white p-1">
|
|
<img src="../assets/img/logo.png" alt="Logo" class="w-full h-full object-cover rounded-full relative z-10">
|
|
<div class="absolute inset-0 z-20 w-1/2 h-full bg-gradient-to-r from-transparent via-white/60 to-transparent -skew-x-12 animate-shine mix-blend-overlay"></div>
|
|
</div>
|
|
<h3 class="text-white text-lg font-bold tracking-wide mt-1">KSH-STAFF Admin</h3>
|
|
</div>
|
|
<nav class="flex-1 pt-6 pb-4 overflow-y-auto flex flex-col gap-1">
|
|
<a href="index.php" class="block px-6 py-3 bg-blue-600 text-white font-medium transition duration-200 shadow-sm">
|
|
<i class="fas fa-home w-6 text-center mr-2"></i> แดชบอร์ด
|
|
</a>
|
|
<a href="staff_list.php" class="block px-6 py-3 hover:bg-gray-700 hover:text-white transition duration-200">
|
|
<i class="fas fa-users w-6 text-center mr-2"></i> รายชื่อเจ้าหน้าที่
|
|
</a>
|
|
<?php if ($is_superadmin): ?>
|
|
<a href="manage_admins.php" class="block px-6 py-3 hover:bg-gray-700 hover:text-white transition duration-200">
|
|
<i class="fas fa-crown w-6 text-center mr-2"></i> จัดการแอดมิน
|
|
</a>
|
|
<?php endif; ?>
|
|
|
|
<div class="mt-auto px-6 pt-4">
|
|
<a href="logout.php" class="flex items-center text-red-400 hover:text-red-300 hover:bg-red-400/10 py-2 px-3 rounded transition duration-200">
|
|
<i class="fas fa-sign-out-alt w-6 text-center mr-1"></i> ออกจากระบบ
|
|
</a>
|
|
</div>
|
|
</nav>
|
|
</aside>
|
|
|
|
<!-- Main Content -->
|
|
<main class="flex-1 ml-64 flex flex-col min-h-screen">
|
|
<header class="bg-white px-8 py-5 border-b border-gray-200 flex justify-between items-center shadow-sm z-10 sticky top-0">
|
|
<h4 class="text-xl font-bold text-gray-700">การตั้งค่าระบบ</h4>
|
|
<div class="text-sm text-gray-500 font-medium px-4 py-1.5 bg-gray-100 rounded-full border border-gray-200 flex items-center gap-2">
|
|
ผู้ใช้งาน: <span class="text-blue-600 font-bold"><?= htmlspecialchars($current_admin['username'] ?? $_SESSION['admin_username'] ?? 'Admin') ?></span>
|
|
<span class="bg-gray-200 text-gray-600 px-2 py-0.5 rounded text-xs"><?= htmlspecialchars($current_admin['role'] ?? '') ?></span>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="p-8 flex-1">
|
|
<?php if (!empty($msg)): ?>
|
|
<script>
|
|
Swal.fire({ icon: 'success', title: 'สำเร็จ', text: '<?= $msg ?>', timer: 2000, confirmButtonColor: '#2563eb' });
|
|
</script>
|
|
<?php endif; ?>
|
|
|
|
<div class="bg-white rounded-xl p-8 shadow-sm border border-gray-200 max-w-3xl">
|
|
<h3 class="text-lg font-bold text-gray-800 border-b border-gray-100 pb-4 mb-6"><i class="fas fa-cog text-gray-400 mr-2"></i> ตั้งค่าระบบประเมิน</h3>
|
|
<form method="post">
|
|
<div class="flex items-center gap-4 mb-8 bg-gray-50 p-4 rounded-lg border border-gray-100">
|
|
<label class="relative inline-flex items-center cursor-pointer">
|
|
<input type="checkbox" name="require_assessment" value="1" class="sr-only peer" <?= $require_assessment == '1' ? 'checked' : '' ?>>
|
|
<div class="w-14 h-7 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-6 after:w-6 after:transition-all peer-checked:bg-blue-600"></div>
|
|
</label>
|
|
<span class="text-gray-700 font-medium">เปิดใช้งานการบังคับทำแบบประเมิน <span class="text-gray-500 text-sm font-normal block mt-1">(เมนูต่างๆ จะถูกล็อกหากเจ้าหน้าที่ยังไม่ทำประเมิน)</span></span>
|
|
</div>
|
|
<button type="submit" name="update_settings" class="bg-blue-600 hover:bg-blue-700 text-white font-medium py-2.5 px-6 rounded-lg transition duration-200 shadow-sm flex items-center gap-2">
|
|
<i class="fas fa-save"></i> บันทึกการตั้งค่า
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</body>
|
|
</html>
|