diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index b9316f4653..9b2f506003 100644 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -3717,13 +3717,16 @@ class CourseManager { $course_info = api_get_course_info($my_course['course_code']); $my_course['extra_info'] = $course_info; $my_course['extra_info']['go_to_course_button'] = ''; + $my_course['extra_info']['register_button'] = ''; $access_link = self::get_access_link_by_user(api_get_user_id(), $course_info, $my_course_code_list); //Course visibility - if (0 === strcmp($access_link,'register')) { + if (in_array('register', $access_link)) { $stok = Security::get_token(); - $my_course['extra_info']['go_to_course_button'] = Display::url(get_lang('Subscribe'), api_get_path(WEB_COURSE_PATH).$course_info['path'].'/index.php?action=subscribe&sec_token='.$stok, array('class' => 'btn btn-primary')); - } elseif (0 === strcmp($access_link,'enter')) { + $my_course['extra_info']['register_button'] = Display::url(get_lang('Subscribe'), api_get_path(WEB_COURSE_PATH).$course_info['path'].'/index.php?action=subscribe&sec_token='.$stok, array('class' => 'btn btn-primary')); + } + + if (in_array('enter', $access_link)) { $my_course['extra_info']['go_to_course_button'] = Display::url(get_lang('GoToCourse'), api_get_path(WEB_COURSE_PATH).$course_info['path'].'/index.php', array('class' => 'btn btn-primary')); } @@ -3806,30 +3809,40 @@ class CourseManager { if (empty($uid) or empty($course)) { return false; } if (empty($user_courses)) { // get the array of courses to which the user is subscribed - $user_courses = CourseManager::get_courses_list_by_user_id($uid); + $user_courses = CourseManager::get_courses_list_by_user_id($uid); foreach ($user_courses as $k => $v) { $user_courses[$k] = $v['real_id']; } } + if (!isset($course['real_id']) && empty($course['real_id'])) { + $course = api_get_course_info($course['code']); + } + $is_admin = api_is_platform_admin_by_id($uid); + $options = array(); + // Register button - if (!api_is_anonymous($uid) && !$is_admin - && ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) - && $course['subscribe_allowed'] == SUBSCRIBE_ALLOWED - && (!in_array($course['real_id'], $user_courses) || empty($user_courses)) + if (!api_is_anonymous($uid) && + !$is_admin && + ( + ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || + $course['visibility'] == COURSE_VISIBILITY_REGISTERED && $course['subscribe'] == SUBSCRIBE_ALLOWED + ) && + $course['subscribe'] == SUBSCRIBE_ALLOWED && + (!in_array($course['real_id'], $user_courses) || empty($user_courses)) ) { - return 'register'; + $options[]= 'register'; } + // Go To Course button (only if admin, if course public or if student already subscribed) if ($is_admin || $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || (api_user_is_login($uid) && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || (in_array($course['real_id'], $user_courses) && $course['visibility'] != COURSE_VISIBILITY_CLOSED) ) { - return 'enter'; + $options[]= 'enter'; } - // Print register button (if any) - return false; + return $options; } } //end class CourseManager diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index fdd418c879..918f1d1d71 100644 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -1338,7 +1338,8 @@ function api_format_course_array($course_data) { $_course['categoryName' ] = $course_data['faName' ]; $_course['visibility' ] = $course_data['visibility' ]; - $_course['subscribe_allowed'] = $course_data['subscribe' ]; + $_course['subscribe_allowed'] = $course_data['subscribe']; + $_course['subscribe'] = $course_data['subscribe']; $_course['unsubscribe'] = $course_data['unsubscribe' ]; $_course['course_language'] = $course_data['course_language']; @@ -1357,10 +1358,8 @@ function api_format_course_array($course_data) { } else { $url_image = api_get_path(WEB_IMG_PATH).'without_picture.png'; } - $_course['course_image'] = $url_image; - - return $_course; - + $_course['course_image'] = $url_image; + return $_course; } diff --git a/main/template/default/auth/courses_categories.php b/main/template/default/auth/courses_categories.php index 86942317a6..ba30ad85a1 100644 --- a/main/template/default/auth/courses_categories.php +++ b/main/template/default/auth/courses_categories.php @@ -118,8 +118,7 @@ $stok = Security::get_token(); echo "
".get_lang('SearchResultsFor')." ".Security::remove_XSS($_POST['search_term'])."
";
}
- $ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
-
+ $ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
if (!empty($browse_courses_in_category)) {
@@ -170,21 +169,20 @@ $stok = Security::get_token();
if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
echo ''.get_lang('Description').'';
}
- // Get access type for course button ("enter" or "register")
- $course['subscribe_allowed'] = $course['subscribe'];
- $access_type = CourseManager::get_access_link_by_user(api_get_user_id(),$course);
- $sub_btn = '';
- // Register button
- if (strcmp($access_type,'register')===0) {
- $sub_btn = ' '.get_lang('Subscribe').'';
- }
+
+ // Get access type for course button ("enter" or/and "register")
+ $access_type = CourseManager::get_access_link_by_user(api_get_user_id(), $course);
+
// Go To Course button (only if admin, if course public or if student already subscribed)
- if (empty($sub_btn)) {
+ if (in_array('enter', $access_type)) {
echo ' '.get_lang('GoToCourse').'';
}
- // Print register button (if any)
- echo $sub_btn;
-
+
+ // Register button
+ if (in_array('register', $access_type)) {
+ echo ' '.get_lang('Subscribe').'';
+ }
+
// If user is already subscribed to the course
if (!api_is_anonymous() && in_array($course['code'], $user_coursecodes)) {
if ($course['unsubscribe'] == UNSUBSCRIBE_ALLOWED) {
diff --git a/main/template/default/layout/hot_course_item.tpl b/main/template/default/layout/hot_course_item.tpl
index 46f24a0471..1e65d13ea5 100644
--- a/main/template/default/layout/hot_course_item.tpl
+++ b/main/template/default/layout/hot_course_item.tpl
@@ -14,9 +14,10 @@
- {{ hot_course.extra_info.go_to_course_button }} +
{{ hot_course.extra_info.description_button }} + {{ hot_course.extra_info.go_to_course_button }} + {{ hot_course.extra_info.register_button }}
diff --git a/main/template/default/layout/hot_course_item_popup.tpl b/main/template/default/layout/hot_course_item_popup.tpl index accee27362..90cad0a7ca 100644 --- a/main/template/default/layout/hot_course_item_popup.tpl +++ b/main/template/default/layout/hot_course_item_popup.tpl @@ -14,9 +14,10 @@- {{ hot_course.extra_info.go_to_course_button }} +
{{ hot_course.extra_info.description_button }} + {{ hot_course.extra_info.go_to_course_button }} + {{ hot_course.extra_info.register_button }}