PNG IHDR x sBIT|d pHYs + tEXtSoftware www.inkscape.org< ,tEXtComment
<?php
session_start();
// 1. Ensure user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
$host = 'localhost';
$dbname = 'u264723324_NuDb';
$user = 'u264723324_NuUu';
$pass = '@WdsdsdAq1231';
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $user, $pass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$userId = $_SESSION['user_id'];
// ========================================================================
// AJAX HANDLER: MARK NOTIFICATIONS AS READ
// ========================================================================
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax_action'])) {
header('Content-Type: application/json');
if ($_POST['ajax_action'] === 'mark_all_read') {
$stmt = $pdo->prepare("UPDATE notifications SET is_read = 1 WHERE user_id = ? AND is_read = 0");
$stmt->execute([$userId]);
echo json_encode(['success' => true, 'message' => 'All notifications marked as read.']);
exit;
}
if ($_POST['ajax_action'] === 'mark_single_read') {
$notifId = filter_input(INPUT_POST, 'notif_id', FILTER_VALIDATE_INT);
if ($notifId) {
$stmt = $pdo->prepare("UPDATE notifications SET is_read = 1 WHERE id = ? AND user_id = ?");
$stmt->execute([$notifId, $userId]);
echo json_encode(['success' => true]);
}
exit;
}
}
// ========================================================================
// STANDARD PAGE LOAD
// ========================================================================
$stmt = $pdo->prepare("SELECT first_name, last_name, kyc_status FROM users WHERE id = :id LIMIT 1");
$stmt->execute([':id' => $userId]);
$userRow = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$userRow) { session_destroy(); header("Location: login.php"); exit(); }
$kyc_status = $userRow['kyc_status'];
$fullName = $userRow['first_name'] . ' ' . $userRow['last_name'];
// Fetch Notifications
$stmtNotifs = $pdo->prepare("SELECT * FROM notifications WHERE user_id = ? ORDER BY created_at DESC");
$stmtNotifs->execute([$userId]);
$notifications = $stmtNotifs->fetchAll(PDO::FETCH_ASSOC);
// Count Unread
$unreadCount = 0;
foreach ($notifications as $n) {
if ($n['is_read'] == 0) $unreadCount++;
}
} catch (PDOException $e) {
$kyc_status = 'pending';
$notifications = [];
$unreadCount = 0;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Notifications - City Prime</title>
<style>
:root {
--bg-dark: #0a0e17; --surface-dark: #131a2a; --surface-light: #1e2738;
--accent-blue: #0ea5e9; --accent-yellow: #facc15; --text-main: #f8fafc;
--text-muted: #94a3b8; --danger: #ef4444; --success: #22c55e;
}
* { margin: 0; padding: 0; box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
body { background-color: var(--bg-dark); color: var(--text-main); }
.app-container { display: flex; flex-direction: column; min-height: 100vh; }
.sidebar { display: none; }
.main-content { flex: 1; padding: 20px; padding-bottom: 90px; overflow-x: hidden; }
.top-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.page-title { font-size: 1.5rem; font-weight: 700; display: flex; align-items: center; gap: 12px;}
.unread-badge { background: var(--danger); color: white; font-size: 0.8rem; padding: 2px 8px; border-radius: 12px; font-weight: bold;}
.action-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.mark-read-btn { background: none; border: none; color: var(--accent-blue); font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: 0.2s; }
.mark-read-btn:active { transform: scale(0.95); opacity: 0.8; }
.mark-read-btn:disabled { color: var(--text-muted); cursor: not-allowed; opacity: 0.5; }
/* Notification List Items */
.notif-list { display: flex; flex-direction: column; gap: 12px; }
.notif-card { background: var(--surface-dark); border-radius: 16px; padding: 16px; display: flex; gap: 16px; border: 1px solid rgba(255,255,255,0.02); transition: 0.3s; position: relative; overflow: hidden; cursor: pointer;}
.notif-card:active { transform: scale(0.98); background: var(--surface-light); }
/* Unread Indicator */
.notif-card.unread { border-left: 3px solid var(--accent-blue); background: rgba(14, 165, 233, 0.05); }
.notif-card.unread::before { content: ''; position: absolute; top: 16px; right: 16px; width: 8px; height: 8px; background: var(--accent-blue); border-radius: 50%; box-shadow: 0 0 8px var(--accent-blue);}
.notif-icon { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; flex-shrink: 0; }
.icon-security { background: rgba(239, 68, 68, 0.1); color: var(--danger); }
.icon-transaction { background: rgba(34, 197, 94, 0.1); color: var(--success); }
.icon-system { background: rgba(14, 165, 233, 0.1); color: var(--accent-blue); }
.icon-alert { background: rgba(250, 204, 21, 0.1); color: var(--accent-yellow); }
.notif-content { flex: 1; }
.notif-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px; }
.notif-title { font-size: 1rem; font-weight: 600; color: var(--text-main); line-height: 1.3;}
.notif-time { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; margin-left: 12px;}
.notif-message { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-icon { font-size: 3rem; margin-bottom: 16px; opacity: 0.5; }
/* Bottom Nav */
.bottom-nav { position: fixed; bottom: 0; width: 100%; background: rgba(19, 26, 42, 0.95); backdrop-filter: blur(10px); display: flex; justify-content: space-around; padding: 12px 0 24px 0; border-top: 1px solid rgba(255,255,255,0.05); z-index: 100; }
.nav-item { display: flex; flex-direction: column; align-items: center; color: var(--text-muted); text-decoration: none; font-size: 0.7rem; gap: 4px; }
.nav-item.active { color: var(--accent-blue); }
.nav-icon { position: relative; }
.nav-badge { position: absolute; top: -4px; right: -8px; background: var(--danger); width: 14px; height: 14px; border-radius: 50%; font-size: 0.55rem; color: white; display: flex; align-items: center; justify-content: center; font-weight: bold; border: 2px solid rgba(19, 26, 42, 1);}
/* Toast */
.toast { position: fixed; top: -100px; left: 50%; transform: translateX(-50%); background: var(--success); color: white; padding: 12px 24px; border-radius: 30px; font-size: 0.9rem; font-weight: 600; box-shadow: 0 4px 12px rgba(0,0,0,0.3); transition: 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); z-index: 2000; text-align: center;}
.toast.show { top: 40px; }
@media (min-width: 1024px) {
.app-container { flex-direction: row; }
.bottom-nav { display: none; }
.sidebar { display: flex; flex-direction: column; width: 260px; background: var(--surface-dark); border-right: 1px solid rgba(255,255,255,0.05); padding: 32px 24px; height: 100vh; position: sticky; top: 0; }
.sidebar .logo { font-size: 1.5rem; font-weight: bold; margin-bottom: 48px; color: var(--accent-blue); }
.side-nav { display: flex; flex-direction: column; gap: 12px; }
.side-nav a { color: var(--text-muted); text-decoration: none; padding: 12px 16px; border-radius: 12px; transition: 0.2s; display: flex; align-items: center; gap: 12px; }
.side-nav a:hover, .side-nav a.active { background: rgba(14, 165, 233, 0.1); color: var(--accent-blue); }
.main-content { padding: 40px 60px; max-width: 800px; margin: 0 auto; }
}
</style>
</head>
<body>
<?php if ($kyc_status === 'pending' || $kyc_status === 'rejected'): ?>
<style> body { overflow: hidden !important; } .restriction-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(10, 14, 23, 0.85); backdrop-filter: blur(12px); z-index: 9999; display: flex; align-items: center; justify-content: center; padding: 20px; } .restriction-box { background: var(--surface-dark); border: 1px solid rgba(255,255,255,0.1); padding: 40px; border-radius: 24px; text-align: center; max-width: 450px; box-shadow: 0 20px 50px rgba(0,0,0,0.8); } .logout-btn-large { display: inline-block; width: 100%; background: rgba(239, 68, 68, 0.1); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.3); padding: 16px; border-radius: 12px; text-decoration: none; font-weight: 600; margin-top: 20px;} </style>
<div class="restriction-overlay">
<div class="restriction-box">
<?php if ($kyc_status === 'pending'): ?>
<div style="font-size: 3rem; margin-bottom: 16px;">⏳</div>
<h2 style="margin-bottom: 12px;">Account Under Review</h2>
<p style="color: var(--text-muted); font-size: 0.95rem;">Hello, <?php echo htmlspecialchars($_SESSION['first_name']); ?>. Your inbox is temporarily locked while we verify your identity.</p>
<?php else: ?>
<div style="font-size: 3rem; margin-bottom: 16px;">🚫</div>
<h2 style="margin-bottom: 12px;">Account Restricted</h2>
<p style="color: var(--text-muted); font-size: 0.95rem;">Access to the secure inbox has been disabled. Please contact support.</p>
<?php endif; ?>
<a href="logout.php" class="logout-btn-large">Sign Out</a>
</div>
</div>
<?php endif; ?>
<div id="toast" class="toast"></div>
<div class="app-container">
<aside class="sidebar">
<div class="logo">City Prime</div>
<nav class="side-nav">
<a href="index.php"><span>🏠</span> Home</a>
<a href="activity.php"><span>📊</span> Activity</a>
<a href="transfer.php"><span>💸</span> Transfer</a>
<a href="cards.php"><span>💳</span> Cards</a>
<a href="profile.php"><span>👤</span> Profile</a>
</nav>
</aside>
<main class="main-content">
<header class="top-header">
<h1 class="page-title">
Inbox
<?php if($unreadCount > 0): ?>
<span class="unread-badge" id="headerBadge"><?php echo $unreadCount; ?> New</span>
<?php endif; ?>
</h1>
</header>
<div class="action-bar">
<p style="color: var(--text-muted); font-size: 0.9rem;">Your recent alerts and messages.</p>
<button class="mark-read-btn" id="markAllBtn" onclick="markAllAsRead()" <?php echo ($unreadCount === 0) ? 'disabled' : ''; ?>>
✓ Mark all as read
</button>
</div>
<div class="notif-list" id="notificationList">
<?php if (empty($notifications)): ?>
<div class="empty-state">
<div class="empty-icon">📭</div>
<h3>No Notifications</h3>
<p>You're all caught up! New alerts will appear here.</p>
</div>
<?php else: ?>
<?php foreach ($notifications as $notif):
// Determine styling based on type
$icon = '🔔'; $iconClass = 'icon-alert';
if ($notif['type'] === 'security') { $icon = '🔐'; $iconClass = 'icon-security'; }
elseif ($notif['type'] === 'transaction') { $icon = '💵'; $iconClass = 'icon-transaction'; }
elseif ($notif['type'] === 'system') { $icon = 'ℹ️'; $iconClass = 'icon-system'; }
$readClass = $notif['is_read'] ? '' : 'unread';
// Format Date nicely
$time = strtotime($notif['created_at']);
$timeDisplay = (time() - $time < 86400) ? date("g:i A", $time) : date("M j, Y", $time);
?>
<div class="notif-card <?php echo $readClass; ?>" id="notif-<?php echo $notif['id']; ?>" onclick="markSingleAsRead(<?php echo $notif['id']; ?>, this)">
<div class="notif-icon <?php echo $iconClass; ?>"><?php echo $icon; ?></div>
<div class="notif-content">
<div class="notif-header">
<h4 class="notif-title"><?php echo htmlspecialchars($notif['title']); ?></h4>
<span class="notif-time"><?php echo $timeDisplay; ?></span>
</div>
<p class="notif-message"><?php echo htmlspecialchars($notif['message']); ?></p>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</main>
<nav class="bottom-nav">
<a href="activity.php" class="nav-item"><span class="nav-icon">📊</span>Activity</a>
<a href="transfer.php" class="nav-item"><span class="nav-icon">💸</span>Transfer</a>
<a href="index.php" class="nav-item"><span class="nav-icon">🏠</span>Home</a>
<a href="cards.php" class="nav-item"><span class="nav-icon">💳</span>Cards</a>
<a href="profile.php" class="nav-item"><span class="nav-icon">👤</span>Profile</a>
</nav>
</div>
<script>
function showToast(msg) {
const toast = document.getElementById('toast');
toast.textContent = msg;
toast.classList.add('show');
setTimeout(() => { toast.classList.remove('show'); }, 3000);
}
function markAllAsRead() {
const btn = document.getElementById('markAllBtn');
if (btn.disabled) return;
const formData = new FormData();
formData.append('ajax_action', 'mark_all_read');
fetch('notification.php', { method: 'POST', body: formData })
.then(res => res.json())
.then(data => {
if(data.success) {
// Visually update all cards
document.querySelectorAll('.notif-card.unread').forEach(card => {
card.classList.remove('unread');
});
// Update UI elements
btn.disabled = true;
const badge = document.getElementById('headerBadge');
if(badge) badge.style.display = 'none';
showToast(data.message);
}
});
}
function markSingleAsRead(id, element) {
// Only trigger AJAX if it is currently unread
if (!element.classList.contains('unread')) return;
const formData = new FormData();
formData.append('ajax_action', 'mark_single_read');
formData.append('notif_id', id);
fetch('notification.php', { method: 'POST', body: formData })
.then(res => res.json())
.then(data => {
if(data.success) {
element.classList.remove('unread');
// Update header count visually
const badge = document.getElementById('headerBadge');
if (badge) {
let currentCount = parseInt(badge.innerText);
if (!isNaN(currentCount) && currentCount > 1) {
badge.innerText = (currentCount - 1) + " New";
} else {
badge.style.display = 'none';
document.getElementById('markAllBtn').disabled = true;
}
}
}
});
}
</script>
</body>
</html>
b IDATxytVսϓ22 A@IR:hCiZ[v*E:WũZA ^dQeQ @ !jZ'>gsV仿$|?g)&x-E