halohalo
bnmbnmbnhjkhjkhjkhjktyutyutyuytutyutyutyhgjgjghjgjghjguytutyry
/
home
/
u295559686
/
domains
/
stanjo.in
/
public_html
/
admin
/
Upload FileeE
HOME
<?php session_start(); if (!isset($_SESSION['user_id'])) { header("Location: login.php"); exit(); } include 'inc/header.php'; ?> <?php include 'inc/sidebar.php'; ?> <?php // Include database connection include 'config.php'; // Initialize variables $error_message = ''; $contacts = []; // Fetch contacts try { $stmt = $conn->prepare("SELECT * FROM contact ORDER BY created_at DESC"); $stmt->execute(); $result = $stmt->get_result(); $contacts = $result->fetch_all(MYSQLI_ASSOC); } catch (Exception $e) { $error_message = "Error fetching contacts: " . $e->getMessage(); } ?> <div class="main-content"> <div class="page-content"> <div class="container-fluid"> <!-- Page Title --> <div class="row"> <div class="col-12"> <div class="page-title-box d-sm-flex align-items-center justify-content-between"> <h4 class="mb-sm-0">Contact Table</h4> <div class="page-title-right"> <ol class="breadcrumb m-0"> <li class="breadcrumb-item"><a href="javascript: void(0);">Contact</a></li> <li class="breadcrumb-item active">Contact Table</li> </ol> </div> </div> </div> </div> <!-- Contact Table --> <div class="row"> <div class="col-12"> <div class="card"> <div class="card-body"> <?php if ($error_message): ?> <div class="alert alert-danger"><?php echo $error_message; ?></div> <?php endif; ?> <div class="table-responsive text-nowrap"> <table id="datatable-buttons" class="table table-striped table-bordered" style="width: 100%;"> <thead> <tr> <th>Sr.No.</th> <th>Name</th> <th>Phone</th> <th>Email</th> <th>Topic</th> <th>Message</th> <th>Created At</th> <th>Action</th> </tr> </thead> <tbody> <?php foreach ($contacts as $index => $contact): ?> <tr> <td><?php echo $index + 1; ?></td> <td><?php echo htmlspecialchars($contact['name']); ?></td> <td><?php echo htmlspecialchars($contact['phone']); ?></td> <td><?php echo htmlspecialchars($contact['email']); ?></td> <td><?php echo htmlspecialchars($contact['topic']); ?></td> <td class="text-muted"> <?php $msg_words = explode(' ', $contact['message']); $short_msg = implode(' ', array_slice($msg_words, 0, 2)); echo htmlspecialchars($short_msg) . (count($msg_words) > 2 ? '...' : ''); ?> </td> <td><?php echo date('d M, Y', strtotime($contact['created_at'])); ?></td> <td> <div class="d-flex gap-2"> <button class="btn btn-custom-edit btn-sm view-btn" data-name="<?= htmlspecialchars($contact['name']) ?>" data-phone="<?= htmlspecialchars($contact['phone']) ?>" data-email="<?= htmlspecialchars($contact['email']) ?>" data-topic="<?= htmlspecialchars($contact['topic']) ?>" data-message="<?= htmlspecialchars($contact['message']) ?>" data-date="<?= date('d M, Y', strtotime($contact['created_at'])) ?>" title="View Message"> View </button> <a href="delete/contact.php?id=<?= $contact['id'] ?>" class="btn btn-custom-delete btn-sm" onclick="return confirm('Are you sure you want to delete this message?')" title="Delete"> Delete </a> </div> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> </div> </div> </div> </div> <!-- View Message Modal --> <div class="modal fade" id="viewMessageModal" tabindex="-1" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Contact Message Details</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <div class="mb-3"> <label class="form-label fw-bold">Name:</label> <p id="modal-name" class="mb-0"></p> </div> <div class="row mb-3"> <div class="col-6"> <label class="form-label fw-bold">Phone:</label> <p id="modal-phone" class="mb-0"></p> </div> <div class="col-6"> <label class="form-label fw-bold">Date:</label> <p id="modal-date" class="mb-0"></p> </div> </div> <div class="mb-3"> <label class="form-label fw-bold">Email:</label> <p id="modal-email" class="mb-0"></p> </div> <div class="mb-3"> <label class="form-label fw-bold">Topic:</label> <p id="modal-topic" class="mb-0"></p> </div> <div class="mb-0"> <label class="form-label fw-bold">Message:</label> <div class="p-3 bg-light rounded border text-wrap" id="modal-message"></div> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> </div> </div> </div> </div> <!-- JS Scripts --> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> <!-- DataTables CSS & JS --> <link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css"> <link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.4.1/css/buttons.dataTables.min.css"> <script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script> <script src="https://cdn.datatables.net/buttons/2.4.1/js/dataTables.buttons.min.js"></script> <script src="https://cdn.datatables.net/buttons/2.4.1/js/buttons.html5.min.js"></script> <script src="https://cdn.datatables.net/buttons/2.4.1/js/buttons.print.min.js"></script> <script> $(document).ready(function () { var table = $('#datatable-buttons').DataTable({ dom: 'Bfrtip', buttons: [ { extend: 'copy', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6], format: { body: function (data, row, column, node) { if (column === 5) { return $(node).closest('tr').find('.view-btn').data('message'); } return data; } } } }, { extend: 'csv', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6], format: { body: function (data, row, column, node) { if (column === 5) { return $(node).closest('tr').find('.view-btn').data('message'); } return data; } } } }, { extend: 'excel', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6], format: { body: function (data, row, column, node) { if (column === 5) { return $(node).closest('tr').find('.view-btn').data('message'); } return data; } } } }, { extend: 'pdf', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6], format: { body: function (data, row, column, node) { if (column === 5) { return $(node).closest('tr').find('.view-btn').data('message'); } return data; } } } }, { extend: 'print', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6], format: { body: function (data, row, column, node) { if (column === 5) { return $(node).closest('tr').find('.view-btn').data('message'); } return data; } } } } ], paging: true, searching: true, ordering: true }); $('#datatable-buttons_filter input').attr('placeholder', 'Search Contacts...'); // Handle View Button Click $('.view-btn').on('click', function () { const name = $(this).data('name'); const phone = $(this).data('phone'); const email = $(this).data('email'); const topic = $(this).data('topic'); const message = $(this).data('message'); const date = $(this).data('date'); $('#modal-name').text(name); $('#modal-phone').text(phone); $('#modal-email').text(email); $('#modal-topic').text(topic); $('#modal-message').html(message.replace(/\n/g, '<br>')); $('#modal-date').text(date); var myModal = new bootstrap.Modal(document.getElementById('viewMessageModal')); myModal.show(); }); }); </script> </div> <?php include 'inc/footer.php'; ?>