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: notifications.php

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

Size: 3.24 KB

Permissions: 0666

<?php
require_once 'config.php';
require_once 'inc/eventlog.php';
if(!is_logged_in()){ header('Location: index.php'); exit; }
$user = current_user();
include __DIR__ . '/inc/header.php';

// Mark all as read if requested
if (isset($_GET['mark_all_read'])) {
    $pdo->prepare('UPDATE notifications SET is_read = 1 WHERE user_id = ?')->execute([$user['id']]);
    
    // Log the event
    log_event('notifications_marked_all_read', ['user_id' => $user['id']]);
    
    echo "<script>window.location.href='notifications.php';</script>";
    exit;
}

// Pagination
$page = intval($_GET['page'] ?? 1);
$per_page = 20;
$offset = ($page - 1) * $per_page;

// Get notifications
$stmt = $pdo->prepare('SELECT * FROM notifications WHERE user_id = ? ORDER BY created_at DESC LIMIT ? OFFSET ?');
$stmt->bindValue(1, $user['id'], PDO::PARAM_INT);
$stmt->bindValue(2, $per_page, PDO::PARAM_INT);
$stmt->bindValue(3, $offset, PDO::PARAM_INT);
$stmt->execute();
$notifications = $stmt->fetchAll();

// Get total count
$stmt = $pdo->prepare('SELECT COUNT(*) FROM notifications WHERE user_id = ?');
$stmt->execute([$user['id']]);
$total_count = $stmt->fetchColumn();
$total_pages = ceil($total_count / $per_page);
?>

<div class="container mt-4">
  <h4 class="mb-4">Notifications</h4>

  <?php if ($total_count > 0): ?>
    <div class="mb-3">
      <a href="?mark_all_read=1" class="btn btn-primary" onclick="return confirm('Mark all notifications as read?')">Mark All as Read</a>
    </div>
  <?php endif; ?>

  <?php if (empty($notifications)): ?>
    <div class="alert alert-info">No notifications found.</div>
  <?php else: ?>
    <div class="list-group">
      <?php foreach ($notifications as $notif): ?>
        <div class="list-group-item <?= $notif['is_read'] ? '' : 'list-group-item-warning' ?>">
          <div class="d-flex w-100 justify-content-between">
            <h6 class="mb-1 <?= $notif['is_read'] ? '' : 'fw-bold' ?>"><?= h($notif['message']) ?></h6>
            <small class="text-muted"><?= date('M d, Y H:i', strtotime($notif['created_at'])) ?></small>
          </div>
          <?php if (!$notif['is_read']): ?>
            <button class="btn btn-sm btn-outline-primary mt-2" onclick="markAsRead(<?= $notif['id'] ?>)">Mark as Read</button>
          <?php endif; ?>
        </div>
      <?php endforeach; ?>
    </div>

    <!-- Pagination -->
    <?php if ($total_pages > 1): ?>
      <nav aria-label="Notifications pagination" class="mt-4">
        <ul class="pagination justify-content-center">
          <?php for ($i = 1; $i <= $total_pages; $i++): ?>
            <li class="page-item <?= $i === $page ? 'active' : '' ?>">
              <a class="page-link" href="?page=<?= $i ?>"><?= $i ?></a>
            </li>
          <?php endfor; ?>
        </ul>
      </nav>
    <?php endif; ?>
  <?php endif; ?>
</div>

<script>
function markAsRead(notificationId) {
  fetch('<?= BASE_URL ?>/api/mark_notification_read.php', {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify({id: notificationId})
  }).then(response => response.json()).then(data => {
    if (data.success) {
      location.reload();
    }
  });
}
</script>

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

← Back to Directory Edit File 🔒 Chmod

WP File Manager