-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotices_admin.php
More file actions
303 lines (252 loc) · 6.89 KB
/
Copy pathnotices_admin.php
File metadata and controls
303 lines (252 loc) · 6.89 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
<?php
session_start();
require "config.php";
/* -------------------------------
AUTH CHECK
-------------------------------- */
if (!isset($_SESSION['id'])) {
die("Access denied.");
}
$posted_by = $_SESSION['id'];
/* -------------------------------
HANDLE POST
-------------------------------- */
$success = "";
if ($_SERVER['REQUEST_METHOD'] === "POST") {
$title = trim($_POST['title']);
$body = trim($_POST['body']);
$visible_to = trim($_POST['visible_to']);
$stmt = $pdo->prepare("
INSERT INTO notices (title, body, posted_by, visible_to, created_at)
VALUES (?, ?, ?, ?, NOW())
");
$stmt->execute([$title, $body, $posted_by, $visible_to]);
$success = "Notice posted successfully.";
}
/* -------------------------------
FETCH NOTICES
-------------------------------- */
$all_notices = $pdo->query("
SELECT n.*, u.full_name
FROM notices n
LEFT JOIN users u ON n.posted_by = u.id
ORDER BY n.created_at DESC
")->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Admin | Notice Board</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
* { box-sizing: border-box; }
body {
margin: 0;
font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
background: #eef1f6;
color: #333;
}
/* -------- PAGE WRAPPER -------- */
.wrapper {
max-width: 1100px;
margin: 35px auto;
padding: 0 20px;
}
/* -------- HEADER -------- */
.page-header {
background: linear-gradient(90deg, #002d72, #0057c4);
color: #fff;
padding: 22px 30px;
border-radius: 14px;
margin-bottom: 25px;
display: flex;
justify-content: space-between;
align-items: center;
}
.page-header h1 {
margin: 0;
font-size: 24px;
font-weight: 600;
}
.page-header span {
font-size: 14px;
opacity: 0.9;
}
/* -------- CARDS -------- */
.card {
background: #fff;
border-radius: 14px;
padding: 25px;
box-shadow: 0 10px 30px rgba(0,0,0,0.08);
margin-bottom: 25px;
}
/* -------- FORM -------- */
.form-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
.form-group {
display: flex;
flex-direction: column;
}
.form-group.full {
grid-column: 1 / -1;
}
label {
font-weight: 600;
font-size: 14px;
margin-bottom: 6px;
}
input, textarea, select {
padding: 13px;
border-radius: 8px;
border: 1px solid #ccc;
font-size: 15px;
transition: 0.2s;
}
textarea { resize: vertical; min-height: 120px; }
input:focus,
textarea:focus,
select:focus {
border-color: #0057c4;
outline: none;
box-shadow: 0 0 0 3px rgba(0,87,196,0.15);
}
/* -------- BUTTON -------- */
.btn {
background: #0057c4;
color: #fff;
border: none;
padding: 13px 22px;
border-radius: 8px;
font-size: 15px;
font-weight: 600;
cursor: pointer;
transition: 0.2s;
}
.btn:hover {
background: #003f8c;
}
/* -------- SUCCESS ALERT -------- */
.alert-success {
background: #e6f6ec;
color: #0b6b2f;
border-left: 5px solid #28a745;
padding: 14px 18px;
border-radius: 8px;
margin-bottom: 20px;
font-size: 14px;
}
/* -------- NOTICE LIST -------- */
.notice-item {
border-left: 5px solid #0057c4;
padding-left: 18px;
margin-bottom: 18px;
}
.notice-title {
font-weight: 600;
font-size: 16px;
}
.notice-meta {
font-size: 13px;
color: #666;
margin: 4px 0 10px;
}
.notice-body {
font-size: 14px;
line-height: 1.6;
}
.notice-tag {
display: inline-block;
margin-top: 10px;
font-size: 12px;
padding: 4px 10px;
border-radius: 20px;
background: #eef1f6;
color: #444;
}
.close-btn {
background: #2563eb;
color: #fff;
padding: 10px 14px;
border-radius: 6px;
text-decoration: none;
font-weight: 600;
cursor: pointer;
}
/* -------- RESPONSIVE -------- */
@media (max-width: 768px) {
.form-grid {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="wrapper">
<!-- HEADER -->
<span class="close-btn" title="Close" onclick="window.location='student_dashboard.php'">×</span>
<div class="page-header">
<div>
<h1>📢 Notice Board</h1>
<span>Create and manage school-wide announcements</span>
</div>
</div>
<!-- SUCCESS -->
<?php if (!empty($success)): ?>
<div class="alert-success">✔ <?= htmlspecialchars($success) ?></div>
<?php endif; ?>
<!-- POST NOTICE -->
<div class="card">
<form method="POST">
<div class="form-grid">
<div class="form-group full">
<label>Notice Title</label>
<input type="text" name="title" placeholder="e.g. Mid-Semester Break" required>
</div>
<div class="form-group full">
<label>Notice Message</label>
<textarea name="body" placeholder="Write the notice details here..." required></textarea>
</div>
<div class="form-group">
<label>Visible To</label>
<select name="visible_to" required>
<option value="all">All Users</option>
<option value="students">Students</option>
<option value="teachers">Teachers</option>
<option value="staff">Staff</option>
</select>
</div>
<div class="form-group" style="align-self:flex-end;">
<button class="btn" type="submit">Post Notice</button>
</div>
</div>
</form>
</div>
<!-- NOTICE LIST -->
<div class="card">
<h2 style="margin-top:0;">📄 Posted Notices</h2>
<?php if (empty($all_notices)): ?>
<p>No notices available.</p>
<?php endif; ?>
<?php foreach ($all_notices as $n): ?>
<div class="notice-item">
<div class="notice-title"><?= htmlspecialchars($n['title']) ?></div>
<div class="notice-meta">
Posted by <?= htmlspecialchars($n['full_name'] ?: 'System') ?>
• <?= date("M d, Y H:i", strtotime($n['created_at'])) ?>
</div>
<div class="notice-body">
<?= nl2br(htmlspecialchars($n['body'])) ?>
</div>
<div class="notice-tag">
Visible to: <?= ucfirst($n['visible_to']) ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</body>
</html>