Fixing course visibility when password is set to ON see #5664

skala
Julio Montoya 13 years ago
parent c56453a9a1
commit 28c497e31c
  1. 4
      main/course_home/course_home.php
  2. 12
      main/inc/lib/course.lib.php
  3. 15
      main/inc/lib/main_api.lib.php
  4. 36
      main/inc/local.inc.php

@ -153,10 +153,6 @@ if ($_GET['action'] == 'subscribe') {
if (!empty($msg)) {
$show_message .= Display::return_message(get_lang($msg));
}
// } else {
// @todo The message should be improved here to make it clear that
// the subscription was not effective
//api_not_allowed(true);
}
}

@ -3820,9 +3820,9 @@ class CourseManager {
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();
$options = array();
// Register button
if (!api_is_anonymous($uid) &&
@ -3838,10 +3838,10 @@ class CourseManager {
}
// 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)
if ($is_admin ||
$course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD && empty($course['registration_code']) ||
(api_user_is_login($uid) && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM && empty($course['registration_code']) ) ||
(in_array($course['real_id'], $user_courses) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
) {
$options[]= 'enter';
}

@ -828,25 +828,29 @@ function api_protect_course_script($print_headers = false, $allow_session_admins
if (isset($course_info) && isset($course_info['visibility'])) {
switch ($course_info['visibility']) {
default:
case 0: //Completely closed: the course is only accessible to the teachers.
case COURSE_VISIBILITY_CLOSED: //Completely closed: the course is only accessible to the teachers. - 0
if (api_get_user_id() && !api_is_anonymous() && (api_is_allowed_to_edit())) {
$is_visible = true;
}
break;
case 1: //Private - access authorized to course members only
case COURSE_VISIBILITY_REGISTERED: //Private - access authorized to course members only - 1
if (api_get_user_id() && !api_is_anonymous() && $is_allowed_in_course) {
$is_visible = true;
}
break;
case 2: // Open - access allowed for users registered on the platform
case COURSE_VISIBILITY_OPEN_PLATFORM: // Open - access allowed for users registered on the platform - 2
if (api_get_user_id() && !api_is_anonymous()) {
$is_visible = true;
}
break;
case 3: //Open - access allowed for the whole world
case COURSE_VISIBILITY_OPEN_WORLD: //Open - access allowed for the whole world - 3
$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'])) {
$is_visible = false;
}
}
//Check session visibility
@ -1358,6 +1362,9 @@ function api_format_course_array($course_data) {
$_course['department_name'] = $course_data['department_name'];
$_course['department_url'] = $course_data['department_url' ];
//Course password
$_course['registration_code'] = !empty($course_data['registration_code']) ? sha1($course_data['registration_code']) : null;
$_course['disk_quota'] = $course_data['disk_quota'];
$_course['course_public_url'] = api_get_path(WEB_COURSE_PATH).$course_data['directory'].'/index.php';

@ -1017,6 +1017,17 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) {
}
}
if (!$is_platformAdmin) {
if (!$is_courseMember && isset($_course['registration_code']) && !empty($_course['registration_code'])) {
$is_courseMember = false;
$is_courseAdmin = false;
$is_courseTutor = false;
$is_courseCoach = false;
$is_sessionAdmin = false;
$is_allowed_in_course = false;
}
}
// check the session visibility
if ($is_allowed_in_course == true) {
@ -1056,31 +1067,6 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) {
$is_allowed_in_course = isset($_SESSION ['is_allowed_in_course']) ? $_SESSION ['is_allowed_in_course'] : false;
}
/* GROUP INIT */
/*
if ((isset($gidReset) && $gidReset) || (isset($cidReset) && $cidReset)) {
// session data refresh requested
if ($gidReq && $_cid && !empty($_course['real_id'])) { // have keys to search data
$group_table = Database::get_course_table(TABLE_GROUP);
$sql = "SELECT * FROM $group_table WHERE c_id = ".$_course['real_id']." AND id = '$gidReq'";
$result = Database::query($sql);
if (Database::num_rows($result) > 0) { // This group has recorded status related to this course
$gpData = Database::fetch_array($result);
$_gid = $gpData ['id'];
Session::write('_gid',$_gid);
} else {
Session::erase('_gid');
}
} elseif (isset($_SESSION['_gid']) or isset($_gid)) { // Keys missing => not anymore in the group - course relation
Session::erase('_gid');
}
} elseif (isset($_SESSION['_gid'])) { // continue with the previous values
$_gid = $_SESSION['_gid'];
} else { //if no previous value, assign caracteristic undefined value
$_gid = -1;
}
*/
//set variable according to student_view_enabled choices
if (api_get_setting('student_view_enabled') == "true") {
if (isset($_GET['isStudentView'])) {

Loading…
Cancel
Save