File manager - Edit - /home/webapp69.cm.in.th/u69319090030/030 shop/admin/approvals.php
Back
<?php require_once __DIR__ . '/../config/db.php'; require_once __DIR__ . '/../helpers/jwt_helper.php'; require_once __DIR__ . '/../helpers/auth.php'; // บังคับให้เฉพาะ Super Admin เท่านั้นที่สามารถเปิดหน้านี้ได้ $currentUser = require_login(['super_admin']); $error = ''; $success = ''; // จัดการการกดยอมรับ / ปฏิเสธสิทธิ์แอดมิน if ($_SERVER['REQUEST_METHOD'] === 'POST') { $target_user_id = (int)($_POST['user_id'] ?? 0); $action = $_POST['action'] ?? ''; if ($target_user_id > 0 && in_array($action, ['approve', 'reject'])) { try { $status = ($action === 'approve') ? 'approved' : 'rejected'; $stmt = $pdo->prepare("UPDATE users SET status = ? WHERE id = ? AND role = 'admin'"); $stmt->execute([$status, $target_user_id]); if ($stmt->rowCount() > 0) { $success = "อัปเดตสิทธิ์การเข้าใช้งานของผู้ใช้งานเป็น " . strtoupper($status) . " เรียบร้อยแล้ว"; } else { $error = "ไม่พบแอดมินคนดังกล่าว หรือบทบาทไม่ใช่แอดมิน"; } } catch (PDOException $e) { $error = "เกิดข้อผิดพลาดในการเปลี่ยนสิทธิ์: " . $e->getMessage(); } } else { $error = "พารามิเตอร์ไม่ถูกต้อง"; } } // ดึงรายชื่อแอดมินทั้งหมด $admins = []; try { $stmt = $pdo->query("SELECT id, username, email, role, status, created_at FROM users WHERE role = 'admin' ORDER BY status DESC, id DESC"); $admins = $stmt->fetchAll(); } catch (PDOException $e) { $error = "ไม่สามารถดึงข้อมูลแอดมินได้"; } // นำเข้าเลย์เอาต์ส่วนหัว include __DIR__ . '/header.php'; ?> <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem;"> <div> <h1 style="font-size: 2.2rem; text-shadow: 0 0 10px var(--glow-red); color: var(--text-white);">อนุมัติสิทธิ์แอดมิน</h1> <p style="color: var(--text-gray); font-size: 0.95rem;">จัดการคำขอและอนุมัติสิทธิ์การเข้าถึงระบบควบคุมของแอดมินใหม่</p> </div> </div> <?php if ($error): ?> <div class="cyber-alert cyber-alert-error"> <strong>[เกิดข้อผิดพลาด]</strong> <?php echo htmlspecialchars($error); ?> </div> <?php endif; ?> <?php if ($success): ?> <div class="cyber-alert cyber-alert-success"> <strong>[สำเร็จ]</strong> <?php echo htmlspecialchars($success); ?> </div> <?php endif; ?> <div class="cyber-card"> <h3 style="margin-bottom: 1.5rem; text-transform: uppercase;">>_ รายการผู้ยื่นคำขอแอดมิน</h3> <div class="table-responsive"> <table class="cyber-table"> <thead> <tr> <th>รหัสผู้สมัคร</th> <th>ชื่อผู้ใช้งาน</th> <th>อีเมลความปลอดภัย</th> <th>บทบาท</th> <th>สถานะปัจจุบัน</th> <th>วันที่ยื่นคำขอ</th> <th style="text-align: right; width: 220px;">การจัดการสิทธิ์</th> </tr> </thead> <tbody> <?php if (empty($admins)): ?> <tr> <td colspan="7" style="text-align: center; color: var(--text-muted);">ไม่มีรายการสมัครแอดมินในระบบ</td> </tr> <?php else: ?> <?php foreach ($admins as $admin): ?> <tr> <td style="font-family: 'Orbitron', sans-serif;">#<?php echo $admin['id']; ?></td> <td style="font-weight: bold; color: var(--text-white);"><?php echo htmlspecialchars($admin['username']); ?></td> <td><?php echo htmlspecialchars($admin['email']); ?></td> <td> <span class="badge" style="background: rgba(255, 255, 255, 0.05); color: #fff; border: 1px solid #444;"> <?php echo strtoupper($admin['role']); ?> </span> </td> <td> <span class="badge badge-<?php echo strtolower($admin['status']); ?>"> <?php echo $admin['status']; ?> </span> </td> <td style="font-size: 0.9rem;"><?php echo $admin['created_at']; ?></td> <td style="text-align: right; white-space: nowrap;"> <?php if ($admin['status'] === 'pending' || $admin['status'] === 'rejected'): ?> <form action="approvals.php" method="POST" style="display: inline-block; margin-right: 0.5rem;"> <input type="hidden" name="user_id" value="<?php echo $admin['id']; ?>"> <input type="hidden" name="action" value="approve"> <button type="submit" class="btn-cyber btn-green" style="padding: 0.4rem 0.8rem; font-size: 0.75rem;">อนุมัติสิทธิ์</button> </form> <?php endif; ?> <?php if ($admin['status'] === 'pending' || $admin['status'] === 'approved'): ?> <form action="approvals.php" method="POST" style="display: inline-block;"> <input type="hidden" name="user_id" value="<?php echo $admin['id']; ?>"> <input type="hidden" name="action" value="reject"> <button type="submit" class="btn-cyber" style="padding: 0.4rem 0.8rem; font-size: 0.75rem; border-color: var(--neon-red); color: var(--neon-red);" onclick="return confirm('คุณต้องการปฏิเสธสิทธิ์การเป็นแอดมินของ <?php echo htmlspecialchars($admin['username']); ?> ใช่หรือไม่?');">ปฏิเสธสิทธิ์</button> </form> <?php endif; ?> </td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> </table> </div> </div> <?php require_once __DIR__ . '/footer.php'; ?>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.25 |
proxy
|
phpinfo
|
Settings