Files
2026-09-16 23:20:08 +07:00

76 lines
4.3 KiB
PHP

<?php
require_once 'header.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['insert_dummy'])) {
for ($i = 1; $i <= 10; $i++) {
// Meeting Dummy
$stmt = $pdo->prepare("INSERT INTO meeting_minutes (title, meeting_date, details) VALUES (?, ?, ?)");
$stmt->execute(["การประชุมคณะกรรมการ P4Q ครั้งที่ $i/2569", date('Y-m-d', strtotime("-$i days")), "<p>รายละเอียดการประชุมครั้งที่ $i</p>"]);
// Competition Dummy
$year = 2569 - ($i % 3);
$stmt = $pdo->prepare("INSERT INTO competitions (title, details, rank_result, year_th) VALUES (?, ?, ?, ?)");
$stmt->execute(["ผลงานพัฒนาคุณภาพ เรื่องที่ $i", "<p>รายละเอียดผลงานพัฒนาคุณภาพเรื่องที่ $i</p>", "รางวัลที่ " . rand(1, 3), $year]);
$comp_id = $pdo->lastInsertId();
// Authors Dummy
$stmt = $pdo->prepare("INSERT INTO competition_authors (competition_id, author_name) VALUES (?, ?)");
$stmt->execute([$comp_id, "นายแพทย์ทดสอบ คนที่ $i"]);
}
logActivity($pdo, 'INSERT_DUMMY', "เพิ่มข้อมูลตัวอย่าง 10 รายการ");
$success = "เพิ่มข้อมูลตัวอย่าง 10 รายการสำเร็จ";
}
if (isset($_POST['clear_dummy'])) {
// We will just clear all tables except settings
$pdo->query("SET FOREIGN_KEY_CHECKS = 0;");
$pdo->query("TRUNCATE TABLE meeting_attachments;");
$pdo->query("TRUNCATE TABLE meeting_minutes;");
$pdo->query("TRUNCATE TABLE competition_attachments;");
$pdo->query("TRUNCATE TABLE competition_authors;");
$pdo->query("TRUNCATE TABLE competitions;");
$pdo->query("SET FOREIGN_KEY_CHECKS = 1;");
logActivity($pdo, 'CLEAR_DUMMY', "ล้างข้อมูลทั้งหมด");
$success = "ล้างข้อมูลทั้งหมดสำเร็จ";
}
}
?>
<div class="mb-8">
<h1 class="text-3xl font-bold text-gray-900">จัดการข้อมูลตัวอย่าง</h1>
</div>
<?php if (!empty($success)): ?>
<div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative mb-4" role="alert">
<span class="block sm:inline"><?= $success ?></span>
</div>
<?php endif; ?>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6 text-center">
<h2 class="text-xl font-bold mb-4 text-blue-600">เพิ่มข้อมูลตัวอย่าง</h2>
<p class="text-gray-600 mb-6">สร้างข้อมูลบันทึกการประชุม 10 รายการ และผลงานประกวด 10 รายการ</p>
<form action="" method="POST">
<input type="hidden" name="insert_dummy" value="1">
<button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded w-full">
สร้างข้อมูลตัวอย่าง
</button>
</form>
</div>
<div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6 text-center">
<h2 class="text-xl font-bold mb-4 text-red-600">ล้างข้อมูลทั้งหมด</h2>
<p class="text-gray-600 mb-6">ลบข้อมูลบันทึกการประชุม ผลงาน และไฟล์แนบทั้งหมดในระบบ</p>
<form action="" method="POST" onsubmit="return confirm('ยืนยันการล้างข้อมูลทั้งหมด? ข้อมูลจะไม่สามารถกู้คืนได้');">
<input type="hidden" name="clear_dummy" value="1">
<button type="submit" class="bg-red-600 hover:bg-red-700 text-white font-bold py-2 px-4 rounded w-full">
ล้างข้อมูล
</button>
</form>
</div>
</div>
<?php require_once 'footer.php'; ?>