-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathresume_course.php
More file actions
73 lines (62 loc) · 1.81 KB
/
Copy pathresume_course.php
File metadata and controls
73 lines (62 loc) · 1.81 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Stimma - Lär dig i små steg
* Copyright (C) 2025 Christian Alfredsson
*
* This program is free software; licensed under GPL v2.
* See LICENSE and LICENSE-AND-TRADEMARK.md for details.
*
* The name "Stimma" is a trademark and subject to restrictions.
*
* POST-endpoint: återuppta en avbruten kurs.
* Återställer course_enrollments.status från 'abandoned' till 'active'.
*/
require_once 'include/config.php';
require_once 'include/database.php';
require_once 'include/functions.php';
require_once 'include/auth.php';
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
redirect('index.php');
exit;
}
if (!isLoggedIn()) {
redirect('index.php');
exit;
}
if (!isset($_POST['csrf_token']) || !validateCsrfToken($_POST['csrf_token'])) {
redirect('index.php');
exit;
}
$userId = $_SESSION['user_id'];
$courseId = isset($_POST['course_id']) ? (int)$_POST['course_id'] : 0;
if ($courseId <= 0) {
redirect('index.php');
exit;
}
$course = queryOne("SELECT * FROM " . DB_DATABASE . ".courses WHERE id = ?", [$courseId]);
if (!$course) {
redirect('index.php');
exit;
}
$enrollment = queryOne(
"SELECT * FROM " . DB_DATABASE . ".course_enrollments
WHERE user_id = ? AND course_id = ? AND status = 'abandoned'",
[$userId, $courseId]
);
if ($enrollment) {
execute(
"UPDATE " . DB_DATABASE . ".course_enrollments
SET status = 'active',
abandoned_at = NULL,
abandon_reason = NULL,
opt_out_reminders = 0
WHERE user_id = ? AND course_id = ?",
[$userId, $courseId]
);
logActivity($_SESSION['user_email'], 'Återupptog kurs', [
'action' => 'course_resumed',
'course_id' => $courseId,
'course_title' => $course['title']
]);
}
redirect('index.php#mina-kurser');