diff --git a/main/auth/courses.php b/main/auth/courses.php
index 319851b356..b55e468a85 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', 'display_courses','display_random_courses');
+$actions = array('sortmycourses', 'createcoursecategory', 'subscribe', 'deletecoursecategory', 'display_courses', 'display_random_courses' , 'subscribe_user_with_password');
$action = 'display_random_courses';
$nameTools = get_lang('SortMyCourses');
@@ -88,6 +88,10 @@ if ($action == 'subscribe') {
$nameTools = get_lang('CourseManagement');
}
+if ($action == 'subscribe_user_with_password') {
+ $nameTools = get_lang('CourseManagement');
+}
+
if ($action == 'display_random_courses' || $action == 'display_courses' ) {
$nameTools = get_lang('CourseManagement');
}
@@ -164,9 +168,9 @@ if (isset($_REQUEST['search_course'])) {
}
}
-// subscribe user to course
-if (isset($_GET['subscribe_course'])) {
- if ($ctok == $_GET['sec_token']) {
+// Subscribe user to course
+if (isset($_REQUEST['subscribe_course'])) {
+ if ($ctok == $_GET['sec_token']) {
$courses_controller->subscribe_user($_GET['subscribe_course'], $_GET['search_term'], $_GET['category_code']);
}
}
@@ -185,6 +189,10 @@ if (isset($_POST['unsubscribe'])) {
}
}
switch ($action) {
+ case 'subscribe_user_with_password':
+ $courses_controller->subscribe_user($_POST['subscribe_user_with_password'], $_POST['search_term'], $_POST['category_code']);
+ exit;
+ break;
case 'createcoursecategory':
$courses_controller->categories_list($action);
break;
diff --git a/main/auth/courses_controller.php b/main/auth/courses_controller.php
index 947c33d655..747e13b237 100644
--- a/main/auth/courses_controller.php
+++ b/main/auth/courses_controller.php
@@ -79,7 +79,7 @@ class CoursesController { // extends Controller {
* @param string action
* @param string Category code (optional)
*/
- public function courses_categories($action, $category_code = null, $message = '', $error = '') {
+ public function courses_categories($action, $category_code = null, $message = '', $error = '', $content = null) {
$data = array();
$browse_course_categories = $this->model->browse_course_categories();
@@ -117,6 +117,7 @@ class CoursesController { // extends Controller {
$data['user_coursecodes'] = $user_coursecodes;
$data['action'] = $action;
$data['message'] = $message;
+ $data['content'] = $content;
$data['error'] = $error;
// render to the view
@@ -170,23 +171,19 @@ class CoursesController { // extends Controller {
*/
public function subscribe_user($course_code, $search_term, $category_code) {
$data = array();
- $result = $this->model->subscribe_user($course_code);
+ $result = $this->model->subscribe_user($course_code);
if (!$result) {
$error = get_lang('CourseRegistrationCodeIncorrect');
} else {
//Redirect directly to the course after subscription
- /*
- if ($result) {
- $url = api_get_course_url($course_code);
- header('Location: '.$url);
- exit;
- }*/
- $message = $result;
+ $message = $result['message'];
+ $content = $result['content'];
}
+
if (!empty($search_term)) {
$this->search_courses($search_term, $message, $error);
} else {
- $this->courses_categories('subcribe', $category_code, $message, $error);
+ $this->courses_categories('subcribe', $category_code, $message, $error, $content);
}
return $result;
}
diff --git a/main/inc/lib/auth.lib.php b/main/inc/lib/auth.lib.php
index 2fc74ee475..6325cc7a88 100644
--- a/main/inc/lib/auth.lib.php
+++ b/main/inc/lib/auth.lib.php
@@ -614,40 +614,42 @@ class Auth {
* @return string Message about results
*/
public function subscribe_user($course_code) {
- global $_user;
-
+ $user_id = api_get_user_id();
$all_course_information = CourseManager::get_course_information($course_code);
+
if ($all_course_information['registration_code'] == '' || $_POST['course_registration_code'] == $all_course_information['registration_code']) {
if (api_is_platform_admin()) {
$status_user_in_new_course = COURSEMANAGER;
} else {
$status_user_in_new_course = null;
}
- if (CourseManager::add_user_to_course($_user['user_id'], $course_code, $status_user_in_new_course)) {
+ if (CourseManager::add_user_to_course($user_id, $course_code, $status_user_in_new_course)) {
$send = api_get_course_setting('email_alert_to_teacher_on_new_user_in_course', $course_code);
if ($send == 1) {
- CourseManager::email_to_tutor($_user['user_id'], $course_code, $send_to_tutor_also = false);
+ CourseManager::email_to_tutor($user_id, $course_code, $send_to_tutor_also = false);
} else if ($send == 2) {
- CourseManager::email_to_tutor($_user['user_id'], $course_code, $send_to_tutor_also = true);
+ CourseManager::email_to_tutor($user_id, $course_code, $send_to_tutor_also = true);
}
- return get_lang('EnrollToCourseSuccessful');
+ $message = get_lang('EnrollToCourseSuccessful');
} else {
- return get_lang('ErrorContactPlatformAdmin');
- }
+ $message = get_lang('ErrorContactPlatformAdmin');
+ }
+ return array('message' => $message);
} else {
-
- $return = '';
if (isset($_POST['course_registration_code']) && $_POST['course_registration_code'] != $all_course_information['registration_code']) {
return false;
}
- $return .= get_lang('CourseRequiresPassword') . '
';
- $return .= $all_course_information['visual_code'] . ' - ' . $all_course_information['title'];
-
- $return .= "