-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgrade_submission.php
More file actions
42 lines (36 loc) · 1.33 KB
/
Copy pathgrade_submission.php
File metadata and controls
42 lines (36 loc) · 1.33 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
<?php
session_start();
require_once 'db.php';
// Check if user is logged in and is a professor
if (!isset($_SESSION['user']) || $_SESSION['user']['role'] !== 'professor') {
http_response_code(403);
echo json_encode(['status' => 'error', 'message' => 'Unauthorized']);
exit();
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$submission_id = $_POST['submission_id'] ?? '';
$grade = $_POST['grade'] ?? '';
$feedback = $_POST['feedback'] ?? '';
if (empty($submission_id) || empty($grade)) {
echo json_encode(['status' => 'error', 'message' => 'Missing required fields']);
exit();
}
// Validate grade
$grade = intval($grade);
if ($grade < 0 || $grade > 100) {
echo json_encode(['status' => 'error', 'message' => 'Grade must be between 0 and 100']);
exit();
}
// Update submission
$stmt = $conn->prepare("UPDATE submissions SET grade = ?, status = 'graded' WHERE id = ?");
$stmt->bind_param("ii", $grade, $submission_id);
if ($stmt->execute()) {
echo json_encode(['status' => 'success', 'message' => 'Grade submitted successfully']);
} else {
echo json_encode(['status' => 'error', 'message' => 'Failed to update grade']);
}
} else {
http_response_code(405);
echo json_encode(['status' => 'error', 'message' => 'Method not allowed']);
}
?>