From 7fcbd56b4ab4807fe54ba47b3ed669fae41f6c9d Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Sun, 25 Aug 2013 01:33:57 -0500 Subject: [PATCH] Implementation of "hidden" visibility for courses - still misses visibility switch for courses in session for platform admin - refs BT#6585 --- main/admin/course_add.php | 1 + main/admin/course_edit.php | 1 + main/admin/course_list.php | 4 ++++ main/auth/courses_controller.php | 2 +- main/course_info/infocours.php | 4 ++++ main/img/bullet_grey.gif | Bin 0 -> 1106 bytes main/inc/lib/course.lib.php | 17 +++++++++++++---- main/inc/lib/login.lib.php | 5 +++++ main/inc/lib/main_api.lib.php | 10 +++++++++- main/inc/lib/social.lib.php | 2 +- main/inc/lib/userportal.lib.php | 10 ++++++---- .../default/auth/courses_categories.php | 2 +- .../block_global_info.class.php | 1 + 13 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 main/img/bullet_grey.gif diff --git a/main/admin/course_add.php b/main/admin/course_add.php index 6b7369a575..8046956948 100644 --- a/main/admin/course_add.php +++ b/main/admin/course_add.php @@ -92,6 +92,7 @@ $group[]= $form->createElement('radio', 'visibility', get_lang('CourseAccess'), $group[]= $form->createElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM); $group[]= $form->createElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED); $group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED); +$group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN); $form->addGroup($group,'', get_lang('CourseAccess'), '
'); diff --git a/main/admin/course_edit.php b/main/admin/course_edit.php index 02557b321b..f0ca8518d9 100644 --- a/main/admin/course_edit.php +++ b/main/admin/course_edit.php @@ -157,6 +157,7 @@ $group[]= $form->createElement('radio', 'visibility', get_lang("CourseAccess"), $group[]= $form->createElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM); $group[]= $form->createElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED); $group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED); +$group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN); $form->addGroup($group,'', get_lang('CourseAccess'), '
'); $group = array(); diff --git a/main/admin/course_list.php b/main/admin/course_list.php index f3ce4c1ec6..c77212890d 100644 --- a/main/admin/course_list.php +++ b/main/admin/course_list.php @@ -148,6 +148,9 @@ function get_course_visibility_icon($v) { case 3: return Display::return_icon('bullet_blue.gif', get_lang('OpenToTheWorld'), array('style' => $style)); break; + case 4: + return Display::return_icon('bullet_grey.gif', get_lang('CourseVisibilityHidden'), array('style' => $style)); + break; default: return ''; } @@ -192,6 +195,7 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') { $form->addElement('radio', 'keyword_visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM); $form->addElement('radio', 'keyword_visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED); $form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED); + $form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN); $form->addElement('radio', 'keyword_visibility', null, get_lang('All'), '%'); $form->addElement('radio', 'keyword_subscribe', get_lang('Subscription'), get_lang('Allowed'), 1); $form->addElement('radio', 'keyword_subscribe', null, get_lang('Denied'), 0); diff --git a/main/auth/courses_controller.php b/main/auth/courses_controller.php index 4ea8f6b29c..33d2bde955 100644 --- a/main/auth/courses_controller.php +++ b/main/auth/courses_controller.php @@ -173,7 +173,7 @@ class CoursesController { // extends Controller { $data = array(); $courseInfo = api_get_course_info($course_code); // The course must be open in order to access the auto subscription - if (in_array($courseInfo['visibility'], array(COURSE_VISIBILITY_CLOSED, COURSE_VISIBILITY_REGISTERED))) { + if (in_array($courseInfo['visibility'], array(COURSE_VISIBILITY_CLOSED, COURSE_VISIBILITY_REGISTERED, COURSE_VISIBILITY_HIDDEN))) { $error = get_lang('SubscribingNotAllowed'); //$message = get_lang('SubscribingNotAllowed'); } else { diff --git a/main/course_info/infocours.php b/main/course_info/infocours.php index 786c5ff379..419009e70d 100644 --- a/main/course_info/infocours.php +++ b/main/course_info/infocours.php @@ -196,6 +196,10 @@ $group[]= $form->createElement('radio', 'visibility', get_lang("CourseAccess"), $group[]= $form->createElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM); $group[]= $form->createElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED); $group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED); +// The "hidden" visibility is only available to portal admins +if (api_is_platform_admin()) { + $group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN); +} $form->addGroup($group, '', array(get_lang("CourseAccess"), get_lang("CourseAccessConfigTip")), ''); $url = api_get_path(WEB_CODE_PATH)."auth/inscription.php?c=$course_code&e=1"; diff --git a/main/img/bullet_grey.gif b/main/img/bullet_grey.gif new file mode 100644 index 0000000000000000000000000000000000000000..f00836df66dabc2f267c9732801606270594fe9a GIT binary patch literal 1106 zcmV-Y1g-l=Nk%w1VHN-u0OtSz000010RaL60s{jB1Ox;H1qB8M1_uWR2nYxX2?+`c z3JVJh3=9kn4Gj(s4i66x5D*X%5fKs+5)%^>6ciK{6%`g178e&67#J8C85tTH8XFrM z92^`S9UUGX9v>ecARr(iAt53nA|oRsBqSsyB_$>%CMPE+C@3f?DJd!{Dl021EG#T7 zEiEoCE-x=HFfcGNF)=bSGBYzXG&D3dH8nOiHa9mnI5;>tIXOByIy*Z%JUl!-Jv}}? zK0iM{KtM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 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -2961,6 +2961,9 @@ class CourseManager { if ($number_of_courses > 0) { while ($course = Database::fetch_array($rs_special_course)) { $course_info = api_get_course_info($course['code']); + if ($course_info['visibility'] != COURSE_VISIBILITY_HIDDEN) { + continue; + } $params = array(); // Get notifications. //$course['id_session'] = null; @@ -3108,6 +3111,9 @@ class CourseManager { // Browse through all courses. while ($course = Database::fetch_array($result)) { $course_info = api_get_course_info($course['code']); + if ($course_info['visibility'] == COURSE_VISIBILITY_HIDDEN) { + continue; + } //$course['id_session'] = null; $course_info['id_session'] = null; $course_info['status'] = $course['status']; @@ -3281,7 +3287,7 @@ class CourseManager { $session_title = ''; if ($session_accessible) { - if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) { + if ($course_visibility != COURSE_VISIBILITY_HIDDEN && ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER)) { if (!$nosession) { if (empty($course_info['id_session'])) { $course_info['id_session'] = 0; @@ -3308,7 +3314,7 @@ class CourseManager { $params['right_actions'] = ''; - if ($course_visibility != COURSE_VISIBILITY_CLOSED) { + if ($course_visibility != COURSE_VISIBILITY_CLOSED && $course_visibility != COURSE_VISIBILITY_HIDDEN) { if ($load_dirs) { $params['right_actions'] .= ''.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).''; $params['right_actions'] .= Display::div('', array('id' => 'document_result_'.$course_info['real_id'].'_'.$course_info['id_session'], 'class'=>'document_preview_container')); @@ -3338,7 +3344,7 @@ class CourseManager { $session_title .= isset($course['special_course']) ? ' '.Display::return_icon('klipper.png', get_lang('CourseAutoRegister')) : ''; // Display the "what's new" icons - if ($course_visibility != COURSE_VISIBILITY_CLOSED) { + if ($course_visibility != COURSE_VISIBILITY_CLOSED && $course_visibility != COURSE_VISIBILITY_HIDDEN) { $session_title .= Display :: show_notification($course_info); } @@ -3802,7 +3808,7 @@ class CourseManager { " WHERE u.access_url_id = ".$_configuration['access_url']." AND". " login_course_date <= now() AND ". " login_course_date > DATE_SUB(now(), INTERVAL $days DAY) AND". - " visibility <> '".COURSE_VISIBILITY_CLOSED."'". + " visibility <> '".COURSE_VISIBILITY_CLOSED."' AND visibility <> '".COURSE_VISIBILITY_HIDDEN."'". " GROUP BY course_code". " ORDER BY course_count DESC". " LIMIT $limit"; @@ -3925,6 +3931,9 @@ class CourseManager { if (!isset($course['real_id']) && empty($course['real_id'])) { $course = api_get_course_info($course['code']); } + if ($course['visibility'] != COURSE_VISIBILITY_HIDDEN) { + return array(); + } $is_admin = api_is_platform_admin_by_id($uid); $options = array(); diff --git a/main/inc/lib/login.lib.php b/main/inc/lib/login.lib.php index 91ed47f713..b25e850449 100644 --- a/main/inc/lib/login.lib.php +++ b/main/inc/lib/login.lib.php @@ -673,6 +673,11 @@ class Login $is_allowed_in_course = true; } break; + case COURSE_VISIBILITY_HIDDEN: //4 + if ($is_platformAdmin) { + $is_allowed_in_course = true; + } + break; } } diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index 225bb40395..381982598e 100644 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -64,7 +64,8 @@ define('COURSE_VISIBILITY_REGISTERED', 1); define('COURSE_VISIBILITY_OPEN_PLATFORM', 2); /** Open for the whole world */ define('COURSE_VISIBILITY_OPEN_WORLD', 3); - +/** Invisible to all except admin */ +define('COURSE_VISIBILITY_HIDDEN', 4); // SESSION VISIBILITY CONSTANTS define('SESSION_VISIBLE_READ_ONLY', 1); @@ -887,6 +888,11 @@ function api_protect_course_script($print_headers = false, $allow_session_admins case COURSE_VISIBILITY_OPEN_WORLD: //Open - access allowed for the whole world - 3 $is_visible = true; break; + case COURSE_VISIBILITY_HIDDEN: //Completely closed: the course is only accessible to the teachers. - 0 + if (api_is_platform_admin()) { + $is_visible = true; + } + break; } //If pasword is set and user is not registered to the course then the course is not visible if ($is_allowed_in_course == false & isset($course_info['registration_code']) && !empty($course_info['registration_code'])) { @@ -4824,6 +4830,8 @@ function api_is_course_visible_for_user($userid = null, $cid = null) { case COURSE_VISIBILITY_REGISTERED: case COURSE_VISIBILITY_CLOSED: return $is_platformAdmin || $is_courseMember || $is_courseAdmin; + case COURSE_VISIBILITY_HIDDEN: + return $is_platformAdmin; } return false; } diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index 48007e434a..010c6ea506 100644 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -460,7 +460,7 @@ class SocialManager extends UserManager $result .= $s_htlm_status_icon; //show a hyperlink to the course, unless the course is closed and user is not course admin - if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) { + if ($course_visibility != COURSE_VISIBILITY_HIDDEN && ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER)) { $result .= ' '.$course_title.''; } else { $result .= $course_title." "." ".get_lang('CourseClosed').""; diff --git a/main/inc/lib/userportal.lib.php b/main/inc/lib/userportal.lib.php index 9a46cf5ad7..5186682673 100644 --- a/main/inc/lib/userportal.lib.php +++ b/main/inc/lib/userportal.lib.php @@ -497,7 +497,7 @@ class IndexManager { foreach ($course_list as $course) { // $setting_show_also_closed_courses - + if ($course['visibility'] == COURSE_VISIBILITY_HIDDEN) { continue; } if (!$setting_show_also_closed_courses) { // If we do not show the closed courses // we only show the courses that are open to the world (to everybody) @@ -532,15 +532,17 @@ class IndexManager { $courses_list_string .= "
  • "; if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) - || ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED) + || ($user_identified && key_exists($course['code'], $courses_of_user) + && $course['visibility'] != COURSE_VISIBILITY_CLOSED) || $courses_of_user[$course['code']]['status'] == '1' || api_is_platform_admin()) { $courses_list_string .= ''; } - $courses_list_string .= $course['title']; + $courses_list_string .= $course['title']; if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) - || ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED) + || ($user_identified && key_exists($course['code'], $courses_of_user) + && $course['visibility'] != COURSE_VISIBILITY_CLOSED) || $courses_of_user[$course['code']]['status'] == '1' || api_is_platform_admin()) { $courses_list_string .= '
    '; diff --git a/main/template/default/auth/courses_categories.php b/main/template/default/auth/courses_categories.php index 17986fd3da..e0c6273691 100644 --- a/main/template/default/auth/courses_categories.php +++ b/main/template/default/auth/courses_categories.php @@ -147,7 +147,7 @@ $stok = Security::get_token(); foreach ($browse_courses_in_category as $course) { // if course is closed, don't show it. - if ($course['visibility'] == COURSE_VISIBILITY_CLOSED) { + if ($course['visibility'] == COURSE_VISIBILITY_CLOSED || $course['visibility'] == COURSE_VISIBILITY_HIDDEN) { continue; } // course isn't closed diff --git a/plugin/dashboard/block_global_info/block_global_info.class.php b/plugin/dashboard/block_global_info/block_global_info.class.php index 6d9f6f1754..27f78cb7aa 100644 --- a/plugin/dashboard/block_global_info/block_global_info.class.php +++ b/plugin/dashboard/block_global_info/block_global_info.class.php @@ -142,6 +142,7 @@ class BlockGlobalInfo extends Block array(get_lang('NumberOfCoursesOpen'), ''.Statistics::count_courses_by_visibility(COURSE_VISIBILITY_OPEN_PLATFORM).''), array(get_lang('NumberOfCoursesPrivate'), ''.Statistics::count_courses_by_visibility(COURSE_VISIBILITY_REGISTERED).''), array(get_lang('NumberOfCoursesClosed'), ''.Statistics::count_courses_by_visibility(COURSE_VISIBILITY_CLOSED).'') + array(get_lang('NumberOfCoursesHidden'), ''.Statistics::count_courses_by_visibility(COURSE_VISIBILITY_HIDDEN).'') ); return $global_info; }