-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
500 lines (461 loc) · 29.9 KB
/
Copy pathadmin.php
File metadata and controls
500 lines (461 loc) · 29.9 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
<?php
$c = require __DIR__ . '/config.php';
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['password'])) {
if ($_POST['password'] === $c['admin_password']) {
$_SESSION['admin'] = true;
} else {
$login_error = true;
}
}
if (!($_SESSION['admin'] ?? false)) {
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Admin Login</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet" />
<style>
body { font-family: 'Inter', sans-serif; display:flex; align-items:center; justify-content:center; min-height:100vh; background:#f5e6d3; margin:0; }
.box { background:#fff; padding:40px; border-radius:16px; box-shadow:0 8px 32px rgba(0,0,0,.1); width:320px; }
h2 { font-size:22px; color:#2d1a0e; margin-bottom:20px; }
input[type=password] { width:100%; padding:11px 13px; border:1.5px solid #e5d5c5; border-radius:8px; font-size:15px; margin-bottom:14px; outline:none; }
input[type=password]:focus { border-color:#c07840; }
button { width:100%; padding:12px; background:#c07840; color:#fff; border:none; border-radius:8px; font-size:15px; font-weight:600; cursor:pointer; }
.err { color:#b91c1c; font-size:13px; margin-bottom:12px; }
</style>
</head>
<body>
<div class="box">
<h2>Memory Book Admin</h2>
<?php if (!empty($login_error)): ?><p class="err">Wrong password.</p><?php endif; ?>
<form method="post">
<input type="password" name="password" placeholder="Password" autofocus />
<button type="submit">Log In</button>
</form>
</div>
</body>
</html>
<?php
exit;
}
$data_file = __DIR__ . '/submissions/data.json';
$data = [];
if (file_exists($data_file)) {
$data = json_decode(file_get_contents($data_file), true) ?? [];
}
usort($data, fn($a, $b) => strcmp($b['timestamp'], $a['timestamp']));
$memorial_file = __DIR__ . '/submissions/memorial.json';
$memorial = [];
if (file_exists($memorial_file)) {
$memorial = json_decode(file_get_contents($memorial_file), true) ?? [];
}
usort($memorial, fn($a, $b) => strcmp(strtolower($a['name']), strtolower($b['name'])));
// ── Edit submission ──────────────────────────────────────────────────────────
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'edit') {
$edit_id = $_POST['edit_id'] ?? '';
if ($edit_id && file_exists($data_file)) {
$fp = fopen($data_file, 'c+');
if (flock($fp, LOCK_EX)) {
$rows = json_decode(stream_get_contents($fp, -1, 0), true) ?? [];
foreach ($rows as &$row) {
if (($row['id'] ?? '') !== $edit_id) continue;
if (trim($_POST['edit_name'] ?? '')) $row['name'] = trim($_POST['edit_name']);
$row['memory'] = trim($_POST['edit_memory'] ?? '');
$row['whereNow'] = trim($_POST['edit_whereNow'] ?? '');
$row['message'] = trim($_POST['edit_message'] ?? '');
break;
}
unset($row);
ftruncate($fp, 0); rewind($fp);
fwrite($fp, json_encode($rows, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
flock($fp, LOCK_UN);
}
fclose($fp);
}
header('Location: admin.php'); exit;
}
// ── Delete submission ────────────────────────────────────────────────────────
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'delete_person') {
$del_id = $_POST['sub_id'] ?? '';
$upload_dir = __DIR__ . '/uploads/photos/';
if ($del_id && file_exists($data_file)) {
$fp = fopen($data_file, 'c+');
if (flock($fp, LOCK_EX)) {
$rows = json_decode(stream_get_contents($fp, -1, 0), true) ?? [];
$rows = array_values(array_filter($rows, function($row) use ($del_id, $upload_dir) {
if (($row['id'] ?? '') !== $del_id) return true;
foreach ($row['photos'] ?? [] as $photo) {
if ($photo && file_exists($upload_dir . $photo)) @unlink($upload_dir . $photo);
}
return false;
}));
ftruncate($fp, 0); rewind($fp);
fwrite($fp, json_encode($rows, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
flock($fp, LOCK_UN);
}
fclose($fp);
}
header('Location: admin.php'); exit;
}
// ── Photo management (replace / delete / add) ────────────────────────────────
if ($_SERVER['REQUEST_METHOD'] === 'POST' && in_array($_POST['action'] ?? '', ['replace_photo','delete_photo','add_photo'])) {
$sub_id = $_POST['sub_id'] ?? '';
$action = $_POST['action'];
$photo_idx = (int)($_POST['photo_index'] ?? 0);
$upload_dir = __DIR__ . '/uploads/photos/';
$allowed = ['jpg','jpeg','png','gif','webp','heic'];
$max_size = 10 * 1024 * 1024;
if (!is_dir($upload_dir)) mkdir($upload_dir, 0755, true);
if ($sub_id && file_exists($data_file)) {
$fp = fopen($data_file, 'c+');
if (flock($fp, LOCK_EX)) {
$rows = json_decode(stream_get_contents($fp, -1, 0), true) ?? [];
foreach ($rows as &$row) {
if (($row['id'] ?? '') !== $sub_id) continue;
if ($action === 'delete_photo') {
$old = $row['photos'][$photo_idx] ?? '';
if ($old && file_exists($upload_dir . $old)) @unlink($upload_dir . $old);
array_splice($row['photos'], $photo_idx, 1);
} elseif (in_array($action, ['replace_photo','add_photo'])) {
$file = $_FILES['new_photo'] ?? null;
if ($file && $file['error'] === UPLOAD_ERR_OK && $file['size'] <= $max_size) {
$ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
if (in_array($ext, $allowed)) {
$new_name = uniqid('photo_', true) . '.' . $ext;
if (move_uploaded_file($file['tmp_name'], $upload_dir . $new_name)) {
if ($action === 'replace_photo') {
$old = $row['photos'][$photo_idx] ?? '';
if ($old && file_exists($upload_dir . $old)) @unlink($upload_dir . $old);
$row['photos'][$photo_idx] = $new_name;
} else {
$row['photos'][] = $new_name;
}
}
}
}
}
break;
}
unset($row);
ftruncate($fp, 0); rewind($fp);
fwrite($fp, json_encode($rows, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
flock($fp, LOCK_UN);
}
fclose($fp);
}
header('Location: admin.php'); exit;
}
// ── Memorial: add ────────────────────────────────────────────────────────────
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'add_memorial') {
$name = trim($_POST['mem_name'] ?? '');
if ($name) {
if (!is_dir(dirname($memorial_file))) mkdir(dirname($memorial_file), 0755, true);
$rows = file_exists($memorial_file) ? (json_decode(file_get_contents($memorial_file), true) ?? []) : [];
$rows[] = ['id' => 'mem_' . uniqid(), 'name' => $name, 'years' => '', 'remembering' => '', 'memory' => '', 'photos' => []];
usort($rows, fn($a, $b) => strcmp(strtolower($a['name']), strtolower($b['name'])));
file_put_contents($memorial_file, json_encode($rows, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
}
header('Location: admin.php#memorial'); exit;
}
// ── Memorial: edit ───────────────────────────────────────────────────────────
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'edit_memorial') {
$mem_id = $_POST['mem_id'] ?? '';
if ($mem_id && file_exists($memorial_file)) {
$rows = json_decode(file_get_contents($memorial_file), true) ?? [];
foreach ($rows as &$row) {
if ($row['id'] !== $mem_id) continue;
if (trim($_POST['mem_name'] ?? '')) $row['name'] = trim($_POST['mem_name']);
$row['years'] = trim($_POST['mem_years'] ?? '');
$row['remembering'] = trim($_POST['mem_remembering'] ?? '');
$row['memory'] = trim($_POST['mem_memory'] ?? '');
break;
}
unset($row);
file_put_contents($memorial_file, json_encode($rows, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
}
header('Location: admin.php#memorial'); exit;
}
// ── Memorial: photo management ───────────────────────────────────────────────
if ($_SERVER['REQUEST_METHOD'] === 'POST' && in_array($_POST['action'] ?? '', ['add_memorial_photo','replace_memorial_photo','delete_memorial_photo'])) {
$mem_id = $_POST['mem_id'] ?? '';
$action = $_POST['action'];
$photo_idx = (int)($_POST['photo_index'] ?? 0);
$upload_dir = __DIR__ . '/uploads/photos/';
$allowed = ['jpg','jpeg','png','gif','webp','heic'];
$max_size = 10 * 1024 * 1024;
if (!is_dir($upload_dir)) mkdir($upload_dir, 0755, true);
if (!is_dir(dirname($memorial_file))) mkdir(dirname($memorial_file), 0755, true);
if ($mem_id && file_exists($memorial_file)) {
$rows = json_decode(file_get_contents($memorial_file), true) ?? [];
foreach ($rows as &$row) {
if ($row['id'] !== $mem_id) continue;
if ($action === 'delete_memorial_photo') {
$old = $row['photos'][$photo_idx] ?? '';
if ($old && file_exists($upload_dir . $old)) @unlink($upload_dir . $old);
array_splice($row['photos'], $photo_idx, 1);
} elseif (in_array($action, ['add_memorial_photo','replace_memorial_photo'])) {
$file = $_FILES['new_photo'] ?? null;
if ($file && $file['error'] === UPLOAD_ERR_OK && $file['size'] <= $max_size) {
$ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
if (in_array($ext, $allowed)) {
$new_name = uniqid('photo_', true) . '.' . $ext;
if (move_uploaded_file($file['tmp_name'], $upload_dir . $new_name)) {
if ($action === 'replace_memorial_photo') {
$old = $row['photos'][$photo_idx] ?? '';
if ($old && file_exists($upload_dir . $old)) @unlink($upload_dir . $old);
$row['photos'][$photo_idx] = $new_name;
} else {
$row['photos'][] = $new_name;
}
}
}
}
}
break;
}
unset($row);
file_put_contents($memorial_file, json_encode($rows, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
}
header('Location: admin.php#memorial'); exit;
}
// ── Memorial: delete ─────────────────────────────────────────────────────────
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'delete_memorial') {
$mem_id = $_POST['mem_id'] ?? '';
$upload_dir = __DIR__ . '/uploads/photos/';
if ($mem_id && file_exists($memorial_file)) {
$rows = json_decode(file_get_contents($memorial_file), true) ?? [];
$rows = array_values(array_filter($rows, function($row) use ($mem_id, $upload_dir) {
if ($row['id'] !== $mem_id) return true;
foreach ($row['photos'] ?? [] as $photo) {
if ($photo && file_exists($upload_dir . $photo)) @unlink($upload_dir . $photo);
}
return false;
}));
file_put_contents($memorial_file, json_encode($rows, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
}
header('Location: admin.php#memorial'); exit;
}
$total = count($data);
$with_photo = count(array_filter($data, fn($s) => !empty($s['photos'])));
$with_email = count(array_filter($data, fn($s) => !empty($s['email'])));
$still_waiting = max(0, (int)$c['expected_count'] - $total);
function h($s) { return htmlspecialchars($s ?? '', ENT_QUOTES); }
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Memory Book Admin</title>
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@700&family=Inter:wght@400;500;600&display=swap" rel="stylesheet" />
<style>
*, *::before, *::after { box-sizing: border-box; margin:0; padding:0; }
body { font-family:'Inter',sans-serif; background:#f5ece0; color:#2d1a0e; min-height:100vh; }
.topbar { background:#2d1a0e; color:#fff; padding:14px 32px; display:flex; align-items:center; justify-content:space-between; }
.topbar h1 { font-family:'Playfair Display',serif; font-size:22px; }
.topbar a { color:#e8a063; font-size:13px; text-decoration:none; }
.stats { display:flex; gap:16px; padding:24px 32px; flex-wrap:wrap; }
.stat-card { background:#fff; border-radius:12px; padding:18px 24px; box-shadow:0 2px 12px rgba(0,0,0,.07); min-width:130px; }
.stat-card .num { font-size:36px; font-weight:700; color:#c07840; }
.stat-card .lbl { font-size:13px; color:#6b4c36; margin-top:2px; }
.search-bar { padding: 0 32px 20px; }
.search-bar input { width:100%; max-width:400px; padding:10px 14px; border:1.5px solid #e5d5c5; border-radius:8px; font-size:14px; outline:none; background:#fff; }
.search-bar input:focus { border-color:#c07840; }
.submissions { padding: 0 32px 48px; }
.sub-card { background:#fff; border-radius:14px; box-shadow:0 2px 12px rgba(0,0,0,.07); margin-bottom:20px; overflow:hidden; }
.sub-header { display:flex; align-items:center; gap:16px; padding:16px 20px; border-bottom:1px solid #f0e4d4; cursor:pointer; user-select:none; }
.sub-header:hover { background:#fdfaf7; }
.sub-avatar { width:52px; height:52px; border-radius:50%; object-fit:cover; flex-shrink:0; border:2px solid #e8d5c5; }
.sub-avatar-placeholder { width:52px; height:52px; border-radius:50%; background:#f0e4d4; display:flex; align-items:center; justify-content:center; font-size:22px; flex-shrink:0; }
.sub-meta { flex:1; }
.sub-meta .sub-name { font-weight:600; font-size:16px; color:#2d1a0e; }
.sub-meta .sub-time { font-size:12px; color:#a08070; margin-top:2px; }
.sub-chevron { color:#a08070; font-size:20px; transition:transform 0.2s; }
.sub-card.open .sub-chevron { transform:rotate(180deg); }
.sub-body { display:none; padding:20px 24px; border-top:1px solid #f0e4d4; }
.sub-card.open .sub-body { display:block; }
.sub-body .field { margin-bottom:18px; }
.sub-body .field-label { font-size:11px; font-weight:700; letter-spacing:2px; text-transform:uppercase; color:#b06a3a; margin-bottom:6px; }
.sub-body .field-value { font-size:14px; line-height:1.65; color:#3d2510; white-space:pre-wrap; }
.empty { text-align:center; padding:60px 20px; color:#a08070; font-size:16px; }
@media(max-width:600px) {
.stats, .submissions, .search-bar { padding-left:16px; padding-right:16px; }
.topbar { padding:14px 16px; }
}
</style>
</head>
<body>
<div class="topbar">
<h1>Memory Book Admin — <?= h($c['group_name']) ?></h1>
<a href="?logout=1">Log out</a>
</div>
<?php
if (isset($_GET['logout'])) { session_destroy(); header('Location: admin.php'); exit; }
?>
<div class="stats">
<div class="stat-card"><div class="num"><?= $total ?></div><div class="lbl">Submissions</div></div>
<div class="stat-card"><div class="num"><?= $with_photo ?></div><div class="lbl">With Photo</div></div>
<div class="stat-card"><div class="num"><?= $still_waiting ?></div><div class="lbl">Still Waiting</div></div>
<div class="stat-card"><div class="num"><?= $with_email ?></div><div class="lbl">Gave Email</div></div>
</div>
<div class="search-bar">
<input type="text" id="search" placeholder="Search by name..." oninput="filterCards(this.value)" />
</div>
<div class="submissions" id="submissions-list">
<?php if (empty($data)): ?>
<div class="empty">No submissions yet. Share the link and they'll start coming in!</div>
<?php else: foreach ($data as $s): ?>
<div class="sub-card" data-name="<?= h(strtolower($s['name'])) ?>">
<div class="sub-header" onclick="this.parentElement.classList.toggle('open')">
<?php if (!empty($s['photos'])): ?>
<img class="sub-avatar" src="uploads/photos/<?= h($s['photos'][0]) ?>" alt="<?= h($s['name']) ?>" loading="lazy" />
<?php else: ?>
<div class="sub-avatar-placeholder">👤</div>
<?php endif; ?>
<div class="sub-meta">
<div class="sub-name"><?= h($s['name']) ?></div>
<div class="sub-time"><?= h($s['timestamp']) ?><?= $s['email'] ? ' · ' . h($s['email']) : '' ?></div>
</div>
<div class="sub-chevron">▾</div>
</div>
<div class="sub-body">
<div class="field" style="margin-bottom:20px;padding-bottom:20px;border-bottom:1px solid #f0e4d4;">
<div class="field-label">Edit</div>
<form method="post" style="display:flex;flex-direction:column;gap:12px;margin-top:10px;">
<input type="hidden" name="action" value="edit" />
<input type="hidden" name="edit_id" value="<?= h($s['id']) ?>" />
<?php
$fs = 'width:100%;padding:8px 11px;border:1.5px solid #e5d5c5;border-radius:7px;font-size:14px;outline:none;font-family:\'Inter\',sans-serif;background:#fdfaf7;color:#2d1a0e;';
$ls = 'font-size:11px;font-weight:700;letter-spacing:.18em;text-transform:uppercase;color:#9a5a2c;display:block;margin-bottom:4px;';
?>
<div><label style="<?= $ls ?>">Name</label><input type="text" name="edit_name" value="<?= h($s['name']) ?>" style="<?= $fs ?>" /></div>
<div><label style="<?= $ls ?>">Favorite Memory</label><textarea name="edit_memory" rows="3" style="<?= $fs ?>resize:vertical;"><?= h($s['memory']) ?></textarea></div>
<div><label style="<?= $ls ?>">Where Are You Now</label><textarea name="edit_whereNow" rows="2" style="<?= $fs ?>resize:vertical;"><?= h($s['whereNow']) ?></textarea></div>
<div><label style="<?= $ls ?>">Message to the Group</label><textarea name="edit_message" rows="2" style="<?= $fs ?>resize:vertical;"><?= h($s['message'] ?? '') ?></textarea></div>
<div><button type="submit" style="padding:9px 20px;background:#c07840;color:#fff;border:none;border-radius:7px;font-size:13px;font-weight:600;cursor:pointer;">Save Changes</button></div>
</form>
</div>
<div class="field">
<div class="field-label">Photos (<?= count($s['photos'] ?? []) ?> / 5)</div>
<div style="display:flex;flex-wrap:wrap;gap:12px;margin-top:8px;align-items:flex-start;">
<?php foreach (($s['photos'] ?? []) as $pi => $photo): ?>
<div style="position:relative;flex-shrink:0;">
<img src="uploads/photos/<?= h($photo) ?>" loading="lazy" style="width:120px;height:120px;object-fit:cover;border-radius:8px;display:block;border:1px solid #e5d5c5;" />
<form method="post" enctype="multipart/form-data" style="display:inline;">
<input type="hidden" name="action" value="replace_photo" /><input type="hidden" name="sub_id" value="<?= h($s['id']) ?>" /><input type="hidden" name="photo_index" value="<?= $pi ?>" />
<label title="Replace" style="position:absolute;bottom:5px;left:5px;background:rgba(0,0,0,0.62);color:#fff;font-size:11px;font-weight:600;padding:3px 8px;border-radius:4px;cursor:pointer;">Replace<input type="file" name="new_photo" accept="image/*" style="display:none;" onchange="this.form.submit()" /></label>
</form>
<form method="post" style="display:inline;" onsubmit="return confirm('Delete this photo from <?= h(addslashes($s['name'])) ?>?')">
<input type="hidden" name="action" value="delete_photo" /><input type="hidden" name="sub_id" value="<?= h($s['id']) ?>" /><input type="hidden" name="photo_index" value="<?= $pi ?>" />
<button type="submit" title="Delete" style="position:absolute;top:5px;right:5px;width:22px;height:22px;background:rgba(0,0,0,0.62);color:#fff;border:none;border-radius:50%;font-size:15px;line-height:1;cursor:pointer;padding:0;">×</button>
</form>
</div>
<?php endforeach; ?>
<?php if (count($s['photos'] ?? []) < 5): ?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="action" value="add_photo" /><input type="hidden" name="sub_id" value="<?= h($s['id']) ?>" />
<label style="display:flex;flex-direction:column;align-items:center;justify-content:center;width:120px;height:120px;border:1.5px dashed #c07840;border-radius:8px;cursor:pointer;color:#c07840;font-size:12px;font-weight:600;gap:6px;background:#fdfaf7;">
<span style="font-size:22px;">+</span>Add Photo<input type="file" name="new_photo" accept="image/*" style="display:none;" onchange="this.form.submit()" />
</label>
</form>
<?php endif; ?>
</div>
</div>
<div style="margin-top:20px;padding-top:16px;border-top:1px solid #f0e4d4;">
<form method="post" onsubmit="return confirm('Permanently delete <?= h(addslashes($s['name'])) ?> and all their photos?')">
<input type="hidden" name="action" value="delete_person" /><input type="hidden" name="sub_id" value="<?= h($s['id']) ?>" />
<button type="submit" style="padding:8px 16px;background:#fff;color:#b91c1c;border:1.5px solid #fca5a5;border-radius:7px;font-size:13px;font-weight:600;cursor:pointer;">Delete Person</button>
</form>
</div>
</div>
</div>
<?php endforeach; endif; ?>
</div>
<script>
function filterCards(query) {
const q = query.toLowerCase();
document.querySelectorAll('.sub-card[data-name]').forEach(card => {
card.style.display = card.dataset.name.includes(q) ? '' : 'none';
});
}
</script>
<!-- ============ MEMORIAL SECTION ============ -->
<div id="memorial" style="padding:0 32px 48px;">
<h2 style="font-family:'Playfair Display',serif;font-size:22px;color:#2d1a0e;margin:0 0 6px;">In Memoriam</h2>
<p style="font-size:13px;color:#9a5a2c;margin:0 0 20px;">These pages appear in the book after a dark divider page, before the class photo.</p>
<?php foreach ($memorial as $m): ?>
<div class="sub-card" style="margin-bottom:20px;">
<div class="sub-header" onclick="this.parentElement.classList.toggle('open')" style="border-left:4px solid #8f4a22;">
<?php if (!empty($m['photos'])): ?>
<img class="sub-avatar" src="uploads/photos/<?= h($m['photos'][0]) ?>" alt="<?= h($m['name']) ?>" loading="lazy" />
<?php else: ?>
<div class="sub-avatar-placeholder" style="background:#ede0d4;">🕯</div>
<?php endif; ?>
<div class="sub-meta">
<div class="sub-name"><?= h($m['name']) ?></div>
<div class="sub-time" style="color:#8f4a22;"><?= $m['years'] ? h($m['years']) : 'Years not set' ?></div>
</div>
<div class="sub-chevron">▾</div>
</div>
<div class="sub-body">
<?php $fs = 'width:100%;padding:8px 11px;border:1.5px solid #e5d5c5;border-radius:7px;font-size:14px;outline:none;font-family:\'Inter\',sans-serif;background:#fdfaf7;color:#2d1a0e;'; $ls = 'font-size:11px;font-weight:700;letter-spacing:.18em;text-transform:uppercase;color:#9a5a2c;display:block;margin-bottom:4px;'; ?>
<div class="field" style="margin-bottom:20px;padding-bottom:20px;border-bottom:1px solid #f0e4d4;">
<div class="field-label">Edit</div>
<form method="post" style="display:flex;flex-direction:column;gap:12px;margin-top:10px;">
<input type="hidden" name="action" value="edit_memorial" /><input type="hidden" name="mem_id" value="<?= h($m['id']) ?>" />
<div><label style="<?= $ls ?>">Name</label><input type="text" name="mem_name" value="<?= h($m['name']) ?>" style="<?= $fs ?>" /></div>
<div><label style="<?= $ls ?>">Years <span style="font-weight:400;color:#a08070;text-transform:none;letter-spacing:0;">(e.g. 1966–2019)</span></label><input type="text" name="mem_years" value="<?= h($m['years']) ?>" placeholder="1966–2019" style="<?= $fs ?>" /></div>
<div><label style="<?= $ls ?>">Remembering</label><textarea name="mem_remembering" rows="4" style="<?= $fs ?>resize:vertical;"><?= h($m['remembering']) ?></textarea></div>
<div><label style="<?= $ls ?>">A Memory We Hold <span style="font-weight:400;color:#a08070;text-transform:none;letter-spacing:0;">(italic quote)</span></label><textarea name="mem_memory" rows="3" style="<?= $fs ?>resize:vertical;"><?= h($m['memory']) ?></textarea></div>
<div><button type="submit" style="padding:9px 20px;background:#8f4a22;color:#fff;border:none;border-radius:7px;font-size:13px;font-weight:600;cursor:pointer;">Save Changes</button></div>
</form>
</div>
<div class="field">
<div class="field-label">Photos (<?= count($m['photos'] ?? []) ?> / 4)</div>
<div style="display:flex;flex-wrap:wrap;gap:12px;margin-top:8px;align-items:flex-start;">
<?php foreach (($m['photos'] ?? []) as $pi => $photo): ?>
<div style="position:relative;flex-shrink:0;">
<img src="uploads/photos/<?= h($photo) ?>" loading="lazy" style="width:120px;height:120px;object-fit:cover;border-radius:8px;display:block;border:2px solid #8f4a22;" />
<form method="post" enctype="multipart/form-data" style="display:inline;">
<input type="hidden" name="action" value="replace_memorial_photo" /><input type="hidden" name="mem_id" value="<?= h($m['id']) ?>" /><input type="hidden" name="photo_index" value="<?= $pi ?>" />
<label title="Replace" style="position:absolute;bottom:5px;left:5px;background:rgba(0,0,0,0.62);color:#fff;font-size:11px;font-weight:600;padding:3px 8px;border-radius:4px;cursor:pointer;">Replace<input type="file" name="new_photo" accept="image/*" style="display:none;" onchange="this.form.submit()" /></label>
</form>
<form method="post" style="display:inline;" onsubmit="return confirm('Delete this photo?')">
<input type="hidden" name="action" value="delete_memorial_photo" /><input type="hidden" name="mem_id" value="<?= h($m['id']) ?>" /><input type="hidden" name="photo_index" value="<?= $pi ?>" />
<button type="submit" style="position:absolute;top:5px;right:5px;width:22px;height:22px;background:rgba(0,0,0,0.62);color:#fff;border:none;border-radius:50%;font-size:15px;line-height:1;cursor:pointer;padding:0;">×</button>
</form>
</div>
<?php endforeach; ?>
<?php if (count($m['photos'] ?? []) < 4): ?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="action" value="add_memorial_photo" /><input type="hidden" name="mem_id" value="<?= h($m['id']) ?>" />
<label style="display:flex;flex-direction:column;align-items:center;justify-content:center;width:120px;height:120px;border:1.5px dashed #8f4a22;border-radius:8px;cursor:pointer;color:#8f4a22;font-size:12px;font-weight:600;gap:6px;background:#fdfaf7;">
<span style="font-size:22px;">+</span>Add Photo<input type="file" name="new_photo" accept="image/*" style="display:none;" onchange="this.form.submit()" />
</label>
</form>
<?php endif; ?>
</div>
</div>
<div style="margin-top:20px;padding-top:16px;border-top:1px solid #f0e4d4;">
<form method="post" onsubmit="return confirm('Remove <?= h(addslashes($m['name'])) ?> from the memorial section?')">
<input type="hidden" name="action" value="delete_memorial" /><input type="hidden" name="mem_id" value="<?= h($m['id']) ?>" />
<button type="submit" style="padding:8px 16px;background:#fff;color:#b91c1c;border:1.5px solid #fca5a5;border-radius:7px;font-size:13px;font-weight:600;cursor:pointer;">Remove from Memorial</button>
</form>
</div>
</div>
</div>
<?php endforeach; ?>
<div style="background:#fff;border-radius:14px;box-shadow:0 2px 12px rgba(0,0,0,.07);padding:20px 24px;border:1.5px dashed #c0a080;">
<div style="font-size:13px;font-weight:700;letter-spacing:.18em;text-transform:uppercase;color:#9a5a2c;margin-bottom:12px;">Add Another Person</div>
<form method="post" style="display:flex;gap:10px;align-items:flex-end;">
<input type="hidden" name="action" value="add_memorial" />
<div style="flex:1;"><input type="text" name="mem_name" placeholder="Full name" required style="width:100%;padding:9px 12px;border:1.5px solid #e5d5c5;border-radius:7px;font-size:14px;outline:none;background:#fdfaf7;" /></div>
<button type="submit" style="padding:9px 20px;background:#8f4a22;color:#fff;border:none;border-radius:7px;font-size:13px;font-weight:600;cursor:pointer;white-space:nowrap;">Add Entry</button>
</form>
</div>
</div>
</body>
</html>