<?php
require_once __DIR__ . '/config/config.php';
require_login();
$u = current_user();

$id = (int)($_GET['id'] ?? 0);
$stmt = $pdo->prepare("SELECT link FROM notifications WHERE id = ? AND user_id = ?");
$stmt->execute([$id, $u['id']]);
$note = $stmt->fetch();

if ($note) {
    $pdo->prepare("UPDATE notifications SET is_read = 1 WHERE id = ?")->execute([$id]);
    redirect($note['link'] ?: 'dashboard.php');
} else {
    redirect('notifications.php');
}
