-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbildirimler.php
More file actions
213 lines (194 loc) · 9.26 KB
/
Copy pathbildirimler.php
File metadata and controls
213 lines (194 loc) · 9.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
declare(strict_types=1);
require_once __DIR__ . '/uygulama/baslat.php';
Auth::requireLogin();
$pdo = Database::getInstance()->getConnection();
$userId = Auth::getUserId();
$pageTitle = 'Bildirimler';
$activeNav = 'notifications';
if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['json'])) {
header('Content-Type: application/json; charset=UTF-8');
header('X-Content-Type-Options: nosniff');
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
echo json_encode([
'unread' => NotificationService::unreadCount($pdo, (int) $userId),
'items' => NotificationService::latest($pdo, (int) $userId, 10),
], JSON_UNESCAPED_UNICODE);
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
Csrf::check();
if (isset($_POST['mark_read_id'])) {
NotificationService::markRead($pdo, (int) $userId, (int) $_POST['mark_read_id']);
if (isset($_POST['ajax'])) {
header('Content-Type: application/json; charset=UTF-8');
echo json_encode(['ok' => true], JSON_UNESCAPED_UNICODE);
exit;
}
Flash::success('Bildirim okundu olarak işaretlendi.');
}
if (isset($_POST['mark_all_read'])) {
NotificationService::markAllRead($pdo, (int) $userId);
Flash::success('Tüm bildirimler okundu olarak işaretlendi.');
}
header('Location: ' . BASE_PATH . '/bildirimler');
exit;
}
$labels = NotificationService::eventLabels();
$filterType = trim((string) ($_GET['type'] ?? ''));
$filterStatus = trim((string) ($_GET['status'] ?? ''));
$page = max(1, (int) ($_GET['page'] ?? 1));
$perPage = 30;
$typeFilterOn = $filterType !== '' && isset($labels[$filterType]);
$statusFilterOn = in_array($filterStatus, ['0', '1'], true);
$notificationParams = [
':uid' => (int) $userId,
':type_filter_on' => $typeFilterOn ? 1 : 0,
':event_key' => $typeFilterOn ? $filterType : '',
':status_filter_on' => $statusFilterOn ? 1 : 0,
':status_value' => $statusFilterOn ? (int) $filterStatus : 0,
];
$countStmt = $pdo->prepare(
"SELECT COUNT(*)
FROM notifications n
WHERE n.recipient_user_id = :uid
AND (:type_filter_on = 0 OR n.event_key = :event_key)
AND (:status_filter_on = 0 OR n.is_read = :status_value)"
);
$countStmt->execute($notificationParams);
$total = (int) $countStmt->fetchColumn();
$totalPages = max(1, (int) ceil($total / $perPage));
if ($page > $totalPages) {
$page = $totalPages;
}
$offset = ($page - 1) * $perPage;
$stmt = $pdo->prepare(
"SELECT n.*
FROM notifications n
WHERE n.recipient_user_id = :uid
AND (:type_filter_on = 0 OR n.event_key = :event_key)
AND (:status_filter_on = 0 OR n.is_read = :status_value)
ORDER BY n.created_at DESC
LIMIT :lim OFFSET :off"
);
foreach ($notificationParams as $key => $value) {
$stmt->bindValue($key, $value);
}
$stmt->bindValue(':lim', $perPage, PDO::PARAM_INT);
$stmt->bindValue(':off', $offset, PDO::PARAM_INT);
$stmt->execute();
$items = array_map([NotificationService::class, 'decorate'], $stmt->fetchAll(PDO::FETCH_ASSOC));
$unread = NotificationService::unreadCount($pdo, (int) $userId);
require_once APP_ROOT . '/uygulama/yerlesim/ust.php';
?>
<div class="d-flex justify-content-between align-items-center mb-3">
<div>
<h5 class="fw-bold mb-0"><i class="bi bi-bell me-2 text-primary"></i>Bildirimler</h5>
<small class="text-muted"><?= number_format($total) ?> bildirim · <?= number_format($unread) ?> okunmamış</small>
</div>
<?php if ($unread > 0): ?>
<form method="POST">
<?= Csrf::field() ?>
<input type="hidden" name="mark_all_read" value="1">
<button class="btn btn-sm btn-outline-primary">
<i class="bi bi-check2-all me-1"></i>Tümünü Okundu İşaretle
</button>
</form>
<?php endif; ?>
</div>
<div class="card mb-3">
<div class="card-body py-2">
<form method="GET" action="<?= BASE_PATH ?>/bildirimler" class="row g-2 align-items-end">
<div class="col-md-3">
<label class="form-label mb-1 small">Olay</label>
<select name="type" class="form-select form-select-sm">
<option value="">Tümü</option>
<?php foreach ($labels as $key => $cfg): ?>
<option value="<?= htmlspecialchars($key, ENT_QUOTES, 'UTF-8') ?>" <?= $filterType === $key ? 'selected' : '' ?>>
<?= htmlspecialchars($cfg['label'], ENT_QUOTES, 'UTF-8') ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-3">
<label class="form-label mb-1 small">Durum</label>
<select name="status" class="form-select form-select-sm">
<option value="" <?= $filterStatus === '' ? 'selected' : '' ?>>Tümü</option>
<option value="0" <?= $filterStatus === '0' ? 'selected' : '' ?>>Okunmamış</option>
<option value="1" <?= $filterStatus === '1' ? 'selected' : '' ?>>Okundu</option>
</select>
</div>
<div class="col-md-3 d-flex gap-2">
<button class="btn btn-sm btn-primary"><i class="bi bi-funnel me-1"></i>Filtrele</button>
<a href="<?= BASE_PATH ?>/bildirimler" class="btn btn-sm btn-outline-secondary"><i class="bi bi-x"></i></a>
</div>
</form>
</div>
</div>
<div class="card">
<div class="list-group list-group-flush">
<?php if (empty($items)): ?>
<div class="text-center text-muted py-4">Bildirim bulunamadı.</div>
<?php endif; ?>
<?php foreach ($items as $n): ?>
<div class="list-group-item d-flex gap-3 align-items-start <?= !$n['is_read'] ? 'bg-primary-subtle' : '' ?>">
<div class="mt-1">
<span class="badge bg-<?= htmlspecialchars($n['type_cls'], ENT_QUOTES, 'UTF-8') ?>-subtle text-<?= htmlspecialchars($n['type_cls'], ENT_QUOTES, 'UTF-8') ?> p-2">
<i class="bi <?= htmlspecialchars($n['icon'], ENT_QUOTES, 'UTF-8') ?>"></i>
</span>
</div>
<div class="flex-grow-1" style="min-width:0;">
<div class="d-flex justify-content-between align-items-start gap-3">
<div style="min-width:0;">
<div class="fw-semibold"><?= htmlspecialchars($n['title'], ENT_QUOTES, 'UTF-8') ?></div>
<div class="small text-muted"><?= htmlspecialchars($n['message'], ENT_QUOTES, 'UTF-8') ?></div>
</div>
<div class="text-end" style="white-space:nowrap;">
<span class="badge bg-<?= htmlspecialchars($n['type_cls'], ENT_QUOTES, 'UTF-8') ?>-subtle text-<?= htmlspecialchars($n['type_cls'], ENT_QUOTES, 'UTF-8') ?>">
<?= htmlspecialchars($n['type_label'], ENT_QUOTES, 'UTF-8') ?>
</span>
<div class="small text-muted"><?= htmlspecialchars($n['created_at'], ENT_QUOTES, 'UTF-8') ?></div>
</div>
</div>
<div class="mt-2 d-flex gap-2">
<?php if (!empty($n['link'])): ?>
<a href="<?= htmlspecialchars($n['link'], ENT_QUOTES, 'UTF-8') ?>" class="btn btn-sm btn-outline-primary">
<i class="bi bi-box-arrow-up-right me-1"></i>Git
</a>
<?php endif; ?>
<?php if (!$n['is_read']): ?>
<form method="POST" class="d-inline">
<?= Csrf::field() ?>
<input type="hidden" name="mark_read_id" value="<?= (int) $n['id'] ?>">
<button class="btn btn-sm btn-outline-secondary"><i class="bi bi-check2 me-1"></i>Okundu</button>
</form>
<?php endif; ?>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php if ($totalPages > 1):
$baseQuery = [];
if ($typeFilterOn) {
$baseQuery['type'] = $filterType;
}
if ($statusFilterOn) {
$baseQuery['status'] = $filterStatus;
}
$pageUrl = function (int $p) use ($baseQuery): string {
return '?' . http_build_query(array_merge($baseQuery, ['page' => $p]));
};
?>
<nav class="mt-3">
<ul class="pagination pagination-sm mb-0 justify-content-center">
<li class="page-item <?php echo $page <= 1 ? 'disabled' : ''; ?>"><a class="page-link" href="<?php echo htmlspecialchars($pageUrl(max(1, $page - 1)), ENT_QUOTES, 'UTF-8'); ?>">«</a></li>
<?php for ($p = max(1, $page - 3); $p <= min($totalPages, $page + 3); $p++): ?>
<li class="page-item <?php echo $p === $page ? 'active' : ''; ?>"><a class="page-link" href="<?php echo htmlspecialchars($pageUrl($p), ENT_QUOTES, 'UTF-8'); ?>"><?php echo htmlentities((string) (int) $p, ENT_QUOTES, 'UTF-8'); ?></a></li>
<?php endfor; ?>
<li class="page-item <?php echo $page >= $totalPages ? 'disabled' : ''; ?>"><a class="page-link" href="<?php echo htmlspecialchars($pageUrl(min($totalPages, $page + 1)), ENT_QUOTES, 'UTF-8'); ?>">»</a></li>
</ul>
</nav>
<?php endif; ?>
<?php require_once APP_ROOT . '/uygulama/yerlesim/alt.php'; ?>