203 lines
8.2 KiB
PHP
203 lines
8.2 KiB
PHP
<?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'; ?>
|