EHDEM commited on
Commit
d78b5b8
·
verified ·
1 Parent(s): 58cd75e

add another part in admin dashboard which is so i can add and remove students, add and remove classes , or entirely change the school list

Browse files
Files changed (1) hide show
  1. admin-dashboard.html +303 -6
admin-dashboard.html CHANGED
@@ -26,10 +26,9 @@
26
  </button>
27
  </div>
28
  </header>
29
-
30
  <!-- Admin Controls -->
31
- <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
32
- <!-- Quick Actions -->
33
  <div class="bg-white rounded-lg shadow-md p-6">
34
  <h2 class="text-xl font-semibold mb-4 text-gray-800">Quick Actions</h2>
35
  <div class="grid grid-cols-2 gap-4">
@@ -49,10 +48,125 @@
49
  <i class="fas fa-cog text-2xl mb-2"></i>
50
  <span>Settings</span>
51
  </a>
 
 
 
 
52
  </div>
53
  </div>
54
 
55
- <!-- System Overview -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  <div class="bg-white rounded-lg shadow-md p-6">
57
  <h2 class="text-xl font-semibold mb-4 text-gray-800">System Overview</h2>
58
  <div class="space-y-4">
@@ -75,8 +189,11 @@
75
  </div>
76
  </div>
77
  </div>
 
 
 
78
  <!-- Attendance Data Tables -->
79
- <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
80
  <!-- Form A Data -->
81
  <div class="bg-white rounded-lg shadow-md p-6">
82
  <h2 class="text-xl font-semibold mb-4 text-gray-800">Students Who Want To Eat</h2>
@@ -144,8 +261,188 @@
144
  </div>
145
  <script src="config.js"></script>
146
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  // Check if user is logged in
148
- if (localStorage.getItem('isAdminLoggedIn') !== 'true') {
149
  alert('Please login first');
150
  window.location.href = 'admin-login.html';
151
  }
 
26
  </button>
27
  </div>
28
  </header>
 
29
  <!-- Admin Controls -->
30
+ <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8">
31
+ <!-- Quick Actions -->
32
  <div class="bg-white rounded-lg shadow-md p-6">
33
  <h2 class="text-xl font-semibold mb-4 text-gray-800">Quick Actions</h2>
34
  <div class="grid grid-cols-2 gap-4">
 
48
  <i class="fas fa-cog text-2xl mb-2"></i>
49
  <span>Settings</span>
50
  </a>
51
+ <a href="#" id="manage-students-btn" class="bg-pink-50 hover:bg-pink-100 text-pink-700 p-4 rounded-lg flex flex-col items-center justify-center transition-colors">
52
+ <i class="fas fa-users text-2xl mb-2"></i>
53
+ <span>Manage Students</span>
54
+ </a>
55
  </div>
56
  </div>
57
 
