-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_view_timetable.php
More file actions
223 lines (192 loc) · 5.91 KB
/
Copy pathadmin_view_timetable.php
File metadata and controls
223 lines (192 loc) · 5.91 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
<?php
session_start();
require "config.php";
if (!isset($_SESSION['id']) || $_SESSION['role'] !== 'admin') {
die("Access denied");
}
/* FETCH DROPDOWNS */
$teachers = $pdo->query("
SELECT id, full_name
FROM users
WHERE role = 'teacher'
ORDER BY full_name
")->fetchAll(PDO::FETCH_ASSOC);
$courses = $pdo->query("
SELECT id, code, title
FROM courses
ORDER BY code
")->fetchAll(PDO::FETCH_ASSOC);
$subjects = $pdo->query("
SELECT id, subject_code, subject_title
FROM course_subjects
ORDER BY subject_title
")->fetchAll(PDO::FETCH_ASSOC);
$levels = $pdo->query("SELECT id, level_name FROM levels")->fetchAll(PDO::FETCH_ASSOC);
$departments = $pdo->query("SELECT id, name FROM departments")->fetchAll(PDO::FETCH_ASSOC);
/* SAVE TIMETABLE */
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$required = ['day','start_time','end_time','course_id','subject_id','teacher_id','level_id','department_id','start_date','end_date'];
foreach ($required as $field) {
if (empty($_POST[$field])) {
die("Missing required field: $field");
}
}
$stmt = $pdo->prepare("
INSERT INTO timetables
(day, start_time, end_time, course_id, subject_id, teacher_id, level_id, department_id, venue, start_date, end_date, recurring)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
");
$stmt->execute([
$_POST['day'],
$_POST['start_time'],
$_POST['end_time'],
$_POST['course_id'],
$_POST['subject_id'],
$_POST['teacher_id'],
$_POST['level_id'],
$_POST['department_id'],
$_POST['venue'] ?? null,
$_POST['start_date'],
$_POST['end_date'],
'weekly'
]);
$success = true;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Admin • Create Timetable</title>
<style>
body {
font-family: "Segoe UI", Tahoma, Arial;
background: #f4f6f9;
padding: 40px;
}
.card {
max-width: 720px;
background: #fff;
padding: 30px;
border-radius: 14px;
margin: auto;
box-shadow: 0 12px 30px rgba(0,0,0,.08);
}
h2 {
margin-bottom: 20px;
}
label {
font-size: 0.85rem;
font-weight: 600;
display: block;
margin-top: 14px;
}
select, input {
width: 100%;
padding: 10px;
border-radius: 8px;
border: 1px solid #d1d5db;
margin-top: 6px;
}
button {
margin-top: 25px;
padding: 12px;
width: 100%;
background: #2563eb;
color: white;
border: none;
border-radius: 8px;
font-weight: 600;
cursor: pointer;
}
.success {
background: #dcfce7;
padding: 12px;
border-radius: 8px;
margin-bottom: 15px;
color: #166534;
}
.close-btn {
background: #2563eb;
color: #fff;
padding: 10px 14px;
border-radius: 6px;
text-decoration: none;
font-weight: 600;
cursor: pointer;
}
</style>
</head>
<body>
<div class="card">
<span class="close-btn" title="Close" onclick="window.location='index.php'">×</span>
<h2>📅 Create Timetable</h2>
<?php if (!empty($success)): ?>
<div class="success">Timetable created successfully.</div>
<?php endif; ?>
<form method="post">
<label>Day</label>
<select name="day" required>
<option value="">Select Day</option>
<option>Monday</option>
<option>Tuesday</option>
<option>Wednesday</option>
<option>Thursday</option>
<option>Friday</option>
<option>Saturday</option>
</select>
<label>Start Time</label>
<input type="time" name="start_time" required>
<label>End Time</label>
<input type="time" name="end_time" required>
<label>Course</label>
<select name="course_id" required>
<option value="">Select Course</option>
<?php foreach ($courses as $c): ?>
<option value="<?= $c['id'] ?>">
<?= $c['code'] ?> — <?= $c['title'] ?>
</option>
<?php endforeach; ?>
</select>
<label>Subject</label>
<select name="subject_id" required>
<option value="">Select Subject</option>
<?php foreach ($subjects as $s): ?>
<option value="<?= $s['id'] ?>">
<?= $s['subject_code'] ?> — <?= $s['subject_title'] ?>
</option>
<?php endforeach; ?>
</select>
<label>Teacher</label>
<select name="teacher_id" required>
<option value="">Select Teacher</option>
<?php foreach ($teachers as $t): ?>
<option value="<?= $t['id'] ?>">
<?= htmlspecialchars($t['full_name']) ?>
</option>
<?php endforeach; ?>
</select>
<label>Level</label>
<select name="level_id" required>
<option value="">Select Level</option>
<?php foreach ($levels as $l): ?>
<option value="<?= $l['id'] ?>"><?= $l['level_name'] ?></option>
<?php endforeach; ?>
</select>
<label>Department</label>
<select name="department_id" required>
<option value="">Select Department</option>
<?php foreach ($departments as $d): ?>
<option value="<?= $d['id'] ?>"><?= $d['name'] ?></option>
<?php endforeach; ?>
</select>
<label>Venue / Room</label>
<input type="text" name="venue" placeholder="Room 203 / Lab A">
<label>Start Date</label>
<input type="date" name="start_date" required>
<label>End Date</label>
<input type="date" name="end_date" required>
<button type="submit">Save Timetable</button>
</form>
</div>
</body>
</html>