-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_assignments.php
More file actions
54 lines (50 loc) · 1.76 KB
/
Copy pathadmin_assignments.php
File metadata and controls
54 lines (50 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
session_start();
require "config.php";
if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin') die("Access denied");
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = trim($_POST['title']);
$description = trim($_POST['description']);
$department_id = $_POST['department_id'] ?: null;
$due_date = $_POST['due_date'] ?: null;
$posted_by = $_SESSION['id'];
$stmt = $pdo->prepare("
INSERT INTO assignments (title, description, posted_by, department_id, due_date, created_at)
VALUES (:title, :description, :posted_by, :dept, :due, NOW())
");
$stmt->execute([
'title'=>$title,
'description'=>$description,
'posted_by'=>$posted_by,
'dept'=>$department_id,
'due'=>$due_date
]);
$msg = "Assignment posted.";
}
// fetch departments for select
$depts = $pdo->query("SELECT id, name FROM departments")->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html>
<head><title>Post Assignment</title></head>
<body>
<h2>Post Assignment</h2>
<?php if (!empty($msg)) echo "<p style='color:green;'>$msg</p>"; ?>
<form method="post">
<label>Title</label><br>
<input name="title" required><br>
<label>Description</label><br>
<textarea name="description" rows="6"></textarea><br>
<label>Department (leave blank for all)</label><br>
<select name="department_id">
<option value="">All Departments</option>
<?php foreach($depts as $d): ?>
<option value="<?= $d['id'] ?>"><?= htmlspecialchars($d['name']) ?></option>
<?php endforeach; ?>
</select><br>
<label>Due date</label><br>
<input type="date" name="due_date"><br><br>
<button type="submit">Post</button>
</form>
</body>
</html>