v01
This commit is contained in:
parent
a43985e210
commit
7a3409404c
27
admin.php
Normal file
27
admin.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
include 'templates/header.php';
|
||||
|
||||
// Admin-only page
|
||||
if (!isset($_SESSION['role_id']) || $_SESSION['role_id'] != 1) {
|
||||
header('Location: dashboard.php');
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<h2>Admin Dashboard</h2>
|
||||
<p>Welcome to the admin area. Here you can manage the application settings and data.</p>
|
||||
|
||||
<div class="list-group">
|
||||
<a href="admin_institutions.php" class="list-group-item list-group-item-action">Manage Institutions</a>
|
||||
<a href="admin_schools.php" class="list-group-item list-group-item-action">Manage Schools</a>
|
||||
<a href="admin_programs.php" class="list-group-item list-group-item-action">Manage Programs</a>
|
||||
<a href="admin_courses.php" class="list-group-item list-group-item-action">Manage Courses</a>
|
||||
</div>
|
||||
|
||||
<h3 class="mt-4">Assessment Documents</h3>
|
||||
<div class="list-group">
|
||||
<a href="admin_mission_statements.php" class="list-group-item list-group-item-action">Manage Mission Statements</a>
|
||||
<a href="admin_learning_outcomes.php" class="list-group-item list-group-item-action">Manage Learning Outcomes</a>
|
||||
</div>
|
||||
|
||||
<?php include 'templates/footer.php'; ?>
|
||||
143
admin_courses.php
Normal file
143
admin_courses.php
Normal file
@ -0,0 +1,143 @@
|
||||
<?php
|
||||
include 'templates/header.php';
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Admin-only page
|
||||
if (!isset($_SESSION['role_id']) || $_SESSION['role_id'] != 1) {
|
||||
header('Location: dashboard.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
$action = $_GET['action'] ?? 'list';
|
||||
$id = $_GET['id'] ?? null;
|
||||
|
||||
// Fetch programs for the dropdown
|
||||
$programs_stmt = $pdo->query('SELECT id, name FROM programs ORDER BY name');
|
||||
$programs = $programs_stmt->fetchAll();
|
||||
|
||||
// Handle form submissions
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$name = trim($_POST['name']);
|
||||
$program_id = $_POST['program_id'];
|
||||
|
||||
if (isset($_POST['add_course'])) {
|
||||
if (!empty($name) && !empty($program_id)) {
|
||||
$stmt = $pdo->prepare('INSERT INTO courses (name, program_id) VALUES (?, ?)');
|
||||
$stmt->execute([$name, $program_id]);
|
||||
}
|
||||
} elseif (isset($_POST['update_course'])) {
|
||||
if (!empty($name) && !empty($program_id) && !empty($id)) {
|
||||
$stmt = $pdo->prepare('UPDATE courses SET name = ?, program_id = ? WHERE id = ?');
|
||||
$stmt->execute([$name, $program_id, $id]);
|
||||
}
|
||||
header('Location: admin_courses.php');
|
||||
exit;
|
||||
} elseif (isset($_POST['delete_course'])) {
|
||||
if (!empty($id)) {
|
||||
$stmt = $pdo->prepare('DELETE FROM courses WHERE id = ?');
|
||||
$stmt->execute([$id]);
|
||||
}
|
||||
header('Location: admin_courses.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<h2>Assessment Planning: Courses</h2>
|
||||
|
||||
<p><a href="admin.php"> ← Back to Admin Dashboard</a></p>
|
||||
|
||||
<?php if ($action === 'edit' && $id): ?>
|
||||
<?php
|
||||
$stmt = $pdo->prepare('SELECT * FROM courses WHERE id = ?');
|
||||
$stmt->execute([$id]);
|
||||
$course = $stmt->fetch();
|
||||
?>
|
||||
<h3>Edit Course</h3>
|
||||
<form action="admin_courses.php?action=edit&id=<?php echo $id; ?>" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Course Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($course['name']); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="program_id" class="form-label">Program</label>
|
||||
<select class="form-select" id="program_id" name="program_id" required>
|
||||
<?php foreach ($programs as $program): ?>
|
||||
<option value="<?php echo $program['id']; ?>" <?php echo ($program['id'] == $course['program_id']) ? 'selected' : ''; ?>><?php echo htmlspecialchars($program['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<input type="hidden" name="id" value="<?php echo $id; ?>">
|
||||
<button type="submit" name="update_course" class="btn btn-primary">Update</button>
|
||||
<a href="admin_courses.php" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
|
||||
<?php elseif ($action === 'delete' && $id): ?>
|
||||
<?php
|
||||
$stmt = $pdo->prepare('SELECT * FROM courses WHERE id = ?');
|
||||
$stmt->execute([$id]);
|
||||
$course = $stmt->fetch();
|
||||
?>
|
||||
<h3>Delete Course</h3>
|
||||
<p>Are you sure you want to delete the course "<?php echo htmlspecialchars($course['name']); ?>"?</p>
|
||||
<form action="admin_courses.php?action=delete&id=<?php echo $id; ?>" method="post">
|
||||
<input type="hidden" name="id" value="<?php echo $id; ?>">
|
||||
<button type="submit" name="delete_course" class="btn btn-danger">Delete</button>
|
||||
<a href="admin_courses.php" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<h3>Add New Course</h3>
|
||||
<form action="admin_courses.php" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Course Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="program_id" class="form-label">Program</label>
|
||||
<select class="form-select" id="program_id" name="program_id" required>
|
||||
<option value="">Select a Program</option>
|
||||
<?php foreach ($programs as $program): ?>
|
||||
<option value="<?php echo $program['id']; ?>"><?php echo htmlspecialchars($program['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" name="add_course" class="btn btn-primary">Add Course</button>
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
|
||||
<h3>Existing Courses</h3>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Program</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$stmt = $pdo->query('SELECT c.id, c.name, p.name AS program_name FROM courses c JOIN programs p ON c.program_id = p.id ORDER BY c.id');
|
||||
while ($row = $stmt->fetch()) {
|
||||
echo "<tr>";
|
||||
echo "<td>" . htmlspecialchars($row['id']) . "</td>";
|
||||
echo "<td>" . htmlspecialchars($row['name']) . "</td>";
|
||||
echo "<td>" . htmlspecialchars($row['program_name']) . "</td>";
|
||||
echo '<td>
|
||||
<a href="admin_courses.php?action=edit&id=' . $row['id'] . '" class="btn btn-sm btn-outline-primary">Edit</a>
|
||||
<a href="admin_courses.php?action=delete&id=' . $row['id'] . '" class="btn btn-sm btn-outline-danger">Delete</a>
|
||||
</td>';
|
||||
echo "</tr>";
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php include 'templates/footer.php'; ?>
|
||||
117
admin_institutions.php
Normal file
117
admin_institutions.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
include 'templates/header.php';
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Admin-only page
|
||||
if (!isset($_SESSION['role_id']) || $_SESSION['role_id'] != 1) {
|
||||
header('Location: dashboard.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
$action = $_GET['action'] ?? 'list';
|
||||
$id = $_GET['id'] ?? null;
|
||||
|
||||
// Handle form submissions
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (isset($_POST['add_institution'])) {
|
||||
$name = trim($_POST['name']);
|
||||
if (!empty($name)) {
|
||||
$stmt = $pdo->prepare('INSERT INTO institutions (name) VALUES (?)');
|
||||
$stmt->execute([$name]);
|
||||
}
|
||||
} elseif (isset($_POST['update_institution'])) {
|
||||
$name = trim($_POST['name']);
|
||||
if (!empty($name) && !empty($id)) {
|
||||
$stmt = $pdo->prepare('UPDATE institutions SET name = ? WHERE id = ?');
|
||||
$stmt->execute([$name, $id]);
|
||||
}
|
||||
header('Location: admin_institutions.php');
|
||||
exit;
|
||||
} elseif (isset($_POST['delete_institution'])) {
|
||||
if (!empty($id)) {
|
||||
$stmt = $pdo->prepare('DELETE FROM institutions WHERE id = ?');
|
||||
$stmt->execute([$id]);
|
||||
}
|
||||
header('Location: admin_institutions.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<h2>Assessment Planning: Institutions</h2>
|
||||
|
||||
<?php if ($action === 'edit' && $id): ?>
|
||||
<?php
|
||||
$stmt = $pdo->prepare('SELECT * FROM institutions WHERE id = ?');
|
||||
$stmt->execute([$id]);
|
||||
$institution = $stmt->fetch();
|
||||
?>
|
||||
<h3>Edit Institution</h3>
|
||||
<form action="admin_institutions.php?action=edit&id=<?php echo $id; ?>" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Institution Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($institution['name']); ?>" required>
|
||||
</div>
|
||||
<input type="hidden" name="id" value="<?php echo $id; ?>">
|
||||
<button type="submit" name="update_institution" class="btn btn-primary">Update</button>
|
||||
<a href="admin_institutions.php" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
|
||||
<?php elseif ($action === 'delete' && $id): ?>
|
||||
<?php
|
||||
$stmt = $pdo->prepare('SELECT * FROM institutions WHERE id = ?');
|
||||
$stmt->execute([$id]);
|
||||
$institution = $stmt->fetch();
|
||||
?>
|
||||
<h3>Delete Institution</h3>
|
||||
<p>Are you sure you want to delete the institution "<?php echo htmlspecialchars($institution['name']); ?>"?</p>
|
||||
<form action="admin_institutions.php?action=delete&id=<?php echo $id; ?>" method="post">
|
||||
<input type="hidden" name="id" value="<?php echo $id; ?>">
|
||||
<button type="submit" name="delete_institution" class="btn btn-danger">Delete</button>
|
||||
<a href="admin_institutions.php" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<h3>Add New Institution</h3>
|
||||
<form action="admin_institutions.php" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Institution Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" required>
|
||||
</div>
|
||||
<button type="submit" name="add_institution" class="btn btn-primary">Add Institution</button>
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
|
||||
<h3>Existing Institutions</h3>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$stmt = $pdo->query('SELECT * FROM institutions ORDER BY id');
|
||||
while ($row = $stmt->fetch()) {
|
||||
echo "<tr>";
|
||||
echo "<td>" . htmlspecialchars($row['id']) . "</td>";
|
||||
echo "<td>" . htmlspecialchars($row['name']) . "</td>";
|
||||
echo '<td>
|
||||
<a href="admin_institutions.php?action=edit&id=' . $row['id'] . '" class="btn btn-sm btn-outline-primary">Edit</a>
|
||||
<a href="admin_institutions.php?action=delete&id=' . $row['id'] . '" class="btn btn-sm btn-outline-danger">Delete</a>
|
||||
</td>';
|
||||
echo "</tr>";
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php include 'templates/footer.php'; ?>
|
||||
202
admin_learning_outcomes.php
Normal file
202
admin_learning_outcomes.php
Normal file
@ -0,0 +1,202 @@
|
||||
<?php
|
||||
include 'templates/header.php';
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Admin-only page
|
||||
if (!isset($_SESSION['role_id']) || $_SESSION['role_id'] != 1) {
|
||||
header('Location: dashboard.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
$action = $_GET['action'] ?? 'list';
|
||||
$id = $_GET['id'] ?? null;
|
||||
|
||||
// Fetch related items for dropdowns
|
||||
$institutions = $pdo->query('SELECT id, name FROM institutions ORDER BY name')->fetchAll();
|
||||
$programs = $pdo->query('SELECT id, name FROM programs ORDER BY name')->fetchAll();
|
||||
$courses = $pdo->query('SELECT id, name FROM courses ORDER BY name')->fetchAll();
|
||||
|
||||
// Handle form submissions
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$description = trim($_POST['description']);
|
||||
$rel_type = $_POST['rel_type'];
|
||||
$rel_id = $_POST['rel_id'];
|
||||
|
||||
if (isset($_POST['add_outcome'])) {
|
||||
if (!empty($description) && !empty($rel_type) && !empty($rel_id)) {
|
||||
$stmt = $pdo->prepare('INSERT INTO learning_outcomes (description, rel_type, rel_id) VALUES (?, ?, ?)');
|
||||
$stmt->execute([$description, $rel_type, $rel_id]);
|
||||
}
|
||||
} elseif (isset($_POST['update_outcome'])) {
|
||||
if (!empty($description) && !empty($rel_type) && !empty($rel_id) && !empty($id)) {
|
||||
$stmt = $pdo->prepare('UPDATE learning_outcomes SET description = ?, rel_type = ?, rel_id = ? WHERE id = ?');
|
||||
$stmt->execute([$description, $rel_type, $rel_id, $id]);
|
||||
}
|
||||
header('Location: admin_learning_outcomes.php');
|
||||
exit;
|
||||
} elseif (isset($_POST['delete_outcome'])) {
|
||||
if (!empty($id)) {
|
||||
$stmt = $pdo->prepare('DELETE FROM learning_outcomes WHERE id = ?');
|
||||
$stmt->execute([$id]);
|
||||
}
|
||||
header('Location: admin_learning_outcomes.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<h2>Assessment Planning: Learning Outcomes</h2>
|
||||
|
||||
<p><a href="admin.php"> ← Back to Admin Dashboard</a></p>
|
||||
|
||||
<?php if ($action === 'edit' && $id): ?>
|
||||
<?php
|
||||
$stmt = $pdo->prepare('SELECT * FROM learning_outcomes WHERE id = ?');
|
||||
$stmt->execute([$id]);
|
||||
$outcome = $stmt->fetch();
|
||||
?>
|
||||
<h3>Edit Learning Outcome</h3>
|
||||
<form action="admin_learning_outcomes.php?action=edit&id=<?php echo $id; ?>" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="description" class="form-label">Learning Outcome</label>
|
||||
<textarea class="form-control" id="description" name="description" rows="3" required><?php echo htmlspecialchars($outcome['description']); ?></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="rel_type" class="form-label">Link to:</label>
|
||||
<select class="form-select" name="rel_type" id="rel_type" required>
|
||||
<option value="institution" <?php echo ($outcome['rel_type'] == 'institution') ? 'selected' : ''; ?>>Institution</option>
|
||||
<option value="program" <?php echo ($outcome['rel_type'] == 'program') ? 'selected' : ''; ?>>Program</option>
|
||||
<option value="course" <?php echo ($outcome['rel_type'] == 'course') ? 'selected' : ''; ?>>Course</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="rel_id" class="form-label">Specific Item</label>
|
||||
<select class="form-select" name="rel_id" id="rel_id" required>
|
||||
<!-- Options will be populated by JavaScript -->
|
||||
</select>
|
||||
</div>
|
||||
<input type="hidden" name="id" value="<?php echo $id; ?>">
|
||||
<button type="submit" name="update_outcome" class="btn btn-primary">Update</button>
|
||||
<a href="admin_learning_outcomes.php" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<h3>Add New Learning Outcome</h3>
|
||||
<form action="admin_learning_outcomes.php" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="description" class="form-label">Learning Outcome</label>
|
||||
<textarea class="form-control" id="description" name="description" rows="3" required></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="rel_type" class="form-label">Link to:</label>
|
||||
<select class="form-select" name="rel_type" id="rel_type_add" required>
|
||||
<option value="">Select Type</option>
|
||||
<option value="institution">Institution</option>
|
||||
<option value="program">Program</option>
|
||||
<option value="course">Course</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="rel_id" class="form-label">Specific Item</label>
|
||||
<select class="form-select" name="rel_id" id="rel_id_add" required>
|
||||
<!-- Options will be populated by JavaScript -->
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" name="add_outcome" class="btn btn-primary">Add Learning Outcome</button>
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
|
||||
<h3>Existing Learning Outcomes</h3>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Description</th>
|
||||
<th>Linked To</th>
|
||||
<th>Actions</th>
|
||||
<th>Manage</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$stmt = $pdo->query('SELECT * FROM learning_outcomes ORDER BY id DESC');
|
||||
while ($row = $stmt->fetch()) {
|
||||
$rel_name = '';
|
||||
if ($row['rel_type'] == 'institution') {
|
||||
$rel_stmt = $pdo->prepare("SELECT name FROM institutions WHERE id = ?");
|
||||
$rel_stmt->execute([$row['rel_id']]);
|
||||
$rel_name = $rel_stmt->fetchColumn();
|
||||
} elseif ($row['rel_type'] == 'program') {
|
||||
$rel_stmt = $pdo->prepare("SELECT name FROM programs WHERE id = ?");
|
||||
$rel_stmt->execute([$row['rel_id']]);
|
||||
$rel_name = $rel_stmt->fetchColumn();
|
||||
} elseif ($row['rel_type'] == 'course') {
|
||||
$rel_stmt = $pdo->prepare("SELECT name FROM courses WHERE id = ?");
|
||||
$rel_stmt->execute([$row['rel_id']]);
|
||||
$rel_name = $rel_stmt->fetchColumn();
|
||||
}
|
||||
|
||||
echo "<tr>";
|
||||
echo "<td>" . htmlspecialchars($row['description']) . "</td>";
|
||||
echo "<td>" . ucfirst($row['rel_type']) . ': ' . htmlspecialchars($rel_name) . "</td>";
|
||||
echo '<td>
|
||||
<a href="admin_learning_outcomes.php?action=edit&id=' . $row['id'] . '" class="btn btn-sm btn-outline-primary">Edit</a>
|
||||
<a href="admin_learning_outcomes.php?action=delete&id=' . $row['id'] . '" class="btn btn-sm btn-outline-danger">Delete</a>
|
||||
</td>';
|
||||
echo '<td>
|
||||
<a href="admin_success_criteria.php?lo_id=' . $row['id'] . '" class="btn btn-sm btn-outline-secondary">Success Criteria</a>
|
||||
<a href="admin_assessment_measures.php?lo_id=' . $row['id'] . '" class="btn btn-sm btn-outline-info">Assessment Measures</a>
|
||||
</td>';
|
||||
echo "</tr>";
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<script>
|
||||
const institutions = <?php echo json_encode($institutions); ?>;
|
||||
const programs = <?php echo json_encode($programs); ?>;
|
||||
const courses = <?php echo json_encode($courses); ?>;
|
||||
|
||||
function populateSelect(typeSelectId, itemSelectId) {
|
||||
const typeSelect = document.getElementById(typeSelectId);
|
||||
const itemSelect = document.getElementById(itemSelectId);
|
||||
|
||||
typeSelect.addEventListener('change', function() {
|
||||
itemSelect.innerHTML = '';
|
||||
const selectedType = this.value;
|
||||
let items = [];
|
||||
|
||||
if (selectedType === 'institution') {
|
||||
items = institutions;
|
||||
} else if (selectedType === 'program') {
|
||||
items = programs;
|
||||
} else if (selectedType === 'course') {
|
||||
items = courses;
|
||||
}
|
||||
|
||||
items.forEach(function(item) {
|
||||
const option = document.createElement('option');
|
||||
option.value = item.id;
|
||||
option.textContent = item.name;
|
||||
itemSelect.appendChild(option);
|
||||
});
|
||||
});
|
||||
|
||||
// Trigger change on page load for edit form
|
||||
if (typeSelect.value) {
|
||||
typeSelect.dispatchEvent(new Event('change'));
|
||||
}
|
||||
}
|
||||
|
||||
populateSelect('rel_type_add', 'rel_id_add');
|
||||
populateSelect('rel_type', 'rel_id');
|
||||
|
||||
</script>
|
||||
|
||||
<?php include 'templates/footer.php'; ?>
|
||||
197
admin_mission_statements.php
Normal file
197
admin_mission_statements.php
Normal file
@ -0,0 +1,197 @@
|
||||
<?php
|
||||
include 'templates/header.php';
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Admin-only page
|
||||
if (!isset($_SESSION['role_id']) || $_SESSION['role_id'] != 1) {
|
||||
header('Location: dashboard.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
$action = $_GET['action'] ?? 'list';
|
||||
$id = $_GET['id'] ?? null;
|
||||
|
||||
// Fetch related items for dropdowns
|
||||
$institutions = $pdo->query('SELECT id, name FROM institutions ORDER BY name')->fetchAll();
|
||||
$programs = $pdo->query('SELECT id, name FROM programs ORDER BY name')->fetchAll();
|
||||
$courses = $pdo->query('SELECT id, name FROM courses ORDER BY name')->fetchAll();
|
||||
|
||||
// Handle form submissions
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$statement = trim($_POST['statement']);
|
||||
$rel_type = $_POST['rel_type'];
|
||||
$rel_id = $_POST['rel_id'];
|
||||
|
||||
if (isset($_POST['add_statement'])) {
|
||||
if (!empty($statement) && !empty($rel_type) && !empty($rel_id)) {
|
||||
$stmt = $pdo->prepare('INSERT INTO mission_statements (statement, rel_type, rel_id) VALUES (?, ?, ?)');
|
||||
$stmt->execute([$statement, $rel_type, $rel_id]);
|
||||
}
|
||||
} elseif (isset($_POST['update_statement'])) {
|
||||
if (!empty($statement) && !empty($rel_type) && !empty($rel_id) && !empty($id)) {
|
||||
$stmt = $pdo->prepare('UPDATE mission_statements SET statement = ?, rel_type = ?, rel_id = ? WHERE id = ?');
|
||||
$stmt->execute([$statement, $rel_type, $rel_id, $id]);
|
||||
}
|
||||
header('Location: admin_mission_statements.php');
|
||||
exit;
|
||||
} elseif (isset($_POST['delete_statement'])) {
|
||||
if (!empty($id)) {
|
||||
$stmt = $pdo->prepare('DELETE FROM mission_statements WHERE id = ?');
|
||||
$stmt->execute([$id]);
|
||||
}
|
||||
header('Location: admin_mission_statements.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<h2>Assessment Planning: Mission Statements</h2>
|
||||
|
||||
<p><a href="admin.php"> ← Back to Admin Dashboard</a></p>
|
||||
|
||||
<?php if ($action === 'edit' && $id): ?>
|
||||
<?php
|
||||
$stmt = $pdo->prepare('SELECT * FROM mission_statements WHERE id = ?');
|
||||
$stmt->execute([$id]);
|
||||
$statement = $stmt->fetch();
|
||||
?>
|
||||
<h3>Edit Mission Statement</h3>
|
||||
<form action="admin_mission_statements.php?action=edit&id=<?php echo $id; ?>" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="statement" class="form-label">Mission Statement</label>
|
||||
<textarea class="form-control" id="statement" name="statement" rows="3" required><?php echo htmlspecialchars($statement['statement']); ?></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="rel_type" class="form-label">Link to:</label>
|
||||
<select class="form-select" name="rel_type" id="rel_type" required>
|
||||
<option value="institution" <?php echo ($statement['rel_type'] == 'institution') ? 'selected' : ''; ?>>Institution</option>
|
||||
<option value="program" <?php echo ($statement['rel_type'] == 'program') ? 'selected' : ''; ?>>Program</option>
|
||||
<option value="course" <?php echo ($statement['rel_type'] == 'course') ? 'selected' : ''; ?>>Course</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="rel_id" class="form-label">Specific Item</label>
|
||||
<select class="form-select" name="rel_id" id="rel_id" required>
|
||||
<!-- Options will be populated by JavaScript based on the selection above -->
|
||||
</select>
|
||||
</div>
|
||||
<input type="hidden" name="id" value="<?php echo $id; ?>">
|
||||
<button type="submit" name="update_statement" class="btn btn-primary">Update</button>
|
||||
<a href="admin_mission_statements.php" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<h3>Add New Mission Statement</h3>
|
||||
<form action="admin_mission_statements.php" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="statement" class="form-label">Mission Statement</label>
|
||||
<textarea class="form-control" id="statement" name="statement" rows="3" required></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="rel_type" class="form-label">Link to:</label>
|
||||
<select class="form-select" name="rel_type" id="rel_type_add" required>
|
||||
<option value="">Select Type</option>
|
||||
<option value="institution">Institution</option>
|
||||
<option value="program">Program</option>
|
||||
<option value="course">Course</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="rel_id" class="form-label">Specific Item</label>
|
||||
<select class="form-select" name="rel_id" id="rel_id_add" required>
|
||||
<!-- Options will be populated by JavaScript -->
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" name="add_statement" class="btn btn-primary">Add Mission Statement</button>
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
|
||||
<h3>Existing Mission Statements</h3>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Statement</th>
|
||||
<th>Linked To</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$stmt = $pdo->query('SELECT * FROM mission_statements ORDER BY id DESC');
|
||||
while ($row = $stmt->fetch()) {
|
||||
$rel_name = '';
|
||||
if ($row['rel_type'] == 'institution') {
|
||||
$rel_stmt = $pdo->prepare("SELECT name FROM institutions WHERE id = ?");
|
||||
$rel_stmt->execute([$row['rel_id']]);
|
||||
$rel_name = $rel_stmt->fetchColumn();
|
||||
} elseif ($row['rel_type'] == 'program') {
|
||||
$rel_stmt = $pdo->prepare("SELECT name FROM programs WHERE id = ?");
|
||||
$rel_stmt->execute([$row['rel_id']]);
|
||||
$rel_name = $rel_stmt->fetchColumn();
|
||||
} elseif ($row['rel_type'] == 'course') {
|
||||
$rel_stmt = $pdo->prepare("SELECT name FROM courses WHERE id = ?");
|
||||
$rel_stmt->execute([$row['rel_id']]);
|
||||
$rel_name = $rel_stmt->fetchColumn();
|
||||
}
|
||||
|
||||
echo "<tr>";
|
||||
echo "<td>" . htmlspecialchars($row['statement']) . "</td>";
|
||||
echo "<td>" . ucfirst($row['rel_type']) . ': ' . htmlspecialchars($rel_name) . "</td>";
|
||||
echo '<td>
|
||||
<a href="admin_mission_statements.php?action=edit&id=' . $row['id'] . '" class="btn btn-sm btn-outline-primary">Edit</a>
|
||||
<a href="admin_mission_statements.php?action=delete&id=' . $row['id'] . '" class="btn btn-sm btn-outline-danger">Delete</a>
|
||||
</td>';
|
||||
echo "</tr>";
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<script>
|
||||
const institutions = <?php echo json_encode($institutions); ?>;
|
||||
const programs = <?php echo json_encode($programs); ?>;
|
||||
const courses = <?php echo json_encode($courses); ?>;
|
||||
|
||||
function populateSelect(typeSelectId, itemSelectId) {
|
||||
const typeSelect = document.getElementById(typeSelectId);
|
||||
const itemSelect = document.getElementById(itemSelectId);
|
||||
|
||||
typeSelect.addEventListener('change', function() {
|
||||
itemSelect.innerHTML = '';
|
||||
const selectedType = this.value;
|
||||
let items = [];
|
||||
|
||||
if (selectedType === 'institution') {
|
||||
items = institutions;
|
||||
} else if (selectedType === 'program') {
|
||||
items = programs;
|
||||
} else if (selectedType === 'course') {
|
||||
items = courses;
|
||||
}
|
||||
|
||||
items.forEach(function(item) {
|
||||
const option = document.createElement('option');
|
||||
option.value = item.id;
|
||||
option.textContent = item.name;
|
||||
itemSelect.appendChild(option);
|
||||
});
|
||||
});
|
||||
|
||||
// Trigger change on page load for edit form
|
||||
if (typeSelect.value) {
|
||||
typeSelect.dispatchEvent(new Event('change'));
|
||||
}
|
||||
}
|
||||
|
||||
populateSelect('rel_type_add', 'rel_id_add');
|
||||
populateSelect('rel_type', 'rel_id');
|
||||
|
||||
</script>
|
||||
|
||||
<?php include 'templates/footer.php'; ?>
|
||||
143
admin_programs.php
Normal file
143
admin_programs.php
Normal file
@ -0,0 +1,143 @@
|
||||
<?php
|
||||
include 'templates/header.php';
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Admin-only page
|
||||
if (!isset($_SESSION['role_id']) || $_SESSION['role_id'] != 1) {
|
||||
header('Location: dashboard.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
$action = $_GET['action'] ?? 'list';
|
||||
$id = $_GET['id'] ?? null;
|
||||
|
||||
// Fetch schools for the dropdown
|
||||
$schools_stmt = $pdo->query('SELECT id, name FROM schools ORDER BY name');
|
||||
$schools = $schools_stmt->fetchAll();
|
||||
|
||||
// Handle form submissions
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$name = trim($_POST['name']);
|
||||
$school_id = $_POST['school_id'];
|
||||
|
||||
if (isset($_POST['add_program'])) {
|
||||
if (!empty($name) && !empty($school_id)) {
|
||||
$stmt = $pdo->prepare('INSERT INTO programs (name, school_id) VALUES (?, ?)');
|
||||
$stmt->execute([$name, $school_id]);
|
||||
}
|
||||
} elseif (isset($_POST['update_program'])) {
|
||||
if (!empty($name) && !empty($school_id) && !empty($id)) {
|
||||
$stmt = $pdo->prepare('UPDATE programs SET name = ?, school_id = ? WHERE id = ?');
|
||||
$stmt->execute([$name, $school_id, $id]);
|
||||
}
|
||||
header('Location: admin_programs.php');
|
||||
exit;
|
||||
} elseif (isset($_POST['delete_program'])) {
|
||||
if (!empty($id)) {
|
||||
$stmt = $pdo->prepare('DELETE FROM programs WHERE id = ?');
|
||||
$stmt->execute([$id]);
|
||||
}
|
||||
header('Location: admin_programs.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<h2>Assessment Planning: Programs</h2>
|
||||
|
||||
<p><a href="admin.php"> ← Back to Admin Dashboard</a></p>
|
||||
|
||||
<?php if ($action === 'edit' && $id): ?>
|
||||
<?php
|
||||
$stmt = $pdo->prepare('SELECT * FROM programs WHERE id = ?');
|
||||
$stmt->execute([$id]);
|
||||
$program = $stmt->fetch();
|
||||
?>
|
||||
<h3>Edit Program</h3>
|
||||
<form action="admin_programs.php?action=edit&id=<?php echo $id; ?>" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Program Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($program['name']); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="school_id" class="form-label">School</label>
|
||||
<select class="form-select" id="school_id" name="school_id" required>
|
||||
<?php foreach ($schools as $school): ?>
|
||||
<option value="<?php echo $school['id']; ?>" <?php echo ($school['id'] == $program['school_id']) ? 'selected' : ''; ?>><?php echo htmlspecialchars($school['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<input type="hidden" name="id" value="<?php echo $id; ?>">
|
||||
<button type="submit" name="update_program" class="btn btn-primary">Update</button>
|
||||
<a href="admin_programs.php" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
|
||||
<?php elseif ($action === 'delete' && $id): ?>
|
||||
<?php
|
||||
$stmt = $pdo->prepare('SELECT * FROM programs WHERE id = ?');
|
||||
$stmt->execute([$id]);
|
||||
$program = $stmt->fetch();
|
||||
?>
|
||||
<h3>Delete Program</h3>
|
||||
<p>Are you sure you want to delete the program "<?php echo htmlspecialchars($program['name']); ?>"?</p>
|
||||
<form action="admin_programs.php?action=delete&id=<?php echo $id; ?>" method="post">
|
||||
<input type="hidden" name="id" value="<?php echo $id; ?>">
|
||||
<button type="submit" name="delete_program" class="btn btn-danger">Delete</button>
|
||||
<a href="admin_programs.php" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<h3>Add New Program</h3>
|
||||
<form action="admin_programs.php" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Program Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="school_id" class="form-label">School</label>
|
||||
<select class="form-select" id="school_id" name="school_id" required>
|
||||
<option value="">Select a School</option>
|
||||
<?php foreach ($schools as $school): ?>
|
||||
<option value="<?php echo $school['id']; ?>"><?php echo htmlspecialchars($school['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" name="add_program" class="btn btn-primary">Add Program</button>
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
|
||||
<h3>Existing Programs</h3>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>School</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$stmt = $pdo->query('SELECT p.id, p.name, s.name AS school_name FROM programs p JOIN schools s ON p.school_id = s.id ORDER BY p.id');
|
||||
while ($row = $stmt->fetch()) {
|
||||
echo "<tr>";
|
||||
echo "<td>" . htmlspecialchars($row['id']) . "</td>";
|
||||
echo "<td>" . htmlspecialchars($row['name']) . "</td>";
|
||||
echo "<td>" . htmlspecialchars($row['school_name']) . "</td>";
|
||||
echo '<td>
|
||||
<a href="admin_programs.php?action=edit&id=' . $row['id'] . '" class="btn btn-sm btn-outline-primary">Edit</a>
|
||||
<a href="admin_programs.php?action=delete&id=' . $row['id'] . '" class="btn btn-sm btn-outline-danger">Delete</a>
|
||||
</td>';
|
||||
echo "</tr>";
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php include 'templates/footer.php'; ?>
|
||||
143
admin_schools.php
Normal file
143
admin_schools.php
Normal file
@ -0,0 +1,143 @@
|
||||
<?php
|
||||
include 'templates/header.php';
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Admin-only page
|
||||
if (!isset($_SESSION['role_id']) || $_SESSION['role_id'] != 1) {
|
||||
header('Location: dashboard.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
$action = $_GET['action'] ?? 'list';
|
||||
$id = $_GET['id'] ?? null;
|
||||
|
||||
// Fetch institutions for the dropdown
|
||||
$institutions_stmt = $pdo->query('SELECT id, name FROM institutions ORDER BY name');
|
||||
$institutions = $institutions_stmt->fetchAll();
|
||||
|
||||
// Handle form submissions
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$name = trim($_POST['name']);
|
||||
$institution_id = $_POST['institution_id'];
|
||||
|
||||
if (isset($_POST['add_school'])) {
|
||||
if (!empty($name) && !empty($institution_id)) {
|
||||
$stmt = $pdo->prepare('INSERT INTO schools (name, institution_id) VALUES (?, ?)');
|
||||
$stmt->execute([$name, $institution_id]);
|
||||
}
|
||||
} elseif (isset($_POST['update_school'])) {
|
||||
if (!empty($name) && !empty($institution_id) && !empty($id)) {
|
||||
$stmt = $pdo->prepare('UPDATE schools SET name = ?, institution_id = ? WHERE id = ?');
|
||||
$stmt->execute([$name, $institution_id, $id]);
|
||||
}
|
||||
header('Location: admin_schools.php');
|
||||
exit;
|
||||
} elseif (isset($_POST['delete_school'])) {
|
||||
if (!empty($id)) {
|
||||
$stmt = $pdo->prepare('DELETE FROM schools WHERE id = ?');
|
||||
$stmt->execute([$id]);
|
||||
}
|
||||
header('Location: admin_schools.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<h2>Assessment Planning: Schools</h2>
|
||||
|
||||
<p><a href="admin.php"> ← Back to Admin Dashboard</a></p>
|
||||
|
||||
<?php if ($action === 'edit' && $id): ?>
|
||||
<?php
|
||||
$stmt = $pdo->prepare('SELECT * FROM schools WHERE id = ?');
|
||||
$stmt->execute([$id]);
|
||||
$school = $stmt->fetch();
|
||||
?>
|
||||
<h3>Edit School</h3>
|
||||
<form action="admin_schools.php?action=edit&id=<?php echo $id; ?>" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">School Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($school['name']); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="institution_id" class="form-label">Institution</label>
|
||||
<select class="form-select" id="institution_id" name="institution_id" required>
|
||||
<?php foreach ($institutions as $institution): ?>
|
||||
<option value="<?php echo $institution['id']; ?>" <?php echo ($institution['id'] == $school['institution_id']) ? 'selected' : ''; ?>><?php echo htmlspecialchars($institution['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<input type="hidden" name="id" value="<?php echo $id; ?>">
|
||||
<button type="submit" name="update_school" class="btn btn-primary">Update</button>
|
||||
<a href="admin_schools.php" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
|
||||
<?php elseif ($action === 'delete' && $id): ?>
|
||||
<?php
|
||||
$stmt = $pdo->prepare('SELECT * FROM schools WHERE id = ?');
|
||||
$stmt->execute([$id]);
|
||||
$school = $stmt->fetch();
|
||||
?>
|
||||
<h3>Delete School</h3>
|
||||
<p>Are you sure you want to delete the school "<?php echo htmlspecialchars($school['name']); ?>"?</p>
|
||||
<form action="admin_schools.php?action=delete&id=<?php echo $id; ?>" method="post">
|
||||
<input type="hidden" name="id" value="<?php echo $id; ?>">
|
||||
<button type="submit" name="delete_school" class="btn btn-danger">Delete</button>
|
||||
<a href="admin_schools.php" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<h3>Add New School</h3>
|
||||
<form action="admin_schools.php" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">School Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="institution_id" class="form-label">Institution</label>
|
||||
<select class="form-select" id="institution_id" name="institution_id" required>
|
||||
<option value="">Select an Institution</option>
|
||||
<?php foreach ($institutions as $institution): ?>
|
||||
<option value="<?php echo $institution['id']; ?>"><?php echo htmlspecialchars($institution['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" name="add_school" class="btn btn-primary">Add School</button>
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
|
||||
<h3>Existing Schools</h3>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Institution</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$stmt = $pdo->query('SELECT s.id, s.name, i.name AS institution_name FROM schools s JOIN institutions i ON s.institution_id = i.id ORDER BY s.id');
|
||||
while ($row = $stmt->fetch()) {
|
||||
echo "<tr>";
|
||||
echo "<td>" . htmlspecialchars($row['id']) . "</td>";
|
||||
echo "<td>" . htmlspecialchars($row['name']) . "</td>";
|
||||
echo "<td>" . htmlspecialchars($row['institution_name']) . "</td>";
|
||||
echo '<td>
|
||||
<a href="admin_schools.php?action=edit&id=' . $row['id'] . '" class="btn btn-sm btn-outline-primary">Edit</a>
|
||||
<a href="admin_schools.php?action=delete&id=' . $row['id'] . '" class="btn btn-sm btn-outline-danger">Delete</a>
|
||||
</td>';
|
||||
echo "</tr>";
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php include 'templates/footer.php'; ?>
|
||||
74
contact.php
Normal file
74
contact.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/mail/MailService.php';
|
||||
|
||||
$success_message = '';
|
||||
$error_message = '';
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$name = strip_tags(trim($_POST["name"]));
|
||||
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
|
||||
$message = strip_tags(trim($_POST["message"]));
|
||||
|
||||
if (empty($name) || empty($message) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$error_message = "Please fill out all fields and provide a valid email address.";
|
||||
} else {
|
||||
$to = getenv('MAIL_TO') ?: null;
|
||||
$subject = "New contact from " . $name;
|
||||
|
||||
$email_body = "You have received a new message from your website contact form.\n\n";
|
||||
$email_body .= "Here are the details:\n";
|
||||
$email_body .= "Name: $name\n";
|
||||
$email_body .= "Email: $email\n";
|
||||
$email_body .= "Message:\n$message\n";
|
||||
|
||||
$res = MailService::sendContactMessage($name, $email, $message, $to, $subject);
|
||||
|
||||
if (!empty($res['success'])) {
|
||||
$success_message = "Thank you for your message. It has been sent.";
|
||||
} else {
|
||||
$error_message = "Sorry, there was an error sending your message. 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>Contact Us</title>
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container mt-5">
|
||||
<h1>Contact Us</h1>
|
||||
<p>Fill out the form below to get in touch with us.</p>
|
||||
|
||||
<?php if(!empty($success_message)): ?>
|
||||
<div class="alert alert-success"><?php echo $success_message; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if(!empty($error_message)): ?>
|
||||
<div class="alert alert-danger"><?php echo $error_message; ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form action="contact.php" method="post">
|
||||
<div class="form-group">
|
||||
<label for="name">Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email">Email</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="message">Message</label>
|
||||
<textarea class="form-control" id="message" name="message" rows="5" required></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Send Message</button>
|
||||
</form>
|
||||
<p class="mt-3">
|
||||
<a href="/">Back to Home</a>
|
||||
</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
30
dashboard.php
Normal file
30
dashboard.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// If user is not logged in, redirect to login page
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
include 'templates/header.php';
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>Dashboard</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h3>Welcome, <?php echo htmlspecialchars($_SESSION['user_name']); ?>!</h3>
|
||||
<p>You are logged in as a(n) <strong><?php echo htmlspecialchars($_SESSION['user_role']); ?></strong>.</p>
|
||||
<p>This is your dashboard. More features will be added soon.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'templates/footer.php'; ?>
|
||||
16
db/migrations/001_create_initial_tables.sql
Normal file
16
db/migrations/001_create_initial_tables.sql
Normal file
@ -0,0 +1,16 @@
|
||||
CREATE TABLE IF NOT EXISTS `roles` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(50) NOT NULL UNIQUE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
INSERT INTO `roles` (name) VALUES ('Admin'), ('Faculty'), ('Program Coordinator'), ('Internal Reviewer'), ('External Evaluator');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `users` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`username` VARCHAR(50) NOT NULL UNIQUE,
|
||||
`password` VARCHAR(255) NOT NULL,
|
||||
`email` VARCHAR(100) NOT NULL UNIQUE,
|
||||
`role_id` INT,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
5
db/migrations/002_create_institutions_table.sql
Normal file
5
db/migrations/002_create_institutions_table.sql
Normal file
@ -0,0 +1,5 @@
|
||||
CREATE TABLE IF NOT EXISTS `institutions` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
7
db/migrations/003_create_schools_table.sql
Normal file
7
db/migrations/003_create_schools_table.sql
Normal file
@ -0,0 +1,7 @@
|
||||
CREATE TABLE IF NOT EXISTS `schools` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`institution_id` INT NOT NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`institution_id`) REFERENCES `institutions`(`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
7
db/migrations/004_create_programs_table.sql
Normal file
7
db/migrations/004_create_programs_table.sql
Normal file
@ -0,0 +1,7 @@
|
||||
CREATE TABLE IF NOT EXISTS `programs` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`school_id` INT NOT NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`school_id`) REFERENCES `schools`(`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
7
db/migrations/005_create_courses_table.sql
Normal file
7
db/migrations/005_create_courses_table.sql
Normal file
@ -0,0 +1,7 @@
|
||||
CREATE TABLE IF NOT EXISTS `courses` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`program_id` INT NOT NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`program_id`) REFERENCES `programs`(`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
34
db/migrations/006_create_assessment_documents_tables.sql
Normal file
34
db/migrations/006_create_assessment_documents_tables.sql
Normal file
@ -0,0 +1,34 @@
|
||||
CREATE TABLE IF NOT EXISTS `mission_statements` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`rel_id` INT NOT NULL,
|
||||
`rel_type` VARCHAR(50) NOT NULL, -- 'institution', 'program', 'course'
|
||||
`statement` TEXT NOT NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
INDEX `rel_index` (`rel_id`, `rel_type`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `learning_outcomes` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`rel_id` INT NOT NULL,
|
||||
`rel_type` VARCHAR(50) NOT NULL, -- 'institution', 'program', 'course'
|
||||
`description` TEXT NOT NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
INDEX `rel_index` (`rel_id`, `rel_type`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `success_criteria` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`learning_outcome_id` INT NOT NULL,
|
||||
`description` TEXT NOT NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`learning_outcome_id`) REFERENCES `learning_outcomes`(`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `assessment_measures` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`learning_outcome_id` INT NOT NULL,
|
||||
`measure_type` VARCHAR(50) NOT NULL, -- 'direct', 'indirect'
|
||||
`description` TEXT NOT NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`learning_outcome_id`) REFERENCES `learning_outcomes`(`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
27
db/migrations/007_create_users_and_roles_tables.sql
Normal file
27
db/migrations/007_create_users_and_roles_tables.sql
Normal file
@ -0,0 +1,27 @@
|
||||
-- Create roles table
|
||||
CREATE TABLE IF NOT EXISTS `roles` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(50) NOT NULL UNIQUE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- Seed the roles table with the confirmed roles
|
||||
INSERT INTO `roles` (`name`) VALUES
|
||||
('Admin'),
|
||||
('Faculty'),
|
||||
('Program Coordinator'),
|
||||
('Internal Reviewer'),
|
||||
('External Evaluator')
|
||||
ON DUPLICATE KEY UPDATE name=name; -- Avoid errors on re-running
|
||||
|
||||
-- Create users table
|
||||
CREATE TABLE IF NOT EXISTS `users` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`email` VARCHAR(255) NOT NULL UNIQUE,
|
||||
`password` VARCHAR(255) NOT NULL,
|
||||
`first_name` VARCHAR(100),
|
||||
`last_name` VARCHAR(100),
|
||||
`role_id` INT,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`) ON DELETE SET NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
158
index.php
158
index.php
@ -1,150 +1,12 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
<?php include 'templates/header.php'; ?>
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
?>
|
||||
<!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>
|
||||
</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>
|
||||
<div class="text-center">
|
||||
<h1>Welcome to the Assessment Management System</h1>
|
||||
<p class="lead">Your solution for streamlined planning, assessment, and reporting.</p>
|
||||
<hr class="my-4">
|
||||
<p>To get started, you can register for a new account or log in if you already have one.</p>
|
||||
<a class="btn btn-primary btn-lg" href="register.php" role="button">Register</a>
|
||||
<a class="btn btn-secondary btn-lg" href="login.php" role="button">Login</a>
|
||||
</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>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?php include 'templates/footer.php'; ?>
|
||||
89
login.php
Normal file
89
login.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
// If user is already logged in, redirect to dashboard
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
header("Location: dashboard.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
$errors = [];
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$email = trim($_POST['email']);
|
||||
$password = $_POST['password'];
|
||||
|
||||
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$errors[] = "A valid email is required.";
|
||||
}
|
||||
if (empty($password)) {
|
||||
$errors[] = "Password is required.";
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("SELECT users.*, roles.name as role_name FROM users JOIN roles ON users.role_id = roles.id WHERE email = ?");
|
||||
$stmt->execute([$email]);
|
||||
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($user && password_verify($password, $user['password'])) {
|
||||
// Password is correct, start session
|
||||
session_regenerate_id();
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
$_SESSION['user_email'] = $user['email'];
|
||||
$_SESSION['user_role'] = $user['role_name'];
|
||||
$_SESSION['user_name'] = $user['first_name'] . ' ' . $user['last_name'];
|
||||
|
||||
// Redirect to dashboard
|
||||
header("Location: dashboard.php");
|
||||
exit;
|
||||
} else {
|
||||
$errors[] = "Invalid email or password.";
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$errors[] = "Database error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
include 'templates/header.php';
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>Login</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p><?php echo $error; ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form action="login.php" method="post">
|
||||
<div class="form-group mb-3">
|
||||
<label for="email">Email address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="card-footer text-center">
|
||||
<p>Don't have an account? <a href="register.php">Register here</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'templates/footer.php'; ?>
|
||||
23
logout.php
Normal file
23
logout.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// Unset all of the session variables
|
||||
$_SESSION = array();
|
||||
|
||||
// If it's desired to kill the session, also delete the session cookie.
|
||||
// Note: This will destroy the session, and not just the session data!
|
||||
if (ini_get("session.use_cookies")) {
|
||||
$params = session_get_cookie_params();
|
||||
setcookie(session_name(), '', time() - 42000,
|
||||
$params["path"], $params["domain"],
|
||||
$params["secure"], $params["httponly"]
|
||||
);
|
||||
}
|
||||
|
||||
// Finally, destroy the session.
|
||||
session_destroy();
|
||||
|
||||
// Redirect to login page
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
?>
|
||||
46
migrate.php
Normal file
46
migrate.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
require_once 'db/config.php';
|
||||
|
||||
echo "Starting database setup...\n";
|
||||
|
||||
try {
|
||||
// Connect without specifying a database to create it if it doesn't exist
|
||||
$pdo_setup = new PDO('mysql:host='.DB_HOST.';charset=utf8mb4', DB_USER, DB_PASS, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
]);
|
||||
$pdo_setup->exec('CREATE DATABASE IF NOT EXISTS `'.DB_NAME.'`');
|
||||
echo "Database `".DB_NAME."` ensured to exist.\n";
|
||||
|
||||
// Now connect to the database
|
||||
$pdo = db();
|
||||
|
||||
// 1. Ensure migrations table exists
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS `migrations` ( `id` INT AUTO_INCREMENT PRIMARY KEY, `migration` VARCHAR(255) NOT NULL, `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
|
||||
|
||||
// 2. Get all executed migrations
|
||||
$executedMigrations = $pdo->query("SELECT migration FROM migrations")->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
// 3. Get all migration files
|
||||
$migrationsDir = __DIR__ . '/db/migrations';
|
||||
$migrationFiles = glob($migrationsDir . '/*.sql');
|
||||
sort($migrationFiles);
|
||||
|
||||
// 4. Run pending migrations
|
||||
foreach ($migrationFiles as $file) {
|
||||
$migrationName = basename($file);
|
||||
if (!in_array($migrationName, $executedMigrations)) {
|
||||
echo "Running migration: " . $migrationName . "\n";
|
||||
$sql = file_get_contents($file);
|
||||
$pdo->exec($sql);
|
||||
|
||||
// 5. Log the migration
|
||||
$stmt = $pdo->prepare("INSERT INTO migrations (migration) VALUES (?)");
|
||||
$stmt->execute([$migrationName]);
|
||||
}
|
||||
}
|
||||
|
||||
echo "Migrations completed successfully.\n";
|
||||
|
||||
} catch (PDOException $e) {
|
||||
die("Database setup or migration failed: " . $e->getMessage() . "\n");
|
||||
}
|
||||
129
register.php
Normal file
129
register.php
Normal file
@ -0,0 +1,129 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
$roles = [];
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->query("SELECT id, name FROM roles ORDER BY name");
|
||||
$roles = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
// If roles table doesn't exist yet, we can proceed without it
|
||||
// The migration will create it.
|
||||
}
|
||||
|
||||
$errors = [];
|
||||
$success = '';
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$email = trim($_POST['email']);
|
||||
$password = $_POST['password'];
|
||||
$first_name = trim($_POST['first_name']);
|
||||
$last_name = trim($_POST['last_name']);
|
||||
$role_id = $_POST['role_id'];
|
||||
|
||||
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$errors[] = "A valid email is required.";
|
||||
}
|
||||
if (empty($password) || strlen($password) < 8) {
|
||||
$errors[] = "Password must be at least 8 characters long.";
|
||||
}
|
||||
if (empty($first_name)) {
|
||||
$errors[] = "First name is required.";
|
||||
}
|
||||
if (empty($last_name)) {
|
||||
$errors[] = "Last name is required.";
|
||||
}
|
||||
if (empty($role_id)) {
|
||||
$errors[] = "Please select a role.";
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
try {
|
||||
$pdo = db();
|
||||
|
||||
// Check if user already exists
|
||||
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
|
||||
$stmt->execute([$email]);
|
||||
if ($stmt->fetch()) {
|
||||
$errors[] = "An account with this email already exists.";
|
||||
} else {
|
||||
// Insert new user
|
||||
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||
$stmt = $pdo->prepare("INSERT INTO users (email, password, first_name, last_name, role_id) VALUES (?, ?, ?, ?, ?)");
|
||||
if ($stmt->execute([$email, $hashed_password, $first_name, $last_name, $role_id])) {
|
||||
$success = "Registration successful! You can now <a href='login.php'>log in</a>.";
|
||||
} else {
|
||||
$errors[] = "Something went wrong. Please try again later.";
|
||||
}
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$errors[] = "Database error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
include 'templates/header.php';
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>Register</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p><?php echo $error; ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($success): ?>
|
||||
<div class="alert alert-success">
|
||||
<p><?php echo $success; ?></p>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<form action="register.php" method="post">
|
||||
<div class="form-group mb-3">
|
||||
<label for="first_name">First Name</label>
|
||||
<input type="text" class="form-control" id="first_name" name="first_name" required>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label for="last_name">Last Name</label>
|
||||
<input type="text" class="form-control" id="last_name" name="last_name" required>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label for="email">Email address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" minlength="8" required>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label for="role_id">Role</label>
|
||||
<select class="form-control" id="role_id" name="role_id" required>
|
||||
<option value="">-- Select a Role --</option>
|
||||
<?php foreach ($roles as $role): ?>
|
||||
<option value="<?php echo htmlspecialchars($role['id']); ?>">
|
||||
<?php echo htmlspecialchars($role['name']); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Register</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="card-footer text-center">
|
||||
<p>Already have an account? <a href="login.php">Login here</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'templates/footer.php'; ?>
|
||||
4
templates/footer.php
Normal file
4
templates/footer.php
Normal file
@ -0,0 +1,4 @@
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
40
templates/header.php
Normal file
40
templates/header.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
session_start();
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Assessment Management System</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="index.php">AMS</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">
|
||||
<?php if (isset($_SESSION['user_id'])): ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="dashboard.php">Dashboard</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="logout.php">Logout</a>
|
||||
</li>
|
||||
<?php else: ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="login.php">Login</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="register.php">Register</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="container mt-4">
|
||||
Loading…
x
Reference in New Issue
Block a user