����JFIF��`�`�����Viewing File: /home/u820193700/domains/throtllr.in/public_html/admin/manage_enquiries.php
<?php
require_once '../includes/db.php';
require_once '../includes/functions.php';

if(!is_logged_in()) {
    redirect("login.php");
}

// Database upgrade check (temporary fix to ensure the subject column exists)
try {
    $pdo->exec("ALTER TABLE enquiries ADD COLUMN subject VARCHAR(255) AFTER phone");
} catch(PDOException $e) {
    // Column likely already exists
}

// Handle action (mark replied or delete)
if(isset($_GET['action']) && isset($_GET['id'])) {
    $id = (int)$_GET['id'];
    if($_GET['action'] == 'replied') {
        $stmt = $pdo->prepare("UPDATE enquiries SET status = 'replied' WHERE id = ?");
        $stmt->execute([$id]);
    } elseif($_GET['action'] == 'delete') {
        $stmt = $pdo->prepare("DELETE FROM enquiries WHERE id = ?");
        $stmt->execute([$id]);
    }
    header("Location: manage_enquiries.php");
    exit;
}

// Fetch enquiries
$stmt = $pdo->query("SELECT * FROM enquiries ORDER BY created_at DESC");
$enquiries = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Manage Enquiries - ReOwn Admin</title>
    <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="admin.css">
</head>
<body>

<?php include 'admin_sidebar.php'; ?>

<div id="main-content">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>Manage Enquiries</h2>
    </div>

    <div class="glass-card p-4">
        <div class="table-responsive">
            <table class="table table-dark table-hover align-middle">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Name</th>
                        <th>Phone</th>
                        <th>Subject</th>
                        <th>Message</th>
                        <th>Status</th>
                        <th>Date</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if(empty($enquiries)): ?>
                    <tr>
                        <td colspan="8" class="text-center py-4 text-muted">No enquiries found</td>
                    </tr>
                    <?php else: ?>
                        <?php foreach($enquiries as $enquiry): ?>
                        <tr>
                            <td><?= htmlspecialchars($enquiry['id']) ?></td>
                            <td><?= htmlspecialchars($enquiry['name']) ?></td>
                            <td><?= htmlspecialchars($enquiry['phone']) ?></td>
                            <td><?= htmlspecialchars($enquiry['subject'] ?? 'N/A') ?></td>
                            <td>
                                <!-- View Message Button triggers modal -->
                                <button type="button" class="btn btn-sm btn-outline-info" data-bs-toggle="modal" data-bs-target="#messageModal<?= $enquiry['id'] ?>">
                                    View Message
                                </button>
                            </td>
                            <td>
                                <?php if($enquiry['status'] == 'new'): ?>
                                    <span class="badge bg-warning text-dark">New</span>
                                <?php elseif($enquiry['status'] == 'replied'): ?>
                                    <span class="badge bg-success">Replied</span>
                                <?php else: ?>
                                    <span class="badge bg-secondary"><?= htmlspecialchars($enquiry['status']) ?></span>
                                <?php endif; ?>
                            </td>
                            <td><?= date('Y-m-d H:i', strtotime($enquiry['created_at'])) ?></td>
                            <td>
                                <a href="https://wa.me/<?= preg_replace('/[^0-9]/', '', $enquiry['phone']) ?>" target="_blank" class="btn btn-sm btn-outline-success me-1" title="Reply on WhatsApp"><i class="fab fa-whatsapp"></i></a>
                                <a href="?action=replied&id=<?= $enquiry['id'] ?>" class="btn btn-sm <?= $enquiry['status'] == 'replied' ? 'btn-outline-secondary disabled' : 'btn-outline-primary' ?> me-1" title="Mark Replied"><i class="fas fa-check"></i></a>
                                <a href="?action=delete&id=<?= $enquiry['id'] ?>" class="btn btn-sm btn-outline-danger" title="Delete" onclick="return confirm('Are you sure you want to delete this enquiry?')"><i class="fas fa-trash"></i></a>
                            </td>
                        </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<?php foreach($enquiries as $enquiry): ?>
<!-- Message Modal -->
<div class="modal fade" id="messageModal<?= $enquiry['id'] ?>" tabindex="-1" aria-labelledby="messageModalLabel<?= $enquiry['id'] ?>" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered text-dark">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="messageModalLabel<?= $enquiry['id'] ?>">Message from <?= htmlspecialchars($enquiry['name']) ?></h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body text-start">
        <p><strong>Subject:</strong> <?= htmlspecialchars($enquiry['subject'] ?? 'N/A') ?></p>
        <p><strong>Phone:</strong> <?= htmlspecialchars($enquiry['phone']) ?></p>
        <hr>
        <p style="white-space: pre-wrap;"><?= htmlspecialchars($enquiry['message'] ?? '') ?></p>
      </div>
      <div class="modal-footer">
        <a href="https://wa.me/<?= preg_replace('/[^0-9]/', '', $enquiry['phone']) ?>" target="_blank" class="btn btn-success"><i class="fab fa-whatsapp"></i> Reply on WhatsApp</a>
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
<?php endforeach; ?>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Back to Directory �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�������������������������������������������������������������������������������� ������w�!1AQaq"2�B���� #3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz������������������������������������������������������������������������ ��?��_��+��?��(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(�����