📁 File Manager
Editing:
/home/wvl7mof7402e/public_html/chemtechieg.com/admin/admin_dashboard.php
<?php // Database connection $con = mysqli_connect("localhost", "chemtech", "chemtech@123", "chemtech"); if (!$con) { die("Connection failed: " . mysqli_connect_error()); } // Fetch messages $query = "SELECT * FROM chat_messages ORDER BY timestamp ASC"; $result = mysqli_query($con, $query); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Admin Chat Panel</title> <style> body { font-family: Arial, sans-serif; background-color: #f4f4f4; padding: 20px; } h2 { text-align: center; color: #333; } #chat-body { margin-bottom: 20px; border: 1px solid #ddd; padding: 10px; background: #fff; height: 300px; overflow-y: auto; } .message { padding: 10px; margin: 5px 0; border-radius: 5px; } .user-message { background: #007bff; color: white; text-align: left; } .admin-message { background: #28a745; color: white; text-align: right; } .reply-form { display: flex; gap: 5px; margin-top: 10px; } .reply-form input { flex: 1; padding: 8px; border: 1px solid #ddd; border-radius: 5px; } .reply-form button { padding: 8px; background: #007bff; color: white; border: none; cursor: pointer; } .reply-form button:hover { background: #0056b3; } </style> <script> var conn = new WebSocket('wss://chemtechieg.com:8080'); // Update WebSocket URL conn.onopen = function () { console.log("✅ Connected to WebSocket Server!"); }; conn.onmessage = function (e) { let chatBody = document.getElementById("chat-body"); let newMessage = document.createElement("div"); newMessage.className = "message user-message"; newMessage.textContent = e.data; chatBody.appendChild(newMessage); chatBody.scrollTop = chatBody.scrollHeight; }; function sendReply() { var message = document.getElementById("reply-message").value.trim(); if (message === "") return; var chatBody = document.getElementById("chat-body"); var newMessage = document.createElement("div"); newMessage.className = "message admin-message"; newMessage.textContent = "Admin: " + message; chatBody.appendChild(newMessage); chatBody.scrollTop = chatBody.scrollHeight; conn.send("Admin: " + message); // Save the reply in the database saveMessageToDatabase('admin', message); document.getElementById("reply-message").value = ""; } function saveMessageToDatabase(sender, message) { var xhr = new XMLHttpRequest(); xhr.open("POST", "save_chat_message.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { console.log("Message saved to database"); } }; xhr.send("sender=" + sender + "&message=" + encodeURIComponent(message)); } </script> </head> <body> <h2>Admin Live Chat</h2> <div id="chat-body"> <?php while ($row = mysqli_fetch_assoc($result)): ?> <div class="message <?= ($row['sender'] == 'admin') ? 'admin-message' : 'user-message' ?>"> <strong><?= ucfirst($row['sender']) ?>:</strong> <?= htmlspecialchars($row['message']) ?> </div> <?php endwhile; ?> </div> <!-- Reply Form --> <div class="reply-form"> <input type="text" id="reply-message" placeholder="Type a reply..." onkeypress="if(event.key === 'Enter') sendReply()" /> <button onclick="sendReply()">Send</button> </div> </body> </html> <?php mysqli_close($con); ?>
Save
Cancel