Editing: /home/goacom/public_html/scratch_extract/mail.php
<?php // Start session session_start(); // 1. Database Connection $host = 'localhost'; $db_user = 'tishanw1_melbets'; // Change to your DB username $db_pass = 'tishanw1_melbets'; // Change to your DB password $db_name = 'tishanw1_melbets'; // Your DB name $conn = new mysqli($host, $db_user, $db_pass, $db_name); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Get current user ID $current_user_id = isset($_SESSION['user_id']) ? $_SESSION['user_id'] : 1; // 2. Handle DELETE Request if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'delete') { if (!empty($_POST['msg_ids']) && is_array($_POST['msg_ids'])) { // Prepare statement to insert into message_deletions // This hides the message for THIS user only $stmt = $conn->prepare("INSERT IGNORE INTO message_deletions (message_id, user_id) VALUES (?, ?)"); foreach ($_POST['msg_ids'] as $msg_id) { $stmt->bind_param("ii", $msg_id, $current_user_id); $stmt->execute(); } $stmt->close(); } // Redirect to self to prevent form resubmission and refresh list header("Location: " . $_SERVER['PHP_SELF']); exit(); } // 3. Fetch Messages (Excluding deleted ones for this user) // We select messages sent to everyone (0) OR this user, // BUT we exclude messages found in the deletions table for this user $sql = "SELECT m.* FROM internal_messages m WHERE (m.user_id = 0 OR m.user_id = ?) AND m.id NOT IN (SELECT message_id FROM message_deletions WHERE user_id = ?) ORDER BY m.created_at DESC"; $stmt = $conn->prepare($sql); $stmt->bind_param("ii", $current_user_id, $current_user_id); $stmt->execute(); $result = $stmt->get_result(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="description" content="MELBETE - Official Gaming & Betting Platform." /> <title>MELBETE - Internal Message</title> <link rel="stylesheet" href="index.css" /> <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800;900&display=swap" rel="stylesheet" /> </head> <body> <div id="root"> <div class="w-full bg-bodyColor"> <div class="max-w-[1000px] mx-auto"> <!-- Header Section --> <div class="bg-[#333]"> <div class="flex justify-between items-center h-12" style="background: rgb(240, 104, 39);"> <!-- Back Button (Working) --> <a href="javascript:history.back()" class="text-white cursor-pointer text-[26px] w-16 flex items-center justify-center"> <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"> <path d="M217.9 256L345 129c9.4-9.4 9.4-24.6 0-33.9-9.4-9.4-24.6-9.3-34 0L167 239c-9.1 9.1-9.3 23.7-.7 33.1L310.9 417c4.7 4.7 10.9 7 17 7s12.3-2.3 17-7c9.4-9.4 9.4-24.6 0-33.9L217.9 256z"></path> </svg> </a> <!-- Title --> <div class="w-full text-white text-[19px] text-center"> Internal Message </div> </div> </div> <!-- Main Content --> <div class="min-h-screen bg-gray-50 flex justify-center py-4"> <div class="bg-white w-full max-w-md rounded"> <!-- Inbox Header --> <div class="border-b p-3 text-center text-blue-500 font-medium text-sm"> Inbox </div> <!-- Toolbar Form --> <form method="POST" action=""> <!-- Hidden action for delete logic --> <input type="hidden" name="action" value="delete"> <div class="flex items-center justify-between p-3 border-b text-sm"> <div class="flex items-center space-x-2"> <!-- Select All Checkbox (Working) --> <input class="w-4 h-4 cursor-pointer" type="checkbox" id="selectAll" onclick="toggleSelectAll()"> <label for="selectAll" class="cursor-pointer">Select</label> </div> <div class="flex items-center space-x-3 text-gray-500 text-lg"> <!-- Refresh Button (Working) --> <a href="" class="cursor-pointer hover:text-blue-500"> <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"> <path d="M370.72 133.28C339.458 104.008 298.888 87.962 255.848 88c-77.458.068-144.328 53.178-162.791 126.85-1.344 5.363-6.122 9.15-11.651 9.15H24.103c-7.498 0-13.194-6.807-11.807-14.176C33.933 94.924 134.813 8 256 8c66.448 0 126.791 26.136 171.315 68.685L463.03 40.97C478.149 25.851 504 36.559 504 57.941V192c0 13.255-10.745 24-24 24H345.941c-21.382 0-32.09-25.851-16.971-40.971l41.75-41.749zM32 296h134.059c21.382 0 32.09 25.851 16.971 40.971l-41.75 41.75c31.262 29.273 71.835 45.319 114.876 45.28 77.418-.07 144.315-53.144 162.787-126.849 1.344-5.363 6.122-9.15 11.651-9.15h57.304c7.498 0 13.194 6.807 11.807 14.176C478.067 417.076 377.187 504 256 504c-66.448 0-126.791-26.136-171.315-68.685L48.97 471.03C33.851 486.149 8 475.441 8 454.059V320c0-13.255 10.745-24 24-24z"></path> </svg> </a> <!-- Delete Button (Working) --> <!-- type="submit" triggers the form to POST --> <button type="submit" class="cursor-pointer hover:text-red-500 bg-transparent border-0 p-0"> <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 448 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"> <path d="M432 32H312l-9.4-18.7A24 24 0 0 0 281.1 0H166.8a23.72 23.72 0 0 0-21.4 13.3L136 32H16A16 16 0 0 0 0 48v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16V48a16 16 0 0 0-16-16zM53.2 467a48 48 0 0 0 47.9 45h245.8a48 48 0 0 0 47.9-45L416 128H32z"></path> </svg> </button> </div> </div> <!-- Message List (Dynamic PHP Loop) --> <div> <?php if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $date_time = date('Y-m-d H:i:s', strtotime($row['created_at'])); ?> <div class="flex items-start justify-between px-3 py-3 border-b cursor-pointer hover:bg-gray-50"> <div class="flex items-start space-x-2"> <!-- Individual Checkbox --> <input class="mt-1 w-4 h-4 msg-checkbox" type="checkbox" name="msg_ids[]" value="<?php echo $row['id']; ?>"> <div class="text-sm"> <div class="flex items-center space-x-1 mb-1"> <span class="w-2 h-2 bg-green-500 rounded-full inline-block"></span> <span class="text-gray-700 font-medium"> Sender: <?php echo htmlspecialchars($row['sender']); ?> </span> <span class="text-xs text-gray-400"> <?php echo $date_time; ?> </span> </div> <div class="text-gray-800 font-medium"> Title: <?php echo htmlspecialchars($row['title']); ?> </div> </div> </div> <span class="text-gray-400 text-xl">›</span> </div> <?php } } else { echo '<div class="p-5 text-center text-gray-500 text-sm">No messages found.</div>'; } ?> </div> </form> </div> </div> </div> </div> </div> <!-- Notification Container --> <section class="Toastify" aria-live="polite" aria-atomic="false" aria-relevant="additions text" aria-label="Notifications Alt+T"></section> <!-- JavaScript for Select All Logic --> <script> function toggleSelectAll() { var selectAllCheckbox = document.getElementById('selectAll'); var checkboxes = document.querySelectorAll('.msg-checkbox'); checkboxes.forEach(function(checkbox) { checkbox.checked = selectAllCheckbox.checked; }); } </script> </body> </html> <?php $conn->close(); ?>
💾 Save