149 lines
6.3 KiB
PHP
149 lines
6.3 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
require_once 'db/config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
// Auto-apply migrations
|
|
if (file_exists('db/migrations/007_create_classes_table.sql')) {
|
|
$pdo->exec(file_get_contents('db/migrations/007_create_classes_table.sql'));
|
|
}
|
|
if (file_exists('db/migrations/008_create_subjects_table.sql')) {
|
|
$pdo->exec(file_get_contents('db/migrations/008_create_subjects_table.sql'));
|
|
}
|
|
|
|
// Fetch classes
|
|
$stmt_classes = $pdo->query("SELECT id, name FROM classes ORDER BY name");
|
|
$classes = $stmt_classes->fetchAll();
|
|
|
|
// Fetch subjects
|
|
$stmt_subjects = $pdo->query("SELECT id, name FROM subjects ORDER BY name");
|
|
$subjects = $stmt_subjects->fetchAll();
|
|
|
|
} catch (Exception $e) {
|
|
die("Could not connect to the database: " . $e->getMessage());
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Subjects & Classes - Admin Dashboard</title>
|
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&family=Open+Sans&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body class="admin-body">
|
|
<div class="admin-container">
|
|
<aside class="sidebar">
|
|
<div class="sidebar-header">
|
|
<h2>School Admin</h2>
|
|
</div>
|
|
<nav class="sidebar-nav">
|
|
<a href="admin.php">Dashboard</a>
|
|
<a href="users.php">User Management</a>
|
|
<a href="school_settings.php">School Settings</a>
|
|
<a href="subjects_classes.php" class="active">Subjects & Classes</a>
|
|
<a href="#">Student Promotions</a>
|
|
<a href="#">Reports</a>
|
|
<a href="logout.php" class="logout">Logout</a>
|
|
</nav>
|
|
</aside>
|
|
<main class="main-content">
|
|
<header class="main-header">
|
|
<h1>Subjects & Classes</h1>
|
|
</header>
|
|
|
|
<?php if (isset($_SESSION['success_message'])): ?>
|
|
<div class="alert alert-success"><?= htmlspecialchars($_SESSION['success_message']) ?></div>
|
|
<?php unset($_SESSION['success_message']); ?>
|
|
<?php endif; ?>
|
|
|
|
<?php if (isset($_SESSION['error_message'])): ?>
|
|
<div class="alert alert-danger"><?= htmlspecialchars($_SESSION['error_message']) ?></div>
|
|
<?php unset($_SESSION['error_message']); ?>
|
|
<?php endif; ?>
|
|
|
|
<div class="content-grid">
|
|
<!-- Classes Section -->
|
|
<div class="card full-width-card">
|
|
<div class="card-header">
|
|
<h3>Manage Classes</h3>
|
|
</div>
|
|
<div class="card-body">
|
|
<table class="user-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Class Name</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($classes as $class): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($class['name']) ?></td>
|
|
<td>
|
|
<a href="edit_class.php?id=<?= $class['id'] ?>" class="action-link">Edit</a>
|
|
<a href="delete_class.php?id=<?= $class['id'] ?>" class="action-link" onclick="return confirm('Are you sure?')">Delete</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<form action="add_class.php" method="POST" class="add-form">
|
|
<div class="form-group">
|
|
<label>Add New Class</label>
|
|
<input type="text" name="name" class="form-control" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-secondary">Add Class</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Subjects Section -->
|
|
<div class="card full-width-card">
|
|
<div class="card-header">
|
|
<h3>Manage Subjects</h3>
|
|
</div>
|
|
<div class="card-body">
|
|
<table class="user-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Subject Name</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($subjects as $subject): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($subject['name']) ?></td>
|
|
<td>
|
|
<a href="edit_subject.php?id=<?= $subject['id'] ?>" class="action-link">Edit</a>
|
|
<a href="delete_subject.php?id=<?= $subject['id'] ?>" class="action-link" onclick="return confirm('Are you sure?')">Delete</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<form action="add_subject.php" method="POST" class="add-form">
|
|
<div class="form-group">
|
|
<label>Add New Subject</label>
|
|
<input type="text" name="name" class="form-control" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-secondary">Add Subject</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
</body>
|
|
</html>
|