1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
4
|
|
|
|
5
|
|
|
use Chamilo\CoreBundle\Entity\SequenceResource; |
6
|
|
|
|
7
|
|
|
// Delete the globals['_cid'], we don't need it here. |
8
|
|
|
$cidReset = true; |
9
|
|
|
|
10
|
|
|
require_once __DIR__.'/../inc/global.inc.php'; |
11
|
|
|
|
12
|
|
|
// Section for the tabs. |
13
|
|
|
$this_section = SECTION_CATALOG; |
14
|
|
|
|
15
|
|
|
if ('true' !== api_get_setting('course_catalog_published')) { |
16
|
|
|
// Access rights: anonymous users can't do anything useful here. |
17
|
|
|
api_block_anonymous_users(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
$userCanViewPage = CoursesAndSessionsCatalog::userCanView(); |
21
|
|
|
|
22
|
|
|
$defaultAction = CoursesAndSessionsCatalog::is(CATALOG_SESSIONS) ? 'display_sessions' : 'display_courses'; |
23
|
|
|
$action = isset($_REQUEST['action']) ? Security::remove_XSS($_REQUEST['action']) : $defaultAction; |
24
|
|
|
$categoryCode = isset($_REQUEST['category_code']) ? Security::remove_XSS($_REQUEST['category_code']) : ''; |
25
|
|
|
$searchTerm = isset($_REQUEST['search_term']) ? Security::remove_XSS($_REQUEST['search_term']) : ''; |
26
|
|
|
|
27
|
|
|
$nameTools = CourseCategory::getCourseCatalogNameTools($action); |
28
|
|
|
if (empty($nameTools)) { |
29
|
|
|
$nameTools = get_lang('CourseManagement'); |
30
|
|
|
} else { |
31
|
|
|
if (!in_array( |
32
|
|
|
$action, |
33
|
|
|
['display_random_courses', 'display_courses', 'subscribe'] |
34
|
|
|
)) { |
35
|
|
|
$interbreadcrumb[] = [ |
36
|
|
|
'url' => api_get_path(WEB_CODE_PATH).'auth/courses.php', |
37
|
|
|
'name' => get_lang('CourseManagement'), |
38
|
|
|
]; |
39
|
|
|
} |
40
|
|
|
$interbreadcrumb[] = ['url' => '#', 'name' => $nameTools]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
switch ($action) { |
44
|
|
|
case 'unsubscribe': |
45
|
|
|
// We are unsubscribing from a course (=Unsubscribe from course). |
46
|
|
|
$ctok = Security::get_existing_token(); |
47
|
|
|
|
48
|
|
|
if (!empty($_GET['sec_token']) && $ctok == $_GET['sec_token']) { |
49
|
|
|
$auth = new Auth(); |
50
|
|
|
$result = $auth->remove_user_from_course($_GET['unsubscribe']); |
51
|
|
|
if ($result) { |
52
|
|
|
Display::addFlash( |
53
|
|
|
Display::return_message(get_lang('YouAreNowUnsubscribed'), 'success') |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$currentUrl = api_get_path(WEB_CODE_PATH).'auth/courses.php?category_code='.$categoryCode.'&search_term='.$searchTerm; |
59
|
|
|
|
60
|
|
|
header('Location: '.$currentUrl); |
61
|
|
|
exit; |
62
|
|
|
case 'subscribe_course': |
63
|
|
|
$courseCodeToSubscribe = isset($_GET['course_code']) ? Security::remove_XSS($_GET['course_code']) : ''; |
64
|
|
|
if (api_is_anonymous()) { |
65
|
|
|
header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php?c='.$courseCodeToSubscribe); |
66
|
|
|
exit; |
67
|
|
|
} |
68
|
|
|
if (Security::check_token('get')) { |
69
|
|
|
$courseInfo = api_get_course_info($courseCodeToSubscribe); |
70
|
|
|
CourseManager::autoSubscribeToCourse($courseCodeToSubscribe); |
71
|
|
|
$redirectionTarget = CoursesAndSessionsCatalog::generateRedirectUrlAfterSubscription( |
72
|
|
|
$courseInfo['course_public_url'] |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
header("Location: $redirectionTarget"); |
76
|
|
|
exit; |
77
|
|
|
} |
78
|
|
|
break; |
79
|
|
|
case 'subscribe_course_validation': |
80
|
|
|
$toolTitle = get_lang('Subscribe'); |
81
|
|
|
$courseCodeToSubscribe = isset($_GET['course_code']) ? Security::remove_XSS($_GET['course_code']) : ''; |
82
|
|
|
$courseInfo = api_get_course_info($courseCodeToSubscribe); |
83
|
|
|
if (empty($courseInfo)) { |
84
|
|
|
header('Location: '.api_get_self()); |
85
|
|
|
exit; |
86
|
|
|
} |
87
|
|
|
$message = get_lang('CourseRequiresPassword').' '; |
88
|
|
|
$message .= $courseInfo['title'].' ('.$courseInfo['visual_code'].') '; |
89
|
|
|
|
90
|
|
|
$action = api_get_self().'?action=subscribe_course_validation&sec_token='. |
91
|
|
|
Security::getTokenFromSession().'&course_code='.$courseInfo['code']; |
92
|
|
|
$form = new FormValidator( |
93
|
|
|
'subscribe_user_with_password', |
94
|
|
|
'post', |
95
|
|
|
$action |
96
|
|
|
); |
97
|
|
|
$form->addHeader($message); |
98
|
|
|
$form->addElement('hidden', 'sec_token', Security::getTokenFromSession()); |
99
|
|
|
$form->addElement('hidden', 'subscribe_user_with_password', $courseInfo['code']); |
100
|
|
|
$form->addElement('text', 'course_registration_code'); |
101
|
|
|
$form->addButtonSave(get_lang('SubmitRegistrationCode')); |
102
|
|
|
$content = $form->returnForm(); |
103
|
|
|
|
104
|
|
|
if ($form->validate()) { |
105
|
|
|
if (sha1($_POST['course_registration_code']) === $courseInfo['registration_code']) { |
106
|
|
|
CourseManager::autoSubscribeToCourse($_POST['subscribe_user_with_password']); |
107
|
|
|
|
108
|
|
|
$redirectionTarget = CoursesAndSessionsCatalog::generateRedirectUrlAfterSubscription( |
109
|
|
|
$courseInfo['course_public_url'] |
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
header("Location: $redirectionTarget"); |
113
|
|
|
} else { |
114
|
|
|
Display::addFlash(Display::return_message(get_lang('CourseRegistrationCodeIncorrect'), 'warning')); |
115
|
|
|
header('Location: '.$action); |
116
|
|
|
} |
117
|
|
|
exit; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
$template = new Template($toolTitle, true, true, false, false, false); |
121
|
|
|
$template->assign('content', $content); |
122
|
|
|
$template->display_one_col_template(); |
123
|
|
|
break; |
124
|
|
|
case 'subscribe': |
125
|
|
|
if (!$userCanViewPage) { |
126
|
|
|
api_not_allowed(true); |
127
|
|
|
} |
128
|
|
|
header('Location: '.api_get_self()); |
129
|
|
|
exit; |
130
|
|
|
case 'display_random_courses': |
131
|
|
|
case 'display_courses': |
132
|
|
|
case 'search_course': |
133
|
|
|
if (!$userCanViewPage) { |
134
|
|
|
api_not_allowed(true); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
CoursesAndSessionsCatalog::displayCoursesList($action, $searchTerm, $categoryCode); |
138
|
|
|
exit; |
139
|
|
|
case 'display_sessions': |
140
|
|
|
if (!$userCanViewPage) { |
141
|
|
|
api_not_allowed(true); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
CoursesAndSessionsCatalog::sessionList(); |
145
|
|
|
exit; |
146
|
|
|
case 'subscribe_to_session': |
147
|
|
|
if (!$userCanViewPage) { |
148
|
|
|
api_not_allowed(true); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
$userId = api_get_user_id(); |
152
|
|
|
$confirmed = isset($_GET['confirm']); |
153
|
|
|
$sessionId = (int) $_GET['session_id']; |
154
|
|
|
|
155
|
|
|
if (empty($userId)) { |
156
|
|
|
api_not_allowed(); |
157
|
|
|
exit; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
if (!$confirmed) { |
161
|
|
|
$template = new Template(null, false, false, false, false, false); |
162
|
|
|
$template->assign('session_id', $sessionId); |
163
|
|
|
$layout = $template->get_template('auth/confirm_session_subscription.tpl'); |
164
|
|
|
echo $template->fetch($layout); |
165
|
|
|
exit; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
$registrationAllowed = api_get_setting('catalog_allow_session_auto_subscription'); |
169
|
|
|
if ('true' === $registrationAllowed) { |
170
|
|
|
$entityManager = Database::getManager(); |
171
|
|
|
$repository = $entityManager->getRepository('ChamiloCoreBundle:SequenceResource'); |
172
|
|
|
$sequences = $repository->getRequirements( |
173
|
|
|
$sessionId, |
174
|
|
|
SequenceResource::SESSION_TYPE |
175
|
|
|
); |
176
|
|
|
|
177
|
|
|
if (count($sequences) > 0) { |
178
|
|
|
$requirementsData = $repository->checkRequirementsForUser( |
179
|
|
|
$sequences, |
180
|
|
|
SequenceResource::SESSION_TYPE, |
181
|
|
|
$userId, |
182
|
|
|
$sessionId |
183
|
|
|
); |
184
|
|
|
|
185
|
|
|
$continueWithSubscription = $repository->checkSequenceAreCompleted($requirementsData); |
186
|
|
|
|
187
|
|
|
if (!$continueWithSubscription) { |
188
|
|
|
header('Location: '.api_get_path(WEB_CODE_PATH).'auth/courses.php'); |
189
|
|
|
exit; |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
SessionManager::subscribeUsersToSession( |
194
|
|
|
$sessionId, |
195
|
|
|
[$userId], |
196
|
|
|
SESSION_VISIBLE_READ_ONLY, |
197
|
|
|
false |
198
|
|
|
); |
199
|
|
|
|
200
|
|
|
$coursesList = SessionManager::get_course_list_by_session_id($sessionId); |
201
|
|
|
$count = count($coursesList); |
202
|
|
|
$url = ''; |
203
|
|
|
|
204
|
|
|
if ($count <= 0) { |
205
|
|
|
// no course in session -> return to catalog |
206
|
|
|
$url = api_get_path(WEB_CODE_PATH).'auth/courses.php'; |
207
|
|
|
} elseif (1 == $count) { |
208
|
|
|
// only one course, so redirect directly to this course |
209
|
|
|
foreach ($coursesList as $course) { |
210
|
|
|
$url = api_get_path(WEB_COURSE_PATH).$course['directory'].'/index.php?id_session='.$sessionId; |
211
|
|
|
} |
212
|
|
|
} else { |
213
|
|
|
$url = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$sessionId; |
214
|
|
|
} |
215
|
|
|
header('Location: '.$url); |
216
|
|
|
exit; |
217
|
|
|
} |
218
|
|
|
break; |
219
|
|
|
case 'search_tag': |
220
|
|
|
if (!$userCanViewPage) { |
221
|
|
|
api_not_allowed(true); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
CoursesAndSessionsCatalog::sessionsListByCoursesTag(); |
225
|
|
|
exit; |
226
|
|
|
case 'search_session_title': |
227
|
|
|
if (!$userCanViewPage) { |
228
|
|
|
api_not_allowed(true); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
CoursesAndSessionsCatalog::sessionsListByName(); |
232
|
|
|
exit; |
233
|
|
|
} |
234
|
|
|
|