Register more schools and trs enter workload
This commit is contained in:
parent
83fdeb8365
commit
8c6afdf3d9
@ -9,6 +9,20 @@ $school_id = $_SESSION['school_id'];
|
|||||||
|
|
||||||
$pdo = db();
|
$pdo = db();
|
||||||
|
|
||||||
|
// Handle permission toggle
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['toggle_permission_id'])) {
|
||||||
|
try {
|
||||||
|
$teacher_id = $_POST['toggle_permission_id'];
|
||||||
|
$new_status = $_POST['new_status'];
|
||||||
|
$stmt = $pdo->prepare("UPDATE teachers SET can_edit_workload = ? WHERE id = ? AND school_id = ?");
|
||||||
|
$stmt->execute([$new_status, $teacher_id, $school_id]);
|
||||||
|
$message = "Permission updated successfully.";
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error = "Error updating permission: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Handle Delete request
|
// Handle Delete request
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_id'])) {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_id'])) {
|
||||||
try {
|
try {
|
||||||
@ -187,7 +201,7 @@ try {
|
|||||||
|
|
||||||
<main class="container py-5">
|
<main class="container py-5">
|
||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
<div class="col-lg-8">
|
<div class="col-lg-10">
|
||||||
<h1 class="h2 fw-bold mb-4">Manage Teachers</h1>
|
<h1 class="h2 fw-bold mb-4">Manage Teachers</h1>
|
||||||
|
|
||||||
<?php if ($message): ?>
|
<?php if ($message): ?>
|
||||||
@ -213,7 +227,7 @@ try {
|
|||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="password" class="form-label">Password</label>
|
<label for="password" class="form-label">Password</label>
|
||||||
<input type="password" class="form-control" id="password" name="password" <?php echo $editing_teacher ? '' : 'required'; ?>>
|
<input type="password" class="form-.form-control" id="password" name="password" <?php echo $editing_teacher ? '' : 'required'; ?>>
|
||||||
<?php if ($editing_teacher): ?>
|
<?php if ($editing_teacher): ?>
|
||||||
<small class="form-text text-muted">Leave blank to keep the current password.</small>
|
<small class="form-text text-muted">Leave blank to keep the current password.</small>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
@ -239,6 +253,7 @@ try {
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Email</th>
|
<th>Email</th>
|
||||||
|
<th>Workload Editing</th>
|
||||||
<th>Actions</th>
|
<th>Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -248,10 +263,29 @@ try {
|
|||||||
<td><?php echo htmlspecialchars($teacher['name']); ?></td>
|
<td><?php echo htmlspecialchars($teacher['name']); ?></td>
|
||||||
<td><?php echo htmlspecialchars($teacher['email']); ?></td>
|
<td><?php echo htmlspecialchars($teacher['email']); ?></td>
|
||||||
<td>
|
<td>
|
||||||
<a href="?edit_id=<?php echo $teacher['id']; ?>" class="btn btn-sm btn-outline-primary">Edit</a>
|
<?php if ($teacher['can_edit_workload']): ?>
|
||||||
|
<span class="badge bg-success">Allowed</span>
|
||||||
|
<?php else: ?>
|
||||||
|
<span class="badge bg-secondary">Not Allowed</span>
|
||||||
|
<?php endif; ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="?edit_id=<?php echo $teacher['id']; ?>" class="btn btn-sm btn-outline-primary mb-1">Edit</a>
|
||||||
|
|
||||||
|
<form action="admin_teachers.php" method="POST" class="d-inline">
|
||||||
|
<input type="hidden" name="toggle_permission_id" value="<?php echo $teacher['id']; ?>">
|
||||||
|
<?php if ($teacher['can_edit_workload']): ?>
|
||||||
|
<input type="hidden" name="new_status" value="0">
|
||||||
|
<button type="submit" class="btn btn-sm btn-warning mb-1">Revoke</button>
|
||||||
|
<?php else: ?>
|
||||||
|
<input type="hidden" name="new_status" value="1">
|
||||||
|
<button type="submit" class="btn btn-sm btn-success mb-1">Allow</button>
|
||||||
|
<?php endif; ?>
|
||||||
|
</form>
|
||||||
|
|
||||||
<form action="admin_teachers.php" method="POST" class="d-inline" onsubmit="return confirm('Are you sure you want to delete this teacher?');">
|
<form action="admin_teachers.php" method="POST" class="d-inline" onsubmit="return confirm('Are you sure you want to delete this teacher?');">
|
||||||
<input type="hidden" name="delete_id" value="<?php echo $teacher['id']; ?>">
|
<input type="hidden" name="delete_id" value="<?php echo $teacher['id']; ?>">
|
||||||
<button type="submit" class="btn btn-sm btn-outline-danger">Delete</button>
|
<button type="submit" class="btn btn-sm btn-outline-danger mb-1">Delete</button>
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
2
db/migrations/022_add_can_edit_workload_to_teachers.sql
Normal file
2
db/migrations/022_add_can_edit_workload_to_teachers.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE `teachers`
|
||||||
|
ADD COLUMN `can_edit_workload` BOOLEAN NOT NULL DEFAULT 0 COMMENT 'If true, the teacher can edit their own workload';
|
||||||
@ -31,6 +31,11 @@ $role = $_SESSION['role'] ?? '';
|
|||||||
</li>
|
</li>
|
||||||
<li class="nav-item"><a class="nav-link <?php echo ($current_page == 'timetable.php') ? 'active' : ''; ?>" href="/timetable.php">Class Timetable</a></li>
|
<li class="nav-item"><a class="nav-link <?php echo ($current_page == 'timetable.php') ? 'active' : ''; ?>" href="/timetable.php">Class Timetable</a></li>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($role === 'teacher' && !empty($_SESSION['can_edit_workload'])): ?>
|
||||||
|
<li class="nav-item"><a class="nav-link <?php echo ($current_page == 'teacher_workload.php') ? 'active' : ''; ?>" href="/teacher_workload.php">My Workload</a></li>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<li class="nav-item"><a class="nav-link <?php echo ($current_page == 'teacher_timetable.php') ? 'active' : ''; ?>" href="/teacher_timetable.php">Teacher Timetable</a></li>
|
<li class="nav-item"><a class="nav-link <?php echo ($current_page == 'teacher_timetable.php') ? 'active' : ''; ?>" href="/teacher_timetable.php">Teacher Timetable</a></li>
|
||||||
<li class="nav-item"><a class="nav-link" href="/logout.php">Logout</a></li>
|
<li class="nav-item"><a class="nav-link" href="/logout.php">Logout</a></li>
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
|
|||||||
@ -31,6 +31,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$_SESSION['role'] = $user['role'];
|
$_SESSION['role'] = $user['role'];
|
||||||
$_SESSION['school_id'] = $user['school_id'];
|
$_SESSION['school_id'] = $user['school_id'];
|
||||||
|
|
||||||
|
// If the user is a teacher, fetch their workload editing permission
|
||||||
|
if ($user['role'] === 'teacher') {
|
||||||
|
$stmt = $pdo->prepare("SELECT can_edit_workload FROM teachers WHERE user_id = ?");
|
||||||
|
$stmt->execute([$user['id']]);
|
||||||
|
$teacher_permission = $stmt->fetchColumn();
|
||||||
|
$_SESSION['can_edit_workload'] = (bool)$teacher_permission;
|
||||||
|
}
|
||||||
|
|
||||||
// Redirect to the main page
|
// Redirect to the main page
|
||||||
header("Location: dashboard.php");
|
header("Location: dashboard.php");
|
||||||
exit;
|
exit;
|
||||||
|
|||||||
21
register.php
21
register.php
@ -3,19 +3,8 @@ require_once __DIR__ . '/db/config.php';
|
|||||||
|
|
||||||
$message = '';
|
$message = '';
|
||||||
$error = '';
|
$error = '';
|
||||||
$registration_open = false;
|
|
||||||
|
|
||||||
try {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$pdo = db();
|
|
||||||
$stmt = $pdo->query("SELECT COUNT(*) FROM schools");
|
|
||||||
if ($stmt->fetchColumn() == 0) {
|
|
||||||
$registration_open = true;
|
|
||||||
}
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
$error = 'Database error: ' . $e->getMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($registration_open && $_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
||||||
$username = $_POST['username'] ?? null;
|
$username = $_POST['username'] ?? null;
|
||||||
$password = $_POST['password'] ?? null;
|
$password = $_POST['password'] ?? null;
|
||||||
$school_name = $_POST['school_name'] ?? null;
|
$school_name = $_POST['school_name'] ?? null;
|
||||||
@ -25,6 +14,7 @@ if ($registration_open && $_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$error = 'All fields are required.';
|
$error = 'All fields are required.';
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
$pdo = db();
|
||||||
$pdo->beginTransaction();
|
$pdo->beginTransaction();
|
||||||
|
|
||||||
// Check if school name already exists
|
// Check if school name already exists
|
||||||
@ -99,7 +89,7 @@ if ($registration_open && $_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
<div class="alert alert-danger"><?php echo $error; ?></div>
|
<div class="alert alert-danger"><?php echo $error; ?></div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if (!$message && $registration_open): ?>
|
<?php if (!$message): ?>
|
||||||
<form action="register.php" method="POST">
|
<form action="register.php" method="POST">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="school_name" class="form-label">School Name</label>
|
<label for="school_name" class="form-label">School Name</label>
|
||||||
@ -124,11 +114,6 @@ if ($registration_open && $_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
<div class="text-center mt-3">
|
<div class="text-center mt-3">
|
||||||
<p>Already have an account? <a href="login.php">Login here</a>.</p>
|
<p>Already have an account? <a href="login.php">Login here</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
<?php elseif (!$message): ?>
|
|
||||||
<div class="alert alert-info">
|
|
||||||
Registration is currently closed. Only one school can be registered.
|
|
||||||
<p class="mt-3"><a href="login.php" class="btn btn-primary">Go to Login</a></p>
|
|
||||||
</div>
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user