diff --git a/admin_workloads.php b/admin_workloads.php index b4f733d..a581588 100644 --- a/admin_workloads.php +++ b/admin_workloads.php @@ -2,6 +2,8 @@ require_once __DIR__ . '/includes/auth_check.php'; require_once __DIR__ . '/db/config.php'; + + $message = ''; $error = ''; $pdo = db(); @@ -11,6 +13,8 @@ $school_id = $_SESSION['school_id']; // Handle Delete request if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_id'])) { try { + // First, remove teacher from schedule + $stmt = $pdo->prepare("DELETE FROM workloads WHERE id = ? AND school_id = ?"); if ($stmt->execute([$_POST['delete_id'], $school_id])) { $message = 'Workload deleted successfully!'; @@ -45,6 +49,7 @@ elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { } else { // Insert $stmt = $pdo->prepare("INSERT INTO workloads (class_id, subject_id, teacher_id, lessons_per_week, school_id) VALUES (?, ?, ?, ?, ?)"); if ($stmt->execute([$class_id, $subject_id, $teacher_id, $lessons_per_week, $school_id])) { + $new_workload_id = $pdo->lastInsertId(); $message = 'Workload created successfully!'; } else { $error = 'Failed to create workload.'; diff --git a/dashboard.php b/dashboard.php index 6c2f7fb..e8d66da 100644 --- a/dashboard.php +++ b/dashboard.php @@ -33,33 +33,7 @@ if ($role === 'teacher') { - +

Welcome, !

diff --git a/includes/auth_check.php b/includes/auth_check.php index 404e4b0..7dfa7dd 100644 --- a/includes/auth_check.php +++ b/includes/auth_check.php @@ -2,7 +2,7 @@ session_start(); // If user is not logged in or is not an admin, redirect to login page -if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') { +if (!isset($_SESSION['user_id']) || ($_SESSION['role'] !== 'admin' && $_SESSION['role'] !== 'teacher')) { header("Location: login.php"); exit; } diff --git a/includes/auth_check_workload.php b/includes/auth_check_workload.php index 83da712..ce70b68 100644 --- a/includes/auth_check_workload.php +++ b/includes/auth_check_workload.php @@ -1,7 +1,7 @@ Class Timetable + + + + diff --git a/index.php b/index.php index fbd3bb5..69bc12a 100644 --- a/index.php +++ b/index.php @@ -12,38 +12,7 @@ - +
diff --git a/teacher_timetable.php b/teacher_timetable.php index 6007ac7..ebd8b0d 100644 --- a/teacher_timetable.php +++ b/teacher_timetable.php @@ -125,42 +125,7 @@ foreach ($teacher_schedule_raw as $lesson) { - +
diff --git a/teacher_workload.php b/teacher_workload.php index 8a966f3..0c41bff 100644 --- a/teacher_workload.php +++ b/teacher_workload.php @@ -94,12 +94,12 @@ try { $workloads = []; try { $workloads_stmt = $pdo->prepare(" - SELECT w.id, c.name as class_name, s.name as subject_name, w.lessons_per_week, w.created_at, w.class_id, w.subject_id + SELECT w.id, c.name as class_name, s.name as subject_name, w.lessons_per_week, w.class_id, w.subject_id FROM workloads w JOIN classes c ON w.class_id = c.id JOIN subjects s ON w.subject_id = s.id WHERE w.teacher_id = ? AND w.school_id = ? - ORDER BY w.created_at DESC + ORDER BY c.name, s.name "); $workloads_stmt->execute([$teacher_id, $school_id]); $workloads = $workloads_stmt->fetchAll(PDO::FETCH_ASSOC); @@ -120,22 +120,7 @@ try { - +
diff --git a/timetable.php b/timetable.php index 654b302..92b2f24 100644 --- a/timetable.php +++ b/timetable.php @@ -204,8 +204,8 @@ function save_timetable($pdo, $class_timetables, $timeslots) { try { $pdo->beginTransaction(); $pdo->exec('SET FOREIGN_KEY_CHECKS=0'); - $pdo->exec('TRUNCATE TABLE schedule_teachers'); - $pdo->exec('TRUNCATE TABLE schedules'); + $pdo->exec('DELETE FROM schedule_teachers'); + $pdo->exec('DELETE FROM schedules'); $pdo->exec('SET FOREIGN_KEY_CHECKS=1'); $stmt = $pdo->prepare(