🤩 File Manager - Mr.X
PHP:
8.3.33
Server:
Apache
OS:
Linux 5.14.0-611.49.1.el9_7.x86_64
User:
websparkit
Navigate
Upload:
Upload
New File
New Folder
Editing:messages.php
<?php /** * ARCHI-TECH Admin Messages Inbox Viewer */ require_once __DIR__ . '/../includes/db.php'; require_once __DIR__ . '/../includes/functions.php'; check_admin_auth(); $id = isset($_GET['id']) ? intval($_GET['id']) : 0; $success_msg = ''; $error_msg = ''; // Success Notice Handling if (isset($_GET['success'])) { if ($_GET['success'] === 'deleted') $success_msg = "Message successfully removed from inbox."; if ($_GET['success'] === 'read_all') $success_msg = "All messages successfully marked as read."; } // Delete Message action if (isset($_GET['delete'])) { $delete_id = intval($_GET['delete']); try { $stmt = $pdo->prepare("DELETE FROM contact_messages WHERE id = :id"); $stmt->execute(['id' => $delete_id]); header("Location: " . BASE_URL . "admin/messages.php?success=deleted"); exit(); } catch (PDOException $e) { $error_msg = "Failed to delete message: " . $e->getMessage(); } } // Mark All as Read action if (isset($_GET['action']) && $_GET['action'] === 'read_all') { try { $pdo->query("UPDATE contact_messages SET is_read = 1"); header("Location: " . BASE_URL . "admin/messages.php?success=read_all"); exit(); } catch (PDOException $e) { $error_msg = "Failed to update messages: " . $e->getMessage(); } } // Load a specific message details and flag as read $selected_msg = null; if ($id > 0) { try { // Flag message as read $stmt_read = $pdo->prepare("UPDATE contact_messages SET is_read = 1 WHERE id = :id"); $stmt_read->execute(['id' => $id]); $stmt = $pdo->prepare("SELECT * FROM contact_messages WHERE id = :id"); $stmt->execute(['id' => $id]); $selected_msg = $stmt->fetch(); } catch (PDOException $e) { $error_msg = "Error reading message: " . $e->getMessage(); } } // Load all messages $all_messages = []; try { $stmt = $pdo->query("SELECT * FROM contact_messages ORDER BY is_read ASC, id DESC"); $all_messages = $stmt->fetchAll(); } catch (PDOException $e) { // offline } require_once __DIR__ . '/header.php'; require_once __DIR__ . '/navbar.php'; ?> <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-4 border-bottom border-secondary"> <h1 class="h2 text-white text-uppercase" style="letter-spacing: -0.01em; font-family: 'Syne', sans-serif;">Client Inbox</h1> <div class="btn-toolbar mb-2 mb-md-0"> <?php if ($id > 0): ?> <a href="<?= BASE_URL ?>admin/messages.php" class="btn btn-outline-light btn-sm py-2 px-3"><i class="bi bi-arrow-left me-2"></i>Back to Inbox</a> <?php else: ?> <a href="<?= BASE_URL ?>admin/messages.php?action=read_all" class="btn btn-gold btn-sm py-2 px-3" onclick="return confirm('Mark all messages as read?')"><i class="bi bi-envelope-open me-2"></i>Mark All Read</a> <?php endif; ?> </div> </div> <!-- Notice Alerts --> <?php if (!empty($success_msg)): ?> <div class="alert alert-success border-0 bg-success text-white mb-4"> <i class="bi bi-check-circle-fill me-2"></i><?= sanitize_input($success_msg) ?> </div> <?php endif; ?> <?php if (!empty($error_msg)): ?> <div class="alert alert-danger border-0 bg-danger text-white mb-4"> <i class="bi bi-exclamation-triangle-fill me-2"></i><?= sanitize_input($error_msg) ?> </div> <?php endif; ?> <?php if ($id === 0): ?> <!-- MESSAGES LIST TABLE --> <div class="glass-card p-4"> <div class="table-responsive"> <table class="table table-dark table-striped table-hover align-middle border-secondary table-dark-custom"> <thead> <tr> <th scope="col" style="width: 25%;">Client Name</th> <th scope="col" style="width: 35%;">Subject</th> <th scope="col" style="width: 20%;">Date Received</th> <th scope="col" style="width: 10%;">Status</th> <th scope="col" style="width: 10%; text-align: center;">Actions</th> </tr> </thead> <tbody> <?php if (!empty($all_messages)): ?> <?php foreach ($all_messages as $msg): ?> <tr class="<?= (intval($msg['is_read']) === 0) ? 'fw-bold text-white' : 'text-white-50' ?>"> <td> <?= sanitize_input($msg['name']) ?> <small class="d-block text-muted" style="font-weight: normal;"><?= sanitize_input($msg['email']) ?></small> </td> <td> <?php if (strpos($msg['subject'], 'Quotation Request') !== false): ?> <span class="badge bg-warning text-dark me-2 small">QUOTE</span> <?php endif; ?> <?= sanitize_input($msg['subject']) ?> </td> <td class="small text-muted"><?= date('M d, Y - H:i', strtotime($msg['created_at'])) ?></td> <td> <?php if (intval($msg['is_read']) === 1): ?> <span class="badge bg-secondary">Read</span> <?php else: ?> <span class="badge bg-warning text-dark">Unread</span> <?php endif; ?> </td> <td align="center"> <a href="<?= BASE_URL ?>admin/messages.php?id=<?= $msg['id'] ?>" class="btn btn-outline-light btn-sm me-2" title="Read"><i class="bi bi-eye"></i></a> <a href="<?= BASE_URL ?>admin/messages.php?delete=<?= $msg['id'] ?>" class="btn btn-outline-danger btn-sm" onclick="return confirm('Delete this message?')" title="Delete"><i class="bi bi-trash"></i></a> </td> </tr> <?php endforeach; ?> <?php else: ?> <tr> <td colspan="5" class="text-center text-muted py-4">No message entries. Your customer contact logs are empty.</td> </tr> <?php endif; ?> </tbody> </table> </div> </div> <?php else: ?> <!-- READ SINGLE MESSAGE DETAIL --> <?php if ($selected_msg): ?> <div class="row justify-content-center"> <div class="col-lg-10"> <div class="glass-card"> <div class="d-flex align-items-center justify-content-between mb-4 border-bottom border-secondary pb-3"> <h4 class="text-white text-uppercase mb-0" style="font-size: 1.15rem; letter-spacing: 0.05em;"> <i class="bi bi-envelope-open text-accent-color me-2"></i>Inquiry Details </h4> <span class="small text-muted"><?= date('F d, Y - H:i:s', strtotime($selected_msg['created_at'])) ?></span> </div> <div class="row g-4 mb-4"> <div class="col-md-6"> <h6 class="text-uppercase text-muted small fw-bold">Client Identity</h6> <p class="mb-1"><strong>Name:</strong> <?= sanitize_input($selected_msg['name']) ?></p> <p class="mb-1"><strong>Email:</strong> <a href="mailto:<?= $selected_msg['email'] ?>" class="text-accent-color"><?= sanitize_input($selected_msg['email']) ?></a></p> <p class="mb-0"><strong>Phone:</strong> <?= !empty($selected_msg['phone']) ? sanitize_input($selected_msg['phone']) : 'Not Provided' ?></p> </div> <div class="col-md-6"> <h6 class="text-uppercase text-muted small fw-bold">Subject Info</h6> <p class="mb-0"><strong>Topic:</strong> <?= sanitize_input($selected_msg['subject']) ?></p> </div> </div> <div class="bg-dark p-4 rounded border border-secondary mb-4"> <h6 class="text-uppercase text-muted small fw-bold mb-3">Message Body</h6> <p class="text-white" style="white-space: pre-line; line-height: 1.8; font-size: 0.95rem;"><?= sanitize_input($selected_msg['message']) ?></p> </div> <div class="text-end pt-3"> <a href="<?= BASE_URL ?>admin/messages.php?delete=<?= $selected_msg['id'] ?>" class="btn btn-outline-danger me-2" onclick="return confirm('Are you sure you want to delete this message?')"><i class="bi bi-trash me-2"></i>Delete Message</a> <a href="<?= BASE_URL ?>admin/messages.php" class="btn btn-gold-filled px-4">Back to Inbox</a> </div> </div> </div> </div> <?php else: ?> <p class="text-center text-muted">Message details not found.</p> <?php endif; ?> <?php endif; ?> <?php require_once __DIR__ . '/footer.php'; ?>
Save Changes
Cancel
Create New File
Create New Folder