kiveu new version
This commit is contained in:
parent
8d3f50641f
commit
386664137b
148
admin_classes.php
Normal file
148
admin_classes.php
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/includes/auth_check.php';
|
||||||
|
require_once __DIR__ . '/db/config.php';
|
||||||
|
|
||||||
|
$message = '';
|
||||||
|
$error = '';
|
||||||
|
|
||||||
|
// Handle POST request to add a new class
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['class_name'])) {
|
||||||
|
$className = trim($_POST['class_name']);
|
||||||
|
if (empty($className)) {
|
||||||
|
$error = 'Class name cannot be empty.';
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO classes (name) VALUES (?)");
|
||||||
|
if ($stmt->execute([$className])) {
|
||||||
|
$message = "Class '" . htmlspecialchars($className) . "' created successfully!";
|
||||||
|
} else {
|
||||||
|
$error = 'Failed to create class.';
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
if ($e->errorInfo[1] == 1062) { // Duplicate entry
|
||||||
|
$error = "Error: Class '" . htmlspecialchars($className) . "' already exists.";
|
||||||
|
} else {
|
||||||
|
$error = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch all classes to display
|
||||||
|
$classes = [];
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$classes_stmt = $pdo->query("SELECT id, name, created_at FROM classes ORDER BY created_at DESC");
|
||||||
|
$classes = $classes_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Admin: Manage Classes - Haki Schedule</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top shadow-sm">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand fw-bold" href="/">Haki Schedule</a>
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
|
<ul class="navbar-nav ms-auto">
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/">Home</a></li>
|
||||||
|
<?php if (isset($_SESSION['user_id'])): ?>
|
||||||
|
<li class="nav-item dropdown">
|
||||||
|
<a class="nav-link dropdown-toggle active" href="#" id="manageDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
|
Manage
|
||||||
|
</a>
|
||||||
|
<ul class="dropdown-menu" aria-labelledby="manageDropdown">
|
||||||
|
<li><a class="dropdown-item active" href="/admin_classes.php">Classes</a></li>
|
||||||
|
<li><a class="dropdown-item" href="/admin_subjects.php">Subjects</a></li>
|
||||||
|
<li><a class="dropdown-item" href="/admin_teachers.php">Teachers</a></li>
|
||||||
|
<li><a class="dropdown-item" href="/admin_workloads.php">Workloads</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/timetable.php">Timetable</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/logout.php">Logout</a></li>
|
||||||
|
<?php else: ?>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/demo.php">Demo</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/login.php">Login</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/register.php">Register</a></li>
|
||||||
|
<?php endif; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main class="container py-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-lg-8">
|
||||||
|
<h1 class="h2 fw-bold mb-4">Manage Classes</h1>
|
||||||
|
|
||||||
|
<?php if ($message): ?>
|
||||||
|
<div class="alert alert-success"><?php echo $message; ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ($error): ?>
|
||||||
|
<div class="alert alert-danger"><?php echo $error; ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<!-- Create Class Form -->
|
||||||
|
<div class="card mb-4">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Create a New Class</h5>
|
||||||
|
<form action="admin_classes.php" method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="class_name" class="form-label">Class Name</label>
|
||||||
|
<input type="text" class="form-control" id="class_name" name="class_name" placeholder="e.g., Form 1 North" required>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Create Class</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Existing Classes List -->
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Existing Classes</h5>
|
||||||
|
<?php if (empty($classes) && !$error): ?>
|
||||||
|
<p class="text-muted">No classes have been created yet. Use the form above to add the first one.</p>
|
||||||
|
<?php else:
|
||||||
|
if(!empty($classes)) : ?>
|
||||||
|
<ul class="list-group list-group-flush">
|
||||||
|
<?php foreach ($classes as $class):
|
||||||
|
// Corrected: removed unnecessary escaping around $class['name']
|
||||||
|
// Corrected: removed unnecessary escaping around $class['created_at']
|
||||||
|
?>
|
||||||
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||||
|
<?php echo htmlspecialchars($class['name']); ?>
|
||||||
|
<small class="text-muted">Created: <?php echo date("M j, Y", strtotime($class['created_at'])); ?></small>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
<?php endif; endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="bg-dark text-white py-4 mt-5">
|
||||||
|
<div class="container text-center">
|
||||||
|
<p>© <?php echo date("Y"); ?> Haki Schedule. All Rights Reserved.</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
212
admin_subjects.php
Normal file
212
admin_subjects.php
Normal file
@ -0,0 +1,212 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/includes/auth_check.php';
|
||||||
|
require_once __DIR__ . '/db/config.php';
|
||||||
|
|
||||||
|
$message = '';
|
||||||
|
$error = '';
|
||||||
|
$editing_subject = null;
|
||||||
|
|
||||||
|
$pdo = db();
|
||||||
|
|
||||||
|
// Handle Delete request
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_id'])) {
|
||||||
|
try {
|
||||||
|
$delete_id = $_POST['delete_id'];
|
||||||
|
$stmt = $pdo->prepare("DELETE FROM subjects WHERE id = ?");
|
||||||
|
$stmt->execute([$delete_id]);
|
||||||
|
$message = "Subject deleted successfully.";
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error = "Error deleting subject: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle POST request to add or update a subject
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['subject_name'])) {
|
||||||
|
$subjectName = trim($_POST['subject_name']);
|
||||||
|
$has_double_lesson = isset($_POST['has_double_lesson']) ? 1 : 0;
|
||||||
|
$elective_group = !empty($_POST['elective_group']) ? trim($_POST['elective_group']) : null;
|
||||||
|
$subject_id = $_POST['subject_id'] ?? null;
|
||||||
|
|
||||||
|
if (empty($subjectName)) {
|
||||||
|
$error = 'Subject name cannot be empty.';
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
if ($subject_id) {
|
||||||
|
// Update existing subject
|
||||||
|
$stmt = $pdo->prepare("UPDATE subjects SET name = ?, has_double_lesson = ?, elective_group = ? WHERE id = ?");
|
||||||
|
$stmt->execute([$subjectName, $has_double_lesson, $elective_group, $subject_id]);
|
||||||
|
$message = "Subject updated successfully!";
|
||||||
|
} else {
|
||||||
|
// Insert new subject
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO subjects (name, has_double_lesson, elective_group) VALUES (?, ?, ?)");
|
||||||
|
$stmt->execute([$subjectName, $has_double_lesson, $elective_group]);
|
||||||
|
$message = "Subject created successfully!";
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
if ($e->errorInfo[1] == 1062) { // Duplicate entry
|
||||||
|
$error = "Error: Subject '" . htmlspecialchars($subjectName) . "' already exists.";
|
||||||
|
} else {
|
||||||
|
$error = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle Edit request
|
||||||
|
if (isset($_GET['edit_id'])) {
|
||||||
|
try {
|
||||||
|
$edit_id = $_GET['edit_id'];
|
||||||
|
$stmt = $pdo->prepare("SELECT * FROM subjects WHERE id = ?");
|
||||||
|
$stmt->execute([$edit_id]);
|
||||||
|
$editing_subject = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error = "Error fetching subject: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch all subjects to display
|
||||||
|
$subjects = [];
|
||||||
|
try {
|
||||||
|
$subjects_stmt = $pdo->query("SELECT * FROM subjects ORDER BY created_at DESC");
|
||||||
|
$subjects = $subjects_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Admin: Manage Subjects - Haki Schedule</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top shadow-sm">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand fw-bold" href="/">Haki Schedule</a>
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
|
<ul class="navbar-nav ms-auto">
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/">Home</a></li>
|
||||||
|
<?php if (isset($_SESSION['user_id'])): ?>
|
||||||
|
<li class="nav-item dropdown">
|
||||||
|
<a class="nav-link dropdown-toggle active" href="#" id="manageDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
|
Manage
|
||||||
|
</a>
|
||||||
|
<ul class="dropdown-menu" aria-labelledby="manageDropdown">
|
||||||
|
<li><a class="dropdown-item" href="/admin_classes.php">Classes</a></li>
|
||||||
|
<li><a class="dropdown-item active" href="/admin_subjects.php">Subjects</a></li>
|
||||||
|
<li><a class="dropdown-item" href="/admin_teachers.php">Teachers</a></li>
|
||||||
|
<li><a class="dropdown-item" href="/admin_workloads.php">Workloads</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/timetable.php">Timetable</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/logout.php">Logout</a></li>
|
||||||
|
<?php else: ?>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/demo.php">Demo</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/login.php">Login</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/register.php">Register</a></li>
|
||||||
|
<?php endif; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main class="container py-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-lg-10">
|
||||||
|
<h1 class="h2 fw-bold mb-4">Manage Subjects</h1>
|
||||||
|
|
||||||
|
<?php if ($message): ?>
|
||||||
|
<div class="alert alert-success"><?php echo $message; ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ($error): ?>
|
||||||
|
<div class="alert alert-danger"><?php echo $error; ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<!-- Create/Edit Subject Form -->
|
||||||
|
<div class="card mb-4">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title"><?php echo $editing_subject ? 'Edit Subject' : 'Create a New Subject'; ?></h5>
|
||||||
|
<form action="admin_subjects.php" method="POST">
|
||||||
|
<input type="hidden" name="subject_id" value="<?php echo $editing_subject['id'] ?? ''; ?>">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="subject_name" class="form-label">Subject Name</label>
|
||||||
|
<input type="text" class="form-control" id="subject_name" name="subject_name" value="<?php echo htmlspecialchars($editing_subject['name'] ?? ''); ?>" placeholder="e.g., Mathematics" required>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="elective_group" class="form-label">Elective Group (Optional)</label>
|
||||||
|
<input type="text" class="form-control" id="elective_group" name="elective_group" value="<?php echo htmlspecialchars($editing_subject['elective_group'] ?? ''); ?>" placeholder="e.g., Languages">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3 form-check">
|
||||||
|
<input type="checkbox" class="form-check-input" id="has_double_lesson" name="has_double_lesson" value="1" <?php echo !empty($editing_subject['has_double_lesson']) ? 'checked' : ''; ?>>
|
||||||
|
<label class="form-check-label" for="has_double_lesson">Has one double lesson per week</label>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary"><?php echo $editing_subject ? 'Update Subject' : 'Create Subject'; ?></button>
|
||||||
|
<?php if ($editing_subject): ?>
|
||||||
|
<a href="admin_subjects.php" class="btn btn-secondary">Cancel Edit</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Existing Subjects List -->
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Existing Subjects</h5>
|
||||||
|
<?php if (empty($subjects)): ?>
|
||||||
|
<p class="text-muted">No subjects have been created yet.</p>
|
||||||
|
<?php else: ?>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Double Lesson</th>
|
||||||
|
<th>Elective Group</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ($subjects as $subject): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($subject['name']); ?></td>
|
||||||
|
<td><?php echo $subject['has_double_lesson'] ? 'Yes' : 'No'; ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($subject['elective_group'] ?? 'N/A'); ?></td>
|
||||||
|
<td>
|
||||||
|
<a href="?edit_id=<?php echo $subject['id']; ?>" class="btn btn-sm btn-outline-primary">Edit</a>
|
||||||
|
<form action="admin_subjects.php" method="POST" class="d-inline" onsubmit="return confirm('Are you sure you want to delete this subject?');">
|
||||||
|
<input type="hidden" name="delete_id" value="<?php echo $subject['id']; ?>">
|
||||||
|
<button type="submit" class="btn btn-sm btn-outline-danger">Delete</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="bg-dark text-white py-4 mt-5">
|
||||||
|
<div class="container text-center">
|
||||||
|
<p>© <?php echo date("Y"); ?> Haki Schedule. All Rights Reserved.</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
156
admin_teachers.php
Normal file
156
admin_teachers.php
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/includes/auth_check.php';
|
||||||
|
require_once __DIR__ . '/db/config.php';
|
||||||
|
|
||||||
|
$message = '';
|
||||||
|
$error = '';
|
||||||
|
|
||||||
|
// Handle POST request to add a new teacher
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$teacherName = trim($_POST['teacher_name'] ?? '');
|
||||||
|
$teacherEmail = trim($_POST['teacher_email'] ?? '');
|
||||||
|
|
||||||
|
if (empty($teacherName) || empty($teacherEmail)) {
|
||||||
|
$error = 'Teacher name and email cannot be empty.';
|
||||||
|
} elseif (!filter_var($teacherEmail, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
$error = 'Invalid email format.';
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO teachers (name, email) VALUES (?, ?)");
|
||||||
|
if ($stmt->execute([$teacherName, $teacherEmail])) {
|
||||||
|
$message = 'Teacher "' . htmlspecialchars($teacherName) . '" created successfully!';
|
||||||
|
} else {
|
||||||
|
$error = 'Failed to create teacher.';
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
if ($e->errorInfo[1] == 1062) { // Duplicate entry
|
||||||
|
$error = 'Error: A teacher with the email "' . htmlspecialchars($teacherEmail) . '" already exists.';
|
||||||
|
} else {
|
||||||
|
$error = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch all teachers to display
|
||||||
|
$teachers = [];
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->query("SELECT id, name, email, created_at FROM teachers ORDER BY created_at DESC");
|
||||||
|
$teachers = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Admin: Manage Teachers - Haki Schedule</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top shadow-sm">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand fw-bold" href="/">Haki Schedule</a>
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
|
<ul class="navbar-nav ms-auto">
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/">Home</a></li>
|
||||||
|
<?php if (isset($_SESSION['user_id'])): ?>
|
||||||
|
<li class="nav-item dropdown">
|
||||||
|
<a class="nav-link dropdown-toggle active" href="#" id="manageDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
|
Manage
|
||||||
|
</a>
|
||||||
|
<ul class="dropdown-menu" aria-labelledby="manageDropdown">
|
||||||
|
<li><a class="dropdown-item" href="/admin_classes.php">Classes</a></li>
|
||||||
|
<li><a class="dropdown-item" href="/admin_subjects.php">Subjects</a></li>
|
||||||
|
<li><a class="dropdown-item active" href="/admin_teachers.php">Teachers</a></li>
|
||||||
|
<li><a class="dropdown-item" href="/admin_workloads.php">Workloads</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/timetable.php">Timetable</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/logout.php">Logout</a></li>
|
||||||
|
<?php else: ?>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/demo.php">Demo</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/login.php">Login</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/register.php">Register</a></li>
|
||||||
|
<?php endif; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main class="container py-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-lg-8">
|
||||||
|
<h1 class="h2 fw-bold mb-4">Manage Teachers</h1>
|
||||||
|
|
||||||
|
<?php if ($message): ?>
|
||||||
|
<div class="alert alert-success"><?php echo $message; ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ($error): ?>
|
||||||
|
<div class="alert alert-danger"><?php echo $error; ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<!-- Create Teacher Form -->
|
||||||
|
<div class="card mb-4">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Create a New Teacher</h5>
|
||||||
|
<form action="admin_teachers.php" method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="teacher_name" class="form-label">Teacher Name</label>
|
||||||
|
<input type="text" class="form-control" id="teacher_name" name="teacher_name" placeholder="e.g., John Doe" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="teacher_email" class="form-label">Teacher Email</label>
|
||||||
|
<input type="email" class="form-control" id="teacher_email" name="teacher_email" placeholder="e.g., john.doe@example.com" required>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Create Teacher</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Existing Teachers List -->
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Existing Teachers</h5>
|
||||||
|
<?php if (empty($teachers) && !$error): ?>
|
||||||
|
<p class="text-muted">No teachers have been created yet. Use the form above to add the first one.</p>
|
||||||
|
<?php else:
|
||||||
|
if(!empty($teachers)) : ?>
|
||||||
|
<ul class="list-group list-group-flush">
|
||||||
|
<?php foreach ($teachers as $teacher): ?>
|
||||||
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||||
|
<div>
|
||||||
|
<strong><?php echo htmlspecialchars($teacher['name']); ?></strong><br>
|
||||||
|
<small class="text-muted"><?php echo htmlspecialchars($teacher['email']); ?></small>
|
||||||
|
</div>
|
||||||
|
<small class="text-muted">Created: <?php echo date("M j, Y", strtotime($teacher['created_at'])); ?></small>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
<?php endif; endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="bg-dark text-white py-4 mt-5">
|
||||||
|
<div class="container text-center">
|
||||||
|
<p>© <?php echo date("Y"); ?> Haki Schedule. All Rights Reserved.</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
232
admin_workloads.php
Normal file
232
admin_workloads.php
Normal file
@ -0,0 +1,232 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/includes/auth_check.php';
|
||||||
|
require_once __DIR__ . '/db/config.php';
|
||||||
|
|
||||||
|
$message = '';
|
||||||
|
$error = '';
|
||||||
|
$pdo = db();
|
||||||
|
$edit_workload = null;
|
||||||
|
|
||||||
|
// Handle Delete request
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_id'])) {
|
||||||
|
try {
|
||||||
|
$stmt = $pdo->prepare("DELETE FROM workloads WHERE id = ?");
|
||||||
|
if ($stmt->execute([$_POST['delete_id']])) {
|
||||||
|
$message = 'Workload deleted successfully!';
|
||||||
|
} else {
|
||||||
|
$error = 'Failed to delete workload.';
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Handle POST request to add or update a workload
|
||||||
|
elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$workload_id = $_POST['workload_id'] ?? null;
|
||||||
|
$class_id = $_POST['class_id'] ?? null;
|
||||||
|
$subject_id = $_POST['subject_id'] ?? null;
|
||||||
|
$teacher_id = $_POST['teacher_id'] ?? null;
|
||||||
|
$lessons_per_week = $_POST['lessons_per_week'] ?? null;
|
||||||
|
|
||||||
|
if (empty($class_id) || empty($subject_id) || empty($teacher_id) || empty($lessons_per_week)) {
|
||||||
|
$error = 'All fields are required.';
|
||||||
|
} elseif (!filter_var($lessons_per_week, FILTER_VALIDATE_INT, ["options" => ["min_range" => 1]])) {
|
||||||
|
$error = 'Lessons per week must be a positive number.';
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
if ($workload_id) { // Update
|
||||||
|
$stmt = $pdo->prepare("UPDATE workloads SET class_id = ?, subject_id = ?, teacher_id = ?, lessons_per_week = ? WHERE id = ?");
|
||||||
|
if ($stmt->execute([$class_id, $subject_id, $teacher_id, $lessons_per_week, $workload_id])) {
|
||||||
|
$message = 'Workload updated successfully!';
|
||||||
|
} else {
|
||||||
|
$error = 'Failed to update workload.';
|
||||||
|
}
|
||||||
|
} else { // Insert
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO workloads (class_id, subject_id, teacher_id, lessons_per_week) VALUES (?, ?, ?, ?)");
|
||||||
|
if ($stmt->execute([$class_id, $subject_id, $teacher_id, $lessons_per_week])) {
|
||||||
|
$message = 'Workload created successfully!';
|
||||||
|
} else {
|
||||||
|
$error = 'Failed to create workload.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
if ($e->errorInfo[1] == 1062) {
|
||||||
|
$error = 'Error: This workload assignment (Class, Subject, Teacher) already exists.';
|
||||||
|
} else {
|
||||||
|
$error = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle Edit request (fetch workload to edit)
|
||||||
|
if (isset($_GET['edit_id'])) {
|
||||||
|
try {
|
||||||
|
$stmt = $pdo->prepare("SELECT * FROM workloads WHERE id = ?");
|
||||||
|
$stmt->execute([$_GET['edit_id']]);
|
||||||
|
$edit_workload = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch related data for dropdowns
|
||||||
|
try {
|
||||||
|
$classes = $pdo->query("SELECT id, name FROM classes ORDER BY name")->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
$subjects = $pdo->query("SELECT id, name FROM subjects ORDER BY name")->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
$teachers = $pdo->query("SELECT id, name FROM teachers ORDER BY name")->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error = 'Database error while fetching data: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch all workloads to display
|
||||||
|
$workloads = [];
|
||||||
|
try {
|
||||||
|
$workloads_stmt = $pdo->query("
|
||||||
|
SELECT w.id, c.name as class_name, s.name as subject_name, t.name as teacher_name, w.lessons_per_week, w.created_at, w.class_id, w.subject_id, w.teacher_id
|
||||||
|
FROM workloads w
|
||||||
|
JOIN classes c ON w.class_id = c.id
|
||||||
|
JOIN subjects s ON w.subject_id = s.id
|
||||||
|
JOIN teachers t ON w.teacher_id = t.id
|
||||||
|
ORDER BY w.created_at DESC
|
||||||
|
");
|
||||||
|
$workloads = $workloads_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error = 'Database error while fetching workloads: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Admin: Manage Workloads - Haki Schedule</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.10.3/font/bootstrap-icons.min.css">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top shadow-sm">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand fw-bold" href="/">Haki Schedule</a>
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
|
<ul class="navbar-nav ms-auto">
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/">Home</a></li>
|
||||||
|
<?php if (isset($_SESSION['user_id'])): ?>
|
||||||
|
<li class="nav-item dropdown">
|
||||||
|
<a class="nav-link dropdown-toggle active" href="#" id="manageDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
|
Manage
|
||||||
|
</a>
|
||||||
|
<ul class="dropdown-menu" aria-labelledby="manageDropdown">
|
||||||
|
<li><a class="dropdown-item" href="/admin_classes.php">Classes</a></li>
|
||||||
|
<li><a class="dropdown-item" href="/admin_subjects.php">Subjects</a></li>
|
||||||
|
<li><a class="dropdown-item" href="/admin_teachers.php">Teachers</a></li>
|
||||||
|
<li><a class="dropdown-item active" href="/admin_workloads.php">Workloads</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/timetable.php">Timetable</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/logout.php">Logout</a></li>
|
||||||
|
<?php else: ?>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/demo.php">Demo</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/login.php">Login</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/register.php">Register</a></li>
|
||||||
|
<?php endif; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main class="container py-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-lg-10">
|
||||||
|
<h1 class="h2 fw-bold mb-4">Manage Workloads</h1>
|
||||||
|
|
||||||
|
<?php if ($message): ?><div class="alert alert-success"><?php echo $message; ?></div><?php endif; ?>
|
||||||
|
<?php if ($error): ?><div class="alert alert-danger"><?php echo $error; ?></div><?php endif; ?>
|
||||||
|
|
||||||
|
<div class="card mb-4">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title"><?php echo $edit_workload ? 'Edit Workload' : 'Assign a New Workload'; ?></h5>
|
||||||
|
<form action="admin_workloads.php" method="POST">
|
||||||
|
<input type="hidden" name="workload_id" value="<?php echo $edit_workload['id'] ?? ''; ?>">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="class_id" class="form-label">Class</label>
|
||||||
|
<select class="form-select" id="class_id" name="class_id" required>
|
||||||
|
<?php foreach ($classes as $class): ?>
|
||||||
|
<option value="<?php echo $class['id']; ?>" <?php echo (isset($edit_workload) && $edit_workload['class_id'] == $class['id']) ? 'selected' : ''; ?>><?php echo htmlspecialchars($class['name']); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="subject_id" class="form-label">Subject</label>
|
||||||
|
<select class="form-select" id="subject_id" name="subject_id" required>
|
||||||
|
<?php foreach ($subjects as $subject): ?>
|
||||||
|
<option value="<?php echo $subject['id']; ?>" <?php echo (isset($edit_workload) && $edit_workload['subject_id'] == $subject['id']) ? 'selected' : ''; ?>><?php echo htmlspecialchars($subject['name']); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="teacher_id" class="form-label">Teacher</label>
|
||||||
|
<select class="form-select" id="teacher_id" name="teacher_id" required>
|
||||||
|
<?php foreach ($teachers as $teacher): ?>
|
||||||
|
<option value="<?php echo $teacher['id']; ?>" <?php echo (isset($edit_workload) && $edit_workload['teacher_id'] == $teacher['id']) ? 'selected' : ''; ?>><?php echo htmlspecialchars($teacher['name']); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="lessons_per_week" class="form-label">Lessons Per Week</label>
|
||||||
|
<input type="number" class="form-control" id="lessons_per_week" name="lessons_per_week" min="1" value="<?php echo $edit_workload['lessons_per_week'] ?? ''; ?>" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary"><?php echo $edit_workload ? 'Update Workload' : 'Create Workload'; ?></button>
|
||||||
|
<?php if ($edit_workload): ?>
|
||||||
|
<a href="admin_workloads.php" class="btn btn-secondary">Cancel Edit</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Existing Workloads</h5>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead><tr><th>Class</th><th>Subject</th><th>Teacher</th><th class="text-center">Lessons/Week</th><th>Actions</th></tr></thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ($workloads as $workload): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($workload['class_name']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($workload['subject_name']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($workload['teacher_name']); ?></td>
|
||||||
|
<td class="text-center"><?php echo htmlspecialchars($workload['lessons_per_week']); ?></td>
|
||||||
|
<td>
|
||||||
|
<a href="?edit_id=<?php echo $workload['id']; ?>" class="btn btn-sm btn-outline-primary"><i class="bi bi-pencil-fill"></i></a>
|
||||||
|
<form action="admin_workloads.php" method="POST" class="d-inline" onsubmit="return confirm('Are you sure you want to delete this workload?');">
|
||||||
|
<input type="hidden" name="delete_id" value="<?php echo $workload['id']; ?>">
|
||||||
|
<button type="submit" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash-fill"></i></button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="bg-dark text-white py-4 mt-5"><div class="container text-center"><p>© <?php echo date("Y"); ?> Haki Schedule. All Rights Reserved.</p></div></footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -153,3 +153,52 @@ body {
|
|||||||
display: none !important;
|
display: none !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* New Timetable Styles */
|
||||||
|
.timetable-table {
|
||||||
|
border-collapse: separate;
|
||||||
|
border-spacing: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time-col {
|
||||||
|
width: 100px;
|
||||||
|
font-weight: bold;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timetable-cell-container {
|
||||||
|
padding: 2px !important;
|
||||||
|
background-color: #F9FAFB;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timetable-cell {
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 12px 8px;
|
||||||
|
color: #111827;
|
||||||
|
height: 100%;
|
||||||
|
min-height: 80px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
transition: transform 0.2s, box-shadow 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timetable-cell:hover {
|
||||||
|
transform: translateY(-3px);
|
||||||
|
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.subject-name {
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.teacher-name {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.break-cell {
|
||||||
|
background-color: #F3F4F6;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|||||||
41
db/migrate.php
Normal file
41
db/migrate.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
// Simple migration runner
|
||||||
|
require_once __DIR__ . '/config.php';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
// Check if PDO connection is valid
|
||||||
|
if (!$pdo) {
|
||||||
|
throw new Exception("PDO connection is not valid. Check db/config.php");
|
||||||
|
}
|
||||||
|
|
||||||
|
$migrationsDir = __DIR__ . '/migrations';
|
||||||
|
if (!is_dir($migrationsDir)) {
|
||||||
|
echo "No migrations directory found. Nothing to do.\n";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
$files = glob($migrationsDir . '/*.sql');
|
||||||
|
sort($files);
|
||||||
|
|
||||||
|
if (empty($files)) {
|
||||||
|
echo "No migration files found. Nothing to do.\n";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($files as $file) {
|
||||||
|
echo "Running migration: " . basename($file) . "\n";
|
||||||
|
$sql = file_get_contents($file);
|
||||||
|
$pdo->exec($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "Migrations completed successfully.\n";
|
||||||
|
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
http_response_code(500);
|
||||||
|
die("Migration failed: " . $e->getMessage() . "\n");
|
||||||
|
} catch (Exception $e) {
|
||||||
|
http_response_code(500);
|
||||||
|
die("An error occurred: " . $e->getMessage() . "\n");
|
||||||
|
}
|
||||||
|
|
||||||
6
db/migrations/001_create_classes_table.sql
Normal file
6
db/migrations/001_create_classes_table.sql
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS classes (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
school_id INT UNSIGNED DEFAULT 1, -- For future multi-tenancy
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
) ENGINE=INNODB;
|
||||||
5
db/migrations/002_create_subjects_table.sql
Normal file
5
db/migrations/002_create_subjects_table.sql
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS subjects (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
name VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
6
db/migrations/003_create_teachers_table.sql
Normal file
6
db/migrations/003_create_teachers_table.sql
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS teachers (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
email VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
12
db/migrations/004_create_workloads_table.sql
Normal file
12
db/migrations/004_create_workloads_table.sql
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS workloads (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
class_id INT NOT NULL,
|
||||||
|
subject_id INT NOT NULL,
|
||||||
|
teacher_id INT NOT NULL,
|
||||||
|
lessons_per_week INT NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (class_id) REFERENCES classes(id) ON DELETE CASCADE,
|
||||||
|
FOREIGN KEY (subject_id) REFERENCES subjects(id) ON DELETE CASCADE,
|
||||||
|
FOREIGN KEY (teacher_id) REFERENCES teachers(id) ON DELETE CASCADE,
|
||||||
|
UNIQUE KEY (class_id, subject_id, teacher_id)
|
||||||
|
);
|
||||||
7
db/migrations/005_create_users_table.sql
Normal file
7
db/migrations/005_create_users_table.sql
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
username VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
password VARCHAR(255) NOT NULL,
|
||||||
|
role VARCHAR(50) NOT NULL DEFAULT 'admin',
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
) ENGINE=INNODB;
|
||||||
3
db/migrations/006_add_subject_options.sql
Normal file
3
db/migrations/006_add_subject_options.sql
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
ALTER TABLE `subjects`
|
||||||
|
ADD COLUMN `has_double_lesson` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
ADD COLUMN `elective_group` VARCHAR(255) NULL;
|
||||||
220
demo.php
220
demo.php
@ -16,92 +16,146 @@
|
|||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
</head>
|
</head>
|
||||||
<body class="bg-light py-5">
|
<body>
|
||||||
|
|
||||||
<div class="container printable-area">
|
<nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top">
|
||||||
<div class="timetable-container">
|
<div class="container">
|
||||||
<div class="timetable-header">
|
<a class="navbar-brand fw-bold" href="/">Haki Schedule</a>
|
||||||
<div>
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
<h1 class="h3 fw-bold">Class Timetable: Grade 10A</h1>
|
<span class="navbar-toggler-icon"></span>
|
||||||
<p class="text-muted">A visual demonstration of a generated schedule.</p>
|
</button>
|
||||||
</div>
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
<div>
|
<ul class="navbar-nav ms-auto">
|
||||||
<a href="/" class="btn btn-outline-secondary me-2">Back to Home</a>
|
<li class="nav-item">
|
||||||
<button onclick="window.print();" class="btn btn-primary">Print Timetable</button>
|
<a class="nav-link" href="/">Home</a>
|
||||||
</div>
|
</li>
|
||||||
</div>
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/#features">Features</a>
|
||||||
<div class="table-responsive">
|
</li>
|
||||||
<table class="table table-bordered timetable-table">
|
<li class="nav-item">
|
||||||
<thead>
|
<a class="nav-link" href="#">Pricing</a>
|
||||||
<tr>
|
</li>
|
||||||
<th>Day</th>
|
<li class="nav-item">
|
||||||
<th>08:00 - 09:00</th>
|
<a class="nav-link active" href="/demo.php">Demo</a>
|
||||||
<th>09:00 - 10:00</th>
|
</li>
|
||||||
<th>10:00 - 10:30</th>
|
<li class="nav-item">
|
||||||
<th>10:30 - 11:30</th>
|
<a class="nav-link" href="/timetable.php">Timetable</a>
|
||||||
<th>11:30 - 12:30</th>
|
</li>
|
||||||
<th>12:30 - 13:30</th>
|
<li class="nav-item dropdown">
|
||||||
<th>13:30 - 14:30</th>
|
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
</tr>
|
Manage
|
||||||
</thead>
|
</a>
|
||||||
<tbody>
|
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||||
<tr>
|
<li><a class="dropdown-item" href="/admin_classes.php">Manage Classes</a></li>
|
||||||
<td class="day-header">Monday</td>
|
<li><a class="dropdown-item" href="/admin_subjects.php">Manage Subjects</a></li>
|
||||||
<td class="timetable-cell"><strong>Mathematics</strong><span>Mr. Smith</span></td>
|
<li><a class="dropdown-item" href="/admin_teachers.php">Manage Teachers</a></li>
|
||||||
<td class="timetable-cell"><strong>Physics</strong><span>Ms. Jones</span></td>
|
<li><a class="dropdown-item" href="/admin_workloads.php">Manage Workloads</a></li>
|
||||||
<td class="break-cell">Break</td>
|
</ul>
|
||||||
<td class="timetable-cell"><strong>English</strong><span>Mr. Doe</span></td>
|
</li>
|
||||||
<td class="timetable-cell"><strong>History</strong><span>Mrs. Dane</span></td>
|
</ul>
|
||||||
<td class="break-cell">Lunch</td>
|
<ul class="navbar-nav ms-lg-3">
|
||||||
<td class="timetable-cell"><strong>Biology</strong><span>Ms. Jones</span></td>
|
<li class="nav-item">
|
||||||
</tr>
|
<a class="btn btn-outline-primary" href="#">Login</a>
|
||||||
<tr>
|
</li>
|
||||||
<td class="day-header">Tuesday</td>
|
<li class="nav-item ms-lg-2 mt-2 mt-lg-0">
|
||||||
<td class="timetable-cell"><strong>Chemistry</strong><span>Mr. White</span></td>
|
<a class="btn btn-primary" href="#">Sign Up</a>
|
||||||
<td class="timetable-cell"><strong>English</strong><span>Mr. Doe</span></td>
|
</li>
|
||||||
<td class="break-cell">Break</td>
|
</ul>
|
||||||
<td class="timetable-cell"><strong>Mathematics</strong><span>Mr. Smith</span></td>
|
|
||||||
<td class="timetable-cell"><strong>Geography</strong><span>Mr. Green</span></td>
|
|
||||||
<td class="break-cell">Lunch</td>
|
|
||||||
<td class="timetable-cell"><strong>Art</strong><span>Ms. Black</span></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="day-header">Wednesday</td>
|
|
||||||
<td class="timetable-cell"><strong>Physics (Double)</strong><span>Ms. Jones</span></td>
|
|
||||||
<td class="timetable-cell"><strong>Physics (Double)</strong><span>Ms. Jones</span></td>
|
|
||||||
<td class="break-cell">Break</td>
|
|
||||||
<td class="timetable-cell"><strong>History</strong><span>Mrs. Dane</span></td>
|
|
||||||
<td class="timetable-cell"><strong>Mathematics</strong><span>Mr. Smith</span></td>
|
|
||||||
<td class="break-cell">Lunch</td>
|
|
||||||
<td class="timetable-cell"><strong>Music</strong><span>Mr. Brown</span></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="day-header">Thursday</td>
|
|
||||||
<td class="timetable-cell"><strong>English</strong><span>Mr. Doe</span></td>
|
|
||||||
<td class="timetable-cell"><strong>Biology</strong><span>Ms. Jones</span></td>
|
|
||||||
<td class="break-cell">Break</td>
|
|
||||||
<td class="timetable-cell"><strong>Chemistry</strong><span>Mr. White</span></td>
|
|
||||||
<td class="timetable-cell"><strong>Physical Ed.</strong><span>Mr. Blue</span></td>
|
|
||||||
<td class="break-cell">Lunch</td>
|
|
||||||
<td class="timetable-cell"><strong>Mathematics</strong><span>Mr. Smith</span></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="day-header">Friday</td>
|
|
||||||
<td class="timetable-cell"><strong>History</strong><span>Mrs. Dane</span></td>
|
|
||||||
<td class="timetable-cell"><strong>Geography</strong><span>Mr. Green</span></td>
|
|
||||||
<td class="break-cell">Break</td>
|
|
||||||
<td class="timetable-cell"><strong>English</strong><span>Mr. Doe</span></td>
|
|
||||||
<td class="timetable-cell"><strong>Mathematics</strong><span>Mr. Smith</span></td>
|
|
||||||
<td class="break-cell">Lunch</td>
|
|
||||||
<td class="timetable-cell"><strong>Elective</strong><span>Various</span></td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</nav>
|
||||||
|
|
||||||
|
<main class="container py-5">
|
||||||
|
<div class="printable-area">
|
||||||
|
<div class="timetable-container">
|
||||||
|
<div class="timetable-header">
|
||||||
|
<div>
|
||||||
|
<h1 class="h3 fw-bold">Class Timetable: Grade 10A</h1>
|
||||||
|
<p class="text-muted">A visual demonstration of a generated schedule.</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<button onclick="window.print();" class="btn btn-primary">Print Timetable</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-bordered timetable-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Day</th>
|
||||||
|
<th>08:00 - 09:00</th>
|
||||||
|
<th>09:00 - 10:00</th>
|
||||||
|
<th>10:00 - 10:30</th>
|
||||||
|
<th>10:30 - 11:30</th>
|
||||||
|
<th>11:30 - 12:30</th>
|
||||||
|
<th>12:30 - 13:30</th>
|
||||||
|
<th>13:30 - 14:30</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td class="day-header">Monday</td>
|
||||||
|
<td class="timetable-cell"><strong>Mathematics</strong><span>Mr. Smith</span></td>
|
||||||
|
<td class="timetable-cell"><strong>Physics</strong><span>Ms. Jones</span></td>
|
||||||
|
<td class="break-cell">Break</td>
|
||||||
|
<td class="timetable-cell"><strong>English</strong><span>Mr. Doe</span></td>
|
||||||
|
<td class="timetable-cell"><strong>History</strong><span>Mrs. Dane</span></td>
|
||||||
|
<td class="break-cell">Lunch</td>
|
||||||
|
<td class="timetable-cell"><strong>Biology</strong><span>Ms. Jones</span></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="day-header">Tuesday</td>
|
||||||
|
<td class="timetable-cell"><strong>Chemistry</strong><span>Mr. White</span></td>
|
||||||
|
<td class="timetable-cell"><strong>English</strong><span>Mr. Doe</span></td>
|
||||||
|
<td class="break-cell">Break</td>
|
||||||
|
<td class="timetable-cell"><strong>Mathematics</strong><span>Mr. Smith</span></td>
|
||||||
|
<td class="timetable-cell"><strong>Geography</strong><span>Mr. Green</span></td>
|
||||||
|
<td class="break-cell">Lunch</td>
|
||||||
|
<td class="timetable-cell"><strong>Art</strong><span>Ms. Black</span></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="day-header">Wednesday</td>
|
||||||
|
<td class="timetable-cell"><strong>Physics (Double)</strong><span>Ms. Jones</span></td>
|
||||||
|
<td class="timetable-cell"><strong>Physics (Double)</strong><span>Ms. Jones</span></td>
|
||||||
|
<td class="break-cell">Break</td>
|
||||||
|
<td class="timetable-cell"><strong>History</strong><span>Mrs. Dane</span></td>
|
||||||
|
<td class="timetable-cell"><strong>Mathematics</strong><span>Mr. Smith</span></td>
|
||||||
|
<td class="break-cell">Lunch</td>
|
||||||
|
<td class="timetable-cell"><strong>Music</strong><span>Mr. Brown</span></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="day-header">Thursday</td>
|
||||||
|
<td class="timetable-cell"><strong>English</strong><span>Mr. Doe</span></td>
|
||||||
|
<td class="timetable-cell"><strong>Biology</strong><span>Ms. Jones</span></td>
|
||||||
|
<td class="break-cell">Break</td>
|
||||||
|
<td class="timetable-cell"><strong>Chemistry</strong><span>Mr. White</span></td>
|
||||||
|
<td class="timetable-cell"><strong>Physical Ed.</strong><span>Mr. Blue</span></td>
|
||||||
|
<td class="break-cell">Lunch</td>
|
||||||
|
<td class="timetable-cell"><strong>Mathematics</strong><span>Mr. Smith</span></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="day-header">Friday</td>
|
||||||
|
<td class="timetable-cell"><strong>History</strong><span>Mrs. Dane</span></td>
|
||||||
|
<td class="timetable-cell"><strong>Geography</strong><span>Mr. Green</span></td>
|
||||||
|
<td class="break-cell">Break</td>
|
||||||
|
<td class="timetable-cell"><strong>English</strong><span>Mr. Doe</span></td>
|
||||||
|
<td class="timetable-cell"><strong>Mathematics</strong><span>Mr. Smith</span></td>
|
||||||
|
<td class="break-cell">Lunch</td>
|
||||||
|
<td class="timetable-cell"><strong>Elective</strong><span>Various</span></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="bg-dark text-white py-4 mt-auto">
|
||||||
|
<div class="container text-center">
|
||||||
|
<p>© <?php echo date("Y"); ?> Haki Schedule. All Rights Reserved.</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
8
includes/auth_check.php
Normal file
8
includes/auth_check.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
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') {
|
||||||
|
header("Location: login.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
55
index.php
55
index.php
@ -1,48 +1,45 @@
|
|||||||
|
<?php session_start(); ?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Haki Schedule</title>
|
<title>Haki Schedule - Automated Timetable Generator</title>
|
||||||
<meta name="description" content="Built with Flatlogic Generator">
|
<meta name="description" content="Haki Schedule is a simple, elegant, and powerful automated timetable generator for educational institutions.">
|
||||||
<meta name="keywords" content="timetable app, school scheduling, automated timetable, class schedule, teacher workload, subscription timetable, school administration, education tech, Haki schedule, Built with Flatlogic Generator">
|
|
||||||
<meta property="og:title" content="Haki Schedule">
|
|
||||||
<meta property="og:description" content="Built with Flatlogic Generator">
|
|
||||||
<meta property="og:image" content="">
|
|
||||||
<meta name="twitter:card" content="summary_large_image">
|
|
||||||
<meta name="twitter:image" content="">
|
|
||||||
|
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.10.3/font/bootstrap-icons.min.css">
|
||||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
<script src="https://unpkg.com/feather-icons"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top">
|
<nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top shadow-sm">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<a class="navbar-brand fw-bold" href="#">Haki Schedule</a>
|
<a class="navbar-brand fw-bold" href="/">Haki Schedule</a>
|
||||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
</button>
|
</button>
|
||||||
<div class="collapse navbar-collapse" id="navbarNav">
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
<ul class="navbar-nav ms-auto">
|
<ul class="navbar-nav ms-auto">
|
||||||
<li class="nav-item">
|
<li class="nav-item"><a class="nav-link active" href="/">Home</a></li>
|
||||||
<a class="nav-link" href="#features">Features</a>
|
<?php if (isset($_SESSION['user_id'])): ?>
|
||||||
</li>
|
<li class="nav-item dropdown">
|
||||||
<li class="nav-item">
|
<a class="nav-link dropdown-toggle" href="#" id="manageDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
<a class="nav-link" href="#">Pricing</a>
|
Manage
|
||||||
</li>
|
</a>
|
||||||
<li class="nav-item">
|
<ul class="dropdown-menu" aria-labelledby="manageDropdown">
|
||||||
<a class="nav-link" href="/demo.php">Demo</a>
|
<li><a class="dropdown-item" href="/admin_classes.php">Classes</a></li>
|
||||||
</li>
|
<li><a class="dropdown-item" href="/admin_subjects.php">Subjects</a></li>
|
||||||
</ul>
|
<li><a class="dropdown-item" href="/admin_teachers.php">Teachers</a></li>
|
||||||
<ul class="navbar-nav ms-lg-3">
|
<li><a class="dropdown-item" href="/admin_workloads.php">Workloads</a></li>
|
||||||
<li class="nav-item">
|
</ul>
|
||||||
<a class="btn btn-outline-primary" href="#">Login</a>
|
</li>
|
||||||
</li>
|
<li class="nav-item"><a class="nav-link" href="/timetable.php">Timetable</a></li>
|
||||||
<li class="nav-item ms-lg-2 mt-2 mt-lg-0">
|
<li class="nav-item"><a class="nav-link" href="/logout.php">Logout</a></li>
|
||||||
<a class="btn btn-primary" href="#">Sign Up</a>
|
<?php else: ?>
|
||||||
</li>
|
<li class="nav-item"><a class="nav-link" href="/demo.php">Demo</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/login.php">Login</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/register.php">Register</a></li>
|
||||||
|
<?php endif; ?>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
96
login.php
Normal file
96
login.php
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
require_once __DIR__ . '/db/config.php';
|
||||||
|
|
||||||
|
$error = '';
|
||||||
|
|
||||||
|
// If user is already logged in, redirect to home
|
||||||
|
if (isset($_SESSION['user_id'])) {
|
||||||
|
header("Location: index.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$username = $_POST['username'] ?? null;
|
||||||
|
$password = $_POST['password'] ?? null;
|
||||||
|
|
||||||
|
if (empty($username) || empty($password)) {
|
||||||
|
$error = 'Username and password are required.';
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?");
|
||||||
|
$stmt->execute([$username]);
|
||||||
|
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if ($user && password_verify($password, $user['password'])) {
|
||||||
|
// Password is correct, start session
|
||||||
|
$_SESSION['user_id'] = $user['id'];
|
||||||
|
$_SESSION['username'] = $user['username'];
|
||||||
|
$_SESSION['role'] = $user['role'];
|
||||||
|
|
||||||
|
// Redirect to the main page
|
||||||
|
header("Location: index.php");
|
||||||
|
exit;
|
||||||
|
} else {
|
||||||
|
$error = 'Invalid username or password.';
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Login - Haki Schedule</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top shadow-sm">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand fw-bold" href="/">Haki Schedule</a>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main class="container py-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-lg-5">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body p-4">
|
||||||
|
<h1 class="h3 fw-bold text-center mb-4">Admin Login</h1>
|
||||||
|
|
||||||
|
<?php if ($error): ?>
|
||||||
|
<div class="alert alert-danger"><?php echo $error; ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<form action="login.php" method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="username" class="form-label">Username</label>
|
||||||
|
<input type="text" class="form-control" id="username" name="username" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="password" class="form-label">Password</label>
|
||||||
|
<input type="password" class="form-control" id="password" name="password" required>
|
||||||
|
</div>
|
||||||
|
<div class="d-grid">
|
||||||
|
<button type="submit" class="btn btn-primary">Login</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<div class="text-center mt-3">
|
||||||
|
<p>Don't have an account? <a href="register.php">Register here</a>.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="bg-dark text-white py-4 mt-5"><div class="container text-center"><p>© <?php echo date("Y"); ?> Haki Schedule. All Rights Reserved.</p></div></footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
6
logout.php
Normal file
6
logout.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
session_unset();
|
||||||
|
session_destroy();
|
||||||
|
header("Location: login.php");
|
||||||
|
exit;
|
||||||
95
register.php
Normal file
95
register.php
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/db/config.php';
|
||||||
|
|
||||||
|
$message = '';
|
||||||
|
$error = '';
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$username = $_POST['username'] ?? null;
|
||||||
|
$password = $_POST['password'] ?? null;
|
||||||
|
|
||||||
|
if (empty($username) || empty($password)) {
|
||||||
|
$error = 'Username and password are required.';
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
// Check if username already exists
|
||||||
|
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = ?");
|
||||||
|
$stmt->execute([$username]);
|
||||||
|
if ($stmt->fetch()) {
|
||||||
|
$error = 'Username already taken. Please choose another one.';
|
||||||
|
} else {
|
||||||
|
// Hash the password
|
||||||
|
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
|
||||||
|
// Insert new user
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO users (username, password, role) VALUES (?, ?, 'admin')");
|
||||||
|
if ($stmt->execute([$username, $hashed_password])) {
|
||||||
|
$message = 'Registration successful! You can now <a href="login.php">login</a>.';
|
||||||
|
} else {
|
||||||
|
$error = 'Failed to register user.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Register - Haki Schedule</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top shadow-sm">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand fw-bold" href="/">Haki Schedule</a>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main class="container py-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-lg-5">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body p-4">
|
||||||
|
<h1 class="h3 fw-bold text-center mb-4">Create an Admin Account</h1>
|
||||||
|
|
||||||
|
<?php if ($message): ?>
|
||||||
|
<div class="alert alert-success"><?php echo $message; ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ($error): ?>
|
||||||
|
<div class="alert alert-danger"><?php echo $error; ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if (!$message): ?>
|
||||||
|
<form action="register.php" method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="username" class="form-label">Username</label>
|
||||||
|
<input type="text" class="form-control" id="username" name="username" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="password" class="form-label">Password</label>
|
||||||
|
<input type="password" class="form-control" id="password" name="password" required>
|
||||||
|
</div>
|
||||||
|
<div class="d-grid">
|
||||||
|
<button type="submit" class="btn btn-primary">Register</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<div class="text-center mt-3">
|
||||||
|
<p>Already have an account? <a href="login.php">Login here</a>.</p>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="bg-dark text-white py-4 mt-5"><div class="container text-center"><p>© <?php echo date("Y"); ?> Haki Schedule. All Rights Reserved.</p></div></footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
434
timetable.php
Normal file
434
timetable.php
Normal file
@ -0,0 +1,434 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/includes/auth_check.php';
|
||||||
|
require_once __DIR__ . '/db/config.php';
|
||||||
|
|
||||||
|
// --- Timetable Generation Logic V3 (with Backtracking) ---
|
||||||
|
|
||||||
|
class Scheduler
|
||||||
|
{
|
||||||
|
// Settings
|
||||||
|
private const DAYS_OF_WEEK = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];
|
||||||
|
private const PERIODS_PER_DAY = 8;
|
||||||
|
private const BREAK_PERIODS = [2, 5];
|
||||||
|
|
||||||
|
// Data
|
||||||
|
private $classes;
|
||||||
|
private $teachers;
|
||||||
|
private $workloads;
|
||||||
|
|
||||||
|
// State
|
||||||
|
private $class_timetables;
|
||||||
|
private $teacher_timetables;
|
||||||
|
private $unplaced_lessons = [];
|
||||||
|
private $lessons_to_schedule;
|
||||||
|
|
||||||
|
public function __construct($classes, $teachers, $workloads)
|
||||||
|
{
|
||||||
|
$this->classes = $classes;
|
||||||
|
$this->teachers = $teachers;
|
||||||
|
$this->workloads = $workloads;
|
||||||
|
|
||||||
|
// Initialize empty timetables
|
||||||
|
foreach ($this->classes as $class) {
|
||||||
|
$this->class_timetables[$class['id']] = array_fill(0, count(self::DAYS_OF_WEEK), array_fill(0, self::PERIODS_PER_DAY, null));
|
||||||
|
}
|
||||||
|
foreach ($this->teachers as $teacher) {
|
||||||
|
$this->teacher_timetables[$teacher['id']] = array_fill(0, count(self::DAYS_OF_WEEK), array_fill(0, self::PERIODS_PER_DAY, null));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generate()
|
||||||
|
{
|
||||||
|
$this->lessons_to_schedule = $this->prepare_lessons();
|
||||||
|
$this->solve($this->lessons_to_schedule); // Run the solver
|
||||||
|
|
||||||
|
return [
|
||||||
|
// The process always "succeeds" in running. Check unplaced_lessons for timetable completeness.
|
||||||
|
'success' => true,
|
||||||
|
'class_timetables' => $this->class_timetables,
|
||||||
|
'unplaced_lessons' => $this->unplaced_lessons,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function prepare_lessons()
|
||||||
|
{
|
||||||
|
$lessons = [];
|
||||||
|
$electives = [];
|
||||||
|
|
||||||
|
// Group electives
|
||||||
|
foreach ($this->workloads as $workload) {
|
||||||
|
if ($workload['elective_group']) {
|
||||||
|
$electives[$workload['elective_group']][] = $workload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create elective lesson blocks
|
||||||
|
foreach ($electives as $group_name => $group_workloads) {
|
||||||
|
for ($i = 0; $i < $group_workloads[0]['lessons_per_week']; $i++) {
|
||||||
|
$lessons[] = [
|
||||||
|
'is_elective' => true,
|
||||||
|
'group_name' => $group_name,
|
||||||
|
'workloads' => $group_workloads,
|
||||||
|
'subject_name' => implode(' / ', array_map(fn($w) => $w['subject_name'], $group_workloads)),
|
||||||
|
'teacher_name' => 'Elective Group',
|
||||||
|
'subject_id' => $group_workloads[0]['subject_id'] // For color
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create double and single lessons
|
||||||
|
foreach ($this->workloads as $workload) {
|
||||||
|
if ($workload['elective_group']) continue;
|
||||||
|
|
||||||
|
$lessons_per_week = $workload['lessons_per_week'];
|
||||||
|
if ($workload['has_double_lesson']) {
|
||||||
|
if ($lessons_per_week >= 2) {
|
||||||
|
$lessons[] = array_merge($workload, ['is_double' => true, 'duration' => 2]);
|
||||||
|
$lessons_per_week -= 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for ($i = 0; $i < $lessons_per_week; $i++) {
|
||||||
|
$lessons[] = array_merge($workload, ['is_double' => false, 'duration' => 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort lessons to prioritize more constrained ones (doubles and electives)
|
||||||
|
usort($lessons, function($a, $b) {
|
||||||
|
$a_score = ($a['is_elective'] ?? false) * 10 + ($a['is_double'] ?? false) * 5;
|
||||||
|
$b_score = ($b['is_elective'] ?? false) * 10 + ($b['is_double'] ?? false) * 5;
|
||||||
|
return $b_score <=> $a_score;
|
||||||
|
});
|
||||||
|
|
||||||
|
return $lessons;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function solve(&$lessons)
|
||||||
|
{
|
||||||
|
if (empty($lessons)) {
|
||||||
|
return true; // Success: all lessons have been scheduled
|
||||||
|
}
|
||||||
|
|
||||||
|
$lesson = array_pop($lessons); // Get the next lesson to try placing
|
||||||
|
$possible_slots = $this->get_possible_slots($lesson);
|
||||||
|
shuffle($possible_slots);
|
||||||
|
|
||||||
|
foreach ($possible_slots as $slot) {
|
||||||
|
$this->place_lesson($lesson, $slot);
|
||||||
|
|
||||||
|
if ($this->solve($lessons)) {
|
||||||
|
return true; // Found a valid solution for the rest of the lessons
|
||||||
|
}
|
||||||
|
|
||||||
|
// Backtrack
|
||||||
|
$this->unplace_lesson($lesson, $slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we get here, no slot worked for the current lesson.
|
||||||
|
$this->unplaced_lessons[] = $lesson; // Record as unplaced
|
||||||
|
|
||||||
|
// BUG FIX: The line below caused an infinite recursion and server crash.
|
||||||
|
// It has been removed. By returning false, we signal the parent to backtrack.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_possible_slots($lesson)
|
||||||
|
{
|
||||||
|
$slots = [];
|
||||||
|
for ($day = 0; $day < count(self::DAYS_OF_WEEK); $day++) {
|
||||||
|
for ($period = 0; $period < self::PERIODS_PER_DAY; $period++) {
|
||||||
|
$slot = ['day' => $day, 'period' => $period];
|
||||||
|
if ($this->is_slot_valid($lesson, $slot)) {
|
||||||
|
$slots[] = $slot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $slots;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function is_slot_valid($lesson, $slot)
|
||||||
|
{
|
||||||
|
$day = $slot['day'];
|
||||||
|
$start_period = $slot['period'];
|
||||||
|
$duration = $lesson['duration'] ?? 1;
|
||||||
|
|
||||||
|
// Check if slot is a break
|
||||||
|
for ($p = 0; $p < $duration; $p++) {
|
||||||
|
$current_period = $start_period + $p;
|
||||||
|
if ($current_period >= self::PERIODS_PER_DAY || in_array($current_period, self::BREAK_PERIODS)) {
|
||||||
|
return false; // Slot is out of bounds or a break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($lesson['is_elective']) {
|
||||||
|
// Check all classes and teachers in the elective group
|
||||||
|
foreach ($lesson['workloads'] as $workload) {
|
||||||
|
if (!$this->check_resource_availability($workload['class_id'], $workload['teacher_id'], $day, $start_period, $duration)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Check for single/double lesson
|
||||||
|
if (!$this->check_resource_availability($lesson['class_id'], $lesson['teacher_id'], $day, $start_period, $duration)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// ** STRICT DISTRIBUTION RULE **
|
||||||
|
$lessons_on_day = 0;
|
||||||
|
foreach ($this->class_timetables[$lesson['class_id']][$day] as $p) {
|
||||||
|
if ($p && $p['subject_id'] === $lesson['subject_id']) {
|
||||||
|
$lessons_on_day++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$max_per_day = ($lesson['lessons_per_week'] > count(self::DAYS_OF_WEEK)) ? 2 : 1;
|
||||||
|
if ($lessons_on_day >= $max_per_day) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function check_resource_availability($class_id, $teacher_id, $day, $start_period, $duration)
|
||||||
|
{
|
||||||
|
for ($p = 0; $p < $duration; $p++) {
|
||||||
|
$period = $start_period + $p;
|
||||||
|
if (!empty($this->class_timetables[$class_id][$day][$period]) || !empty($this->teacher_timetables[$teacher_id][$day][$period])) {
|
||||||
|
return false; // Conflict found
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function place_lesson($lesson, $slot)
|
||||||
|
{
|
||||||
|
$day = $slot['day'];
|
||||||
|
$start_period = $slot['period'];
|
||||||
|
$duration = $lesson['duration'] ?? 1;
|
||||||
|
|
||||||
|
$lesson_info = [
|
||||||
|
'subject' => $lesson['subject_name'],
|
||||||
|
'teacher' => $lesson['teacher_name'],
|
||||||
|
'subject_id' => $lesson['subject_id'],
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($lesson['is_elective']) {
|
||||||
|
foreach ($lesson['workloads'] as $workload) {
|
||||||
|
for ($p = 0; $p < $duration; $p++) {
|
||||||
|
$this->class_timetables[$workload['class_id']][$day][$start_period + $p] = $lesson_info;
|
||||||
|
$this->teacher_timetables[$workload['teacher_id']][$day][$start_period + $p] = $workload['class_id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for ($p = 0; $p < $duration; $p++) {
|
||||||
|
$this->class_timetables[$lesson['class_id']][$day][$start_period + $p] = $lesson_info;
|
||||||
|
$this->teacher_timetables[$lesson['teacher_id']][$day][$start_period + $p] = $lesson['class_id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function unplace_lesson($lesson, $slot)
|
||||||
|
{
|
||||||
|
$day = $slot['day'];
|
||||||
|
$start_period = $slot['period'];
|
||||||
|
$duration = $lesson['duration'] ?? 1;
|
||||||
|
|
||||||
|
if ($lesson['is_elective']) {
|
||||||
|
foreach ($lesson['workloads'] as $workload) {
|
||||||
|
for ($p = 0; $p < $duration; $p++) {
|
||||||
|
$this->class_timetables[$workload['class_id']][$day][$start_period + $p] = null;
|
||||||
|
$this->teacher_timetables[$workload['teacher_id']][$day][$start_period + $p] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for ($p = 0; $p < $duration; $p++) {
|
||||||
|
$this->class_timetables[$lesson['class_id']][$day][$start_period + $p] = null;
|
||||||
|
$this->teacher_timetables[$lesson['teacher_id']][$day][$start_period + $p] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Data Fetching ---
|
||||||
|
$pdo = db();
|
||||||
|
$classes = $pdo->query("SELECT * FROM classes ORDER BY name")->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
$teachers = $pdo->query("SELECT * FROM teachers")->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
$workloads = $pdo->query("
|
||||||
|
SELECT
|
||||||
|
w.class_id, c.name as class_name,
|
||||||
|
w.subject_id, s.name as subject_name, s.has_double_lesson, s.elective_group,
|
||||||
|
w.teacher_id, t.name as teacher_name,
|
||||||
|
w.lessons_per_week
|
||||||
|
FROM workloads w
|
||||||
|
JOIN classes c ON w.class_id = c.id
|
||||||
|
JOIN subjects s ON w.subject_id = s.id
|
||||||
|
JOIN teachers t ON w.teacher_id = t.id
|
||||||
|
")->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
// --- Run Scheduler ---
|
||||||
|
$scheduler = new Scheduler($classes, $teachers, $workloads);
|
||||||
|
$result = $scheduler->generate();
|
||||||
|
$class_timetables = $result['class_timetables'];
|
||||||
|
$raw_unplaced_lessons = $result['unplaced_lessons'];
|
||||||
|
|
||||||
|
// Process unplaced lessons for display
|
||||||
|
$unplaced_lessons_summary = [];
|
||||||
|
foreach($raw_unplaced_lessons as $lesson) {
|
||||||
|
$key = $lesson['is_elective'] ? $lesson['group_name'] : $lesson['class_name'] . '-' . $lesson['subject_name'];
|
||||||
|
if (!isset($unplaced_lessons_summary[$key])) {
|
||||||
|
$unplaced_lessons_summary[$key] = [
|
||||||
|
'class' => $lesson['is_elective'] ? 'All Classes' : $lesson['class_name'],
|
||||||
|
'subject' => $lesson['is_elective'] ? "Elective: " . $lesson['group_name'] : $lesson['subject_name'],
|
||||||
|
'unplaced' => 0,
|
||||||
|
'total' => $lesson['is_elective'] ? $lesson['workloads'][0]['lessons_per_week'] : $lesson['lessons_per_week']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$unplaced_lessons_summary[$key]['unplaced']++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Color Helper ---
|
||||||
|
$subject_colors = [];
|
||||||
|
$color_palette = ['#FFADAD', '#FFD6A5', '#FDFFB6', '#CAFFBF', '#9BF6FF', '#A0C4FF', '#BDB2FF', '#FFC6FF', '#FFC8DD', '#D4A5A5'];
|
||||||
|
function get_subject_color($subject_name, &$subject_colors, $palette) {
|
||||||
|
if (!isset($subject_colors[$subject_name])) {
|
||||||
|
$subject_colors[$subject_name] = $palette[count($subject_colors) % count($palette)];
|
||||||
|
}
|
||||||
|
return $subject_colors[$subject_name];
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Generated Timetable - Haki Schedule</title>
|
||||||
|
<meta name="description" content="View the automatically generated class schedule with a modern, color-coded design.">
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.10.3/font/bootstrap-icons.min.css">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top shadow-sm">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand fw-bold" href="/">Haki Schedule</a>
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
|
<ul class="navbar-nav ms-auto">
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/">Home</a></li>
|
||||||
|
<?php if (isset($_SESSION['user_id'])): ?>
|
||||||
|
<li class="nav-item dropdown">
|
||||||
|
<a class="nav-link dropdown-toggle" href="#" id="manageDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
|
Manage
|
||||||
|
</a>
|
||||||
|
<ul class="dropdown-menu" aria-labelledby="manageDropdown">
|
||||||
|
<li><a class="dropdown-item" href="/admin_classes.php">Classes</a></li>
|
||||||
|
<li><a class="dropdown-item" href="/admin_subjects.php">Subjects</a></li>
|
||||||
|
<li><a class="dropdown-item" href="/admin_teachers.php">Teachers</a></li>
|
||||||
|
<li><a class="dropdown-item" href="/admin_workloads.php">Workloads</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item"><a class="nav-link active" href="/timetable.php">Timetable</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/logout.php">Logout</a></li>
|
||||||
|
<?php else: ?>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/demo.php">Demo</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/login.php">Login</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="/register.php">Register</a></li>
|
||||||
|
<?php endif; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main class="container py-5">
|
||||||
|
<div class="printable-area">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
|
<div>
|
||||||
|
<h1 class="h3 fw-bold">Generated Timetable</h1>
|
||||||
|
<p class="text-muted">Automatically generated, color-coded class schedules.</p>
|
||||||
|
</div>
|
||||||
|
<button onclick="window.print();" class="btn btn-primary d-print-none"><i class="bi bi-printer-fill me-2"></i>Print Timetable</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if (!empty($unplaced_lessons_summary)): ?>
|
||||||
|
<div class="alert alert-warning">
|
||||||
|
<h5 class="alert-heading">Scheduling Conflict</h5>
|
||||||
|
<p>The system could not place all lessons. This is likely due to too many constraints (e.g., not enough available slots for a teacher). Please review workloads and constraints.</p>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($unplaced_lessons_summary as $item): ?>
|
||||||
|
<li>Could not place <?php echo $item['unplaced']; ?> of <?php echo $item['total']; ?> lessons for <strong><?php echo htmlspecialchars($item['subject']); ?></strong> in class <strong><?php echo htmlspecialchars($item['class']); ?></strong>.</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if (empty($classes)): ?>
|
||||||
|
<div class="alert alert-info">Please <a href="admin_classes.php">create a class</a> and <a href="admin_workloads.php">assign workloads</a> to generate a timetable.</div>
|
||||||
|
<?php else: ?>
|
||||||
|
<ul class="nav nav-tabs nav-fill mb-4 d-print-none" id="classTabs" role="tablist">
|
||||||
|
<?php foreach ($classes as $index => $class): ?>
|
||||||
|
<li class="nav-item" role="presentation">
|
||||||
|
<button class="nav-link <?php echo $index === 0 ? 'active' : ''; ?>" id="tab-<?php echo $class['id']; ?>" data-bs-toggle="tab" data-bs-target="#content-<?php echo $class['id']; ?>" type="button" role="tab"><?php echo htmlspecialchars($class['name']); ?></button>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="tab-content" id="classTabsContent">
|
||||||
|
<?php foreach ($classes as $index => $class): ?>
|
||||||
|
<div class="tab-pane fade <?php echo $index === 0 ? 'show active' : ''; ?>" id="content-<?php echo $class['id']; ?>" role="tabpanel">
|
||||||
|
<h4 class="d-none d-print-block mb-3 text-center">Timetable for <?php echo htmlspecialchars($class['name']); ?></h4>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-bordered timetable-table text-center">
|
||||||
|
<thead>
|
||||||
|
<tr class="table-light">
|
||||||
|
<th class="time-col">Time</th>
|
||||||
|
<?php foreach (self::DAYS_OF_WEEK as $day): ?>
|
||||||
|
<th><?php echo $day; ?></th>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php for ($period = 0; $period < self::PERIODS_PER_DAY; $period++): ?>
|
||||||
|
<?php if (in_array($period, self::BREAK_PERIODS)): ?>
|
||||||
|
<tr>
|
||||||
|
<td class="time-col table-light"><strong><?php echo $period === 2 ? 'Break' : 'Lunch'; ?></strong></td>
|
||||||
|
<td class="break-cell" colspan="<?php echo count(self::DAYS_OF_WEEK); ?>"></td>
|
||||||
|
</tr>
|
||||||
|
<?php else: ?>
|
||||||
|
<tr>
|
||||||
|
<td class="time-col table-light"><?php echo sprintf('%02d:00 - %02d:00', 8 + $period + ($period > 2 ? 1 : 0) - ($period > 5 ? 1 : 0), 9 + $period + ($period > 2 ? 1 : 0) - ($period > 5 ? 1 : 0)); ?></td>
|
||||||
|
<?php for ($day = 0; $day < count(self::DAYS_OF_WEEK); $day++): ?>
|
||||||
|
<td class="timetable-cell-container">
|
||||||
|
<?php if (!empty($class_timetables[$class['id']][$day][$period])):
|
||||||
|
$lesson = $class_timetables[$class['id']][$day][$period];
|
||||||
|
$color = get_subject_color($lesson['subject'], $subject_colors, $color_palette);
|
||||||
|
?>
|
||||||
|
<div class="timetable-cell" style="background-color: <?php echo $color; ?>;">
|
||||||
|
<div class="subject-name"><?php echo htmlspecialchars($lesson['subject']); ?></div>
|
||||||
|
<div class="teacher-name"><i class="bi bi-person-circle me-1"></i><?php echo htmlspecialchars($lesson['teacher']); ?></div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</td>
|
||||||
|
<?php endfor; ?>
|
||||||
|
</tr>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php endfor; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="bg-dark text-white py-4 mt-auto">
|
||||||
|
<div class="container text-center">
|
||||||
|
<p>© <?php echo date("Y"); ?> Haki Schedule. All Rights Reserved.</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user