117 lines
5.3 KiB
PHP
117 lines
5.3 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
require_once 'db/config.php';
|
|
|
|
$id = $_GET['id'] ?? null;
|
|
|
|
$errors = $_SESSION['errors'] ?? [];
|
|
$old_input = $_SESSION['old_input'] ?? [];
|
|
|
|
unset($_SESSION['errors']);
|
|
unset($_SESSION['old_input']);
|
|
|
|
$user = null;
|
|
if ($id) {
|
|
if (!empty($old_input)) {
|
|
$user = $old_input;
|
|
$user['id'] = $id;
|
|
} else {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT id, name, role, email FROM users WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
$user = $stmt->fetch();
|
|
} catch (PDOException $e) {
|
|
die("Database error: " . $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!$user) {
|
|
die("User not found.");
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Edit User - Admin Dashboard</title>
|
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&family=Open+Sans&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body class="admin-body">
|
|
<div class="admin-container">
|
|
<aside class="sidebar">
|
|
<div class="sidebar-header">
|
|
<h2>School Admin</h2>
|
|
</div>
|
|
<nav class="sidebar-nav">
|
|
<a href="admin.php">Dashboard</a>
|
|
<a href="users.php" class="active">User Management</a>
|
|
<a href="school_settings.php">School Settings</a>
|
|
<a href="#">Subjects & Classes</a>
|
|
<a href="#">Student Promotions</a>
|
|
<a href="#">Reports</a>
|
|
<a href="logout.php" class="logout">Logout</a>
|
|
</nav>
|
|
</aside>
|
|
<main class="main-content">
|
|
<header class="main-header">
|
|
<h1>Edit User</h1>
|
|
</header>
|
|
<div class="content-grid">
|
|
<div class="card full-width-card">
|
|
<div class="card-body">
|
|
<?php if (!empty($errors['db'])): ?>
|
|
<div class="alert alert-danger"><?= htmlspecialchars($errors['db']) ?></div>
|
|
<?php endif; ?>
|
|
<form action="update_user.php" method="POST">
|
|
<input type="hidden" name="id" value="<?= htmlspecialchars($user['id']) ?>">
|
|
<div class="form-group">
|
|
<label for="name">Name</label>
|
|
<input type="text" id="name" name="name" class="form-control" value="<?= htmlspecialchars($user['name'] ?? '') ?>" required>
|
|
<?php if (!empty($errors['name'])): ?>
|
|
<div class="error-message"><?= htmlspecialchars($errors['name']) ?></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="email">Email</label>
|
|
<input type="email" id="email" name="email" class="form-control" value="<?= htmlspecialchars($user['email'] ?? '') ?>" required>
|
|
<?php if (!empty($errors['email'])): ?>
|
|
<div class="error-message"><?= htmlspecialchars($errors['email']) ?></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password">New Password (leave blank to keep current)</label>
|
|
<input type="password" id="password" name="password" class="form-control">
|
|
<?php if (!empty($errors['password'])): ?>
|
|
<div class="error-message"><?= htmlspecialchars($errors['password']) ?></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="role">Role</label>
|
|
<select id="role" name="role" class="form-control" required>
|
|
<option value="Student" <?= ($user['role'] ?? '') == 'Student' ? 'selected' : '' ?>>Student</option>
|
|
<option value="Teacher" <?= ($user['role'] ?? '') == 'Teacher' ? 'selected' : '' ?>>Teacher</option>
|
|
<option value="Admin" <?= ($user['role'] ?? '') == 'Admin' ? 'selected' : '' ?>>Admin</option>
|
|
<option value="Parent" <?= ($user['role'] ?? '') == 'Parent' ? 'selected' : '' ?>>Parent</option>
|
|
<option value="Bursar" <?= ($user['role'] ?? '') == 'Bursar' ? 'selected' : '' ?>>Bursar</option>
|
|
<option value="Assistant Bursar" <?= ($user['role'] ?? '') == 'Assistant Bursar' ? 'selected' : '' ?>>Assistant Bursar</option>
|
|
</select>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Update User</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
</body>
|
|
</html>
|