58
+ <!-- Student & Class Management -->
59
+ <div class="bg-white rounded-lg shadow-md p-6 hidden" id="management-section">
60
+ <h2 class="text-xl font-semibold mb-4 text-gray-800">Student & Class Management</h2>
61
+
62
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
63
+ <!-- Add Student Form -->
64
+ <div class="bg-gray-50 p-4 rounded-lg">
65
+ <h3 class="text-lg font-medium mb-3">Add New Student</h3>
66
+ <form id="add-student-form">
67
+ <div class="mb-3">
68
+ <label class="block text-gray-700 mb-1">Class</label>
69
+ <select class="w-full px-3 py-2 border rounded" id="add-student-class" required>
70
+ <option value="">Select Class</option>
71
+ <option value="BUDI">BUDI</option>
72
+ <option value="USAHA">USAHA</option>
73
+ <option value="MAJU">MAJU</option>
74
+ <option value="JAYA">JAYA</option>
75
+ </select>
76
+ </div>
77
+ <div class="mb-3">
78
+ <label class="block text-gray-700 mb-1">Form</label>
79
+ <select class="w-full px-3 py-2 border rounded" id="add-student-form" required>
80
+ <option value="">Select Form</option>
81
+ <option value="1">Form 1</option>
82
+ <option value="2">Form 2</option>
83
+ <option value="3">Form 3</option>
84
+ <option value="4">Form 4</option>
85
+ <option value="5">Form 5</option>
86
+ </select>
87
+ </div>
88
+ <div class="mb-3">
89
+ <label class="block text-gray-700 mb-1">Student Name</label>
90
+ <input type="text" class="w-full px-3 py-2 border rounded" id="add-student-name" required>
91
+ </div>
92
+ <button type="submit" class="w-full bg-blue-600 text-white py-2 rounded hover:bg-blue-700">
93
+ Add Student
94
+ </button>
95
+ </form>
96
+ </div>
97
+
98
+ <!-- Remove Student Form -->
99
+ <div class="bg-gray-50 p-4 rounded-lg">
100
+ <h3 class="text-lg font-medium mb-3">Remove Student</h3>
101
+ <form id="remove-student-form">
102
+ <div class="mb-3">
103
+ <label class="block text-gray-700 mb-1">Class</label>
104
+ <select class="w-full px-3 py-2 border rounded" id="remove-student-class" required>
105
+ <option value="">Select Class</option>
106
+ <option value="BUDI">BUDI</option>
107
+ <option value="USAHA">USAHA</option>
108
+ <option value="MAJU">MAJU</option>
109
+ <option value="JAYA">JAYA</option>
110
+ </select>
111
+ </div>
112
+ <div class="mb-3">
113
+ <label class="block text-gray-700 mb-1">Form</label>
114
+ <select class="w-full px-3 py-2 border rounded" id="remove-student-form" required>
115
+ <option value="">Select Form</option>
116
+ <option value="1">Form 1</option>
117
+ <option value="2">Form 2</option>
118
+ <option value="3">Form 3</option>
119
+ <option value="4">Form 4</option>
120
+ <option value="5">Form 5</option>
121
+ </select>
122
+ </div>
123
+ <div class="mb-3">
124
+ <label class="block text-gray-700 mb-1">Student</label>
125
+ <select class="w-full px-3 py-2 border rounded" id="remove-student-name" disabled required>
126
+ <option value="">Select Student</option>
127
+ </select>
128
+ </div>
129
+ <button type="submit" class="w-full bg-red-600 text-white py-2 rounded hover:bg-red-700">
130
+ Remove Student
131
+ </button>
132
+ </form>
133
+ </div>
134
+ </div>
135
+
136
+ <!-- School Structure Management -->
137
+ <div class="mt-6">
138
+ <h3 class="text-lg font-medium mb-3">School Structure</h3>
139
+
140
+ <!-- Add Class -->
141
+ <div class="bg-gray-50 p-4 rounded-lg mb-4">
142
+ <h4 class="font-medium mb-2">Add New Class</h4>
143
+ <form id="add-class-form" class="flex gap-2">
144
+ <input type="text" class="flex-1 px-3 py-2 border rounded" id="new-class-name" placeholder="Class name" required>
145
+ <button type="submit" class="bg-green-600 text-white px-4 py-2 rounded hover:bg-green-700">
146
+ Add Class
147
+ </button>
148
+ </form>
149
+ </div>
150
+
151
+ <!-- Remove Class -->
152
+ <div class="bg-gray-50 p-4 rounded-lg">
153
+ <h4 class="font-medium mb-2">Remove Existing Class</h4>
154
+ <form id="remove-class-form" class="flex gap-2">
155
+ <select class="flex-1 px-3 py-2 border rounded" id="class-to-remove" required>
156
+ <option value="">Select Class to Remove</option>
157
+ <option value="BUDI">BUDI</option>
158
+ <option value="USAHA">USAHA</option>
159
+ <option value="MAJU">MAJU</option>
160
+ <option value="JAYA">JAYA</option>
161
+ </select>
162
+ <button type="submit" class="bg-red-600 text-white px-4 py-2 rounded hover:bg-red-700">
163
+ Remove Class
164
+ </button>
165
+ </form>
166
+ </div>
167
+ </div>
168
+ </div>
169
+ <!-- System Overview -->
170
  <div class="bg-white rounded-lg shadow-md p-6">
171
  <h2 class="text-xl font-semibold mb-4 text-gray-800">System Overview</h2>
172
  <div class="space-y-4">
 
189
  </div>
190
  </div>
191
  </div>
192
+ <!-- Student Management Message -->
193
+ <div id="management-message" class="hidden fixed top-4 right-4 bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded"></div>
194
+
195
  <!-- Attendance Data Tables -->
196
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
197
  <!-- Form A Data -->
198
  <div class="bg-white rounded-lg shadow-md p-6">
199
  <h2 class="text-xl font-semibold mb-4 text-gray-800">Students Who Want To Eat</h2>
 
261
  </div>
262
  <script src="config.js"></script>
263
  <script>
