diff --git a/main/auth/courses.php b/main/auth/courses.php
index 0385d53f80..1f1098f044 100644
--- a/main/auth/courses.php
+++ b/main/auth/courses.php
@@ -73,7 +73,7 @@ if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create
}
// filter actions
-$actions = array('sortmycourses', 'createcoursecategory', 'subscribe', 'deletecoursecategory', 'unsubscribe', 'display_courses','display_random_courses');
+$actions = array('sortmycourses', 'createcoursecategory', 'subscribe', 'deletecoursecategory', 'display_courses','display_random_courses');
$action = 'display_random_courses';
$nameTools = get_lang('SortMyCourses');
@@ -149,14 +149,6 @@ if ($action == 'deletecoursecategory' && isset($_GET['id'])) {
}
}
-// We are unsubscribing from a course (=Unsubscribe from course).
-if (isset($_POST['unsubscribe'])) {
- if ($ctok == $_POST['sec_token']) {
- $courses_controller->unsubscribe_user_from_course($_POST['unsubscribe']);
- //$message = remove_user_from_course($_user['user_id'], $_POST['unsubscribe']);
- }
-}
-
// We are creating a new user defined course category (= Create Course Category).
if (isset($_POST['create_course_category']) && isset($_POST['title_course_category']) && strlen(trim($_POST['title_course_category'])) > 0) {
if ($ctok == $_POST['sec_token']) {
@@ -174,9 +166,23 @@ if (isset($_REQUEST['search_course'])) {
// subscribe user to course
if (isset($_GET['subscribe_course'])) {
- //if ($ctok == $_GET['sec_token'] || $_POST['token'] == $_GET['sec_token']) {
+ if ($ctok == $_GET['sec_token']) {
$courses_controller->subscribe_user($_GET['subscribe_course'], $_GET['search_term'], $_GET['category_code']);
- //}
+ }
+}
+// We are unsubscribing from a course (=Unsubscribe from course).
+if (isset($_GET['unsubscribe'])) {
+ if ($ctok == $_GET['sec_token']) {
+ $courses_controller->unsubscribe_user_from_course($_GET['unsubscribe'], $_GET['search_term'], $_GET['category_code']);
+ //$message = remove_user_from_course($_user['user_id'], $_POST['unsubscribe']);
+ }
+}
+// We are unsubscribing from a course (=Unsubscribe from course).
+if (isset($_POST['unsubscribe'])) {
+ if ($ctok == $_POST['sec_token']) {
+ $courses_controller->unsubscribe_user_from_course($_POST['unsubscribe']);
+ //$message = remove_user_from_course($_user['user_id'], $_POST['unsubscribe']);
+ }
}
switch ($action) {
diff --git a/main/auth/courses_controller.php b/main/auth/courses_controller.php
index b3276913b8..4b65591c45 100644
--- a/main/auth/courses_controller.php
+++ b/main/auth/courses_controller.php
@@ -277,11 +277,15 @@ class CoursesController { // extends Controller {
* render to listing view
* @param string Course code
*/
- public function unsubscribe_user_from_course($course_code) {
+ public function unsubscribe_user_from_course($course_code, $search_term = null, $category_code = null) {
$result = $this->model->remove_user_from_course($course_code);
$message = '';
if ($result) { $message = get_lang('YouAreNowUnsubscribed'); }
$action = 'sortmycourses';
- $this->courses_list($action, $message);
+ if (!empty($search_term)) {
+ $this->search_courses($search_term, $message, $error);
+ } else {
+ $this->courses_categories('subcribe', $category_code, $message, $error);
+ }
}
}
diff --git a/main/inc/lib/auth.lib.php b/main/inc/lib/auth.lib.php
index 0d923a3cab..a68f815b5e 100644
--- a/main/inc/lib/auth.lib.php
+++ b/main/inc/lib/auth.lib.php
@@ -642,4 +642,4 @@ class Auth
return $return;
}
}
-}
\ No newline at end of file
+}
diff --git a/main/template/default/auth/courses_categories.php b/main/template/default/auth/courses_categories.php
index 5247fe1e76..7cb2a52a65 100644
--- a/main/template/default/auth/courses_categories.php
+++ b/main/template/default/auth/courses_categories.php
@@ -170,14 +170,14 @@ $stok = Security::get_token();
}
// Go To Course button (only if admin, if course public or if student already subscribed)
- if (api_is_platform_admin() || (
- $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD ||
- ($course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM && api_user_is_login()) ||
- in_array($course['code'], $user_coursecodes && $course['visibility'] != COURSE_VISIBILITY_CLOSED )
- )
- ) {
+ if (api_is_platform_admin()
+ || $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
+ || (api_user_is_login() && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
+ || in_array($course['code'], $user_coursecodes && $course['visibility'] != COURSE_VISIBILITY_CLOSED )
+ ) {
echo ' '.get_lang('GoToCourse').'';
- } elseif (!api_is_anonymous() // Subscribe button
+ }
+ if (!api_is_anonymous() // Subscribe button
&& ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
&& $course['subscribe'] == SUBSCRIBE_ALLOWED
&& (!in_array($course['code'], $user_coursecodes) || empty($user_coursecodes))) {
@@ -186,6 +186,9 @@ $stok = Security::get_token();
// If user is already subscribed to the course
if (!api_is_anonymous() && in_array($course['code'], $user_coursecodes)) {
+ if ($course['unsubscribe'] == UNSUBSCRIBE_ALLOWED) {
+ echo ' '.get_lang('Unsubscribe').'';
+ }
echo '
';
echo '
';
echo Display::label(get_lang("AlreadyRegisteredToCourse"), "info");