t6
This commit is contained in:
parent
082d14fa79
commit
e15fa31a20
112
activities.php
112
activities.php
@ -1,110 +1,32 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
if (!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true) {
|
|
||||||
header("location: login.php");
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
require_once 'db/config.php';
|
if (!isset($_SESSION['user_id'])) {
|
||||||
|
header('Location: login.php');
|
||||||
try {
|
exit();
|
||||||
$pdo = db();
|
|
||||||
|
|
||||||
$sql = "CREATE TABLE IF NOT EXISTS activities (
|
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
user_id INT,
|
|
||||||
action VARCHAR(255) NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
|
||||||
)";
|
|
||||||
|
|
||||||
$pdo->exec($sql);
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
die("ERROR: Could not connect. " . $e->getMessage());
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!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">
|
||||||
<title>Activities</title>
|
<title>Activities</title>
|
||||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
<link rel="stylesheet" href="assets/css/custom.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<header>
|
||||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
|
||||||
<a class="navbar-brand" href="#">Admin</a>
|
|
||||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-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">
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="index.php">Home</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="users.php">Users</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="roles.php">Roles</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item active">
|
|
||||||
<a class="nav-link" href="activities.php">Activities</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="exams.php">Exams</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="attendance.php">Attendance</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<ul class="navbar-nav ml-auto">
|
|
||||||
<li class="nav-item">
|
|
||||||
<?php if (isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true): ?>
|
|
||||||
<a href="logout.php" class="btn btn-danger">Logout</a>
|
|
||||||
<?php else: ?>
|
|
||||||
<a href="login.php" class="btn btn-primary">Login</a>
|
|
||||||
<?php endif; ?>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<div class="container">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-12">
|
|
||||||
<div class="page-header">
|
|
||||||
<h1>Activities</h1>
|
<h1>Activities</h1>
|
||||||
</div>
|
<nav>
|
||||||
<p>Activity log:</p>
|
<ul>
|
||||||
<?php
|
<li><a href="teacher_dashboard.php">Dashboard</a></li>
|
||||||
$stmt = $pdo->query("SELECT a.id, u.username, a.action, a.created_at FROM activities a JOIN users u ON a.user_id = u.id ORDER BY a.created_at DESC");
|
<li><a href="logout.php">Logout</a></li>
|
||||||
$activities = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
</ul>
|
||||||
?>
|
</nav>
|
||||||
<table class="table table-bordered table-striped">
|
</header>
|
||||||
<thead>
|
<main>
|
||||||
<tr>
|
<h2>Activity Management</h2>
|
||||||
<th>ID</th>
|
<p>This page will contain student activity information.</p>
|
||||||
<th>User</th>
|
</main>
|
||||||
<th>Action</th>
|
|
||||||
<th>Timestamp</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<?php foreach ($activities as $activity): ?>
|
|
||||||
<tr>
|
|
||||||
<td><?php echo $activity["id"]; ?></td>
|
|
||||||
<td><?php echo htmlspecialchars($activity["username"]); ?></td>
|
|
||||||
<td><?php echo htmlspecialchars($activity["action"]); ?></td>
|
|
||||||
<td><?php echo $activity["created_at"]; ?></td>
|
|
||||||
</tr>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
254
attendance.php
254
attendance.php
@ -1,118 +1,216 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
//if (!isset($_SESSION['user_id']) || !in_array($_SESSION['role'], ['teacher', 'admin'])) {
|
|
||||||
// header("Location: login.php");
|
|
||||||
// exit();
|
|
||||||
//}
|
|
||||||
|
|
||||||
require_once 'db/config.php';
|
require_once 'db/config.php';
|
||||||
|
|
||||||
try {
|
if (!isset($_SESSION['user_id'])) {
|
||||||
$pdoconn = db();
|
header('Location: login.php');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
// Create attendance table
|
$role_name = $_SESSION['role_name'];
|
||||||
$pdoconn->exec("CREATE TABLE IF NOT EXISTS attendance (
|
$user_id = $_SESSION['user_id'];
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
user_id INT NOT NULL,
|
|
||||||
login_time DATETIME NOT NULL,
|
|
||||||
logout_time DATETIME DEFAULT NULL,
|
|
||||||
ip_address VARCHAR(45),
|
|
||||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
|
|
||||||
|
|
||||||
// Fetch online users
|
function get_students() {
|
||||||
$online_users_stmt = $pdoconn->prepare("SELECT u.username FROM attendance a JOIN users u ON a.user_id = u.id WHERE a.logout_time IS NULL");
|
$pdo = db();
|
||||||
$online_users_stmt->execute();
|
$stmt = $pdo->prepare("SELECT u.id, u.first_name, u.last_name FROM users u JOIN roles r ON u.role_id = r.id WHERE r.role_name = 'student'");
|
||||||
$online_users = $online_users_stmt->fetchAll(PDO::FETCH_ASSOC);
|
$stmt->execute();
|
||||||
|
return $stmt->fetchAll();
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch attendance history
|
function get_children_for_parent($parent_id) {
|
||||||
$history_stmt = $pdoconn->prepare("SELECT u.username, a.login_time, a.logout_time, a.ip_address FROM attendance a JOIN users u ON a.user_id = u.id ORDER BY a.login_time DESC");
|
$pdo = db();
|
||||||
$history_stmt->execute();
|
$stmt = $pdo->prepare("SELECT u.id, u.first_name, u.last_name FROM users u JOIN parent_child pc ON u.id = pc.child_id WHERE pc.parent_id = ?");
|
||||||
$history = $history_stmt->fetchAll(PDO::FETCH_ASSOC);
|
$stmt->execute([$parent_id]);
|
||||||
|
return $stmt->fetchAll();
|
||||||
|
}
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
function get_student_attendance($student_id) {
|
||||||
die("Could not connect to the database :" . $e->getMessage());
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("SELECT attendance_date, status FROM attendance WHERE student_id = ? ORDER BY attendance_date DESC");
|
||||||
|
$stmt->execute([$student_id]);
|
||||||
|
return $stmt->fetchAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $role_name === 'teacher') {
|
||||||
|
$attendance_date = $_POST['attendance_date'];
|
||||||
|
$students = $_POST['students'];
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO attendance (student_id, attendance_date, status) VALUES (?, ?, ?)");
|
||||||
|
|
||||||
|
foreach ($students as $student_id => $status) {
|
||||||
|
$stmt->execute([$student_id, $attendance_date, $status]);
|
||||||
|
}
|
||||||
|
$success_message = "Attendance for $attendance_date has been saved.";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<!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">
|
||||||
<title>Attendance</title>
|
<title>Attendance</title>
|
||||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
<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">
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<header class="p-3 mb-3 border-bottom sticky-top bg-light">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
<div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start">
|
||||||
<a class="navbar-brand" href="index.php">School Admin</a>
|
<a href="/" class="d-flex align-items-center mb-2 mb-lg-0 text-dark text-decoration-none">
|
||||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
<span class="fs-4">School Management</span>
|
||||||
<span class="navbar-toggler-icon"></span>
|
</a>
|
||||||
</button>
|
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
|
||||||
<div class="collapse navbar-collapse" id="navbarNav">
|
<?php if ($role_name === 'teacher'): ?>
|
||||||
<ul class="navbar-nav">
|
<li><a href="teacher_dashboard.php" class="nav-link px-2 link-dark">Dashboard</a></li>
|
||||||
<li class="nav-item"><a class="nav-link" href="index.php">Home</a></li>
|
<li><a href="attendance.php" class="nav-link px-2 link-secondary">Attendance</a></li>
|
||||||
<li class="nav-item"><a class="nav-link" href="users.php">Users</a></li>
|
<li><a href="exams.php" class="nav-link px-2 link-dark">Exams</a></li>
|
||||||
<li class="nav-item"><a class="nav-link" href="roles.php">Roles</a></li>
|
<li><a href="activities.php" class="nav-link px-2 link-dark">Activities</a></li>
|
||||||
<li class="nav-item"><a class="nav-link" href="activities.php">Activities</a></li>
|
<?php elseif ($role_name === 'student'): ?>
|
||||||
<li class="nav-item"><a class="nav-link" href="exams.php">Exams</a></li>
|
<li><a href="student_dashboard.php" class="nav-link px-2 link-dark">Dashboard</a></li>
|
||||||
<li class="nav-item active"><a class="nav-link" href="attendance.php">Attendance</a></li>
|
<li><a href="attendance.php" class="nav-link px-2 link-secondary">Attendance</a></li>
|
||||||
</ul>
|
<li><a href="exams.php" class="nav-link px-2 link-dark">Exams</a></li>
|
||||||
<ul class="navbar-nav ml-auto">
|
<li><a href="activities.php" class="nav-link px-2 link-dark">Activities</a></li>
|
||||||
<li class="nav-item">
|
<?php elseif ($role_name === 'parent'): ?>
|
||||||
<a href="logout.php" class="btn btn-danger">Logout</a>
|
<li><a href="parent_dashboard.php" class="nav-link px-2 link-dark">Dashboard</a></li>
|
||||||
</li>
|
<li><a href="attendance.php" class="nav-link px-2 link-secondary">Attendance</a></li>
|
||||||
|
<li><a href="exams.php" class="nav-link px-2 link-dark">Exams</a></li>
|
||||||
|
<li><a href="activities.php" class="nav-link px-2 link-dark">Activities</a></li>
|
||||||
|
<?php endif; ?>
|
||||||
</ul>
|
</ul>
|
||||||
|
<div class="text-end">
|
||||||
|
<a href="logout.php" class="btn btn-outline-primary">Logout</a>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</div>
|
||||||
<main class="py-5">
|
</div>
|
||||||
|
</header>
|
||||||
|
<main class="container py-5">
|
||||||
<h1>Attendance</h1>
|
<h1>Attendance</h1>
|
||||||
|
|
||||||
<div class="card my-4">
|
<?php if (isset($success_message)): ?>
|
||||||
<div class="card-header">
|
<div class="alert alert-success"><?php echo $success_message; ?></div>
|
||||||
Currently Online
|
|
||||||
</div>
|
|
||||||
<div class="card-body">
|
|
||||||
<?php if (count($online_users) > 0): ?>
|
|
||||||
<ul class="list-group">
|
|
||||||
<?php foreach ($online_users as $user): ?>
|
|
||||||
<li class="list-group-item"><?php echo htmlspecialchars($user['username']); ?></li>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</ul>
|
|
||||||
<?php else: ?>
|
|
||||||
<p>No users are currently online.</p>
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="card">
|
<?php if ($role_name === 'teacher'): ?>
|
||||||
<div class="card-header">
|
<h2>Take Attendance</h2>
|
||||||
Attendance History
|
<form method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="attendance_date" class="form-label">Date</label>
|
||||||
|
<input type="date" class="form-control" id="attendance_date" name="attendance_date" value="<?php echo date('Y-m-d'); ?>" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<table class="table">
|
||||||
<table class="table table-striped table-bordered">
|
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Username</th>
|
<th>Student Name</th>
|
||||||
<th>Login Time</th>
|
<th>Status</th>
|
||||||
<th>Logout Time</th>
|
|
||||||
<th>IP Address</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach ($history as $record): ?>
|
<?php
|
||||||
|
$students = get_students();
|
||||||
|
foreach ($students as $student):
|
||||||
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?php echo htmlspecialchars($record['username']); ?></td>
|
<td><?php echo htmlspecialchars($student['first_name'] . ' ' . $student['last_name']); ?></td>
|
||||||
<td><?php echo $record['login_time']; ?></td>
|
<td>
|
||||||
<td><?php echo $record['logout_time'] ?? '<i>Still logged in</i>'; ?></td>
|
<div class="form-check form-check-inline">
|
||||||
<td><?php echo htmlspecialchars($record['ip_address']); ?></td>
|
<input class="form-check-input" type="radio" name="students[<?php echo $student['id']; ?>]" id="present_<?php echo $student['id']; ?>" value="present" checked>
|
||||||
|
<label class="form-check-label" for="present_<?php echo $student['id']; ?>">Present</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-check form-check-inline">
|
||||||
|
<input class="form-check-input" type="radio" name="students[<?php echo $student['id']; ?>]" id="absent_<?php echo $student['id']; ?>" value="absent">
|
||||||
|
<label class="form-check-label" for="absent_<?php echo $student['id']; ?>">Absent</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-check form-check-inline">
|
||||||
|
<input class="form-check-input" type="radio" name="students[<?php echo $student['id']; ?>]" id="late_<?php echo $student['id']; ?>" value="late">
|
||||||
|
<label class="form-check-label" for="late_<?php echo $student['id']; ?>">Late</label>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<button type="submit" class="btn btn-primary">Submit Attendance</button>
|
||||||
|
</form>
|
||||||
|
<?php elseif ($role_name === 'student'): ?>
|
||||||
|
<h2>My Attendance</h2>
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Date</th>
|
||||||
|
<th>Status</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
$attendance_records = get_student_attendance($user_id);
|
||||||
|
foreach ($attendance_records as $record):
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($record['attendance_date']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($record['status']); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<?php elseif ($role_name === 'parent'): ?>
|
||||||
|
<h2>My Child's Attendance</h2>
|
||||||
|
<?php
|
||||||
|
$children = get_children_for_parent($user_id);
|
||||||
|
if (count($children) > 0):
|
||||||
|
?>
|
||||||
|
<form method="GET" class="mb-3">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<label for="child_id" class="form-label">Select Child</label>
|
||||||
|
<select class="form-select" id="child_id" name="child_id" onchange="this.form.submit()">
|
||||||
|
<option value="">Select a child</option>
|
||||||
|
<?php foreach ($children as $child): ?>
|
||||||
|
<option value="<?php echo $child['id']; ?>" <?php echo (isset($_GET['child_id']) && $_GET['child_id'] == $child['id']) ? 'selected' : ''; ?>><?php echo htmlspecialchars($child['first_name'] . ' ' . $child['last_name']); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php if (isset($_GET['child_id'])):
|
||||||
|
$child_id = $_GET['child_id'];
|
||||||
|
// Make sure the selected child belongs to the parent
|
||||||
|
$is_child_of_parent = false;
|
||||||
|
foreach ($children as $child) {
|
||||||
|
if ($child['id'] == $child_id) {
|
||||||
|
$is_child_of_parent = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($is_child_of_parent):
|
||||||
|
?>
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Date</th>
|
||||||
|
<th>Status</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
$attendance_records = get_student_attendance($child_id);
|
||||||
|
foreach ($attendance_records as $record):
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($record['attendance_date']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($record['status']); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<?php else: ?>
|
||||||
|
<div class="alert alert-danger">Invalid child selected.</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php else: ?>
|
||||||
|
<p>You have no children linked to your account.</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php endif; ?>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
34
database.sql
Normal file
34
database.sql
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
DROP TABLE IF EXISTS attendance, parent_child, users, roles;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS roles (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
role_name VARCHAR(255) NOT NULL UNIQUE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
username VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
email VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
password VARCHAR(255) NOT NULL,
|
||||||
|
role_id INT,
|
||||||
|
first_name VARCHAR(255),
|
||||||
|
last_name VARCHAR(255),
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE SET NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS attendance (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
student_id INT NOT NULL,
|
||||||
|
attendance_date DATE NOT NULL,
|
||||||
|
status ENUM('present', 'absent', 'late') NOT NULL,
|
||||||
|
FOREIGN KEY (student_id) REFERENCES users(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS parent_child (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
parent_id INT NOT NULL,
|
||||||
|
child_id INT NOT NULL,
|
||||||
|
FOREIGN KEY (parent_id) REFERENCES users(id),
|
||||||
|
FOREIGN KEY (child_id) REFERENCES users(id)
|
||||||
|
);
|
||||||
21
db/migrate.php
Normal file
21
db/migrate.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/config.php';
|
||||||
|
|
||||||
|
function run_migrations() {
|
||||||
|
$pdo = db();
|
||||||
|
$migrations_dir = __DIR__ . '/migrations';
|
||||||
|
$files = glob($migrations_dir . '/*.sql');
|
||||||
|
|
||||||
|
foreach ($files as $file) {
|
||||||
|
$sql = file_get_contents($file);
|
||||||
|
try {
|
||||||
|
$pdo->exec($sql);
|
||||||
|
echo "Migration from $file executed successfully.\n";
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
echo "Error executing migration from $file: " . $e->getMessage() . "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run_migrations();
|
||||||
|
|
||||||
1
db/migrations/000_drop_tables.sql
Normal file
1
db/migrations/000_drop_tables.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS attendance, parent_child, users, roles;
|
||||||
4
db/migrations/001_create_roles_table.sql
Normal file
4
db/migrations/001_create_roles_table.sql
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS roles (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
role_name VARCHAR(255) NOT NULL UNIQUE
|
||||||
|
);
|
||||||
11
db/migrations/002_create_users_table.sql
Normal file
11
db/migrations/002_create_users_table.sql
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
username VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
email VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
password VARCHAR(255) NOT NULL,
|
||||||
|
role_id INT,
|
||||||
|
first_name VARCHAR(255),
|
||||||
|
last_name VARCHAR(255),
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE SET NULL
|
||||||
|
);
|
||||||
7
db/migrations/003_create_attendance_table.sql
Normal file
7
db/migrations/003_create_attendance_table.sql
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS attendance (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
student_id INT NOT NULL,
|
||||||
|
attendance_date DATE NOT NULL,
|
||||||
|
status ENUM('present', 'absent', 'late') NOT NULL,
|
||||||
|
FOREIGN KEY (student_id) REFERENCES users(id)
|
||||||
|
);
|
||||||
7
db/migrations/004_create_parent_child_table.sql
Normal file
7
db/migrations/004_create_parent_child_table.sql
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS parent_child (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
parent_id INT NOT NULL,
|
||||||
|
child_id INT NOT NULL,
|
||||||
|
FOREIGN KEY (parent_id) REFERENCES users(id),
|
||||||
|
FOREIGN KEY (child_id) REFERENCES users(id)
|
||||||
|
);
|
||||||
59
exams.php
59
exams.php
@ -1,61 +1,32 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once 'db/config.php';
|
session_start();
|
||||||
|
|
||||||
try {
|
if (!isset($_SESSION['user_id'])) {
|
||||||
$db = db();
|
header('Location: login.php');
|
||||||
|
exit();
|
||||||
// Create exams table
|
|
||||||
$db->exec("CREATE TABLE IF NOT EXISTS exams (
|
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
title VARCHAR(255) NOT NULL,
|
|
||||||
description TEXT,
|
|
||||||
teacher_id INT,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (teacher_id) REFERENCES users(id) ON DELETE SET NULL
|
|
||||||
)");
|
|
||||||
|
|
||||||
// Create exam_questions table
|
|
||||||
$db->exec("CREATE TABLE IF NOT EXISTS exam_questions (
|
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
exam_id INT,
|
|
||||||
question TEXT NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (exam_id) REFERENCES exams(id) ON DELETE CASCADE
|
|
||||||
)");
|
|
||||||
|
|
||||||
// Create student_exams table
|
|
||||||
$db->exec("CREATE TABLE IF NOT EXISTS student_exams (
|
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
student_id INT,
|
|
||||||
exam_id INT,
|
|
||||||
score INT,
|
|
||||||
completed_at TIMESTAMP,
|
|
||||||
FOREIGN KEY (student_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
||||||
FOREIGN KEY (exam_id) REFERENCES exams(id) ON DELETE CASCADE
|
|
||||||
)");
|
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
die("Error: " . $e->getMessage());
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!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>Exams</title>
|
<title>Exams</title>
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<header>
|
||||||
<h1>Exams</h1>
|
<h1>Exams</h1>
|
||||||
<nav>
|
<nav>
|
||||||
<a href="index.php">Home</a>
|
<ul>
|
||||||
<a href="users.php">Users</a>
|
<li><a href="teacher_dashboard.php">Dashboard</a></li>
|
||||||
<a href="roles.php">Roles</a>
|
<li><a href="logout.php">Logout</a></li>
|
||||||
<a href="activities.php">Activities</a>
|
</ul>
|
||||||
<a href="exams.php">Exams</a>
|
|
||||||
<a href="attendance.php">Attendance</a>
|
|
||||||
</nav>
|
</nav>
|
||||||
<p>Exam management page.</p>
|
</header>
|
||||||
|
<main>
|
||||||
|
<h2>Exam Management</h2>
|
||||||
|
<p>This page will contain student exam information.</p>
|
||||||
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@ -25,6 +25,9 @@ if (!isset($_SESSION['user_id']) || empty($_SESSION['role_name']) || $_SESSION['
|
|||||||
</a>
|
</a>
|
||||||
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
|
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
|
||||||
<li><a href="parent_dashboard.php" class="nav-link px-2 link-secondary">Dashboard</a></li>
|
<li><a href="parent_dashboard.php" class="nav-link px-2 link-secondary">Dashboard</a></li>
|
||||||
|
<li><a href="attendance.php" class="nav-link px-2 link-dark">Attendance</a></li>
|
||||||
|
<li><a href="exams.php" class="nav-link px-2 link-dark">Exams</a></li>
|
||||||
|
<li><a href="activities.php" class="nav-link px-2 link-dark">Activities</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="text-end">
|
<div class="text-end">
|
||||||
<a href="logout.php" class="btn btn-outline-primary">Logout</a>
|
<a href="logout.php" class="btn btn-outline-primary">Logout</a>
|
||||||
|
|||||||
18
roles.php
18
roles.php
@ -15,7 +15,7 @@ try {
|
|||||||
// Create roles table if it doesn't exist
|
// Create roles table if it doesn't exist
|
||||||
$pdo->exec("CREATE TABLE IF NOT EXISTS roles (
|
$pdo->exec("CREATE TABLE IF NOT EXISTS roles (
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
name VARCHAR(255) NOT NULL UNIQUE
|
role_name VARCHAR(255) NOT NULL UNIQUE
|
||||||
)");
|
)");
|
||||||
|
|
||||||
// Function to log activity
|
// Function to log activity
|
||||||
@ -30,8 +30,8 @@ try {
|
|||||||
if (isset($_POST['add_role'])) {
|
if (isset($_POST['add_role'])) {
|
||||||
$name = trim($_POST['role_name']);
|
$name = trim($_POST['role_name']);
|
||||||
if (!empty($name)) {
|
if (!empty($name)) {
|
||||||
$stmt = $pdo->prepare("INSERT INTO roles (name) VALUES (:name)");
|
$stmt = $pdo->prepare("INSERT INTO roles (role_name) VALUES (:role_name)");
|
||||||
$stmt->execute(['name' => $name]);
|
$stmt->execute(['role_name' => $name]);
|
||||||
$new_role_id = $pdo->lastInsertId();
|
$new_role_id = $pdo->lastInsertId();
|
||||||
log_activity($_SESSION['user_id'], "Created role {$name} (ID: {$new_role_id})");
|
log_activity($_SESSION['user_id'], "Created role {$name} (ID: {$new_role_id})");
|
||||||
}
|
}
|
||||||
@ -39,8 +39,8 @@ try {
|
|||||||
$id = $_POST['role_id'];
|
$id = $_POST['role_id'];
|
||||||
$name = trim($_POST['role_name']);
|
$name = trim($_POST['role_name']);
|
||||||
if (!empty($name) && !empty($id)) {
|
if (!empty($name) && !empty($id)) {
|
||||||
$stmt = $pdo->prepare("UPDATE roles SET name = :name WHERE id = :id");
|
$stmt = $pdo->prepare("UPDATE roles SET role_name = :role_name WHERE id = :id");
|
||||||
$stmt->execute(['name' => $name, 'id' => $id]);
|
$stmt->execute(['role_name' => $name, 'id' => $id]);
|
||||||
log_activity($_SESSION['user_id'], "Updated role {$name} (ID: {$id})");
|
log_activity($_SESSION['user_id'], "Updated role {$name} (ID: {$id})");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ try {
|
|||||||
if (isset($_GET['delete_id'])) {
|
if (isset($_GET['delete_id'])) {
|
||||||
$id = $_GET['delete_id'];
|
$id = $_GET['delete_id'];
|
||||||
// Get role name for logging
|
// Get role name for logging
|
||||||
$stmt = $pdo->prepare("SELECT name FROM roles WHERE id = :id");
|
$stmt = $pdo->prepare("SELECT role_name FROM roles WHERE id = :id");
|
||||||
$stmt->execute(['id' => $id]);
|
$stmt->execute(['id' => $id]);
|
||||||
$deleted_role = $stmt->fetch();
|
$deleted_role = $stmt->fetch();
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ try {
|
|||||||
$stmt->execute(['id' => $id]);
|
$stmt->execute(['id' => $id]);
|
||||||
|
|
||||||
if ($deleted_role) {
|
if ($deleted_role) {
|
||||||
log_activity($_SESSION['user_id'], "Deleted role {$deleted_role['name']} (ID: {$id})");
|
log_activity($_SESSION['user_id'], "Deleted role {$deleted_role['role_name']} (ID: {$id})");
|
||||||
}
|
}
|
||||||
header("Location: roles.php");
|
header("Location: roles.php");
|
||||||
exit;
|
exit;
|
||||||
@ -137,7 +137,7 @@ try {
|
|||||||
<?php foreach ($roles as $role): ?>
|
<?php foreach ($roles as $role): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?php echo htmlspecialchars($role['id']); ?></td>
|
<td><?php echo htmlspecialchars($role['id']); ?></td>
|
||||||
<td><?php echo htmlspecialchars($role['name']); ?></td>
|
<td><?php echo htmlspecialchars($role['role_name']); ?></td>
|
||||||
<td>
|
<td>
|
||||||
<a href="roles.php?edit_id=<?php echo $role['id']; ?>" class="btn btn-sm btn-outline-primary">ویرایش</a>
|
<a href="roles.php?edit_id=<?php echo $role['id']; ?>" class="btn btn-sm btn-outline-primary">ویرایش</a>
|
||||||
<a href="roles.php?delete_id=<?php echo $role['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('آیا مطمئن هستید؟')">حذف</a>
|
<a href="roles.php?delete_id=<?php echo $role['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('آیا مطمئن هستید؟')">حذف</a>
|
||||||
@ -156,7 +156,7 @@ try {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="role_name" class="form-label">نام نقش</label>
|
<label for="role_name" class="form-label">نام نقش</label>
|
||||||
<input type="text" class="form-control" id="role_name" name="role_name" value="<?php echo htmlspecialchars($editing_role['name'] ?? ''); ?>" required>
|
<input type="text" class="form-control" id="role_name" name="role_name" value="<?php echo htmlspecialchars($editing_role['role_name'] ?? ''); ?>" required>
|
||||||
</div>
|
</div>
|
||||||
<?php if ($editing_role): ?>
|
<?php if ($editing_role): ?>
|
||||||
<button type="submit" name="update_role" class="btn btn-primary w-100">بهروزرسانی</button>
|
<button type="submit" name="update_role" class="btn btn-primary w-100">بهروزرسانی</button>
|
||||||
|
|||||||
@ -25,6 +25,9 @@ if (!isset($_SESSION['user_id']) || empty($_SESSION['role_name']) || $_SESSION['
|
|||||||
</a>
|
</a>
|
||||||
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
|
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
|
||||||
<li><a href="student_dashboard.php" class="nav-link px-2 link-secondary">Dashboard</a></li>
|
<li><a href="student_dashboard.php" class="nav-link px-2 link-secondary">Dashboard</a></li>
|
||||||
|
<li><a href="attendance.php" class="nav-link px-2 link-dark">Attendance</a></li>
|
||||||
|
<li><a href="exams.php" class="nav-link px-2 link-dark">Exams</a></li>
|
||||||
|
<li><a href="activities.php" class="nav-link px-2 link-dark">Activities</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="text-end">
|
<div class="text-end">
|
||||||
<a href="logout.php" class="btn btn-outline-primary">Logout</a>
|
<a href="logout.php" class="btn btn-outline-primary">Logout</a>
|
||||||
|
|||||||
@ -25,6 +25,9 @@ if (!isset($_SESSION['user_id']) || empty($_SESSION['role_name']) || $_SESSION['
|
|||||||
</a>
|
</a>
|
||||||
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
|
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
|
||||||
<li><a href="teacher_dashboard.php" class="nav-link px-2 link-secondary">Dashboard</a></li>
|
<li><a href="teacher_dashboard.php" class="nav-link px-2 link-secondary">Dashboard</a></li>
|
||||||
|
<li><a href="attendance.php" class="nav-link px-2 link-dark">Attendance</a></li>
|
||||||
|
<li><a href="exams.php" class="nav-link px-2 link-dark">Exams</a></li>
|
||||||
|
<li><a href="activities.php" class="nav-link px-2 link-dark">Activities</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="text-end">
|
<div class="text-end">
|
||||||
<a href="logout.php" class="btn btn-outline-primary">Logout</a>
|
<a href="logout.php" class="btn btn-outline-primary">Logout</a>
|
||||||
|
|||||||
82
users.php
82
users.php
@ -19,12 +19,14 @@ try {
|
|||||||
email VARCHAR(255) NOT NULL UNIQUE,
|
email VARCHAR(255) NOT NULL UNIQUE,
|
||||||
password VARCHAR(255) NOT NULL,
|
password VARCHAR(255) NOT NULL,
|
||||||
role_id INT,
|
role_id INT,
|
||||||
|
first_name VARCHAR(255),
|
||||||
|
last_name VARCHAR(255),
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE SET NULL
|
FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE SET NULL
|
||||||
)");
|
)");
|
||||||
|
|
||||||
// Fetch all roles for the dropdown
|
// Fetch all roles for the dropdown
|
||||||
$roles = $pdo->query("SELECT * FROM roles ORDER BY name")->fetchAll();
|
$roles = $pdo->query("SELECT * FROM roles ORDER BY role_name")->fetchAll();
|
||||||
|
|
||||||
// Function to log activity
|
// Function to log activity
|
||||||
function log_activity($user_id, $action) {
|
function log_activity($user_id, $action) {
|
||||||
@ -40,15 +42,19 @@ try {
|
|||||||
$email = trim($_POST['email']);
|
$email = trim($_POST['email']);
|
||||||
$password = $_POST['password'];
|
$password = $_POST['password'];
|
||||||
$role_id = $_POST['role_id'];
|
$role_id = $_POST['role_id'];
|
||||||
|
$first_name = trim($_POST['first_name']);
|
||||||
|
$last_name = trim($_POST['last_name']);
|
||||||
|
|
||||||
if (!empty($username) && !empty($email) && !empty($password) && !empty($role_id)) {
|
if (!empty($username) && !empty($email) && !empty($password) && !empty($role_id)) {
|
||||||
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||||
$stmt = $pdo->prepare("INSERT INTO users (username, email, password, role_id) VALUES (:username, :email, :password, :role_id)");
|
$stmt = $pdo->prepare("INSERT INTO users (username, email, password, role_id, first_name, last_name) VALUES (:username, :email, :password, :role_id, :first_name, :last_name)");
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
'username' => $username,
|
'username' => $username,
|
||||||
'email' => $email,
|
'email' => $email,
|
||||||
'password' => $hashed_password,
|
'password' => $hashed_password,
|
||||||
'role_id' => $role_id
|
'role_id' => $role_id,
|
||||||
|
'first_name' => $first_name,
|
||||||
|
'last_name' => $last_name
|
||||||
]);
|
]);
|
||||||
$new_user_id = $pdo->lastInsertId();
|
$new_user_id = $pdo->lastInsertId();
|
||||||
log_activity($_SESSION['user_id'], "Created user {$username} (ID: {$new_user_id})");
|
log_activity($_SESSION['user_id'], "Created user {$username} (ID: {$new_user_id})");
|
||||||
@ -59,29 +65,45 @@ try {
|
|||||||
$email = trim($_POST['email']);
|
$email = trim($_POST['email']);
|
||||||
$password = $_POST['password'];
|
$password = $_POST['password'];
|
||||||
$role_id = $_POST['role_id'];
|
$role_id = $_POST['role_id'];
|
||||||
|
$first_name = trim($_POST['first_name']);
|
||||||
|
$last_name = trim($_POST['last_name']);
|
||||||
|
|
||||||
if (!empty($id) && !empty($username) && !empty($email) && !empty($role_id)) {
|
if (!empty($id) && !empty($username) && !empty($email) && !empty($role_id)) {
|
||||||
if (!empty($password)) {
|
if (!empty($password)) {
|
||||||
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||||
$stmt = $pdo->prepare("UPDATE users SET username = :username, email = :email, password = :password, role_id = :role_id WHERE id = :id");
|
$stmt = $pdo->prepare("UPDATE users SET username = :username, email = :email, password = :password, role_id = :role_id, first_name = :first_name, last_name = :last_name WHERE id = :id");
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
'username' => $username,
|
'username' => $username,
|
||||||
'email' => $email,
|
'email' => $email,
|
||||||
'password' => $hashed_password,
|
'password' => $hashed_password,
|
||||||
'role_id' => $role_id,
|
'role_id' => $role_id,
|
||||||
|
'first_name' => $first_name,
|
||||||
|
'last_name' => $last_name,
|
||||||
'id' => $id
|
'id' => $id
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
$stmt = $pdo->prepare("UPDATE users SET username = :username, email = :email, role_id = :role_id WHERE id = :id");
|
$stmt = $pdo->prepare("UPDATE users SET username = :username, email = :email, role_id = :role_id, first_name = :first_name, last_name = :last_name WHERE id = :id");
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
'username' => $username,
|
'username' => $username,
|
||||||
'email' => $email,
|
'email' => $email,
|
||||||
'role_id' => $role_id,
|
'role_id' => $role_id,
|
||||||
|
'first_name' => $first_name,
|
||||||
|
'last_name' => $last_name,
|
||||||
'id' => $id
|
'id' => $id
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
log_activity($_SESSION['user_id'], "Updated user {$username} (ID: {$id})");
|
log_activity($_SESSION['user_id'], "Updated user {$username} (ID: {$id})");
|
||||||
|
} elseif (isset($_POST['link_parent_child'])) {
|
||||||
|
$parent_id = $_POST['parent_id'];
|
||||||
|
$child_id = $_POST['child_id'];
|
||||||
|
|
||||||
|
if (!empty($parent_id) && !empty($child_id)) {
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO parent_child (parent_id, child_id) VALUES (:parent_id, :child_id)");
|
||||||
|
$stmt->execute(['parent_id' => $parent_id, 'child_id' => $child_id]);
|
||||||
|
log_activity($_SESSION['user_id'], "Linked parent (ID: {$parent_id}) to child (ID: {$child_id})");
|
||||||
}
|
}
|
||||||
|
header("Location: users.php?link_success=1");
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
header("Location: users.php");
|
header("Location: users.php");
|
||||||
exit;
|
exit;
|
||||||
@ -107,12 +129,16 @@ try {
|
|||||||
|
|
||||||
// Fetch all users with their role names
|
// Fetch all users with their role names
|
||||||
$users = $pdo->query("
|
$users = $pdo->query("
|
||||||
SELECT users.*, roles.name AS role_name
|
SELECT users.*, roles.role_name AS role_name
|
||||||
FROM users
|
FROM users
|
||||||
LEFT JOIN roles ON users.role_id = roles.id
|
LEFT JOIN roles ON users.role_id = roles.id
|
||||||
ORDER BY users.id DESC
|
ORDER BY users.id DESC
|
||||||
")->fetchAll();
|
")->fetchAll();
|
||||||
|
|
||||||
|
// Fetch all parents and students
|
||||||
|
$parents = $pdo->query("SELECT u.id, u.first_name, u.last_name FROM users u JOIN roles r ON u.role_id = r.id WHERE r.role_name = 'parent'")->fetchAll();
|
||||||
|
$students = $pdo->query("SELECT u.id, u.first_name, u.last_name FROM users u JOIN roles r ON u.role_id = r.id WHERE r.role_name = 'student'")->fetchAll();
|
||||||
|
|
||||||
// Fetch user for editing
|
// Fetch user for editing
|
||||||
$editing_user = null;
|
$editing_user = null;
|
||||||
if (isset($_GET['edit_id'])) {
|
if (isset($_GET['edit_id'])) {
|
||||||
@ -210,6 +236,14 @@ try {
|
|||||||
<label for="email" class="form-label">ایمیل</label>
|
<label for="email" class="form-label">ایمیل</label>
|
||||||
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($editing_user['email'] ?? ''); ?>" required>
|
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($editing_user['email'] ?? ''); ?>" required>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="first_name" class="form-label">نام</label>
|
||||||
|
<input type="text" class="form-control" id="first_name" name="first_name" value="<?php echo htmlspecialchars($editing_user['first_name'] ?? ''); ?>">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="last_name" class="form-label">نام خانوادگی</label>
|
||||||
|
<input type="text" class="form-control" id="last_name" name="last_name" value="<?php echo htmlspecialchars($editing_user['last_name'] ?? ''); ?>">
|
||||||
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="password" class="form-label">رمز عبور <?php echo $editing_user ? '(خالی بگذارید تا بدون تغییر بماند)' : ''; ?></label>
|
<label for="password" class="form-label">رمز عبور <?php echo $editing_user ? '(خالی بگذارید تا بدون تغییر بماند)' : ''; ?></label>
|
||||||
<input type="password" class="form-control" id="password" name="password" <?php echo !$editing_user ? 'required' : ''; ?>>
|
<input type="password" class="form-control" id="password" name="password" <?php echo !$editing_user ? 'required' : ''; ?>>
|
||||||
@ -220,7 +254,7 @@ try {
|
|||||||
<option value="">یک نقش انتخاب کنید</option>
|
<option value="">یک نقش انتخاب کنید</option>
|
||||||
<?php foreach ($roles as $role): ?>
|
<?php foreach ($roles as $role): ?>
|
||||||
<option value="<?php echo $role['id']; ?>" <?php echo (isset($editing_user) && $editing_user['role_id'] == $role['id']) ? 'selected' : ''; ?>>
|
<option value="<?php echo $role['id']; ?>" <?php echo (isset($editing_user) && $editing_user['role_id'] == $role['id']) ? 'selected' : ''; ?>>
|
||||||
<?php echo htmlspecialchars($role['name']); ?>
|
<?php echo htmlspecialchars($role['role_name']); ?>
|
||||||
</option>
|
</option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
@ -234,6 +268,40 @@ try {
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="row mt-5">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<h2>Link Parent to Child</h2>
|
||||||
|
<?php if (isset($_GET['link_success'])): ?>
|
||||||
|
<div class="alert alert-success">Parent and child linked successfully.</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<form method="POST" action="users.php">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-5">
|
||||||
|
<label for="parent_id" class="form-label">Parent</label>
|
||||||
|
<select class="form-select" id="parent_id" name="parent_id" required>
|
||||||
|
<option value="">Select a parent</option>
|
||||||
|
<?php foreach ($parents as $parent): ?>
|
||||||
|
<option value="<?php echo $parent['id']; ?>"><?php echo htmlspecialchars($parent['first_name'] . ' ' . $parent['last_name']); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-5">
|
||||||
|
<label for="child_id" class="form-label">Child</label>
|
||||||
|
<select class="form-select" id="child_id" name="child_id" required>
|
||||||
|
<option value="">Select a child</option>
|
||||||
|
<?php foreach ($students as $student): ?>
|
||||||
|
<option value="<?php echo $student['id']; ?>"><?php echo htmlspecialchars($student['first_name'] . ' ' . $student['last_name']); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2 d-flex align-items-end">
|
||||||
|
<button type="submit" name="link_parent_child" class="btn btn-primary w-100">Link</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<footer class="footer mt-auto py-3 bg-light">
|
<footer class="footer mt-auto py-3 bg-light">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user