diff --git a/admin_classes.php b/admin_classes.php index 8aa8578..0ce16bc 100644 --- a/admin_classes.php +++ b/admin_classes.php @@ -17,7 +17,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_id'])) { $stmt->execute([$delete_id, $school_id]); $message = "Class deleted successfully."; } catch (PDOException $e) { - $error = "Error deleting class: " . $e->getMessage(); + if ($e->getCode() == '23000') { // Integrity constraint violation + $error = "Cannot delete this class because it has subjects, workloads, or schedules associated with it. Please remove those associations before deleting."; + } else { + $error = "Error deleting class: " . $e->getMessage(); + } } } diff --git a/admin_elective_groups.php b/admin_elective_groups.php index cdbde86..c9d5144 100644 --- a/admin_elective_groups.php +++ b/admin_elective_groups.php @@ -17,7 +17,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_id'])) { $stmt->execute([$delete_id, $school_id]); $message = "Elective group deleted successfully."; } catch (PDOException $e) { - $error = "Error deleting group: " . $e->getMessage(); + if ($e->getCode() == '23000') { // Integrity constraint violation + $error = "Cannot delete this elective group because it has subjects associated with it. Please remove those associations before deleting."; + } else { + $error = "Error deleting group: " . $e->getMessage(); + } } } diff --git a/admin_subjects.php b/admin_subjects.php index aa35195..662da2a 100644 --- a/admin_subjects.php +++ b/admin_subjects.php @@ -17,7 +17,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_id'])) { $stmt->execute([$delete_id, $school_id]); $message = "Subject deleted successfully."; } catch (PDOException $e) { - $error = "Error deleting subject: " . $e->getMessage(); + if ($e->getCode() == '23000') { // Integrity constraint violation + $error = "Cannot delete this subject because it is currently used in workloads or schedules. Please remove those associations before deleting."; + } else { + $error = "Error deleting subject: " . $e->getMessage(); + } } } diff --git a/admin_teachers.php b/admin_teachers.php index c55fb63..3f22fba 100644 --- a/admin_teachers.php +++ b/admin_teachers.php @@ -29,7 +29,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_id'])) { $message = "Teacher deleted successfully."; } catch (PDOException $e) { $pdo->rollBack(); - $error = "Error deleting teacher: " . $e->getMessage(); + if ($e->getCode() == '23000') { // Integrity constraint violation + $error = "Cannot delete this teacher because they are assigned to workloads or schedules. Please remove those associations before deleting."; + } else { + $error = "Error deleting teacher: " . $e->getMessage(); + } } } diff --git a/admin_timeslots.php b/admin_timeslots.php index 5e5673c..82d716b 100644 --- a/admin_timeslots.php +++ b/admin_timeslots.php @@ -32,7 +32,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $error = 'Failed to delete timeslot.'; } } catch (PDOException $e) { - $error = 'Database error: ' . $e->getMessage(); + if ($e->getCode() == '23000') { // Integrity constraint violation + $error = "Cannot delete this timeslot because it is currently used in schedules. Please remove those associations before deleting."; + } else { + $error = "Error deleting timeslot: " . $e->getMessage(); + } } } if (isset($_POST['add_timeslot'])) { diff --git a/db/migrations/020_create_elective_group_subjects_table.sql b/db/migrations/020_create_elective_group_subjects_table.sql new file mode 100644 index 0000000..acecdbb --- /dev/null +++ b/db/migrations/020_create_elective_group_subjects_table.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS `elective_group_subjects` ( + `elective_group_id` INT NOT NULL, + `subject_id` INT NOT NULL, + PRIMARY KEY (`elective_group_id`, `subject_id`), + FOREIGN KEY (`elective_group_id`) REFERENCES `elective_groups`(`id`) ON DELETE CASCADE, + FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; \ No newline at end of file diff --git a/db/migrations/021_create_elective_group_subjects_table.sql b/db/migrations/021_create_elective_group_subjects_table.sql new file mode 100644 index 0000000..df415f9 --- /dev/null +++ b/db/migrations/021_create_elective_group_subjects_table.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS elective_group_subjects ( + id INT AUTO_INCREMENT PRIMARY KEY, + elective_group_id INT NOT NULL, + subject_id INT NOT NULL, + FOREIGN KEY (elective_group_id) REFERENCES elective_groups(id) ON DELETE CASCADE, + FOREIGN KEY (subject_id) REFERENCES subjects(id) ON DELETE CASCADE, + UNIQUE KEY (elective_group_id, subject_id) +); diff --git a/includes/navbar.php b/includes/navbar.php new file mode 100644 index 0000000..842197e --- /dev/null +++ b/includes/navbar.php @@ -0,0 +1,42 @@ + + \ No newline at end of file diff --git a/teacher_timetable.php b/teacher_timetable.php index 07a7d9e..6007ac7 100644 --- a/teacher_timetable.php +++ b/teacher_timetable.php @@ -85,9 +85,9 @@ foreach ($timeslots as $timeslot) { } foreach ($teacher_schedule_raw as $lesson) { - $day_idx = $lesson['day_of_week']; + $day_idx = $lesson['day_of_week'] - 1; // Adjust for 0-based array index $timeslot_id = $lesson['timeslot_id']; - if (isset($teacher_timetable[$day_idx][$timeslot_id])) { + if (isset($teacher_timetable[$day_idx]) && isset($teacher_timetable[$day_idx][$timeslot_id])) { $teacher_timetable[$day_idx][$timeslot_id] = $lesson; } } @@ -181,7 +181,7 @@ foreach ($teacher_schedule_raw as $lesson) {