Initial commit

This commit is contained in:
Porawit Dongwang
2026-09-16 23:20:08 +07:00
commit 0041668dbb
32577 changed files with 3687927 additions and 0 deletions
+101
View File
@@ -0,0 +1,101 @@
<?php
require_once '../init.php';
requireLogin();
header('Content-Type: application/json');
$action = $_POST['action'] ?? $_GET['action'] ?? '';
try {
switch ($action) {
case 'add':
$name = trim($_POST['name'] ?? '');
$url = trim($_POST['url'] ?? '');
$display_order = (int)($_POST['display_order'] ?? 0);
$status = $_POST['status'] ?? 'normal';
$logo_url = trim($_POST['logo_url'] ?? '');
if (!$name || !$url) {
throw new Exception("ชื่อและลิงค์เว็บไซต์เป็นข้อมูลจำเป็น");
}
$stmt = $pdo->prepare("INSERT INTO websites (name, url, status, logo_url, display_order) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$name, $url, $status, $logo_url, $display_order]);
logAction($pdo, 'Add Website', "Added website: $name ($url)");
echo json_encode(['success' => true]);
break;
case 'edit':
$id = (int)($_POST['id'] ?? 0);
$name = trim($_POST['name'] ?? '');
$url = trim($_POST['url'] ?? '');
$display_order = (int)($_POST['display_order'] ?? 0);
$status = $_POST['status'] ?? 'normal';
$logo_url = trim($_POST['logo_url'] ?? '');
if (!$id || !$name || !$url) {
throw new Exception("ข้อมูลไม่ครบถ้วน");
}
$stmt = $pdo->prepare("UPDATE websites SET name = ?, url = ?, status = ?, logo_url = ?, display_order = ? WHERE id = ?");
$stmt->execute([$name, $url, $status, $logo_url, $display_order, $id]);
logAction($pdo, 'Edit Website', "Edited website ID $id to: $name");
echo json_encode(['success' => true]);
break;
case 'delete':
$id = (int)($_POST['id'] ?? 0);
if (!$id) throw new Exception("ไม่พบ ID");
$stmt = $pdo->prepare("SELECT name FROM websites WHERE id = ?");
$stmt->execute([$id]);
$web = $stmt->fetch();
if ($web) {
$stmt = $pdo->prepare("DELETE FROM websites WHERE id = ?");
$stmt->execute([$id]);
logAction($pdo, 'Delete Website', "Deleted website: {$web['name']}");
}
echo json_encode(['success' => true]);
break;
case 'reset_clicks':
$id = (int)($_POST['id'] ?? 0);
if (!$id) throw new Exception("ไม่พบ ID");
$stmt = $pdo->prepare("SELECT name FROM websites WHERE id = ?");
$stmt->execute([$id]);
$web = $stmt->fetch();
if ($web) {
$stmt = $pdo->prepare("UPDATE websites SET click_count = 0 WHERE id = ?");
$stmt->execute([$id]);
logAction($pdo, 'Reset Clicks', "Reset click count for website: {$web['name']}");
}
echo json_encode(['success' => true]);
break;
case 'save_settings':
$site_name = trim($_POST['site_name'] ?? '');
$site_subtitle = trim($_POST['site_subtitle'] ?? '');
if (!$site_name) throw new Exception("ชื่อระบบเป็นข้อมูลจำเป็น");
$stmt = $pdo->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value)");
$stmt->execute(['site_name', $site_name]);
$stmt->execute(['site_subtitle', $site_subtitle]);
logAction($pdo, 'Update Settings', "Updated site settings");
echo json_encode(['success' => true]);
break;
default:
throw new Exception("Invalid action");
}
} catch (Exception $e) {
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
+300
View File
@@ -0,0 +1,300 @@
<?php
require_once '../init.php';
requireLogin();
$stmt = $pdo->query("SELECT * FROM websites ORDER BY display_order ASC");
$websites = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>จัดการเว็บไซต์ - <?= htmlspecialchars($globalSettings['site_name'] ?? 'ศูนย์รวมเว็บหน่วยงาน') ?></title>
<link rel="icon" type="image/png" href="../assets/images/logo.png">
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="../assets/css/style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Datatables -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css">
<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
<!-- SweetAlert2 -->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
</head>
<body class="antialiased min-h-screen bg-gray-50 py-10 px-4">
<div class="w-full max-w-6xl mx-auto glass-container">
<div class="flex flex-wrap justify-between items-center mb-8 border-b border-gray-200 pb-4 gap-4">
<h1 class="text-2xl font-bold text-gray-800"><i class="fa-solid fa-list mr-2"></i> จัดการเว็บไซต์</h1>
<div class="flex flex-wrap gap-2">
<a href="settings.php" class="magic-btn-outline"><i class="fa-solid fa-gear mr-1"></i> ตั้งค่าระบบ</a>
<a href="logs.php" class="magic-btn-outline"><i class="fa-solid fa-history mr-1"></i> ประวัติการทำงาน</a>
<a href="../index.php" class="magic-btn-outline"><i class="fa-solid fa-home mr-1"></i> หน้าหลัก</a>
<a href="logout.php" class="bg-red-500 hover:bg-red-600 text-white py-2 px-4 rounded-xl transition"><i class="fa-solid fa-right-from-bracket mr-1"></i> ออกจากระบบ</a>
</div>
</div>
<div class="mb-6 flex flex-wrap gap-2">
<button onclick="openModal()" class="magic-btn"><i class="fa-solid fa-plus mr-1"></i> เพิ่มเว็บไซต์ใหม่</button>
<button onclick="addMockData()" class="magic-btn-outline"><i class="fa-solid fa-vial mr-1"></i> เพิ่มข้อมูลตัวอย่าง 10 รายการ</button>
<button onclick="clearMockData()" class="bg-orange-500 hover:bg-orange-600 text-white py-2 px-4 rounded-xl transition shadow-sm"><i class="fa-solid fa-trash-can mr-1"></i> ล้างข้อมูลตัวอย่าง</button>
</div>
<div class="bg-white rounded-xl shadow-sm p-4 border border-gray-100 overflow-x-auto">
<table id="websitesTable" class="w-full border-collapse">
<thead>
<tr class="bg-gray-50">
<th class="p-3 border-b text-center whitespace-nowrap">ลำดับ</th>
<th class="p-3 border-b text-center whitespace-nowrap">โลโก้</th>
<th class="p-3 border-b text-center whitespace-nowrap">ชื่อเว็บ</th>
<th class="p-3 border-b text-center whitespace-nowrap">ลิงก์</th>
<th class="p-3 border-b text-center whitespace-nowrap">สถานะ</th>
<th class="p-3 border-b text-center whitespace-nowrap">สถิติ (คลิก)</th>
<th class="p-3 border-b text-center whitespace-nowrap">จัดการ</th>
</tr>
</thead>
<tbody>
<?php foreach($websites as $web): ?>
<tr>
<td class="p-3 border-b text-center whitespace-nowrap"><?= htmlspecialchars($web['display_order']) ?></td>
<td class="p-3 border-b text-center whitespace-nowrap">
<?php $logo = !empty($web['logo_url']) ? htmlspecialchars($web['logo_url']) : '../assets/images/logo.png'; ?>
<img src="<?= $logo ?>" alt="logo" class="w-10 h-10 object-contain rounded bg-gray-50 border border-gray-100 mx-auto" onerror="this.src='../assets/images/logo.png'">
</td>
<td class="p-3 border-b font-medium"><?= htmlspecialchars($web['name']) ?> <?php if($web['is_mock']) echo '<span class="text-xs bg-gray-200 text-gray-600 px-2 py-1 rounded ml-2">ตัวอย่าง</span>'; ?></td>
<td class="p-3 border-b text-center">
<a href="<?= htmlspecialchars($web['url']) ?>" target="_blank" class="inline-flex items-center justify-center w-8 h-8 rounded-full bg-blue-50 text-blue-500 hover:bg-blue-100 hover:text-blue-700 transition" title="<?= htmlspecialchars($web['url']) ?>">
<i class="fa-solid fa-link"></i>
</a>
</td>
<td class="p-3 border-b text-center whitespace-nowrap">
<?php
if($web['status'] == 'normal') echo '<span class="px-2 py-1 bg-green-100 text-green-800 rounded-full text-xs">ปกติ</span>';
elseif($web['status'] == 'cancelled') echo '<span class="px-2 py-1 bg-red-100 text-red-800 rounded-full text-xs">ยกเลิก</span>';
elseif($web['status'] == 'maintenance') echo '<span class="px-2 py-1 bg-orange-100 text-orange-800 rounded-full text-xs">ปรับปรุง</span>';
?>
</td>
<td class="p-3 border-b text-center font-bold text-gray-700 whitespace-nowrap"><?= number_format($web['click_count']) ?></td>
<td class="p-3 border-b text-center whitespace-nowrap">
<button onclick="editWeb(<?= $web['id'] ?>, '<?= htmlspecialchars(addslashes($web['name'])) ?>', '<?= htmlspecialchars(addslashes($web['url'])) ?>', <?= $web['display_order'] ?>, '<?= htmlspecialchars(addslashes($web['logo_url'] ?? '')) ?>', '<?= $web['status'] ?>')" class="text-blue-500 hover:text-blue-700 mr-2" title="แก้ไข"><i class="fa-solid fa-pen-to-square text-lg"></i></button>
<button onclick="resetClicks(<?= $web['id'] ?>, '<?= htmlspecialchars(addslashes($web['name'])) ?>')" class="text-orange-500 hover:text-orange-700 mr-2" title="เคลียร์สถิติการเข้าชม"><i class="fa-solid fa-eraser text-lg"></i></button>
<button onclick="deleteWeb(<?= $web['id'] ?>)" class="text-red-500 hover:text-red-700" title="ลบ"><i class="fa-solid fa-trash text-lg"></i></button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<!-- Modal Form -->
<div id="formModal" class="fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50 px-4">
<div class="bg-white rounded-2xl p-6 w-full max-w-md shadow-2xl transform transition-all">
<h2 id="modalTitle" class="text-xl font-bold mb-4">เพิ่มเว็บไซต์ใหม่</h2>
<form id="webForm" onsubmit="saveWeb(event)">
<input type="hidden" id="webId" name="id" value="">
<input type="hidden" id="actionType" name="action" value="add">
<div class="mb-4">
<label class="block text-gray-700 mb-2 font-medium">ชื่อเว็บไซต์</label>
<input type="text" id="webName" name="name" class="magic-input border border-gray-300" required>
</div>
<div class="mb-4">
<label class="block text-gray-700 mb-2 font-medium">ลิงค์ (URL)</label>
<input type="url" id="webUrl" name="url" class="magic-input border border-gray-300" placeholder="https://" required>
</div>
<div class="mb-4">
<label class="block text-gray-700 mb-2 font-medium">ลิงก์โลโก้ (ปล่อยว่างเพื่อใช้โลโก้เริ่มต้น)</label>
<input type="text" id="webLogo" name="logo_url" class="magic-input border border-gray-300" placeholder="https://.../logo.png">
</div>
<div class="mb-4">
<label class="block text-gray-700 mb-2 font-medium">สถานะ</label>
<select id="webStatus" name="status" class="magic-input border border-gray-300">
<option value="normal">ใช้งานปกติ</option>
<option value="cancelled">ยกเลิกใช้งาน</option>
<option value="maintenance">ปรับปรุง</option>
</select>
</div>
<div class="mb-6">
<label class="block text-gray-700 mb-2 font-medium">ลำดับการแสดงผล (ตัวเลข)</label>
<input type="number" id="webOrder" name="display_order" class="magic-input border border-gray-300" value="0" required>
</div>
<div class="flex justify-end gap-2">
<button type="button" onclick="closeModal()" class="px-4 py-2 text-gray-600 bg-gray-100 hover:bg-gray-200 rounded-xl transition font-medium">ยกเลิก</button>
<button type="submit" class="magic-btn">บันทึก</button>
</div>
</form>
</div>
</div>
<script>
$(document).ready(function() {
$('#websitesTable').DataTable({
"language": {
"url": "//cdn.datatables.net/plug-ins/1.13.6/i18n/th.json"
},
"order": [[ 0, "asc" ]]
});
});
function openModal() {
document.getElementById('formModal').classList.remove('hidden');
document.getElementById('formModal').classList.add('flex');
document.getElementById('modalTitle').innerText = 'เพิ่มเว็บไซต์ใหม่';
document.getElementById('webForm').reset();
document.getElementById('webId').value = '';
document.getElementById('actionType').value = 'add';
document.getElementById('webStatus').value = 'normal';
}
function closeModal() {
document.getElementById('formModal').classList.add('hidden');
document.getElementById('formModal').classList.remove('flex');
}
function editWeb(id, name, url, order, logo_url, status) {
openModal();
document.getElementById('modalTitle').innerText = 'แก้ไขเว็บไซต์';
document.getElementById('webId').value = id;
document.getElementById('webName').value = name;
document.getElementById('webUrl').value = url;
document.getElementById('webOrder').value = order;
document.getElementById('webLogo').value = logo_url;
document.getElementById('webStatus').value = status;
document.getElementById('actionType').value = 'edit';
}
function saveWeb(e) {
e.preventDefault();
const formData = new FormData(e.target);
fetch('api.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if(data.success) {
Swal.fire('สำเร็จ', 'บันทึกข้อมูลเรียบร้อยแล้ว', 'success').then(() => {
location.reload();
});
} else {
Swal.fire('ข้อผิดพลาด', data.message, 'error');
}
})
.catch(error => {
Swal.fire('ข้อผิดพลาด', 'ไม่สามารถเชื่อมต่อเซิร์ฟเวอร์ได้', 'error');
});
}
function deleteWeb(id) {
Swal.fire({
title: 'ยืนยันการลบ?',
text: "คุณต้องการลบเว็บไซต์นี้ใช่หรือไม่!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#d33',
cancelButtonColor: '#3085d6',
confirmButtonText: 'ใช่, ลบเลย!',
cancelButtonText: 'ยกเลิก'
}).then((result) => {
if (result.isConfirmed) {
const formData = new FormData();
formData.append('action', 'delete');
formData.append('id', id);
fetch('api.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if(data.success) {
Swal.fire('ลบแล้ว!', 'ลบข้อมูลเรียบร้อยแล้ว.', 'success').then(() => {
location.reload();
});
} else {
Swal.fire('ข้อผิดพลาด', data.message, 'error');
}
});
}
})
}
function resetClicks(id, name) {
Swal.fire({
title: 'ยืนยันการเคลียร์สถิติ?',
text: `คุณต้องการรีเซ็ตยอดผู้เข้าชมของเว็บ ${name} ให้กลับเป็น 0 ใช่หรือไม่?`,
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#f97316',
cancelButtonColor: '#3085d6',
confirmButtonText: 'ใช่, เคลียร์เลย!',
cancelButtonText: 'ยกเลิก'
}).then((result) => {
if (result.isConfirmed) {
const formData = new FormData();
formData.append('action', 'reset_clicks');
formData.append('id', id);
fetch('api.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if(data.success) {
Swal.fire('สำเร็จ!', 'เคลียร์สถิติเรียบร้อยแล้ว.', 'success').then(() => {
location.reload();
});
} else {
Swal.fire('ข้อผิดพลาด', data.message, 'error');
}
});
}
});
}
function addMockData() {
fetch('mock_data.php?action=add')
.then(response => response.json())
.then(data => {
if(data.success) {
Swal.fire('สำเร็จ', 'เพิ่มข้อมูลตัวอย่าง 10 รายการแล้ว', 'success').then(() => {
location.reload();
});
}
});
}
function clearMockData() {
Swal.fire({
title: 'ยืนยันการล้างข้อมูล?',
text: "ลบเฉพาะข้อมูลที่ถูกสร้างเป็นตัวอย่างเท่านั้น",
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'ล้างข้อมูล',
cancelButtonText: 'ยกเลิก'
}).then((result) => {
if (result.isConfirmed) {
fetch('mock_data.php?action=clear')
.then(response => response.json())
.then(data => {
if(data.success) {
Swal.fire('สำเร็จ', 'ล้างข้อมูลตัวอย่างแล้ว', 'success').then(() => {
location.reload();
});
}
});
}
});
}
</script>
</body>
</html>
+61
View File
@@ -0,0 +1,61 @@
<?php
require_once '../init.php';
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$password = $_POST['password'] ?? '';
if ($password === ADMIN_PASSWORD) {
$_SESSION['admin_logged_in'] = true;
logAction($pdo, 'Login', 'Admin logged in successfully');
header("Location: index.php");
exit;
} else {
$error = 'รหัสผ่านไม่ถูกต้อง';
logAction($pdo, 'Login Failed', 'Failed login attempt with incorrect password');
}
}
?>
<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>เข้าสู่ระบบจัดการ - <?= htmlspecialchars($globalSettings['site_name'] ?? 'ศูนย์รวมเว็บหน่วยงาน') ?></title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="../assets/css/style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body class="antialiased min-h-screen flex items-center justify-center p-4">
<div class="w-full max-w-md glass-container">
<div class="text-center mb-8">
<h1 class="text-2xl font-bold text-gray-800 mb-2">ระบบจัดการหลังบ้าน</h1>
<p class="text-gray-600">กรุณาระบุรหัสผ่านเพื่อเข้าใช้งาน</p>
</div>
<?php if($error): ?>
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-4 text-center">
<?= $error ?>
</div>
<?php endif; ?>
<form method="POST" action="">
<div class="mb-6">
<input type="password" name="password" class="magic-input" placeholder="รหัสผ่าน" required autofocus>
</div>
<button type="submit" class="magic-btn w-full">
<i class="fa-solid fa-right-to-bracket mr-2"></i> เข้าสู่ระบบ
</button>
</form>
<div class="mt-6 text-center">
<a href="../index.php" class="text-emerald-600 hover:text-emerald-800 text-sm">
<i class="fa-solid fa-arrow-left mr-1"></i> กลับไปหน้าหลัก
</a>
</div>
</div>
</body>
</html>
+5
View File
@@ -0,0 +1,5 @@
<?php
session_start();
session_destroy();
header("Location: login.php");
exit;
+80
View File
@@ -0,0 +1,80 @@
<?php
require_once '../init.php';
requireLogin();
$stmt = $pdo->query("SELECT * FROM activity_logs ORDER BY created_at DESC");
$logs = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ประวัติการทำงาน - <?= htmlspecialchars($globalSettings['site_name'] ?? 'ศูนย์รวมเว็บหน่วยงาน') ?></title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="../assets/css/style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Datatables -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css">
<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
</head>
<body class="antialiased min-h-screen bg-gray-50 py-10 px-4">
<div class="w-full max-w-6xl mx-auto glass-container">
<div class="flex flex-wrap justify-between items-center mb-8 border-b border-gray-200 pb-4 gap-4">
<h1 class="text-2xl font-bold text-gray-800"><i class="fa-solid fa-history mr-2"></i> ประวัติการทำงาน</h1>
<div class="flex gap-2">
<a href="index.php" class="magic-btn-outline"><i class="fa-solid fa-arrow-left mr-1"></i> กลับไปจัดการเว็บไซต์</a>
</div>
</div>
<div class="bg-white rounded-xl shadow-sm p-4 border border-gray-100 overflow-x-auto">
<table id="logsTable" class="w-full border-collapse">
<thead>
<tr class="bg-gray-50">
<th class="p-3 border-b text-center whitespace-nowrap">วัน-เวลา</th>
<th class="p-3 border-b text-center whitespace-nowrap">การกระทำ</th>
<th class="p-3 border-b text-center whitespace-nowrap">รายละเอียด</th>
<th class="p-3 border-b text-center whitespace-nowrap">IP</th>
</tr>
</thead>
<tbody>
<?php foreach($logs as $log): ?>
<tr>
<td class="p-3 border-b text-sm text-gray-600 text-center whitespace-nowrap"><?= htmlspecialchars($log['created_at']) ?></td>
<td class="p-3 border-b font-medium text-center whitespace-nowrap">
<?php
$badgeColor = 'bg-gray-100 text-gray-800';
if(strpos($log['action'], 'Add') !== false) $badgeColor = 'bg-green-100 text-green-800';
else if(strpos($log['action'], 'Edit') !== false) $badgeColor = 'bg-blue-100 text-blue-800';
else if(strpos($log['action'], 'Delete') !== false) $badgeColor = 'bg-red-100 text-red-800';
else if(strpos($log['action'], 'Login') !== false) $badgeColor = 'bg-purple-100 text-purple-800';
else if(strpos($log['action'], 'Mock') !== false) $badgeColor = 'bg-orange-100 text-orange-800';
?>
<span class="px-2 py-1 rounded text-xs <?= $badgeColor ?>"><?= htmlspecialchars($log['action']) ?></span>
</td>
<td class="p-3 border-b text-gray-700 text-center whitespace-nowrap"><?= htmlspecialchars($log['details']) ?></td>
<td class="p-3 border-b text-sm text-gray-500 text-center whitespace-nowrap"><?= htmlspecialchars($log['ip_address']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<script>
$(document).ready(function() {
$('#logsTable').DataTable({
"language": {
"url": "//cdn.datatables.net/plug-ins/1.13.6/i18n/th.json"
},
"order": [[ 0, "desc" ]]
});
});
</script>
</body>
</html>
+53
View File
@@ -0,0 +1,53 @@
<?php
require_once '../init.php';
requireLogin();
header('Content-Type: application/json');
$action = $_GET['action'] ?? '';
try {
if ($action === 'add') {
$mockData = [
['กระทรวงสาธารณสุข', 'https://www.moph.go.th/', 1, 'normal', ''],
['กรมควบคุมโรค', 'https://ddc.moph.go.th/', 2, 'normal', ''],
['กรมอนามัย', 'https://anamai.moph.go.th/', 3, 'normal', ''],
['กรมการแพทย์', 'https://www.dms.go.th/', 4, 'maintenance', ''],
['สำนักงานคณะกรรมการอาหารและยา', 'https://www.fda.moph.go.th/', 5, 'normal', ''],
['สถาบันวัคซีนแห่งชาติ', 'https://nvi.go.th/', 6, 'normal', ''],
['องค์การเภสัชกรรม', 'https://www.gpo.or.th/', 7, 'normal', ''],
['กรมสุขภาพจิต', 'https://dmh.go.th/', 8, 'normal', ''],
['สำนักงานหลักประกันสุขภาพแห่งชาติ', 'https://www.nhso.go.th/', 9, 'normal', ''],
['แพทยสภา (ทดสอบยกเลิก)', 'https://tmc.or.th/', 10, 'cancelled', ''],
['กระทรวงศึกษาธิการ', 'https://www.moe.go.th/', 11, 'normal', ''],
['กระทรวงมหาดไทย', 'https://www.moi.go.th/', 12, 'normal', ''],
['กระทรวงการคลัง', 'https://www.mof.go.th/', 13, 'normal', ''],
['กระทรวงพาณิชย์', 'https://www.moc.go.th/', 14, 'normal', ''],
['กระทรวงเกษตรและสหกรณ์', 'https://www.moac.go.th/', 15, 'normal', ''],
['กระทรวงคมนาคม', 'https://www.mot.go.th/', 16, 'normal', ''],
['กระทรวงดิจิทัลเพื่อเศรษฐกิจและสังคม', 'https://www.mdes.go.th/', 17, 'normal', ''],
['กระทรวงแรงงาน', 'https://www.mol.go.th/', 18, 'normal', ''],
['กระทรวงอุตสาหกรรม', 'https://www.industry.go.th/', 19, 'normal', ''],
['กระทรวงการต่างประเทศ', 'https://www.mfa.go.th/', 20, 'normal', '']
];
$stmt = $pdo->prepare("INSERT INTO websites (name, url, display_order, status, logo_url, click_count, is_mock) VALUES (?, ?, ?, ?, ?, 0, 1)");
foreach ($mockData as $data) {
$stmt->execute($data);
}
logAction($pdo, 'Mock Data Add', 'Added 20 mock websites');
echo json_encode(['success' => true]);
} elseif ($action === 'clear') {
$pdo->exec("DELETE FROM websites WHERE is_mock = 1");
logAction($pdo, 'Mock Data Clear', 'Cleared all mock websites');
echo json_encode(['success' => true]);
} else {
throw new Exception("Invalid action");
}
} catch (Exception $e) {
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
+75
View File
@@ -0,0 +1,75 @@
<?php
require_once '../init.php';
requireLogin();
?>
<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ตั้งค่าระบบ - <?= htmlspecialchars($globalSettings['site_name'] ?? 'ศูนย์รวมเว็บหน่วยงาน') ?></title>
<link rel="icon" type="image/png" href="../assets/images/logo.png">
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="../assets/css/style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
</head>
<body class="antialiased min-h-screen bg-gray-50 py-10 px-4">
<div class="w-full max-w-4xl mx-auto glass-container">
<div class="flex flex-wrap justify-between items-center mb-8 border-b border-gray-200 pb-4 gap-4">
<h1 class="text-2xl font-bold text-gray-800"><i class="fa-solid fa-gear mr-2"></i> ตั้งค่าระบบ</h1>
<div class="flex flex-wrap gap-2">
<a href="index.php" class="magic-btn-outline"><i class="fa-solid fa-list mr-1"></i> จัดการเว็บไซต์</a>
<a href="../index.php" class="magic-btn-outline"><i class="fa-solid fa-home mr-1"></i> หน้าหลัก</a>
<a href="logout.php" class="bg-red-500 hover:bg-red-600 text-white py-2 px-4 rounded-xl transition"><i class="fa-solid fa-right-from-bracket mr-1"></i> ออกจากระบบ</a>
</div>
</div>
<div class="bg-white rounded-xl shadow-sm p-6 border border-gray-100">
<form id="settingsForm" onsubmit="saveSettings(event)">
<input type="hidden" name="action" value="save_settings">
<div class="mb-4">
<label class="block text-gray-700 mb-2 font-medium">ชื่อระบบ (Site Name)</label>
<input type="text" name="site_name" class="magic-input border border-gray-300" value="<?= htmlspecialchars($globalSettings['site_name'] ?? '') ?>" required>
</div>
<div class="mb-6">
<label class="block text-gray-700 mb-2 font-medium">คำอธิบายระบบ (Site Subtitle)</label>
<input type="text" name="site_subtitle" class="magic-input border border-gray-300" value="<?= htmlspecialchars($globalSettings['site_subtitle'] ?? '') ?>">
</div>
<button type="submit" class="magic-btn w-full md:w-auto"><i class="fa-solid fa-save mr-1"></i> บันทึกการตั้งค่า</button>
</form>
</div>
</div>
<script>
function saveSettings(e) {
e.preventDefault();
const formData = new FormData(e.target);
fetch('api.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if(data.success) {
Swal.fire('สำเร็จ', 'บันทึกการตั้งค่าเรียบร้อยแล้ว', 'success').then(() => {
location.reload();
});
} else {
Swal.fire('ข้อผิดพลาด', data.message, 'error');
}
})
.catch(error => {
Swal.fire('ข้อผิดพลาด', 'ไม่สามารถเชื่อมต่อเซิร์ฟเวอร์ได้', 'error');
});
}
</script>
</body>
</html>