File manager - Edit - /var/www/order.cmtc.ac.th/build_zip.php
Back
<?php /* ============================================================ build_zip.php - ตัวสร้างระบบ cmtc_booking_system อัตโนมัติ ============================================================ สร้างโดย ChatGPT (OpenAI) สำหรับระบบจองพระออนไลน์ ------------------------------------------------------------ โครงสร้างที่จะสร้าง: /cmtc_booking_system/ ├── config/ ├── assets/css/ ├── admin/ ├── user/ ├── uploads/products/ ├── uploads/slip/ ├── index.php ├── README.txt └── cmtc_booking.sql ------------------------------------------------------------ */ // ===== CONFIG ===== $systemName = "cmtc_booking_system"; $dbName = "cmtc_booking"; $adminPass = "1234"; // ===== สร้างโฟลเดอร์ทั้งหมด ===== $dirs = [ "$systemName", "$systemName/config", "$systemName/assets/css", "$systemName/admin", "$systemName/user", "$systemName/uploads", "$systemName/uploads/products", "$systemName/uploads/slip" ]; foreach ($dirs as $dir) { if (!is_dir($dir)) { mkdir($dir, 0777, true); } } // ===== เขียนไฟล์ config/db.php ===== $dbphp = <<<PHP <?php \$conn = new mysqli("localhost", "root", "", "$dbName"); if (\$conn->connect_error) { die("Database connection failed: " . \$conn->connect_error); } ?> PHP; file_put_contents("$systemName/config/db.php", $dbphp); // ===== เขียนไฟล์ assets/css/style.css ===== $stylecss = <<<CSS @import url('https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600;700&display=swap'); body, * { font-family: 'Kanit', sans-serif !important; } CSS; file_put_contents("$systemName/assets/css/style.css", $stylecss); // ===== เขียนไฟล์ README.txt ===== $readme = <<<TXT ============================================================ ระบบจองพระออนไลน์ (CMTC Booking System) ============================================================ 1. สร้างฐานข้อมูลชื่อ: $dbName 2. นำเข้าไฟล์: cmtc_booking.sql 3. แก้ไขการเชื่อมต่อฐานข้อมูลใน: config/db.php 4. เปิดระบบผ่าน URL: http://localhost/$systemName/ 5. รหัสผ่านยืนยันการยกเลิก (Admin): $adminPass ============================================================ TXT; file_put_contents("$systemName/README.txt", $readme); // ===== เตรียมไฟล์ ZIP ===== $zipFile = "$systemName.zip"; if (file_exists($zipFile)) unlink($zipFile); $zip = new ZipArchive(); $zip->open($zipFile, ZipArchive::CREATE | ZipArchive::OVERWRITE); // ฟังก์ชันเพิ่มไฟล์ลง ZIP function addFolderToZip($folder, $zip, $root) { $files = scandir($folder); foreach ($files as $file) { if ($file == '.' || $file == '..') continue; $path = "$folder/$file"; $localpath = str_replace("$root/", "", $path); if (is_dir($path)) { addFolderToZip($path, $zip, $root); } else { $zip->addFile($path, $localpath); } } } // ===== รายงานความคืบหน้า ===== echo "<h2>เริ่มสร้างระบบ $systemName ...</h2>"; echo "<ul>"; foreach ($dirs as $d) echo "<li>สร้างโฟลเดอร์: <b>$d</b></li>"; echo "</ul>"; echo "<p>สร้างไฟล์ config/db.php, assets/css/style.css, README.txt สำเร็จ ✅</p>"; ?> <?php // ==== ส่วนที่ 2: สร้างหน้าแรก index.php และฐานข้อมูล temple_booking.sql ==== $indexphp = <<<PHP <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>CMTC Booking System</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="assets/css/style.css" rel="stylesheet"> </head> <body class="bg-light"> <div class="container py-5"> <h2 class="text-center mb-4">ระบบจองพระวัดสันติสุข (CMTC Booking System)</h2> <div class="row justify-content-center"> <div class="col-md-8"> <div class="card shadow-lg p-4"> <h4 class="text-center mb-3">รายการพระทั้งหมด</h4> <?php include('config/db.php'); \$res = \$conn->query("SELECT * FROM products"); echo '<div class="row">'; while(\$r = \$res->fetch_assoc()): \$img1 = !empty(\$r['img1']) ? "uploads/products/{\$r['img1']}" : ''; \$img2 = !empty(\$r['img2']) ? "uploads/products/{\$r['img2']}" : ''; ?> <div class="col-md-4 mb-4"> <div class="card h-100"> <?php if(\$img1 || \$img2): ?> <div class="dual-img p-2 text-center"> <?php if(\$img1): ?><div class="img-block"><img src="<?=\$img1?>" class="img-fluid rounded"><span class="img-label">ด้านหน้า</span></div><?php endif; ?> <?php if(\$img2): ?><div class="img-block"><img src="<?=\$img2?>" class="img-fluid rounded"><span class="img-label">ด้านหลัง</span></div><?php endif; ?> </div> <?php endif; ?> <div class="card-body text-center"> <h5><?=\$r['name']?></h5> <p>ราคา <?=number_format(\$r['price'],2)?> บาท</p> <p>คงเหลือ: <?=\$r['stock'] > 0 ? \$r['stock'] : '<span class="text-danger">หมด (Free Order)</span>'?></p> </div> </div> </div> <?php endwhile; echo '</div>'; ?> <div class="text-center mt-4"> <a href="user/index.php" class="btn btn-primary">เริ่มต้นจองพระ</a> <a href="admin/index.php" class="btn btn-secondary">เข้าสู่ระบบผู้ดูแล</a> </div> </div> </div> </div> </div> </body> </html> PHP; file_put_contents("$systemName/index.php", $indexphp); // ===== เขียนไฟล์ฐานข้อมูล cmtc_booking.sql ===== $sql = <<<SQL -- Database: $dbName CREATE TABLE admin ( id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(50) NOT NULL, password VARCHAR(255) NOT NULL ); INSERT INTO admin (username, password) VALUES ('admin', '$adminPass'); CREATE TABLE products ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), price DECIMAL(10,2), stock INT DEFAULT 0, img1 VARCHAR(255), img2 VARCHAR(255) ); CREATE TABLE orders ( id INT AUTO_INCREMENT PRIMARY KEY, booking_no VARCHAR(50), fullname VARCHAR(255), phone VARCHAR(50), address TEXT, zipcode VARCHAR(10), receive_method VARCHAR(255), total DECIMAL(10,2), status VARCHAR(100), slip VARCHAR(255), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE order_items ( id INT AUTO_INCREMENT PRIMARY KEY, order_id INT, product_id INT, qty INT, price DECIMAL(10,2) ); SQL; file_put_contents("$systemName/cmtc_booking.sql", $sql); // ===== รายงานสถานะ ===== echo "<p>✅ สร้างไฟล์ index.php และฐานข้อมูล cmtc_booking.sql สำเร็จ</p>"; ?> <?php // ==== ส่วนที่ 3: สร้างระบบหลังบ้าน (Admin Panel) ==== /* ---------- 1. หน้าเข้าสู่ระบบผู้ดูแล ---------- */ $admin_index = <<<PHP <?php session_start(); include('../config/db.php'); if(isset(\$_POST['username'])) { \$u = \$_POST['username']; \$p = \$_POST['password']; \$res = \$conn->query("SELECT * FROM admin WHERE username='\$u' AND password='\$p'"); if(\$res->num_rows > 0) { \$_SESSION['admin'] = \$u; header('Location: products.php'); exit; } else { \$error = "ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง"; } } ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>เข้าสู่ระบบผู้ดูแล</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="../assets/css/style.css" rel="stylesheet"> </head> <body class="bg-light"> <div class="container py-5"> <div class="row justify-content-center"> <div class="col-md-5"> <div class="card shadow-lg p-4"> <h4 class="text-center mb-4">เข้าสู่ระบบผู้ดูแล</h4> <?php if(isset(\$error)): ?> <div class="alert alert-danger text-center"><?= \$error ?></div> <?php endif; ?> <form method="post"> <div class="mb-3"> <label>ชื่อผู้ใช้</label> <input type="text" name="username" class="form-control" required> </div> <div class="mb-3"> <label>รหัสผ่าน</label> <input type="password" name="password" class="form-control" required> </div> <button class="btn btn-primary w-100">เข้าสู่ระบบ</button> </form> </div> </div> </div> </div> </body> </html> PHP; file_put_contents("$systemName/admin/index.php", $admin_index); /* ---------- 2. เมนูหลักของผู้ดูแล ---------- */ $admin_menu = <<<PHP <?php if(!isset(\$_SESSION['admin'])) { header('Location: index.php'); exit; } ?> <nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-3"> <div class="container-fluid"> <a class="navbar-brand" href="products.php">CMTC Admin</a> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav me-auto"> <li class="nav-item"><a class="nav-link" href="products.php">จัดการพระ</a></li> <li class="nav-item"><a class="nav-link" href="orders.php">รายการจอง</a></li> </ul> <span class="navbar-text me-3 text-white"> ผู้ดูแล: <?=\$_SESSION['admin']?> </span> <a href="logout.php" class="btn btn-outline-light btn-sm">ออกจากระบบ</a> </div> </div> </nav> PHP; file_put_contents("$systemName/admin/menu.php", $admin_menu); /* ---------- 3. จัดการสินค้า (พระ) ---------- */ $admin_products = <<<PHP <?php session_start(); if(!isset(\$_SESSION['admin'])) { header('Location: index.php'); exit; } include('../config/db.php'); // เพิ่มสินค้าใหม่ if(isset(\$_POST['add'])) { \$name = \$_POST['name']; \$price = \$_POST['price']; \$stock = \$_POST['stock']; \$img1 = ""; \$img2 = ""; if(isset(\$_FILES['img1']['name']) && \$_FILES['img1']['name'] != '') { \$img1 = time() . "_1_" . basename(\$_FILES['img1']['name']); move_uploaded_file(\$_FILES['img1']['tmp_name'], "../uploads/products/" . \$img1); } if(isset(\$_FILES['img2']['name']) && \$_FILES['img2']['name'] != '') { \$img2 = time() . "_2_" . basename(\$_FILES['img2']['name']); move_uploaded_file(\$_FILES['img2']['tmp_name'], "../uploads/products/" . \$img2); } \$conn->query("INSERT INTO products (name, price, stock, img1, img2) VALUES ('\$name', '\$price', '\$stock', '\$img1', '\$img2')"); } // ลบสินค้า if(isset(\$_GET['del'])) { \$id = \$_GET['del']; \$conn->query("DELETE FROM products WHERE id=\$id"); header("Location: products.php"); exit; } // ดึงข้อมูลสินค้า \$res = \$conn->query("SELECT * FROM products ORDER BY id DESC"); ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>จัดการสินค้า</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="../assets/css/style.css" rel="stylesheet"> </head> <body class="bg-light"> <?php include("menu.php"); ?> <div class="container py-4"> <h3 class="mb-4">📦 จัดการสินค้า</h3> <div class="card p-4 mb-4 shadow-sm"> <form method="post" enctype="multipart/form-data"> <div class="row g-3 align-items-end"> <div class="col-md-3"> <label>ชื่อพระ</label> <input type="text" name="name" class="form-control" required> </div> <div class="col-md-2"> <label>ราคา</label> <input type="number" name="price" step="0.01" class="form-control" required> </div> <div class="col-md-2"> <label>คงเหลือ</label> <input type="number" name="stock" class="form-control" required> </div> <div class="col-md-2"> <label>ภาพด้านหน้า</label> <input type="file" name="img1" class="form-control"> </div> <div class="col-md-2"> <label>ภาพด้านหลัง</label> <input type="file" name="img2" class="form-control"> </div> <div class="col-md-1"> <button type="submit" name="add" class="btn btn-primary w-100">เพิ่ม</button> </div> </div> </form> </div> <table class="table table-bordered bg-white shadow-sm align-middle"> <thead class="table-dark"> <tr class="text-center"> <th>รหัส</th> <th>ชื่อพระ</th> <th>ราคา</th> <th>คงเหลือ</th> <th>รูปภาพ</th> <th>ลบ</th> </tr> </thead> <?php while(\$r = \$res->fetch_assoc()): ?> <tr> <td class="text-center"><?= \$r['id'] ?></td> <td><?= \$r['name'] ?></td> <td class="text-center"><?= number_format(\$r['price'],2) ?></td> <td class="text-center"><?= \$r['stock'] ?></td> <td class="text-center"> <?php if(\$r['img1']): ?><img src="../uploads/products/<?=\$r['img1']?>" width="60"><?php endif; ?> <?php if(\$r['img2']): ?><img src="../uploads/products/<?=\$r['img2']?>" width="60"><?php endif; ?> </td> <td class="text-center"><a href="?del=<?=\$r['id']?>" class="btn btn-danger btn-sm" onclick="return confirm('ยืนยันการลบ?')">ลบ</a></td> </tr> <?php endwhile; ?> </table> </div> </body> </html> PHP; file_put_contents("$systemName/admin/products.php", $admin_products); echo "<p>✅ สร้าง admin/index.php, admin/menu.php, admin/products.php สำเร็จ</p>"; ?> <?php // ==== ส่วนที่ 4: สร้าง admin/orders.php และ admin/print_invoice.php ==== /* ---------- 1. orders.php ---------- */ $admin_orders = <<<PHP <?php session_start(); if(!isset(\$_SESSION['admin'])) { header('Location: index.php'); exit; } include('../config/db.php'); \$admin_password = "1234"; // ใช้ค่ายืนยันเริ่มต้น // ✅ ยืนยันคำสั่งซื้อ (ตัดสต็อก) if(isset(\$_GET['confirm'])) { \$id = intval(\$_GET['confirm']); \$items = \$conn->query("SELECT product_id, qty FROM order_items WHERE order_id=\$id"); while(\$it = \$items->fetch_assoc()) { \$conn->query("UPDATE products SET stock = stock - {\$it['qty']} WHERE id = {\$it['product_id']} AND stock >= {\$it['qty']}"); } \$conn->query("UPDATE orders SET status='ชำระเงินแล้ว' WHERE id=\$id"); header("Location: orders.php?done=1"); exit; } // ✅ ยกเลิก (คืนสินค้า + รหัสผ่าน) if(isset(\$_POST['cancel_id'])) { \$oid = intval(\$_POST['cancel_id']); \$pw = trim(\$_POST['password']); if(\$pw === \$admin_password) { \$items = \$conn->query("SELECT product_id, qty FROM order_items WHERE order_id=\$oid"); while(\$it = \$items->fetch_assoc()) { \$conn->query("UPDATE products SET stock = stock + {\$it['qty']} WHERE id = {\$it['product_id']}"); } \$conn->query("UPDATE orders SET status='ยกเลิกแล้ว' WHERE id=\$oid"); \$msg = "✅ ยกเลิกคำสั่งซื้อเรียบร้อย"; } else { \$msg = "❌ รหัสผ่านไม่ถูกต้อง!"; } } // ✅ เปลี่ยนสถานะทั่วไป if(isset(\$_GET['id']) && isset(\$_GET['status'])) { \$id = intval(\$_GET['id']); \$st = \$_GET['status']; \$conn->query("UPDATE orders SET status='\$st' WHERE id=\$id"); header("Location: orders.php?updated=1"); exit; } // ✅ ดึงรายการคำสั่งซื้อทั้งหมด \$res = \$conn->query(" SELECT o.*, GROUP_CONCAT(CONCAT(p.name,' x',i.qty) SEPARATOR ', ') AS items FROM orders o JOIN order_items i ON o.id=i.order_id JOIN products p ON i.product_id=p.id GROUP BY o.id ORDER BY o.id DESC "); ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>จัดการคำสั่งจอง</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="../assets/css/style.css" rel="stylesheet"> <style> .password-box { display:none; margin-top:5px; } </style> </head> <body class="bg-light"> <?php include("menu.php"); ?> <div class="container py-4"> <h3 class="mb-3">📜 จัดการคำสั่งจอง</h3> <?php if(isset(\$msg)): ?><div class="alert alert-info"><?= \$msg ?></div><?php endif; ?> <table class="table table-bordered bg-white shadow-sm align-middle"> <thead class="table-dark"> <tr> <th>เลขที่ใบจอง</th> <th>ชื่อผู้จอง</th> <th>รายการพระ</th> <th>ยอดรวม</th> <th>สถานะ</th> <th>สลิป</th> <th>จัดการ</th> <th>ใบเสร็จ</th> </tr> </thead> <?php while(\$r=\$res->fetch_assoc()): ?> <tr> <td><?=\$r['booking_no']?></td> <td><?=\$r['fullname']?></td> <td><?=\$r['items']?></td> <td><?=number_format(\$r['total'],2)?></td> <td><b><?=\$r['status']?></b></td> <td> <?php if(\$r['slip']): ?> <a href="../uploads/slip/<?=\$r['slip']?>" target="_blank">ดู</a> <?php else: ?> - <?php endif; ?> </td> <td> <?php if(\$r['status']=='รอตรวจสอบ' || \$r['status']=='ยืนยันแล้ว'): ?> <a href="?confirm=<?=\$r['id']?>" class="btn btn-success btn-sm">✔ ยืนยัน</a> <?php elseif(\$r['status']=='ชำระเงินแล้ว'): ?> <div class="dropdown d-inline mb-1"> <button class="btn btn-secondary btn-sm dropdown-toggle" data-bs-toggle="dropdown">เปลี่ยนสถานะ</button> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="?id=<?=\$r['id']?>&status=รับ order แล้ว">รับ order แล้ว</a></li> <li><a class="dropdown-item" href="?id=<?=\$r['id']?>&status=มารับเหรียญได้ที่วิทยาลัยฯ">มารับเหรียญได้ที่วิทยาลัยฯ</a></li> <li><a class="dropdown-item" href="?id=<?=\$r['id']?>&status=กำลังจัดส่ง">กำลังจัดส่ง</a></li> <li><a class="dropdown-item" href="?id=<?=\$r['id']?>&status=รับเหรียญเรียบร้อยแล้ว">รับเหรียญเรียบร้อยแล้ว</a></li> <li><a class="dropdown-item" href="?id=<?=\$r['id']?>&status=จัดส่งเรียบร้อยแล้ว">จัดส่งเรียบร้อยแล้ว</a></li> </ul> </div> <button class="btn btn-danger btn-sm" onclick="toggleCancel(<?=\$r['id']?>)">❌ ยกเลิก</button> <div id="cancelBox<?=\$r['id']?>" class="password-box"> <form method="post"> <input type="hidden" name="cancel_id" value="<?=\$r['id']?>"> <input type="password" name="password" class="form-control form-control-sm mt-1" placeholder="รหัสผ่าน"> <button type="submit" class="btn btn-warning btn-sm mt-1">ยืนยัน</button> </form> </div> <?php elseif(\$r['status']=='ยกเลิกแล้ว'): ?> <span class="text-muted">คำสั่งนี้ถูกยกเลิก</span> <?php else: ?> <span class="text-secondary">-</span> <?php endif; ?> </td> <td><a href="print_invoice.php?id=<?=\$r['id']?>" target="_blank" class="btn btn-outline-primary btn-sm">🖨 พิมพ์</a></td> </tr> <?php endwhile; ?> </table> </div> <script> function toggleCancel(id){ const box=document.getElementById('cancelBox'+id); box.style.display = (box.style.display=='block'?'none':'block'); } </script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html> PHP; file_put_contents("$systemName/admin/orders.php", $admin_orders); /* ---------- 2. print_invoice.php ---------- */ $admin_invoice = <<<PHP <?php session_start(); if(!isset(\$_SESSION['admin'])) { header('Location: index.php'); exit; } include('../config/db.php'); \$id = intval(\$_GET['id']); \$o = \$conn->query("SELECT * FROM orders WHERE id=\$id")->fetch_assoc(); \$items = \$conn->query("SELECT p.name, i.qty, i.price FROM order_items i JOIN products p ON i.product_id=p.id WHERE i.order_id=\$id"); ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>ใบเสร็จรับเงิน - <?=\$o['booking_no']?></title> <link href="https://fonts.googleapis.com/css2?family=Kanit:wght@400;600&display=swap" rel="stylesheet"> <style> body { font-family: 'Kanit', sans-serif; margin: 40px; } table { width:100%; border-collapse: collapse; } th,td { border:1px solid #999; padding:8px; } th { background:#eee; } .text-right { text-align:right; } .text-center { text-align:center; } .info-box { border:1px solid #ccc; padding:15px; margin-bottom:15px; border-radius:6px; } </style> </head> <body> <h2 class="text-center">ใบเสร็จรับเงิน / ใบจัดส่งสินค้า</h2> <hr> <div class="info-box"> <b>เลขที่ใบจอง:</b> <?=\$o['booking_no']?><br> <b>ชื่อผู้จอง:</b> <?=\$o['fullname']?><br> <b>เบอร์โทร:</b> <?=\$o['phone']?><br> <b>ที่อยู่:</b> <?=\$o['address']?><br> <b>รหัสไปรษณีย์:</b> <?=\$o['zipcode']?><br> <b>วิธีรับสินค้า:</b> <?=\$o['receive_method']?><br> </div> <table> <thead><tr><th>รายการสินค้า</th><th>จำนวน</th><th>ราคา/หน่วย</th><th>รวม</th></tr></thead> <tbody> <?php \$total=0; while(\$r=\$items->fetch_assoc()): \$sum=\$r['qty']*\$r['price']; \$total+=\$sum; ?> <tr> <td><?=\$r['name']?></td> <td class="text-center"><?=\$r['qty']?></td> <td class="text-right"><?=number_format(\$r['price'],2)?></td> <td class="text-right"><?=number_format(\$sum,2)?></td> </tr> <?php endwhile; ?> <tr><th colspan="3" class="text-right">ยอดรวมสุทธิ</th><th class="text-right"><?=number_format(\$total,2)?></th></tr> </tbody> </table> <p style="margin-top:40px;text-align:right;">ลงชื่อ .......................................... ผู้รับเงิน</p> <script>window.print();</script> </body> </html> PHP; file_put_contents("$systemName/admin/print_invoice.php", $admin_invoice); echo "<p>✅ สร้าง admin/orders.php และ admin/print_invoice.php สำเร็จ</p>"; ?> <?php // ==== ส่วนที่ 5: สร้างฝั่งผู้ใช้ (User Interface) ==== // ---------- user/index.php ---------- $user_index = <<<PHP <?php include('../config/db.php'); ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>จองพระวัดสันติสุข</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="../assets/css/style.css" rel="stylesheet"> <style> .dual-img{display:flex;justify-content:center;gap:10px;flex-wrap:wrap} .img-block{text-align:center} .img-block img{width:80px;height:80px;object-fit:cover;border-radius:5px;border:1px solid #ccc} .img-label{font-size:0.8rem;color:#555;display:block} .step-box{display:none} .step-box.active{display:block} </style> </head> <body class="bg-light"> <div class="container py-5"> <h2 class="text-center mb-4">ระบบจองพระวัดสันติสุข</h2> <form id="bookingForm" action="checkout.php" method="post"> <div id="step1" class="step-box active"> <h5>1️⃣ เลือกรายการพระ</h5> <table class="table table-bordered bg-white"> <thead class="table-secondary text-center"> <tr><th>เลือก</th><th>รูปภาพ</th><th>ชื่อพระ</th><th>ราคา</th><th>คงเหลือ</th><th>จำนวน</th></tr> </thead> <tbody> <?php \$res = \$conn->query("SELECT * FROM products"); while(\$r=\$res->fetch_assoc()): \$img1 = !empty(\$r['img1'])?"../uploads/products/{\$r['img1']}":""; \$img2 = !empty(\$r['img2'])?"../uploads/products/{\$r['img2']}":""; ?> <tr> <td class="text-center"><input type="checkbox" name="product_id[]" value="<?=\$r['id']?>"></td> <td class="text-center"> <?php if(\$img1||\$img2): ?> <div class="dual-img"> <?php if(\$img1): ?><div class="img-block"><img src="<?=\$img1?>"><span class="img-label">ด้านหน้า</span></div><?php endif; ?> <?php if(\$img2): ?><div class="img-block"><img src="<?=\$img2?>"><span class="img-label">ด้านหลัง</span></div><?php endif; ?> </div> <?php endif; ?> </td> <td><?=\$r['name']?></td> <td><?=number_format(\$r['price'],2)?></td> <td><?=\$r['stock']>0?\$r['stock']:"<span class='text-danger'>หมด (Free Order)</span>"?></td> <td><input type="number" name="qty[<?=\$r['id']?>]" value="1" min="1" class="form-control form-control-sm" style="width:90px;"></td> </tr> <?php endwhile; ?> </tbody> </table> <div class="text-end"><button type="button" id="nextStep" class="btn btn-primary">ถัดไป ➜</button></div> </div> <div id="step2" class="step-box"> <h5>2️⃣ เลือกวิธีรับสินค้า</h5> <div class="mb-3"> <select name="receive_method" id="receiveMethod" class="form-control" required> <option value="">-- เลือกวิธีรับสินค้า --</option> <option value="รับสินค้าด้วยตนเอง">รับสินค้าด้วยตนเอง</option> <option value="จัดส่งทางไปรษณีย์">จัดส่งทางไปรษณีย์</option> </select> </div> <div id="customerInfo" class="border rounded p-3 bg-white" style="display:none;"> <h6 class="text-secondary mb-2">ข้อมูลผู้จอง / ผู้รับสินค้า</h6> <div class="row"> <div class="col-md-6 mb-3"><label>ชื่อ-นามสกุล</label><input type="text" name="fullname" id="fullname" class="form-control"></div> <div class="col-md-6 mb-3"><label>เบอร์โทรศัพท์</label><input type="text" name="phone" id="phone" class="form-control"></div> </div> <div class="mb-3"><label>ที่อยู่จัดส่ง</label><textarea name="address" id="address" class="form-control" rows="2"></textarea></div> <div class="col-md-4 mb-3"><label>รหัสไปรษณีย์</label><input type="text" name="zipcode" id="zipcode" class="form-control"></div> </div> <div class="d-flex justify-content-between mt-3"> <button type="button" class="btn btn-secondary" id="prevStep">⬅ ย้อนกลับ</button> <button type="submit" class="btn btn-success">ดำเนินการต่อ ➜</button> </div> </div> </form> </div> <script> document.getElementById('nextStep').onclick=function(){ const chk=document.querySelectorAll('input[name="product_id[]"]:checked'); if(chk.length===0){alert('กรุณาเลือกรายการพระอย่างน้อย 1 รายการ');return;} document.getElementById('step1').classList.remove('active'); document.getElementById('step2').classList.add('active'); } document.getElementById('prevStep').onclick=function(){ document.getElementById('step2').classList.remove('active'); document.getElementById('step1').classList.add('active'); } document.getElementById('receiveMethod').onchange=function(){ document.getElementById('customerInfo').style.display=(this.value!='')?'block':'none'; } document.getElementById('bookingForm').onsubmit=function(e){ const method=document.getElementById('receiveMethod').value; const name=document.getElementById('fullname').value.trim(); const phone=document.getElementById('phone').value.trim(); const addr=document.getElementById('address').value.trim(); if(method=='จัดส่งทางไปรษณีย์' && (!name||!phone||!addr)){ alert('กรุณากรอกข้อมูลให้ครบสำหรับการจัดส่ง'); e.preventDefault(); } } </script> </body> </html> PHP; file_put_contents("$systemName/user/index.php", $user_index); // ---------- user/checkout.php ---------- $user_checkout = <<<PHP <?php include('../config/db.php'); session_start(); \$selected = \$_POST['product_id'] ?? []; if(empty(\$selected)) { header("Location: index.php"); exit; } \$fullname = \$_POST['fullname'] ?? ''; \$phone = \$_POST['phone'] ?? ''; \$address = \$_POST['address'] ?? ''; \$zipcode = \$_POST['zipcode'] ?? ''; \$receive_method = \$_POST['receive_method'] ?? ''; \$total = 0; \$items = []; foreach(\$selected as \$pid){ \$q = intval(\$_POST['qty'][\$pid] ?? 1); \$r = \$conn->query("SELECT * FROM products WHERE id=\$pid")->fetch_assoc(); \$sum = \$r['price']*\$q; \$total += \$sum; \$items[] = ['name'=>\$r['name'],'qty'=>\$q,'price'=>\$r['price'],'sum'=>\$sum]; } ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>สรุปการสั่งจอง</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="../assets/css/style.css" rel="stylesheet"> </head> <body class="bg-light"> <div class="container py-5"> <div class="card shadow p-4"> <h4>สรุปรายการจอง</h4> <table class="table table-bordered mt-3"> <thead><tr><th>ชื่อพระ</th><th>จำนวน</th><th>ราคา/หน่วย</th><th>รวม</th></tr></thead> <tbody> <?php foreach(\$items as \$it): ?> <tr> <td><?=\$it['name']?></td> <td><?=\$it['qty']?></td> <td><?=number_format(\$it['price'],2)?></td> <td><?=number_format(\$it['sum'],2)?></td> </tr> <?php endforeach; ?> <tr><th colspan="3" class="text-end">ยอดรวม</th><th><?=number_format(\$total,2)?></th></tr> </tbody> </table> <h5 class="mt-3">ยอดที่ต้องโอน: <b><?=number_format(\$total,2)?> บาท</b></h5> <p>กรุณาชำระเงินโดยสแกน QR Code ด้านล่าง แล้วอัปโหลดสลิปในขั้นตอนถัดไป</p> <div class="text-center"><img src="../assets/img/qrcode.png" alt="QR" width="200"></div> <form method="post" action="upload_slip.php" enctype="multipart/form-data" class="mt-4"> <input type="hidden" name="fullname" value="<?=\$fullname?>"> <input type="hidden" name="phone" value="<?=\$phone?>"> <input type="hidden" name="address" value="<?=\$address?>"> <input type="hidden" name="zipcode" value="<?=\$zipcode?>"> <input type="hidden" name="receive_method" value="<?=\$receive_method?>"> <input type="hidden" name="total" value="<?=\$total?>"> <?php foreach(\$items as \$i): ?> <input type="hidden" name="product_name[]" value="<?=\$i['name']?>"> <input type="hidden" name="qty[]" value="<?=\$i['qty']?>"> <input type="hidden" name="price[]" value="<?=\$i['price']?>"> <?php endforeach; ?> <div class="mb-3"><label>แนบสลิปชำระเงิน</label><input type="file" name="slip" class="form-control" required></div> <button class="btn btn-success w-100">ส่งหลักฐานการชำระเงิน</button> </form> </div> </div> </body> </html> PHP; file_put_contents("$systemName/user/checkout.php", $user_checkout); // ---------- user/upload_slip.php ---------- $user_upload = <<<PHP <?php include('../config/db.php'); if(\$_SERVER['REQUEST_METHOD']=='POST'){ \$fullname = \$_POST['fullname']; \$phone = \$_POST['phone']; \$address = \$_POST['address']; \$zipcode = \$_POST['zipcode']; \$receive_method = \$_POST['receive_method']; \$total = \$_POST['total']; \$slipFile = ""; if(isset(\$_FILES['slip']['name']) && \$_FILES['slip']['name']!=''){ \$slipFile = time().'_'.basename(\$_FILES['slip']['name']); move_uploaded_file(\$_FILES['slip']['tmp_name'], "../uploads/slip/".\$slipFile); } \$conn->query("INSERT INTO orders (fullname, phone, address, zipcode, receive_method, total, status, slip) VALUES ('\$fullname','\$phone','\$address','\$zipcode','\$receive_method','\$total','รอตรวจสอบ','\$slipFile')"); \$oid = \$conn->insert_id; for(\$i=0;\$i<count(\$_POST['product_name']);\$i++){ \$pname = \$_POST['product_name'][\$i]; \$qty = \$_POST['qty'][\$i]; \$price = \$_POST['price'][\$i]; \$pid = \$conn->query("SELECT id FROM products WHERE name='\$pname' LIMIT 1")->fetch_assoc()['id'] ?? 0; \$conn->query("INSERT INTO order_items (order_id, product_id, qty, price) VALUES (\$oid, \$pid, \$qty, \$price)"); } echo "<script>alert('ส่งข้อมูลเรียบร้อย!');window.location='check_status.php';</script>"; } ?> PHP; file_put_contents("$systemName/user/upload_slip.php", $user_upload); // ---------- user/check_status.php ---------- $user_check = <<<PHP <?php include('../config/db.php'); ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>ตรวจสอบสถานะการจอง</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="../assets/css/style.css" rel="stylesheet"> </head> <body class="bg-light"> <div class="container py-5"> <h3 class="text-center mb-4">ตรวจสอบสถานะการจอง</h3> <form method="get" class="text-center mb-4"> <input type="text" name="phone" class="form-control d-inline-block" style="width:250px" placeholder="กรอกเบอร์โทรศัพท์"> <button class="btn btn-primary">ตรวจสอบ</button> </form> <?php if(isset(\$_GET['phone'])){ \$phone = \$_GET['phone']; \$res = \$conn->query("SELECT * FROM orders WHERE phone='\$phone' ORDER BY id DESC"); if(\$res->num_rows==0){ echo "<div class='alert alert-warning text-center'>ไม่พบข้อมูลการจอง</div>"; } else { echo "<table class='table table-bordered bg-white'>"; echo "<tr><th>เลขที่ใบจอง</th><th>ยอดรวม</th><th>สถานะ</th></tr>"; while(\$r=\$res->fetch_assoc()){ echo "<tr><td>{\$r['booking_no']}</td><td>{number_format(\$r['total'],2)}</td><td>{\$r['status']}</td></tr>"; } echo "</table>"; } } ?> </div> </body> </html> PHP; file_put_contents("$systemName/user/check_status.php", $user_check); echo "<p>✅ สร้างไฟล์ user/index.php, checkout.php, upload_slip.php, check_status.php สำเร็จ</p>"; ?> <?php // ==== ส่วนที่ 6: สรุปและสร้างไฟล์ ZIP ==== echo "<hr><h3>📦 กำลังบีบอัดไฟล์ทั้งหมดเป็น ZIP...</h3>"; // เพิ่มทุกไฟล์ในระบบเข้า ZIP addFolderToZip($systemName, $zip, $systemName); $zip->close(); if (file_exists($zipFile)) { echo "<div style='padding:15px;background:#e9ffe9;border:1px solid #9f9;'>✅ สร้างไฟล์ ZIP สำเร็จ: <b>$zipFile</b></div>"; echo "<p><a href='$zipFile' class='btn btn-success'>ดาวน์โหลด cmtc_booking_system.zip</a></p>"; } else { echo "<div style='padding:15px;background:#ffe9e9;border:1px solid #f99;'>❌ ไม่สามารถสร้างไฟล์ ZIP ได้</div>"; } echo "<hr><p>🎉 เสร็จสมบูรณ์! ตอนนี้คุณสามารถนำไฟล์ <b>$zipFile</b> ไปติดตั้งบน XAMPP หรือ Hosting ได้เลย</p>"; echo "<ul> <li>แตกไฟล์ในโฟลเดอร์ <b>htdocs</b></li> <li>สร้างฐานข้อมูลชื่อ <b>cmtc_booking</b></li> <li>นำเข้าไฟล์ <b>cmtc_booking.sql</b></li> <li>เข้าสู่ระบบ admin ด้วย <b>ชื่อผู้ใช้: admin</b> / <b>รหัสผ่าน: 1234</b></li> </ul>"; echo "<p><b>URL ตัวอย่าง:</b> <a href='http://localhost/$systemName/' target='_blank'>http://localhost/$systemName/</a></p>"; ?>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.42 |
proxy
|
phpinfo
|
Settings