264
+ // Student Management Functions
265
+ document.addEventListener('DOMContentLoaded', function() {
266
+ // Toggle management section
267
+ document.getElementById('manage-students-btn').addEventListener('click', function(e) {
268
+ e.preventDefault();
269
+ document.getElementById('management-section').classList.toggle('hidden');
270
+ });
271
+
272
+ // Load students for removal
273
+ document.getElementById('remove-student-class').addEventListener('change', loadStudentsForRemoval);
274
+ document.getElementById('remove-student-form').addEventListener('change', loadStudentsForRemoval);
275
+
276
+ // Add student form
277
+ document.getElementById('add-student-form').addEventListener('submit', function(e) {
278
+ e.preventDefault();
279
+ const className = document.getElementById('add-student-class').value;
280
+ const form = document.getElementById('add-student-form').value;
281
+ const studentName = document.getElementById('add-student-name').value;
282
+
283
+ if (!className || !form || !studentName) {
284
+ showManagementMessage('Please fill all fields', 'error');
285
+ return;
286
+ }
287
+
288
+ // Add to students data structure
289
+ const key = `${className}-${form}`;
290
+ if (!students[key]) {
291
+ students[key] = [];
292
+ }
293
+ students[key].push(studentName);
294
+
295
+ // Save to localStorage
296
+ localStorage.setItem('studentData', JSON.stringify(students));
297
+
298
+ showManagementMessage('Student added successfully!');
299
+ this.reset();
300
+ });
301
+
302
+ // Remove student form
303
+ document.getElementById('remove-student-form').addEventListener('submit', function(e) {
304
+ e.preventDefault();
305
+ const className = document.getElementById('remove-student-class').value;
306
+ const form = document.getElementById('remove-student-form').value;
307
+ const studentName = document.getElementById('remove-student-name').value;
308
+
309
+ if (!className || !form || !studentName) {
310
+ showManagementMessage('Please fill all fields', 'error');
311
+ return;
312
+ }
313
+
314
+ // Remove from students data structure
315
+ const key = `${className}-${form}`;
316
+ if (students[key]) {
317
+ students[key] = students[key].filter(name => name !== studentName);
318
+
319
+ // Save to localStorage
320
+ localStorage.setItem('studentData', JSON.stringify(students));
321
+
322
+ showManagementMessage('Student removed successfully!');
323
+ loadStudentsForRemoval();
324
+ this.reset();
325
+ }
326
+ });
327
+
328
+ // Add class form
329
+ document.getElementById('add-class-form').addEventListener('submit', function(e) {
330
+ e.preventDefault();
331
+ const newClassName = document.getElementById('new-class-name').value.trim().toUpperCase();
332
+
333
+ if (!newClassName) {
334
+ showManagementMessage('Please enter a class name', 'error');
335
+ return;
336
+ }
337
+
338
+ // Check if class already exists
339
+ const existingClasses = new Set(['BUDI', 'USAHA', 'MAJU', 'JAYA']);
340
+ if (existingClasses.has(newClassName)) {
341
+ showManagementMessage('Class already exists', 'error');
342
+ return;
343
+ }
344
+
345
+ // Add to class options in all selects
346
+ const classSelects = document.querySelectorAll('select[id$="-class"], select[id^="class-"]');
347
+ classSelects.forEach(select => {
348
+ const option = document.createElement('option');
349
+ option.value = newClassName;
350
+ option.textContent = newClassName;
351
+ select.appendChild(option);
352
+ });
353
+
354
+ showManagementMessage(`Class ${newClassName} added successfully!`);
355
+ this.reset();
356
+ });
357
+
358
+ // Remove class form
359
+ document.getElementById('remove-class-form').addEventListener('submit', function(e) {
360
+ e.preventDefault();
361
+ const classToRemove = document.getElementById('class-to-remove').value;
362
+
363
+ if (!classToRemove) {
364
+ showManagementMessage('Please select a class to remove', 'error');
365
+ return;
366
+ }
367
+
368
+ // Remove class from all selects
369
+ const classSelects = document.querySelectorAll('select[id$="-class"], select[id^="class-"]');
370
+ classSelects.forEach(select => {
371
+ Array.from(select.options).forEach(option => {
372
+ if (option.value === classToRemove) {
373
+ option.remove();
374
+ }
375
+ });
376
+ });
377
+
378
+ // Remove all students in this class
379
+ for (const key in students) {
380
+ if (key.startsWith(classToRemove)) {
381
+ delete students[key];
382
+ }
383
+ }
384
+
385
+ // Save to localStorage
386
+ localStorage.setItem('studentData', JSON.stringify(students));
387
+
388
+ showManagementMessage(`Class ${classToRemove} and all its students removed successfully!`);
389
+ this.reset();
390
+ });
391
+
392
+ // Load students for removal dropdown
393
+ function loadStudentsForRemoval() {
394
+ const classVal = document.getElementById('remove-student-class').value;
395
+ const formVal = document.getElementById('remove-student-form').value;
396
+ const studentSelect = document.getElementById('remove-student-name');
397
+
398
+ studentSelect.innerHTML = '<option value="">Select Student</option>';
399
+ studentSelect.disabled = true;
400
+
401
+ if (classVal && formVal) {
402
+ const key = `${classVal}-${formVal}`;
403
+ if (students[key]) {
404
+ students[key].forEach(student => {
405
+ const option = document.createElement('option');
406
+ option.value = student;
407
+ option.textContent = student;
408
+ studentSelect.appendChild(option);
409
+ });
410
+ studentSelect.disabled = false;
411
+ }
412
+ }
413
+ }
414
+
415
+ // Show management message
416
+ function showManagementMessage(message, type = 'success') {
417
+ const messageDiv = document.getElementById('management-message');
418
+ messageDiv.textContent = message;
419
+ messageDiv.className = `fixed top-4 right-4 px-4 py-3 rounded ${type === 'success' ? 'bg-green-100 border border-green-400 text-green-700' : 'bg-red-100 border border-red-400 text-red-700'}`;
420
+ messageDiv.classList.remove('hidden');
421
+
422
+ setTimeout(() => {
423
+ messageDiv.classList.add('hidden');
424
+ }, 3000);
425
+ }
426
+
427
+ // Load student data from localStorage if available
428
+ const savedStudents = localStorage.getItem('studentData');
429
+ if (savedStudents) {
430
+ students = JSON.parse(savedStudents);
431
+ }
432
+ });
433
+ </script>
434
+ <script>
435
+ // Student data organized by class and form
436
+ let students = {
437
+ // Form 1
438
+ 'BUDI-1': [
439
+ 'NUR QISYA AFRINA BINTI MOHD AIZAT', 'ADAM HAQQ BIN MOHD FAHMI', 'IRFAN RIFQI BIN AHMAD RUHAIFI', 'HASSIF HAFIZUDDIN BIN HASZAINUDDEN HASRAF', 'ALEESYA HUMAIRAA BINTI MOHD HAFIZ', 'QAISIR ADDAYYAN BIN NORHISYAM', 'NUR AIMYHANAA BINTI MOH SHUKOR', 'ABHINAYA SRI A/P SRI RESEAI SANNA', 'MUHAMMAD ZAKWAN BIN MUHAMMAD AL MAUDOODI', 'UNGKU MUHAMAD RAFAEL AMSYAR BIN UNGKU MOHAMED HANIF', 'NUR ALLYSA SOFEA BINTI AZMAN', 'WAN SOFFIYA ZAHRA BINTI MEOR SYAZWAN', 'AMIR ARYAN BIN AMIR RASHID', 'FAZLROY HAFIY BIN NIZAM HAFIZ', 'NUR SYAFIFAH IMANI BINTI MUHAMAD AZLAN', 'MOHAMMAD ARIF IMAN BIN MOHAMMAD BADRUL HISHAM', 'MUHAMMAD IRFAN ASYRAAF BIN MOHAMMAD HAFIZ', 'QAYYUM DANI ZAHRAN BIN SYAIFUL IZAM', 'NUR IMAN IRDINA BINTI MOHD RAZLAN', 'HAZEL ZULAIKHA BINTI BADRUL HISHAM', 'AHMAD IRFAN BIN AHMAD ARIFF', 'ANEHA LAKSHNA A/P P.THIAGARAJAN', 'AKIF NAJWAN BIN AZIZUL KARNAIN', 'ADAM HAFIZ BIN AMIRUL MOHD.MAHFUZ', 'PUTERA AZMAN AARIZ RAYYAN BIN AZMAN WISLI', 'DAYANGKU NAQIYAH NUR QISYA BINTI MOHD NAZRI', 'HIMAWARI HUSNA BINTI MOHD ASNAWI', 'RITTVIN A/L ARIVANANTAHAN', 'AFHAM HARITH BIN MOHD SYAZWAN', 'DARWISY NOR AFKAR BIN MOHD SALLEH', 'MUHAMMAD RIZQ BIN MOHD HANAFIA', 'NUR RAIHANNA ZAHRA BINTI MOHD NIZAM',
440
+ ],
441
+ // ... rest of student data ...
442
+ };
443
+
444
  // Check if user is logged in
445
+ if (localStorage.getItem('isAdminLoggedIn') !== 'true') {
446
  alert('Please login first');
447
  window.location.href = 'admin-login.html';
448
  }