-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_upload_resources.php
More file actions
179 lines (159 loc) · 6.85 KB
/
Copy pathadmin_upload_resources.php
File metadata and controls
179 lines (159 loc) · 6.85 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
<?php
session_start();
require "config.php";
if (!isset($_SESSION['id']) || $_SESSION['role'] !== 'admin') {
header("Location: index.php");
exit;
}
$levels = $pdo->query("SELECT id, level_name FROM levels")->fetchAll();
$resources = $pdo->query("
SELECT r.*, l.level_name, c.title AS course_title, cs.subject_title
FROM resources r
JOIN levels l ON r.level_id = l.id
JOIN courses c ON r.course_id = c.id
JOIN course_subjects cs ON r.subject_id = cs.id
ORDER BY r.uploaded_at DESC
")->fetchAll();
?>
<!DOCTYPE html>
<html>
<head>
<title>Upload Course Resources</title>
<link rel="stylesheet" href="resources.css">
<style>
.success-message {
padding: 10px;
background-color: #d4edda;
border: 1px solid #c3e6cb;
color: #155724;
border-radius: 5px;
margin-bottom: 15px;
}
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
th, td { border: 1px solid #ccc; padding: 10px; text-align: left; }
th { background-color: #f2f2f2; }
a { color: #007bff; text-decoration: none; }
a:hover { text-decoration: underline; }
.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="page-wrapper">
<span class="close-btn" title="Close" onclick="window.location='student_dashboard.php'">×</span>
<h2 class="page-title">📚 Course Learning Resources</h2>
<!-- SUCCESS / ERROR MESSAGES -->
<?php if (isset($_GET['success'])): ?>
<p class="success-message">✅ Resource uploaded successfully!</p>
<?php elseif (isset($_GET['error'])): ?>
<p class="success-message" style="background-color:#f8d7da;color:#721c24;border-color:#f5c6cb;">❌ Failed to upload resource.</p>
<?php endif; ?>
<div class="card">
<form action="admin_upload_resources_action.php" method="POST" enctype="multipart/form-data">
<!-- LEVEL -->
<div class="form-group">
<label>Level</label>
<select name="level_id" id="level" required>
<option value="">Select Level</option>
<?php foreach ($levels as $l): ?>
<option value="<?= $l['id'] ?>">
<?= htmlspecialchars($l['level_name']) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<!-- COURSE -->
<div class="form-group">
<label>Course</label>
<select name="course_id" id="course" required disabled>
<option value="">Select Level first</option>
</select>
</div>
<!-- SUBJECT -->
<div class="form-group">
<label>Subject</label>
<select name="subject_id" id="subject" required disabled>
<option value="">Select Course first</option>
</select>
</div>
<!-- FILE -->
<div class="form-group">
<label>Upload File</label>
<input type="file" name="resource" required>
</div>
<button class="btn-primary">Upload Resource</button>
</form>
</div>
<!-- HISTORY OF UPLOADED FILES -->
<h3>📄 Uploaded Resources History</h3>
<?php if (empty($resources)): ?>
<p>No resources uploaded yet.</p>
<?php else: ?>
<table>
<thead>
<tr>
<th>Level</th>
<th>Course</th>
<th>Subject</th>
<th>File Name</th>
<th>Uploaded At</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($resources as $r): ?>
<tr>
<td><?= htmlspecialchars($r['level_name']) ?></td>
<td><?= htmlspecialchars($r['course_title']) ?></td>
<td><?= htmlspecialchars($r['subject_title']) ?></td>
<td><?= htmlspecialchars($r['filename']) ?></td>
<td><?= htmlspecialchars($r['uploaded_at']) ?></td>
<td><a href="<?= htmlspecialchars($r['filepath']) ?>" download>Download</a></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
<script>
// JS for dynamic courses & subjects (your existing code)
const levelSelect = document.getElementById("level");
const courseSelect = document.getElementById("course");
const subjectSelect = document.getElementById("subject");
levelSelect.addEventListener("change", () => {
const levelId = levelSelect.value;
courseSelect.innerHTML = "<option>Loading courses...</option>"; courseSelect.disabled = true;
subjectSelect.innerHTML = "<option>Select Course first</option>"; subjectSelect.disabled = true;
if (!levelId) { courseSelect.innerHTML = "<option>Select Level first</option>"; return; }
fetch(`fetch_courses.php?level_id=${levelId}`).then(res => res.json())
.then(data => {
courseSelect.innerHTML = "";
if (data.length === 0) { courseSelect.innerHTML = "<option>No courses found</option>"; return; }
courseSelect.disabled = false;
courseSelect.innerHTML = "<option value=''>Select Course</option>";
data.forEach(course => { courseSelect.innerHTML += `<option value="${course.id}">${course.title}</option>`; });
}).catch(err => { console.error(err); courseSelect.innerHTML = "<option>Error loading courses</option>"; });
});
courseSelect.addEventListener("change", () => {
const courseId = courseSelect.value;
subjectSelect.innerHTML = "<option>Loading subjects...</option>"; subjectSelect.disabled = true;
if (!courseId) { subjectSelect.innerHTML = "<option>Select Course first</option>"; return; }
fetch(`fetch_subjects.php?course_id=${courseId}`).then(res => res.json())
.then(data => {
subjectSelect.innerHTML = "";
if (data.length === 0) { subjectSelect.innerHTML = "<option>No subjects found</option>"; return; }
subjectSelect.disabled = false;
subjectSelect.innerHTML = "<option value=''>Select Subject</option>";
data.forEach(sub => { subjectSelect.innerHTML += `<option value="${sub.id}">${sub.subject_title}</option>`; });
}).catch(err => { console.error(err); subjectSelect.innerHTML = "<option>Error loading subjects</option>"; });
});
</script>
</body>
</html>