Server : LiteSpeed
System : Linux terra.hostitbro.com 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64
User : outerorb ( 1091)
PHP Version : 8.1.34
Disable Function : mail
Directory :  /home2/outerorb/.trash/survey_system/

📁 Create New:
⬆️ Upload File:
Current Dir [ Writable ] Root [ Writable ]


OR Upload from URL:
URL: Save as:

📄 File: admin_chats.php

Path: /home2/outerorb/.trash/survey_system/admin_chats.php

Size: 5.47 KB

Permissions: 0666

<?php
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/chat/ChatSystem.php';

if (!is_logged_in()) {
    header('Location: ' . BASE_URL . '/index.php');
    exit;
}

$user = current_user();

// Check if user is admin
if ($user['role'] !== 'admin') {
    die('Access denied. Admin only.');
}

require_once __DIR__ . '/inc/header.php';

$chatSystem = new ChatSystem($pdo);
$allChats = $chatSystem->adminGetAllChats($user['id'], 1000, 0); // Show up to 1000 chats
$selectedChatId = isset($_GET['chat_id']) ? (int)$_GET['chat_id'] : null;
$selectedChatMessages = [];

if ($selectedChatId) {
    $selectedChatMessages = $chatSystem->adminGetAllMessages($user['id'], $selectedChatId, 10000); // Show up to 10,000 messages per chat
}
?>

<div class="col-lg-10 p-4">
    <div class="row">
        <div class="col-md-4">
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">All Chats (including deleted)</h5>
                </div>
                <div class="card-body p-0" style="max-height: 600px; overflow-y: auto;">
                    <div class="list-group list-group-flush">
                        <?php foreach ($allChats as $chat): ?>
                            <a href="?chat_id=<?= $chat['id'] ?>" 
                               class="list-group-item list-group-item-action <?= $selectedChatId === $chat['id'] ? 'active' : '' ?> <?= $chat['is_deleted'] ? 'text-muted' : '' ?>"
                               style="<?= $chat['is_deleted'] ? 'opacity: 0.6;' : '' ?>">
                                <div class="d-flex justify-content-between">
                                    <strong><?= h($chat['display_name'] ?? 'Unknown Chat') ?></strong>
                                    <?php if ($chat['is_deleted']): ?>
                                        <span class="badge bg-danger">Deleted</span>
                                    <?php endif; ?>
                                </div>
                                <small class="text-muted">
                                    Type: <?= ucfirst($chat['type']) ?> | 
                                    Created: <?= date('M d, Y', strtotime($chat['created_at'])) ?>
                                </small>
                            </a>
                        <?php endforeach; ?>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-md-8">
            <?php if ($selectedChatId): ?>
                <?php 
                $selectedChat = array_filter($allChats, fn($c) => $c['id'] === $selectedChatId);
                $selectedChat = reset($selectedChat);
                ?>
                <div class="card">
                    <div class="card-header bg-primary text-white">
                        <h5 class="mb-0">Messages: <?= h($selectedChat['display_name'] ?? 'Unknown Chat') ?>
                            <?php 
                            if ($selectedChat && $selectedChat['is_deleted']): 
                            ?>
                                <span class="badge bg-danger ms-2">Chat Deleted</span>
                            <?php endif; ?>
                        </h5>
                    </div>
                    <div class="card-body" style="max-height: 600px; overflow-y: auto;">
                        <div class="messages-container">
                            <?php if (empty($selectedChatMessages)): ?>
                                <div class="alert alert-info">No messages in this chat.</div>
                            <?php else: ?>
                                <?php foreach ($selectedChatMessages as $msg): ?>
                                    <div class="card mb-2 <?= $msg['is_deleted'] ? 'border-danger' : '' ?>">
                                        <div class="card-body p-2">
                                            <div class="d-flex justify-content-between">
                                                <strong><?= h($msg['sender_username'] ?? 'Unknown') ?></strong>
                                                <small class="text-muted"><?= date('M d, H:i', strtotime($msg['created_at'])) ?></small>
                                            </div>
                                            <div class="mt-2">
                                                <?php if ($msg['is_deleted']): ?>
                                                    <em class="text-muted">[Message deleted by <?= h($msg['deleted_by_username'] ?? 'Unknown') ?> on <?= date('M d, H:i', strtotime($msg['deleted_at'])) ?>]</em>
                                                <?php else: ?>
                                                    <?= nl2br(h($msg['message'])) ?>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                    </div>
                                <?php endforeach; ?>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            <?php else: ?>
                <div class="card">
                    <div class="card-body text-center text-muted">
                        <p>Select a chat to view messages</p>
                    </div>
                </div>
            <?php endif; ?>
        </div>
    </div>
</div>

<?php require_once __DIR__ . '/inc/footer.php'; ?>

← Back to Directory Edit File 🔒 Chmod

WP File Manager