上传文件至 /
This commit is contained in:
194
notifications.php
Normal file
194
notifications.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
require_once 'config.php';
|
||||
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 标记通知为已读
|
||||
if (isset($_GET['mark_read'])) {
|
||||
$notification_id = intval($_GET['mark_read']);
|
||||
$stmt = $pdo->prepare("UPDATE notifications SET is_read = TRUE WHERE id = ? AND user_id = ?");
|
||||
$stmt->execute([$notification_id, $_SESSION['user_id']]);
|
||||
header('Location: notifications.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 标记所有为已读
|
||||
if (isset($_POST['mark_all_read'])) {
|
||||
$stmt = $pdo->prepare("UPDATE notifications SET is_read = TRUE WHERE user_id = ?");
|
||||
$stmt->execute([$_SESSION['user_id']]);
|
||||
header('Location: notifications.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 删除通知
|
||||
if (isset($_GET['delete'])) {
|
||||
$notification_id = intval($_GET['delete']);
|
||||
$stmt = $pdo->prepare("DELETE FROM notifications WHERE id = ? AND user_id = ?");
|
||||
$stmt->execute([$notification_id, $_SESSION['user_id']]);
|
||||
header('Location: notifications.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 获取通知列表
|
||||
$notifications = getUserNotifications($_SESSION['user_id'], 50);
|
||||
$unreadCount = getUnreadNotificationCount($_SESSION['user_id']);
|
||||
|
||||
$userSettings = getUserSettings($_SESSION['user_id']);
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN" data-theme="<?php echo $userSettings['dark_mode'] ? 'dark' : 'light'; ?>">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>通知中心 - PicHost</title>
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
<style>
|
||||
.notifications-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.notification-item {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
margin-bottom: 15px;
|
||||
border-radius: 10px;
|
||||
box-shadow: var(--box-shadow);
|
||||
border-left: 4px solid #3498db;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
.notification-item.unread {
|
||||
border-left-color: #e74c3c;
|
||||
background: #fff9f9;
|
||||
}
|
||||
.notification-item.read {
|
||||
opacity: 0.7;
|
||||
}
|
||||
.notification-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.notification-title {
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
.notification-type {
|
||||
padding: 2px 8px;
|
||||
border-radius: 12px;
|
||||
font-size: 0.75rem;
|
||||
background: #f8f9fa;
|
||||
color: #666;
|
||||
}
|
||||
.notification-message {
|
||||
color: #555;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.notification-time {
|
||||
color: #888;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
.notification-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.empty-notifications {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
color: #666;
|
||||
}
|
||||
[data-theme="dark"] .notification-item {
|
||||
background: var(--card-bg);
|
||||
}
|
||||
[data-theme="dark"] .notification-item.unread {
|
||||
background: #2a1f1f;
|
||||
}
|
||||
.notification-announcement { border-left-color: #e74c3c; }
|
||||
.notification-tips { border-left-color: #f39c12; }
|
||||
.notification-feedback { border-left-color: #27ae60; }
|
||||
.notification-image { border-left-color: #9b59b6; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<?php include 'components/navbar.php'; ?>
|
||||
|
||||
<div class="container">
|
||||
<div class="notifications-header">
|
||||
<h1>通知中心</h1>
|
||||
<div>
|
||||
<?php if($unreadCount > 0): ?>
|
||||
<form method="POST" style="display: inline;">
|
||||
<button type="submit" name="mark_all_read" class="btn btn-secondary">
|
||||
标记所有为已读
|
||||
</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<span class="badge"><?php echo $unreadCount; ?> 条未读</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if(empty($notifications)): ?>
|
||||
<div class="empty-notifications">
|
||||
<h3>📭 暂无通知</h3>
|
||||
<p>您还没有收到任何通知</p>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="notifications-list">
|
||||
<?php foreach($notifications as $notification): ?>
|
||||
<div class="notification-item <?php echo $notification['is_read'] ? 'read' : 'unread'; ?> notification-<?php echo $notification['type_name']; ?>">
|
||||
<div class="notification-header">
|
||||
<h3 class="notification-title"><?php echo htmlspecialchars($notification['title']); ?></h3>
|
||||
<span class="notification-type">
|
||||
<?php
|
||||
$typeLabels = [
|
||||
'announcement' => '公告',
|
||||
'tips' => '技巧',
|
||||
'feedback_result' => '反馈',
|
||||
'image_feedback' => '图片'
|
||||
];
|
||||
echo $typeLabels[$notification['type_name']] ?? $notification['type_name'];
|
||||
?>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="notification-message">
|
||||
<?php echo nl2br(htmlspecialchars($notification['message'])); ?>
|
||||
</div>
|
||||
|
||||
<div class="notification-footer">
|
||||
<div class="notification-time">
|
||||
<?php echo date('Y-m-d H:i', strtotime($notification['created_at'])); ?>
|
||||
</div>
|
||||
|
||||
<div class="notification-actions">
|
||||
<?php if(!$notification['is_read']): ?>
|
||||
<a href="notifications.php?mark_read=<?php echo $notification['id']; ?>" class="btn btn-sm">
|
||||
标记已读
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if($notification['related_url']): ?>
|
||||
<a href="<?php echo $notification['related_url']; ?>" class="btn btn-sm btn-primary">
|
||||
查看详情
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
|
||||
<a href="notifications.php?delete=<?php echo $notification['id']; ?>" class="btn btn-sm btn-danger"
|
||||
onclick="return confirm('确定要删除这条通知吗?')">
|
||||
删除
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user