File manager - Edit - /var/www/order.cmtc.ac.th/user/index_1.php
Back
<?php include('../config/db.php'); ?> <?php // ✅ ตรวจสอบค่าสถานะ Free Order จากฐานข้อมูล $setting = $conn->query("SELECT setting_value FROM settings WHERE setting_key='free_order'")->fetch_assoc(); $free_order_status = $setting['setting_value'] ?? 'off'; // ค่าเริ่มต้น // ✅ ดึงข้อมูลสินค้า $res = $conn->query("SELECT * FROM products"); ?> <?php include('template_user_header.php'); ?> <meta charset="UTF-8"> <h3 class="mb-3 text-center">🪙 เลือกรายการเหรียญที่ต้องการจอง</h3> <form action="checkout.php" method="post" id="bookingForm"> <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 while($r=$res->fetch_assoc()): ?> <?php $img1 = !empty($r['img1']) ? "../uploads/products/{$r['img1']}" : ""; $img2 = !empty($r['img2']) ? "../uploads/products/{$r['img2']}" : ""; ?> <tr> <td class="text-center"> <?php if($r['stock'] > 0 || $free_order_status == 'on'): ?> <input type="checkbox" name="product_id[]" value="<?=$r['id']?>"> <?php else: ?> <input type="checkbox" disabled> <?php endif; ?> </td> <td class="text-center"> <?php if($img1 || $img2): ?> <div class="dual-img d-flex justify-content-center gap-2"> <?php if($img1): ?> <div class="img-block text-center"> <img src="<?=$img1?>" width="80"> <div class="small text-muted">ด้านหน้า</div> </div> <?php endif; ?> <?php if($img2): ?> <div class="img-block text-center"> <img src="<?=$img2?>" width="80"> <div class="small text-muted">ด้านหลัง</div> </div> <?php endif; ?> </div> <?php endif; ?> </td> <td><?=$r['name']?></td> <td><?=number_format($r['price'],2)?></td> <td> <?php if($r['stock'] > 0): ?> <?=$r['stock']?> <?php else: ?> <?php if($free_order_status == 'on'): ?> <span class="text-warning fw-bold">หมด (Free Order เปิด)</span> <?php else: ?> <span class="text-danger fw-bold">หมด (ไม่เปิด Free Order)</span> <?php endif; ?> <?php endif; ?> </td> <td> <?php if($r['stock'] > 0 || $free_order_status == 'on'): ?> <input type="number" name="qty[<?=$r['id']?>]" value="1" min="1" class="form-control form-control-sm" style="width:90px;"> <?php else: ?> <input type="number" class="form-control form-control-sm" style="width:90px;" disabled> <?php endif; ?> </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" id="nextStep" 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'; }; // ✅ ตรวจสอบเฉพาะตัวเลขเบอร์โทรศัพท์ const phoneInput = document.getElementById('phone'); if (phoneInput) { phoneInput.addEventListener('input', function() { this.value = this.value.replace(/[^0-9]/g, ''); if (this.value.length > 10) this.value = this.value.slice(0, 10); }); } // ✅ ตรวจสอบเฉพาะตัวเลขรหัสไปรษณีย์ const zipInput = document.getElementById('zipcode'); if (zipInput) { zipInput.addEventListener('input', function() { this.value = this.value.replace(/[^0-9]/g, ''); if (this.value.length > 5) this.value = this.value.slice(0, 5); }); } // ✅ ตรวจสอบข้อมูลก่อนส่งฟอร์ม 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(); const zip = document.getElementById('zipcode').value.trim(); if (method === '') { alert('กรุณาเลือกวิธีรับสินค้า'); e.preventDefault(); return; } if (method === 'รับสินค้าด้วยตนเอง') { if (!name || !phone) { alert('กรุณากรอกชื่อและเบอร์โทรศัพท์ให้ครบ'); e.preventDefault(); return; } } if (method === 'จัดส่งทางไปรษณีย์') { if (!name || !phone || !addr || !zip) { alert('กรุณากรอกข้อมูลที่อยู่จัดส่งให้ครบ'); e.preventDefault(); return; } if (!/^[0-9]{5}$/.test(zip)) { alert('กรุณากรอกรหัสไปรษณีย์ให้ถูกต้อง (5 หลัก)'); e.preventDefault(); return; } } if (!/^[0-9]{10}$/.test(phone)) { alert('กรุณากรอกเบอร์โทรศัพท์ให้ถูกต้อง (10 หลัก)'); e.preventDefault(); return; } }; </script> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.51 |
proxy
|
phpinfo
|
Settings