Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9c5634d9d | ||
|
|
84395a5c8b | ||
|
|
e64eb23c43 |
147
add_student.php
Normal file
147
add_student.php
Normal file
@ -0,0 +1,147 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// If the user is not logged in, redirect to the login page...
|
||||
if (!isset($_SESSION['loggedin'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Role check
|
||||
if ($_SESSION['role'] === 'viewer') {
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$page_title = "Add New Student";
|
||||
$page_description = "Admission form to add a new student to the database.";
|
||||
$notification = null;
|
||||
|
||||
try {
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
|
||||
// Create table if it doesn't exist
|
||||
$pdo = db();
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS students (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
first_name VARCHAR(100) NOT NULL,
|
||||
last_name VARCHAR(100) NOT NULL,
|
||||
date_of_birth DATE NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);");
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$first_name = trim($_POST['first_name']);
|
||||
$last_name = trim($_POST['last_name']);
|
||||
$date_of_birth = trim($_POST['date_of_birth']);
|
||||
|
||||
if (empty($first_name) || empty($last_name) || empty($date_of_birth)) {
|
||||
$notification = ["type" => "danger", "message" => "All fields are required."];
|
||||
} else {
|
||||
$stmt = $pdo->prepare("INSERT INTO students (first_name, last_name, date_of_birth) VALUES (?, ?, ?)");
|
||||
if ($stmt->execute([$first_name, $last_name, $date_of_birth])) {
|
||||
$notification = ["type" => "success", "message" => "Student added successfully!"];
|
||||
} else {
|
||||
$notification = ["type" => "danger", "message" => "Error: Could not add student."];
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$notification = ["type" => "danger", "message" => "Database error: " . $e->getMessage()];
|
||||
error_log("DB 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><?= htmlspecialchars($page_title) ?> - <?= htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'WebApp') ?></title>
|
||||
<meta name="description" content="<?= htmlspecialchars($page_description) ?>">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css">
|
||||
</head>
|
||||
<body class="bg-light">
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="index.php"><?= htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'WebApp') ?></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="#">Welcome, <?= htmlspecialchars($_SESSION['username']) ?>!</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="logout.php">Logout</a>
|
||||
</li>
|
||||
<?php if ($_SESSION['role'] === 'admin'): ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="admin.php">Admin</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main class="container my-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8 col-lg-6">
|
||||
<div class="card border-0 shadow-lg">
|
||||
<div class="card-body p-4 p-md-5">
|
||||
<h1 class="h3 card-title text-center mb-4">New Student Admission</h1>
|
||||
<form action="add_student.php" method="POST" class="needs-validation" novalidate>
|
||||
<div class="mb-3">
|
||||
<label for="first_name" class="form-label">First Name</label>
|
||||
<input type="text" class="form-control" id="first_name" name="first_name" required>
|
||||
<div class="invalid-feedback">Please enter a first name.</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="last_name" class="form-label">Last Name</label>
|
||||
<input type="text" class="form-control" id="last_name" name="last_name" required>
|
||||
<div class="invalid-feedback">Please enter a last name.</div>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label for="date_of_birth" class="form-label">Date of Birth</label>
|
||||
<input type="date" class="form-control" id="date_of_birth" name="date_of_birth" required>
|
||||
<div class="invalid-feedback">Please enter a valid date of birth.</div>
|
||||
</div>
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary btn-lg">Add Student</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<div class="toast-container position-fixed bottom-0 end-0 p-3">
|
||||
<div id="notificationToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
<div class="toast-header">
|
||||
<strong class="me-auto">Notification</strong>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="toast-body">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer class="text-center py-4 text-muted">
|
||||
<p>© <?= date('Y') ?> <?= htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'WebApp') ?>. All Rights Reserved.</p>
|
||||
</footer>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/js/main.js"></script>
|
||||
<?php if ($notification): ?>
|
||||
<script>
|
||||
showToast(<?= json_encode($notification['message']) ?>, '<?= htmlspecialchars($notification['type']) ?>');
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
</body>
|
||||
</html>
|
||||
154
admin.php
Normal file
154
admin.php
Normal file
@ -0,0 +1,154 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// If the user is not logged in, or is not an admin, redirect them away
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['role'] !== 'admin') {
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once 'db/config.php';
|
||||
$pdo = db();
|
||||
|
||||
// Fetch all users and their roles
|
||||
$stmt = $pdo->query("SELECT users.id, users.username, roles.role_name FROM users JOIN roles ON users.role_id = roles.id ORDER BY users.username");
|
||||
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Handle role change
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'change_role') {
|
||||
$user_id = isset($_POST['user_id']) ? (int)$_POST['user_id'] : 0;
|
||||
$role_id = isset($_POST['role_id']) ? (int)$_POST['role_id'] : 0;
|
||||
|
||||
if ($user_id && $role_id) {
|
||||
$stmt = $pdo->prepare("UPDATE users SET role_id = ? WHERE id = ?");
|
||||
$stmt->execute([$role_id, $user_id]);
|
||||
header("Location: admin.php?success=role_changed");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch all roles for the dropdown
|
||||
$roles_stmt = $pdo->query("SELECT id, role_name FROM roles");
|
||||
$roles = $roles_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$page_title = "Admin - User Management";
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= htmlspecialchars($page_title) ?> - Bhuddi School</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||
<link rel="stylesheet" href="assets/css/custom.css">
|
||||
</head>
|
||||
<body class="bg-light">
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="index.php">Bhuddi School</a>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ms-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">Welcome, <?= htmlspecialchars($_SESSION['username']) ?>!</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="logout.php">Logout</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main class="container my-5">
|
||||
<h1 class="h2 mb-4">User Management</h1>
|
||||
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Username</th>
|
||||
<th>Role</th>
|
||||
<th class="text-end">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($users as $user): ?>
|
||||
<tr>
|
||||
<td><?= htmlspecialchars($user['username']) ?></td>
|
||||
<td><?= htmlspecialchars($user['role_name']) ?></td>
|
||||
<td class="text-end">
|
||||
<?php if ($user['username'] !== 'admin'): // Prevent admin from changing their own role ?>
|
||||
<button class="btn btn-sm btn-outline-primary btn-change-role"
|
||||
data-bs-toggle="modal"
|
||||
data-bs-target="#changeRoleModal"
|
||||
data-user-id="<?= $user['id'] ?>"
|
||||
data-username="<?= htmlspecialchars($user['username']) ?>"
|
||||
data-role-id="<?= $user['role_id'] ?>">
|
||||
Change Role
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<!-- Change Role Modal -->
|
||||
<div class="modal fade" id="changeRoleModal" tabindex="-1" aria-labelledby="changeRoleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="changeRoleModalLabel">Change User Role</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<form id="changeRoleForm" method="POST">
|
||||
<div class="modal-body">
|
||||
<input type="hidden" name="action" value="change_role">
|
||||
<input type="hidden" id="user_id" name="user_id">
|
||||
<p>Change role for <strong id="username_display"></strong>:</p>
|
||||
<div class="mb-3">
|
||||
<label for="role_id" class="form-label">Role</label>
|
||||
<select class="form-select" id="role_id" name="role_id" required>
|
||||
<?php foreach ($roles as $role): ?>
|
||||
<option value="<?= $role['id'] ?>"><?= htmlspecialchars($role['role_name']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
<button type="submit" class="btn btn-primary">Save changes</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const changeRoleModal = document.getElementById('changeRoleModal');
|
||||
changeRoleModal.addEventListener('show.bs.modal', function (event) {
|
||||
const button = event.relatedTarget;
|
||||
const userId = button.dataset.userId;
|
||||
const username = button.dataset.username;
|
||||
const currentRoleId = button.dataset.roleId;
|
||||
|
||||
const modalForm = document.getElementById('changeRoleForm');
|
||||
modalForm.action = 'admin.php';
|
||||
|
||||
document.getElementById('user_id').value = userId;
|
||||
document.getElementById('username_display').innerText = username;
|
||||
document.getElementById('role_id').value = currentRoleId;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
43
assets/css/custom.css
Normal file
43
assets/css/custom.css
Normal file
@ -0,0 +1,43 @@
|
||||
body {
|
||||
font-family: 'Poppins', sans-serif;
|
||||
background-color: #F4F7F6;
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
font-weight: 600;
|
||||
color: #4A90E2 !important;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: #4A90E2;
|
||||
border-color: #4A90E2;
|
||||
padding: 0.75rem 1rem;
|
||||
font-weight: 600;
|
||||
transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background-color: #357ABD;
|
||||
border-color: #357ABD;
|
||||
}
|
||||
|
||||
.card {
|
||||
border-radius: 0.75rem;
|
||||
}
|
||||
|
||||
.form-control {
|
||||
border-radius: 0.5rem;
|
||||
padding: 0.75rem 1rem;
|
||||
}
|
||||
|
||||
.form-control:focus {
|
||||
border-color: #4A90E2;
|
||||
box-shadow: 0 0 0 0.25rem rgba(74, 144, 226, 0.25);
|
||||
}
|
||||
|
||||
.toast-header .btn-close {
|
||||
background: none;
|
||||
}
|
||||
|
||||
.toast.bg-success { color: #fff; }
|
||||
.toast.bg-danger { color: #fff; }
|
||||
52
assets/js/main.js
Normal file
52
assets/js/main.js
Normal file
@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Shows a Bootstrap toast notification.
|
||||
* @param {string} message The message to display.
|
||||
* @param {string} type The type of toast (e.g., 'success', 'danger', 'warning').
|
||||
*/
|
||||
function showToast(message, type = 'info') {
|
||||
const toastElement = document.getElementById('notificationToast');
|
||||
if (!toastElement) return;
|
||||
|
||||
const toastBody = toastElement.querySelector('.toast-body');
|
||||
const toastHeader = toastElement.querySelector('.toast-header');
|
||||
|
||||
toastBody.textContent = message;
|
||||
|
||||
// Reset classes
|
||||
toastElement.classList.remove('bg-success', 'bg-danger', 'bg-warning', 'bg-info');
|
||||
|
||||
// Add new class
|
||||
if (type) {
|
||||
toastElement.classList.add(`bg-${type}`);
|
||||
// Make text readable on dark backgrounds
|
||||
if (type === 'success' || type === 'danger') {
|
||||
toastHeader.classList.add('text-white');
|
||||
toastBody.classList.add('text-white');
|
||||
} else {
|
||||
toastHeader.classList.remove('text-white');
|
||||
toastBody.classList.remove('text-white');
|
||||
}
|
||||
}
|
||||
|
||||
const toast = new bootstrap.Toast(toastElement);
|
||||
toast.show();
|
||||
}
|
||||
|
||||
// Basic form validation script
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
'use strict'
|
||||
|
||||
var forms = document.querySelectorAll('.needs-validation')
|
||||
|
||||
Array.prototype.slice.call(forms)
|
||||
.forEach(function (form) {
|
||||
form.addEventListener('submit', function (event) {
|
||||
if (!form.checkValidity()) {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
}
|
||||
|
||||
form.classList.add('was-validated')
|
||||
}, false)
|
||||
})
|
||||
});
|
||||
32
auth.php
Normal file
32
auth.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
require_once 'db/config.php';
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
|
||||
// Create roles table
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS roles (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
role_name VARCHAR(50) NOT NULL UNIQUE
|
||||
);");
|
||||
|
||||
// Create users table
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(50) NOT NULL UNIQUE,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
role_id INT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (role_id) REFERENCES roles(id)
|
||||
);");
|
||||
|
||||
// Insert default roles if they don't exist
|
||||
$stmt = $pdo->query("SELECT COUNT(*) FROM roles");
|
||||
if ($stmt->fetchColumn() == 0) {
|
||||
$pdo->exec("INSERT INTO roles (role_name) VALUES ('admin'), ('teacher');");
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
die("Database error during auth setup: " . $e->getMessage());
|
||||
}
|
||||
?>
|
||||
259
index.php
259
index.php
@ -1,150 +1,133 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
session_start();
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
// If the user is not logged in, redirect to the login page...
|
||||
if (!isset($_SESSION['loggedin'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$page_title = "Dashboard";
|
||||
$page_description = "Main dashboard for the Student Management System.";
|
||||
|
||||
// Fetch a few recent students to display
|
||||
$students = [];
|
||||
try {
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
$pdo = db();
|
||||
// Ensure table exists before querying
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS students (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
first_name VARCHAR(100) NOT NULL,
|
||||
last_name VARCHAR(100) NOT NULL,
|
||||
date_of_birth DATE NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);");
|
||||
$stmt = $pdo->query("SELECT id, first_name, last_name, created_at FROM students ORDER BY created_at DESC LIMIT 5");
|
||||
if($stmt) {
|
||||
$students = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("DB Error on dashboard: " . $e->getMessage());
|
||||
}
|
||||
?>
|
||||
<!doctype html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<?php
|
||||
// Read project preview data from environment
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<?php if ($projectDescription): ?>
|
||||
<!-- Meta description -->
|
||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<!-- Twitter meta tags -->
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php endif; ?>
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<!-- Open Graph image -->
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<!-- Twitter image -->
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<?php endif; ?>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.loader {
|
||||
margin: 1.25rem auto 1.25rem;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.hint {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px; height: 1px;
|
||||
padding: 0; margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap; border: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= htmlspecialchars($page_title) ?> - <?= htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'WebApp') ?></title>
|
||||
<meta name="description" content="<?= htmlspecialchars($page_description) ?>">
|
||||
<meta property="og:title" content="<?= htmlspecialchars($_SERVER['PROJECT_NAME']) ?>">
|
||||
<meta property="og:description" content="<?= htmlspecialchars($_SERVER['PROJECT_DESCRIPTION']) ?>">
|
||||
<meta property="og:image" content="<?= htmlspecialchars($_SERVER['PROJECT_IMAGE_URL']) ?>">
|
||||
<meta property="twitter:card" content="summary_large_image">
|
||||
<meta property="twitter:title" content="<?= htmlspecialchars($_SERVER['PROJECT_NAME']) ?>">
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($_SERVER['PROJECT_DESCRIPTION']) ?>">
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($_SERVER['PROJECT_IMAGE_URL']) ?>">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css">
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
<body class="bg-light">
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="index.php"><?= htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'WebApp') ?></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="#">Welcome, <?= htmlspecialchars($_SESSION['username']) ?>!</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="logout.php">Logout</a>
|
||||
</li>
|
||||
<?php if ($_SESSION['role'] === 'admin'): ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="admin.php">Admin</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main class="container my-5">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h1 class="h2">Dashboard</h1>
|
||||
<a href="add_student.php" class="btn btn-primary">
|
||||
<i class="bi bi-plus-circle-fill me-2"></i>Add New Student
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="card-header bg-white border-bottom-0">
|
||||
<h5 class="card-title mb-0">Recently Added Students</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (empty($students)): ?>
|
||||
<p class="text-center text-muted">No students have been added yet. <a href="add_student.php">Add the first one!</a></p>
|
||||
<?php else: ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">First Name</th>
|
||||
<th scope="col">Last Name</th>
|
||||
<th scope="col">Date Added</th>
|
||||
<th scope="col" class="text-end">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($students as $student): ?>
|
||||
<tr>
|
||||
<th scope="row"><?= htmlspecialchars($student['id']) ?></th>
|
||||
<td><?= htmlspecialchars($student['first_name']) ?></td>
|
||||
<td><?= htmlspecialchars($student['last_name']) ?></td>
|
||||
<td><?= date("M d, Y", strtotime($student['created_at'])) ?></td>
|
||||
<td class="text-end">
|
||||
<a href="student.php?id=<?= htmlspecialchars($student['id']) ?>" class="btn btn-sm btn-outline-primary">View</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
|
||||
<footer class="text-center py-4 text-muted">
|
||||
<p>© <?= date('Y') ?> <?= htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'WebApp') ?>. All Rights Reserved.</p>
|
||||
</footer>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
81
login.php
Normal file
81
login.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
$error = '';
|
||||
$success = '';
|
||||
|
||||
// Check for success message from registration
|
||||
if (isset($_SESSION['success_message'])) {
|
||||
$success = $_SESSION['success_message'];
|
||||
unset($_SESSION['success_message']);
|
||||
}
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$username = trim($_POST['username']);
|
||||
$password = trim($_POST['password']);
|
||||
|
||||
if (empty($username) || empty($password)) {
|
||||
$error = "Please enter both username and password.";
|
||||
} else {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("SELECT users.id, users.username, users.password_hash, roles.role_name FROM users JOIN roles ON users.role_id = roles.id WHERE users.username = ?");
|
||||
$stmt->execute([$username]);
|
||||
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($user && password_verify($password, $user['password_hash'])) {
|
||||
// Password is correct, start a new session
|
||||
session_regenerate_id();
|
||||
$_SESSION['loggedin'] = true;
|
||||
$_SESSION['id'] = $user['id'];
|
||||
$_SESSION['username'] = $user['username'];
|
||||
$_SESSION['role'] = $user['role_name'];
|
||||
|
||||
header("location: index.php");
|
||||
exit;
|
||||
} else {
|
||||
// Display an error message if password or username is not valid
|
||||
$error = "The username or password you entered was not valid.";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login - Bhuddi School Student Management System</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/login.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="login-container">
|
||||
<div class="login-box">
|
||||
<h1 class="login-title">Bhuddi School Student Management System</h1>
|
||||
<?php if(!empty($success)): ?>
|
||||
<div class="alert alert-success" role="alert">
|
||||
<?php echo $success; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if(!empty($error)): ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<?php echo $error; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form action="login.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<input type="text" class="form-control" id="username" name="username" placeholder="Username" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<input type="password" class="form-control" id="password" name="password" placeholder="Password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-login">Login</button>
|
||||
</form>
|
||||
<div class="login-footer">
|
||||
Don't have an account? <a href="signup.php">Sign up here</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
6
logout.php
Normal file
6
logout.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
session_start();
|
||||
session_destroy();
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
?>
|
||||
93
signup.php
Normal file
93
signup.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
require_once 'auth.php'; // Ensure tables are created
|
||||
|
||||
$error = '';
|
||||
$success = '';
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$username = trim($_POST['username']);
|
||||
$password = trim($_POST['password']);
|
||||
|
||||
if (empty($username) || empty($password)) {
|
||||
$error = "Please enter both username and password.";
|
||||
} else {
|
||||
$pdo = db();
|
||||
|
||||
// Check if user already exists
|
||||
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = ?");
|
||||
$stmt->execute([$username]);
|
||||
if ($stmt->fetch()) {
|
||||
$error = "Username already exists. Please choose another one.";
|
||||
} else {
|
||||
// Get 'teacher' role ID
|
||||
$stmt = $pdo->prepare("SELECT id FROM roles WHERE role_name = 'teacher'");
|
||||
$stmt->execute();
|
||||
$role = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$role) {
|
||||
// This is a fallback, 'teacher' role should exist from auth.php
|
||||
$error = "Default role 'teacher' not found. Please contact admin.";
|
||||
} else {
|
||||
$role_id = $role['id'];
|
||||
$password_hash = password_hash($password, PASSWORD_BCRYPT);
|
||||
|
||||
$sql = "INSERT INTO users (username, password_hash, role_id) VALUES (?, ?, ?)";
|
||||
$stmt= $pdo->prepare($sql);
|
||||
if ($stmt->execute([$username, $password_hash, $role_id])) {
|
||||
$_SESSION['success_message'] = "Registration successful! You can now login.";
|
||||
header("Location: login.php");
|
||||
exit();
|
||||
} else {
|
||||
$error = "Something went wrong. Please try again later.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Sign Up - Bhuddi School</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Sign Up
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if(!empty($error)): ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<?php echo $error; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form action="signup.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>
|
||||
<button type="submit" class="btn btn-primary">Sign Up</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="card-footer text-center">
|
||||
Already have an account? <a href="login.php">Login here</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
819
student.php
Normal file
819
student.php
Normal file
@ -0,0 +1,819 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// If the user is not logged in, redirect to the login page...
|
||||
if (!isset($_SESSION['loggedin'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$is_viewer = $_SESSION['role'] === 'viewer';
|
||||
|
||||
// student.php
|
||||
|
||||
// 1. Get student ID from URL
|
||||
$student_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
||||
|
||||
if (!$student_id) {
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// 2. Database connection
|
||||
require_once 'db/config.php';
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("SELECT * FROM students WHERE id = ?");
|
||||
$stmt->execute([$student_id]);
|
||||
$student = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$student) {
|
||||
// Optional: Show a "not found" message or redirect
|
||||
header("Location: index.php?error=not_found");
|
||||
exit();
|
||||
}
|
||||
|
||||
// -- Behavior Insights Logic --
|
||||
|
||||
// 2.1. Create behaviors table if it doesn't exist and add rating column
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS behaviors (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
student_id INT NOT NULL,
|
||||
behavior_description TEXT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (student_id) REFERENCES students(id) ON DELETE CASCADE
|
||||
);");
|
||||
try {
|
||||
$pdo->exec("ALTER TABLE behaviors ADD COLUMN rating INT NOT NULL DEFAULT 5");
|
||||
} catch (PDOException $e) {
|
||||
// Ignore errors, especially if the column already exists.
|
||||
}
|
||||
|
||||
// 2.2. Handle form submission for adding a new behavior
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'add_behavior') {
|
||||
$behavior_description = trim($_POST['behavior_description'] ?? '');
|
||||
$behavior_rating = isset($_POST['behavior_rating']) ? (int)$_POST['behavior_rating'] : 5;
|
||||
|
||||
if (!empty($behavior_description)) {
|
||||
$stmt = $pdo->prepare("INSERT INTO behaviors (student_id, behavior_description, rating) VALUES (?, ?, ?)");
|
||||
$stmt->execute([$student_id, $behavior_description, $behavior_rating]);
|
||||
|
||||
// Redirect to the same page to prevent form resubmission
|
||||
header("Location: student.php?id=" . $student_id . "&success=behavior_logged");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// 2.3. Handle form submission for editing a behavior
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'edit_behavior') {
|
||||
$behavior_id = isset($_POST['behavior_id']) ? (int)$_POST['behavior_id'] : 0;
|
||||
$behavior_description = trim($_POST['behavior_description'] ?? '');
|
||||
$behavior_rating = isset($_POST['behavior_rating']) ? (int)$_POST['behavior_rating'] : 5;
|
||||
|
||||
if ($behavior_id && !empty($behavior_description)) {
|
||||
$stmt = $pdo->prepare("UPDATE behaviors SET behavior_description = ?, rating = ? WHERE id = ? AND student_id = ?");
|
||||
$stmt->execute([$behavior_description, $behavior_rating, $behavior_id, $student_id]);
|
||||
|
||||
header("Location: student.php?id=" . $student_id . "&success=behavior_updated");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// 2.3. Handle form submission for deleting a behavior
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'delete_behavior') {
|
||||
$behavior_id = isset($_POST['behavior_id']) ? (int)$_POST['behavior_id'] : 0;
|
||||
|
||||
if ($behavior_id) {
|
||||
$stmt = $pdo->prepare("DELETE FROM behaviors WHERE id = ? AND student_id = ?");
|
||||
$stmt->execute([$behavior_id, $student_id]);
|
||||
|
||||
header("Location: student.php?id=" . $student_id . "&success=behavior_deleted");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// 2.4. Fetch all behaviors for this student
|
||||
$stmt = $pdo->prepare("SELECT * FROM behaviors WHERE student_id = ? ORDER BY created_at DESC");
|
||||
$stmt->execute([$student_id]);
|
||||
$behaviors = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// -- Academic Insights Logic --
|
||||
|
||||
// 2.4. Create academics table if it doesn't exist
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS academics (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
student_id INT NOT NULL,
|
||||
subject VARCHAR(100) NOT NULL,
|
||||
grade VARCHAR(2) NOT NULL,
|
||||
comments TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (student_id) REFERENCES students(id) ON DELETE CASCADE
|
||||
);");
|
||||
|
||||
// 2.5. Handle form submission for adding a new academic record
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'add_academic') {
|
||||
$subject = trim($_POST['subject'] ?? '');
|
||||
$grade = trim($_POST['grade'] ?? '');
|
||||
$comments = trim($_POST['comments'] ?? '');
|
||||
|
||||
if (!empty($subject) && !empty($grade)) {
|
||||
$stmt = $pdo->prepare("INSERT INTO academics (student_id, subject, grade, comments) VALUES (?, ?, ?, ?)");
|
||||
$stmt->execute([$student_id, $subject, $grade, $comments]);
|
||||
|
||||
header("Location: student.php?id=" . $student_id . "&success=academic_logged");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle form submission for editing an academic record
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'edit_academic') {
|
||||
$academic_id = isset($_POST['academic_id']) ? (int)$_POST['academic_id'] : 0;
|
||||
$subject = trim($_POST['subject'] ?? '');
|
||||
$grade = trim($_POST['grade'] ?? '');
|
||||
$comments = trim($_POST['comments'] ?? '');
|
||||
|
||||
if ($academic_id && !empty($subject) && !empty($grade)) {
|
||||
$stmt = $pdo->prepare("UPDATE academics SET subject = ?, grade = ?, comments = ? WHERE id = ? AND student_id = ?");
|
||||
$stmt->execute([$subject, $grade, $comments, $academic_id, $student_id]);
|
||||
|
||||
header("Location: student.php?id=" . $student_id . "&success=academic_updated");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle form submission for deleting an academic record
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'delete_academic') {
|
||||
$academic_id = isset($_POST['academic_id']) ? (int)$_POST['academic_id'] : 0;
|
||||
|
||||
if ($academic_id) {
|
||||
$stmt = $pdo->prepare("DELETE FROM academics WHERE id = ? AND student_id = ?");
|
||||
$stmt->execute([$academic_id, $student_id]);
|
||||
|
||||
header("Location: student.php?id=" . $student_id . "&success=academic_deleted");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// 2.6. Fetch all academic records for this student
|
||||
$stmt = $pdo->prepare("SELECT * FROM academics WHERE student_id = ? ORDER BY created_at DESC");
|
||||
$stmt->execute([$student_id]);
|
||||
$academics = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// -- Student Details Logic --
|
||||
|
||||
// Create student_details table
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS student_details (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
student_id INT NOT NULL,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
details TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (student_id) REFERENCES students(id) ON DELETE CASCADE
|
||||
);")
|
||||
|
||||
// Fetch all details for this student
|
||||
$stmt = $pdo->prepare("SELECT * FROM student_details WHERE student_id = ? ORDER BY created_at DESC");
|
||||
$stmt->execute([$student_id]);
|
||||
$student_details = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Handle form submission for adding a new student detail
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'add_student_detail') {
|
||||
$title = trim($_POST['detail_title'] ?? '');
|
||||
$details = trim($_POST['detail_content'] ?? '');
|
||||
|
||||
if (!empty($title)) {
|
||||
$stmt = $pdo->prepare("INSERT INTO student_details (student_id, title, details) VALUES (?, ?, ?)");
|
||||
$stmt->execute([$student_id, $title, $details]);
|
||||
|
||||
header("Location: student.php?id=" . $student_id . "&success=detail_added");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle form submission for deleting a student detail
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'delete_student_detail') {
|
||||
$detail_id = isset($_POST['detail_id']) ? (int)$_POST['detail_id'] : 0;
|
||||
|
||||
if ($detail_id) {
|
||||
$stmt = $pdo->prepare("DELETE FROM student_details WHERE id = ? AND student_id = ?");
|
||||
$stmt->execute([$detail_id, $student_id]);
|
||||
|
||||
header("Location: student.php?id=" . $student_id . "&success=detail_deleted");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle form submission for editing a student detail
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'edit_student_detail') {
|
||||
$detail_id = isset($_POST['detail_id']) ? (int)$_POST['detail_id'] : 0;
|
||||
$title = trim($_POST['detail_title'] ?? '');
|
||||
$details = trim($_POST['detail_content'] ?? '');
|
||||
|
||||
if ($detail_id && !empty($title)) {
|
||||
$stmt = $pdo->prepare("UPDATE student_details SET title = ?, details = ? WHERE id = ? AND student_id = ?");
|
||||
$stmt->execute([$title, $details, $detail_id, $student_id]);
|
||||
|
||||
header("Location: student.php?id=" . $student_id . "&success=detail_updated");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
// For development, you might want to log this error.
|
||||
// For production, show a generic error message.
|
||||
die("Database error: Could not retrieve student data.");
|
||||
}
|
||||
|
||||
$pageTitle = htmlspecialchars($student['first_name'] . ' ' . $student['last_name']);
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?php echo $pageTitle; ?> - Student Details</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
||||
</head>
|
||||
<body class="bg-light">
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="index.php">Bhuddi School</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="#">Welcome, <?= htmlspecialchars($_SESSION['username']) ?>!</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="logout.php">Logout</a>
|
||||
</li>
|
||||
<?php if ($_SESSION['role'] === 'admin'): ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="admin.php">Admin</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main class="container mt-5">
|
||||
<div class="card p-4 shadow-sm border-0 rounded-3">
|
||||
<div class="card-body">
|
||||
<div class="d-flex align-items-center mb-4">
|
||||
<i class="bi bi-person-circle text-primary me-3" style="font-size: 3rem;"></i>
|
||||
<div>
|
||||
<h1 class="h3 mb-0"><?php echo htmlspecialchars($student['first_name'] . ' ' . $student['last_name']); ?></h1>
|
||||
<p class="text-muted mb-0">Student Profile</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<strong class="text-secondary">First Name:</strong>
|
||||
<p class="lead"><?php echo htmlspecialchars($student['first_name']); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<strong class="text-secondary">Last Name:</strong>
|
||||
<p class="lead"><?php echo htmlspecialchars($student['last_name']); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<strong class="text-secondary">Date of Birth:</strong>
|
||||
<p class="lead"><?php echo htmlspecialchars(date('F j, Y', strtotime($student['date_of_birth']))); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<strong class="text-secondary">Admission Date:</strong>
|
||||
<p class="lead"><?php echo htmlspecialchars(date('F j, Y, g:i a', strtotime($student['created_at']))); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<a href="index.php" class="btn btn-outline-secondary">
|
||||
<i class="bi bi-arrow-left"></i> Back to Dashboard
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Behavior Insights Section -->
|
||||
<div class="card p-4 mt-4 shadow-sm border-0 rounded-3">
|
||||
<div class="card-body">
|
||||
<h2 class="h4 mb-4">Behavior Insights</h2>
|
||||
|
||||
<!-- Log New Behavior Form -->
|
||||
<?php if (!$is_viewer): ?>
|
||||
<div class="mb-5">
|
||||
<h3 class="h5 mb-3">Log New Behavior</h3>
|
||||
<form method="POST" action="student.php?id=<?php echo $student_id; ?>">
|
||||
<input type="hidden" name="action" value="add_behavior">
|
||||
<div class="mb-3">
|
||||
<label for="behavior_description" class="form-label">Description</label>
|
||||
<textarea class="form-control" id="behavior_description" name="behavior_description" rows="3" required></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="behavior_rating" class="form-label">Severity Scale (<span id="rating_value">5</span>/10)</label>
|
||||
<input type="range" class="form-range" id="behavior_rating" name="behavior_rating" min="1" max="10" value="5" oninput="document.getElementById('rating_value').innerText = this.value;">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-plus-circle"></i> Log Behavior
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Behavior History -->
|
||||
<div>
|
||||
<h3 class="h5 mb-3">Behavior History</h3>
|
||||
<?php if (empty($behaviors)): ?>
|
||||
<p class="text-muted">No behavior entries have been logged for this student yet.</p>
|
||||
<?php else: ?>
|
||||
<ul class="list-group">
|
||||
<?php foreach ($behaviors as $behavior): ?>
|
||||
<li class="list-group-item d-flex justify-content-between align-items-start">
|
||||
<div class="ms-2 me-auto">
|
||||
<div class="fw-bold"><?php echo htmlspecialchars($behavior['behavior_description']); ?></div>
|
||||
<small class="text-muted">Logged on: <?php echo htmlspecialchars(date('F j, Y, g:i a', strtotime($behavior['created_at']))); ?></small>
|
||||
</div>
|
||||
<span class="badge bg-primary rounded-pill me-3">Rating: <?php echo htmlspecialchars($behavior['rating']); ?></span>
|
||||
<?php if (!$is_viewer): ?>
|
||||
<div>
|
||||
<button class="btn btn-sm btn-outline-primary me-1 btn-edit-behavior"
|
||||
data-bs-toggle="modal"
|
||||
data-bs-target="#editBehaviorModal"
|
||||
data-behavior-id="<?php echo $behavior['id']; ?>"
|
||||
data-behavior-description="<?php echo htmlspecialchars($behavior['behavior_description']); ?>"
|
||||
data-behavior-rating="<?php echo htmlspecialchars($behavior['rating']); ?>">
|
||||
<i class="bi bi-pencil"></i>
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-danger btn-delete-behavior" data-behavior-id="<?php echo $behavior['id']; ?>"><i class="bi bi-trash"></i></button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Academic Insights Section -->
|
||||
<div class="card p-4 mt-4 shadow-sm border-0 rounded-3">
|
||||
<div class="card-body">
|
||||
<h2 class="h4 mb-4">Academic Insights</h2>
|
||||
|
||||
<!-- Log New Academic Record Form -->
|
||||
<?php if (!$is_viewer): ?>
|
||||
<div class="mb-5">
|
||||
<h3 class="h5 mb-3">Log New Academic Record</h3>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="action" value="add_academic">
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="subject" class="form-label">Subject</label>
|
||||
<input type="text" class="form-control" id="subject" name="subject" required>
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="grade" class="form-label">Grade</label>
|
||||
<select class="form-select" id="grade" name="grade" required>
|
||||
<option value="" disabled selected>Select a grade</option>
|
||||
<option value="A">A</option>
|
||||
<option value="B">B</option>
|
||||
<option value="C">C</option>
|
||||
<option value="D">D</option>
|
||||
<option value="F">F</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="comments" class="form-label">Comments</label>
|
||||
<textarea class="form-control" id="comments" name="comments" rows="3"></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-plus-circle"></i> Log Academic Record
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Academic History -->
|
||||
<div>
|
||||
<h3 class="h5 mb-3">Academic History</h3>
|
||||
<?php if (empty($academics)): ?>
|
||||
<p class="text-muted">No academic records have been logged for this student yet.</p>
|
||||
<?php else: ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Subject</th>
|
||||
<th>Grade</th>
|
||||
<th>Comments</th>
|
||||
<th>Date</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($academics as $academic): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($academic['subject']); ?></td>
|
||||
<td><span class="badge bg-primary"><?php echo htmlspecialchars($academic['grade']); ?></span></td>
|
||||
<td><?php echo nl2br(htmlspecialchars($academic['comments'])); ?></td>
|
||||
<td><small class="text-muted"><?php echo htmlspecialchars(date('F j, Y', strtotime($academic['created_at']))); ?></small></td>
|
||||
<?php if (!$is_viewer): ?>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-outline-primary me-1 btn-edit-academic"
|
||||
data-bs-toggle="modal"
|
||||
data-bs-target="#editAcademicModal"
|
||||
data-academic-id="<?php echo $academic['id']; ?>"
|
||||
data-subject="<?php echo htmlspecialchars($academic['subject']); ?>"
|
||||
data-grade="<?php echo htmlspecialchars($academic['grade']); ?>"
|
||||
data-comments="<?php echo htmlspecialchars($academic['comments']); ?>">
|
||||
<i class="bi bi-pencil"></i>
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-danger btn-delete-academic" data-academic-id="<?php echo $academic['id']; ?>"><i class="bi bi-trash"></i></button>
|
||||
</td>
|
||||
<?php endif; ?>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Student Details Section -->
|
||||
<div class="card p-4 mt-4 shadow-sm border-0 rounded-3">
|
||||
<div class="card-body">
|
||||
<h2 class="h4 mb-4">Additional Student Details</h2>
|
||||
|
||||
<!-- Add New Detail Form -->
|
||||
<?php if (!$is_viewer): ?>
|
||||
<div class="mb-5">
|
||||
<h3 class="h5 mb-3">Add New Detail</h3>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="action" value="add_student_detail">
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="detail_title" class="form-label">Title</label>
|
||||
<input type="text" class="form-control" id="detail_title" name="detail_title" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="detail_content" class="form-label">Details</label>
|
||||
<textarea class="form-control" id="detail_content" name="detail_content" rows="3"></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-plus-circle"></i> Add Detail
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Details History -->
|
||||
<div>
|
||||
<h3 class="h5 mb-3">Details History</h3>
|
||||
<?php if (empty($student_details)): ?>
|
||||
<p class="text-muted">No additional details have been logged for this student yet.</p>
|
||||
<?php else: ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Details</th>
|
||||
<th>Date</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($student_details as $detail): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($detail['title']); ?></td>
|
||||
<td><?php echo nl2br(htmlspecialchars($detail['details'])); ?></td>
|
||||
<td><small class="text-muted"><?php echo htmlspecialchars(date('F j, Y', strtotime($detail['created_at']))); ?></small></td>
|
||||
<?php if (!$is_viewer): ?>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-outline-primary me-1 btn-edit-detail"
|
||||
data-bs-toggle="modal"
|
||||
data-bs-target="#editDetailModal"
|
||||
data-detail-id="<?php echo $detail['id']; ?>"
|
||||
data-detail-title="<?php echo htmlspecialchars($detail['title']); ?>"
|
||||
data-detail-content="<?php echo htmlspecialchars($detail['details']); ?>">
|
||||
<i class="bi bi-pencil"></i>
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-danger btn-delete-detail" data-detail-id="<?php echo $detail['id']; ?>"><i class="bi bi-trash"></i></button>
|
||||
</td>
|
||||
<?php endif; ?>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<!-- Edit Behavior Modal -->
|
||||
<div class="modal fade" id="editBehaviorModal" tabindex="-1" aria-labelledby="editBehaviorModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="editBehaviorModalLabel">Edit Behavior Entry</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<form id="editBehaviorForm" method="POST">
|
||||
<div class="modal-body">
|
||||
<input type="hidden" name="action" value="edit_behavior">
|
||||
<input type="hidden" id="edit_behavior_id" name="behavior_id">
|
||||
<div class="mb-3">
|
||||
<label for="edit_behavior_description" class="form-label">Description</label>
|
||||
<textarea class="form-control" id="edit_behavior_description" name="behavior_description" rows="3" required></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="edit_behavior_rating" class="form-label">Severity Scale (<span id="edit_rating_value">5</span>/10)</label>
|
||||
<input type="range" class="form-range" id="edit_behavior_rating" name="behavior_rating" min="1" max="10" oninput="document.getElementById('edit_rating_value').innerText = this.value;">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
<button type="submit" class="btn btn-primary">Save changes</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Edit Academic Modal -->
|
||||
<div class="modal fade" id="editAcademicModal" tabindex="-1" aria-labelledby="editAcademicModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="editAcademicModalLabel">Edit Academic Entry</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<form id="editAcademicForm" method="POST">
|
||||
<div class="modal-body">
|
||||
<input type="hidden" name="action" value="edit_academic">
|
||||
<input type="hidden" id="edit_academic_id" name="academic_id">
|
||||
<div class="mb-3">
|
||||
<label for="edit_subject" class="form-label">Subject</label>
|
||||
<input type="text" class="form-control" id="edit_subject" name="subject" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="edit_grade" class="form-label">Grade</label>
|
||||
<select class="form-select" id="edit_grade" name="grade" required>
|
||||
<option value="A">A</option>
|
||||
<option value="B">B</option>
|
||||
<option value="C">C</option>
|
||||
<option value="D">D</option>
|
||||
<option value="F">F</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="edit_comments" class="form-label">Comments</label>
|
||||
<textarea class="form-control" id="edit_comments" name="comments" rows="3"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
<button type="submit" class="btn btn-primary">Save changes</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Edit Student Detail Modal -->
|
||||
<div class="modal fade" id="editDetailModal" tabindex="-1" aria-labelledby="editDetailModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="editDetailModalLabel">Edit Student Detail</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<form id="editDetailForm" method="POST">
|
||||
<div class="modal-body">
|
||||
<input type="hidden" name="action" value="edit_student_detail">
|
||||
<input type="hidden" id="edit_detail_id" name="detail_id">
|
||||
<div class="mb-3">
|
||||
<label for="edit_detail_title" class="form-label">Title</label>
|
||||
<input type="text" class="form-control" id="edit_detail_title" name="detail_title" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="edit_detail_content" class="form-label">Details</label>
|
||||
<textarea class="form-control" id="edit_detail_content" name="detail_content" rows="3"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
<button type="submit" class="btn btn-primary">Save changes</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Toast container -->
|
||||
<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11">
|
||||
<!-- Behavior Toast -->
|
||||
<div id="behaviorToast" class="toast align-items-center text-white bg-success border-0" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
<div class="d-flex">
|
||||
<div class="toast-body">
|
||||
<i class="bi bi-check-circle-fill me-2"></i>
|
||||
New behavior logged successfully!
|
||||
</div>
|
||||
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Academic Toast -->
|
||||
<div id="academicToast" class="toast align-items-center text-white bg-success border-0" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
<div class="d-flex">
|
||||
<div class="toast-body">
|
||||
<i class="bi bi-check-circle-fill me-2"></i>
|
||||
New academic record logged successfully!
|
||||
</div>
|
||||
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const studentId = '<?php echo $student_id; ?>';
|
||||
|
||||
let toastToShow = null;
|
||||
|
||||
if (urlParams.has('success')) {
|
||||
if (urlParams.get('success') === 'behavior_logged') {
|
||||
toastToShow = document.getElementById('behaviorToast');
|
||||
} else if (urlParams.get('success') === 'academic_logged') {
|
||||
toastToShow = document.getElementById('academicToast');
|
||||
}
|
||||
}
|
||||
|
||||
if (toastToShow) {
|
||||
const toast = new bootstrap.Toast(toastToShow);
|
||||
toast.show();
|
||||
|
||||
// Remove the query parameter from the URL without reloading the page
|
||||
const newUrl = window.location.pathname + '?id=' + studentId;
|
||||
window.history.replaceState({}, document.title, newUrl);
|
||||
}
|
||||
|
||||
document.querySelectorAll('.btn-delete-behavior').forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
if (confirm('Are you sure you want to delete this behavior entry?')) {
|
||||
const behaviorId = this.dataset.behaviorId;
|
||||
const form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = 'student.php?id=<?php echo $student_id; ?>';
|
||||
|
||||
const actionInput = document.createElement('input');
|
||||
actionInput.type = 'hidden';
|
||||
actionInput.name = 'action';
|
||||
actionInput.value = 'delete_behavior';
|
||||
form.appendChild(actionInput);
|
||||
|
||||
const idInput = document.createElement('input');
|
||||
idInput.type = 'hidden';
|
||||
idInput.name = 'behavior_id';
|
||||
idInput.value = behaviorId;
|
||||
form.appendChild(idInput);
|
||||
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const editBehaviorModal = document.getElementById('editBehaviorModal');
|
||||
editBehaviorModal.addEventListener('show.bs.modal', function (event) {
|
||||
const button = event.relatedTarget;
|
||||
const behaviorId = button.dataset.behaviorId;
|
||||
const description = button.dataset.behaviorDescription;
|
||||
const rating = button.dataset.behaviorRating;
|
||||
|
||||
const modalForm = document.getElementById('editBehaviorForm');
|
||||
modalForm.action = 'student.php?id=<?php echo $student_id; ?>';
|
||||
|
||||
const behaviorIdInput = document.getElementById('edit_behavior_id');
|
||||
const descriptionInput = document.getElementById('edit_behavior_description');
|
||||
const ratingInput = document.getElementById('edit_behavior_rating');
|
||||
const ratingValue = document.getElementById('edit_rating_value');
|
||||
|
||||
behaviorIdInput.value = behaviorId;
|
||||
descriptionInput.value = description;
|
||||
ratingInput.value = rating;
|
||||
ratingValue.innerText = rating;
|
||||
});
|
||||
|
||||
document.querySelectorAll('.btn-delete-academic').forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
if (confirm('Are you sure you want to delete this academic entry?')) {
|
||||
const academicId = this.dataset.academicId;
|
||||
const form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = 'student.php?id=<?php echo $student_id; ?>';
|
||||
|
||||
const actionInput = document.createElement('input');
|
||||
actionInput.type = 'hidden';
|
||||
actionInput.name = 'action';
|
||||
actionInput.value = 'delete_academic';
|
||||
form.appendChild(actionInput);
|
||||
|
||||
const idInput = document.createElement('input');
|
||||
idInput.type = 'hidden';
|
||||
idInput.name = 'academic_id';
|
||||
idInput.value = academicId;
|
||||
form.appendChild(idInput);
|
||||
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const editAcademicModal = document.getElementById('editAcademicModal');
|
||||
editAcademicModal.addEventListener('show.bs.modal', function (event) {
|
||||
const button = event.relatedTarget;
|
||||
const academicId = button.dataset.academicId;
|
||||
const subject = button.dataset.subject;
|
||||
const grade = button.dataset.grade;
|
||||
const comments = button.dataset.comments;
|
||||
|
||||
const modalForm = document.getElementById('editAcademicForm');
|
||||
modalForm.action = 'student.php?id=<?php echo $student_id; ?>';
|
||||
|
||||
document.getElementById('edit_academic_id').value = academicId;
|
||||
document.getElementById('edit_subject').value = subject;
|
||||
document.getElementById('edit_grade').value = grade;
|
||||
document.getElementById('edit_comments').value = comments;
|
||||
});
|
||||
|
||||
document.querySelectorAll('.btn-delete-detail').forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
if (confirm('Are you sure you want to delete this detail?')) {
|
||||
const detailId = this.dataset.detailId;
|
||||
const form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = 'student.php?id=<?php echo $student_id; ?>';
|
||||
|
||||
const actionInput = document.createElement('input');
|
||||
actionInput.type = 'hidden';
|
||||
actionInput.name = 'action';
|
||||
actionInput.value = 'delete_student_detail';
|
||||
form.appendChild(actionInput);
|
||||
|
||||
const idInput = document.createElement('input');
|
||||
idInput.type = 'hidden';
|
||||
idInput.name = 'detail_id';
|
||||
idInput.value = detailId;
|
||||
form.appendChild(idInput);
|
||||
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const editDetailModal = document.getElementById('editDetailModal');
|
||||
editDetailModal.addEventListener('show.bs.modal', function (event) {
|
||||
const button = event.relatedTarget;
|
||||
const detailId = button.dataset.detailId;
|
||||
const title = button.dataset.detailTitle;
|
||||
const content = button.dataset.detailContent;
|
||||
|
||||
const modalForm = document.getElementById('editDetailForm');
|
||||
modalForm.action = 'student.php?id=<?php echo $student_id; ?>';
|
||||
|
||||
document.getElementById('edit_detail_id').value = detailId;
|
||||
document.getElementById('edit_detail_title').value = title;
|
||||
document.getElementById('edit_detail_content').value = content;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user