diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index f4728c04d1..51517d7f96 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -1131,7 +1131,7 @@ class CourseManager * * @param int the id of the user * @param array info about the course (comes from course table, see database lib) - * + * @deprecated linked_courses definition doesn't exists * @return true if the user is registered in the real course or linked courses, false otherwise */ public static function is_user_subscribed_in_real_or_linked_course($user_id, $course_code, $session_id = '') @@ -2481,19 +2481,24 @@ class CourseManager } // get course list auto-register - $sql = "SELECT DISTINCT(tcfv.course_code) FROM $tbl_course_field_value tcfv INNER JOIN $tbl_course_field tcf + $sql = "SELECT DISTINCT(tcfv.course_code) + FROM $tbl_course_field_value tcfv + INNER JOIN $tbl_course_field tcf ON tcfv.field_id = tcf.id $join_access_url - WHERE tcf.field_variable = 'special_course' AND tcfv.field_value = 1 $where_access_url"; - $special_course_result = Database::query($sql); - $special_course_list = array(); - - if (Database::num_rows($special_course_result) > 0) { - $special_course_list = array(); - while ($result_row = Database::fetch_array($special_course_result)) { - $special_course_list[] = $result_row['course_code']; + WHERE + tcf.field_variable = 'special_course' AND + tcfv.field_value = 1 $where_access_url"; + + $result = Database::query($sql); + $courseList = array(); + + if (Database::num_rows($result) > 0) { + while ($result_row = Database::fetch_array($result)) { + $courseList[] = $result_row['course_code']; } } - return $special_course_list; + + return $courseList; } /** @@ -3515,10 +3520,17 @@ class CourseManager $with_special_courses = ' course.code IN ("' . implode('","', $special_course_list) . '")'; } $html = null; - + $courseCount = 0; if (!empty($with_special_courses)) { - $sql = "SELECT course.id, course.code, course.subscribe subscr, course.unsubscribe unsubscr, course_rel_user.status status, - course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat, course_rel_user.user_id + $sql = "SELECT + course.id, + course.code, + course.subscribe subscr, + course.unsubscribe unsubscr, + course_rel_user.status status, + course_rel_user.sort sort, + course_rel_user.user_course_cat user_course_cat, + course_rel_user.user_id FROM $tbl_course course LEFT JOIN $tbl_course_user course_rel_user ON course.code = course_rel_user.course_code AND course_rel_user.user_id = '$user_id' @@ -3526,6 +3538,7 @@ class CourseManager $rs_special_course = Database::query($sql); $number_of_courses = Database::num_rows($rs_special_course); + $key = 0; if ($number_of_courses > 0) { @@ -3534,9 +3547,9 @@ class CourseManager if ($course_info['visibility'] == COURSE_VISIBILITY_HIDDEN) { continue; } + $courseCount++; $params = array(); // Get notifications. - $course_info['id_session'] = null; $course_info['status'] = $course['status']; $show_notification = Display::show_notification($course_info); @@ -3609,7 +3622,10 @@ class CourseManager } } - return $html; + return [ + 'html' => $html, + 'course_count' => $courseCount + ]; } /** @@ -3632,6 +3648,7 @@ class CourseManager $sql = "SELECT id, title FROM $tucc WHERE user_id='" . $user_id . "' ORDER BY sort ASC"; $result = Database::query($sql); $html = null; + $courseCount = 0; while ($row = Database::fetch_array($result)) { // We simply display the title of the category. $params = array( @@ -3640,16 +3657,24 @@ class CourseManager 'title' => $row['title'], 'class' => 'table_user_course_category' ); + + $courseInCategory = self:: display_courses_in_category($row['id'], $load_dirs); $html .= self::course_item_parent( self::course_item_html($params, true), - self:: display_courses_in_category($row['id'], $load_dirs) + $courseInCategory['html'] ); + $courseCount += $courseInCategory['course_count']; } // Step 2: We display the course without a user category. - $html .= self:: display_courses_in_category(0, $load_dirs); - - return $html; + $courseInCategory = self:: display_courses_in_category(0, $load_dirs); + $html .= $courseInCategory['html']; + $courseCount += $courseInCategory['course_count']; + + return [ + 'html' => $html, + 'course_count' => $courseCount + ]; } /** @@ -3710,7 +3735,7 @@ class CourseManager $course_list = array(); $showCustomIcon = api_get_configuration_value('course_images_in_courses_list'); - + $courseCount = 0; // Browse through all courses. while ($course = Database::fetch_array($result)) { $course_info = api_get_course_info($course['code']); @@ -3729,6 +3754,8 @@ class CourseManager $course_list[] = $course_info['real_id']; } + $courseCount++; + // For each course, get if there is any notification icon to show // (something that would have changed since the user's last visit). $show_notification = Display::show_notification($course_info); @@ -3828,7 +3855,10 @@ class CourseManager $html .= self::course_item_html($params, $isSubcontent); } - return $html; + return [ + 'html' => $html, + 'course_count' => $courseCount + ]; } /** diff --git a/main/inc/lib/userportal.lib.php b/main/inc/lib/userportal.lib.php index 81a4828af7..189326b126 100755 --- a/main/inc/lib/userportal.lib.php +++ b/main/inc/lib/userportal.lib.php @@ -1040,17 +1040,23 @@ class IndexManager $courses_html = ''; $special_courses = ''; + $sessionCount = 0; + $courseCount = 0; // If we're not in the history view... if (!isset($_GET['history'])) { // Display special courses. - $special_courses = CourseManager::display_special_courses($user_id, $this->load_directories_preview); + $specialCourses = CourseManager::display_special_courses($user_id, $this->load_directories_preview); + $special_courses = $specialCourses['html']; // Display courses. - $courses_html .= CourseManager::display_courses($user_id, $this->load_directories_preview); + $courses = CourseManager::display_courses($user_id, $this->load_directories_preview); + $courses_html .= $courses['html']; + $courseCount = $specialCourses['course_count'] + $courses['course_count']; } $sessions_with_category = ''; $sessions_with_no_category = ''; + if (is_array($session_categories)) { foreach ($session_categories as $session_category) { $session_category_id = $session_category['session_category']['id']; @@ -1185,10 +1191,11 @@ class IndexManager $parentInfo = CourseManager::course_item_html_no_icon($params); } - $sessions_with_no_category .= CourseManager::course_item_parent( $parentInfo,null ); + + $sessionCount++; } } } else { @@ -1203,6 +1210,7 @@ class IndexManager if (count($session['courses']) < 1) { continue; } + $date_session_start = $session['date_start']; $date_session_end = $session['date_end']; $days_access_before_beginning = $session['nb_days_access_before_beginning']; @@ -1313,6 +1321,8 @@ class IndexManager } $html_sessions .= $parentInfo . $html_courses_session; + + $sessionCount++; } } } @@ -1354,9 +1364,11 @@ class IndexManager } } - return $sessions_with_category. - $sessions_with_no_category. - $courses_html.$special_courses; + return [ + 'html' => $sessions_with_category.$sessions_with_no_category.$courses_html.$special_courses, + 'session_count' => $sessionCount, + 'course_count' => $courseCount + ]; } /** diff --git a/user_portal.php b/user_portal.php index a259270796..39e0d40aa2 100755 --- a/user_portal.php +++ b/user_portal.php @@ -30,52 +30,48 @@ require_once api_get_path(LIBRARY_PATH).'userportal.lib.php'; api_block_anonymous_users(); // Only users who are logged in can proceed. -$user_id = api_get_user_id(); +$userId = api_get_user_id(); /* Constants and CONFIGURATION parameters */ $load_dirs = api_get_setting('show_documents_preview'); +$controller = new IndexManager(get_lang('MyCourses')); + +// Main courses and session list +$courseAndSessions = $controller->return_courses_and_sessions($userId); + // Check if a user is enrolled only in one course for going directly to the course after the login. if (api_get_setting('go_to_course_after_login') == 'true') { - // Get the courses list - $personal_course_list = UserManager::get_personal_session_course_list($user_id); - - $my_session_list = array(); - $count_of_courses_no_sessions = 0; - $count_of_courses_with_sessions = 0; - - foreach ($personal_course_list as $course) { - if (!empty($course['id_session'])) { - $my_session_list[$course['id_session']] = true; - $count_of_courses_with_sessions++; - } else { - $count_of_courses_no_sessions++; - } - } - $count_of_sessions = count($my_session_list); + $count_of_sessions = $courseAndSessions['session_count']; + $count_of_courses_no_sessions = $courseAndSessions['course_count']; if ($count_of_sessions == 1 && $count_of_courses_no_sessions == 0) { - $key = array_keys($personal_course_list); - $course_info = $personal_course_list[$key[0]]; - $course_directory = $course_info['course_info']['path']; - $id_session = isset($course_info['id_session']) ? $course_info['id_session'] : 0; - $url = api_get_path(WEB_CODE_PATH).'session/?session_id='.$id_session; - - header('location:'.$url); - exit; + $sessions = SessionManager::get_sessions_by_user($userId); + if (isset($sessions[0])) { + $sessionInfo = $sessions[0]; + if (isset($sessionInfo['session_id'])) { + $url = api_get_path(WEB_CODE_PATH).'session/?session_id='.$sessionInfo['session_id']; + + header('Location:'.$url); + exit; + } + } } if (!isset($_SESSION['coursesAlreadyVisited']) && $count_of_sessions == 0 && $count_of_courses_no_sessions == 1 ) { - $key = array_keys($personal_course_list); - $course_info = $personal_course_list[$key[0]]; - $course_directory = $course_info['course_info']['path']; - $id_session = isset($course_info['id_session']) ? $course_info['id_session'] : 0; - $url = api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$id_session; - header('location:'.$url); - exit; + $courses = CourseManager::get_courses_list_by_user_id($userId); + + if (!empty($courses) && isset($courses[0]) && isset($courses[0]['code'])) { + $courseInfo = api_get_course_info($courses[0]['code']); + if (!empty($courseInfo)) { + $courseUrl = $courseInfo['course_public_url']; + header('Location:'.$courseUrl); + exit; + } + } } } @@ -123,38 +119,14 @@ if ($load_dirs) { '; } -/* Sniffing system */ - -//store posts to sessions -/* -if (isset($_SESSION['sniff_navigator']) && $_SESSION['sniff_navigator']!="checked") { - $_SESSION['sniff_navigator']=Security::remove_XSS($_POST['sniff_navigator']); - $_SESSION['sniff_screen_size_w']=Security::remove_XSS($_POST['sniff_navigator_screen_size_w']); - $_SESSION['sniff__screen_size_h']=Security::remove_XSS($_POST['sniff_navigator_screen_size_h']); - $_SESSION['sniff_type_mimetypes']=Security::remove_XSS($_POST['sniff_navigator_type_mimetypes']); - $_SESSION['sniff_suffixes_mimetypes']=Security::remove_XSS($_POST['sniff_navigator_suffixes_mimetypes']); - $_SESSION['sniff_list_plugins']=Security::remove_XSS($_POST['sniff_navigator_list_plugins']); - $_SESSION['sniff_check_some_activex']=Security::remove_XSS($_POST['sniff_navigator_check_some_activex']); - $_SESSION['sniff_check_some_plugins']=Security::remove_XSS($_POST['sniff_navigator_check_some_plugins']); - $_SESSION['sniff_java']=Security::remove_XSS($_POST['sniff_navigator_java']); - $_SESSION['sniff_java_sun_ver']=Security::remove_XSS($_POST['sniff_navigator_java_sun_ver']); -} -*/ -/* MAIN CODE */ - -$controller = new IndexManager(get_lang('MyCourses')); - -// Main courses and session list -$courses_and_sessions = $controller->return_courses_and_sessions($user_id); - //Show the chamilo mascot -if (empty($courses_and_sessions) && !isset($_GET['history'])) { +if (empty($courseAndSessions['html']) && !isset($_GET['history'])) { $controller->tpl->assign('welcome_to_course_block', $controller->return_welcome_to_course_block()); } -$controller->tpl->assign('content', $courses_and_sessions); +$controller->tpl->assign('content', $courseAndSessions['html']); if (api_get_setting('allow_browser_sniffer') == 'true') { if ($_SESSION['sniff_navigator']!="checked") {