tpl = new Template($title); $this->home = api_get_home_path(); $this->user_id = api_get_user_id(); $this->load_directories_preview = false; if (api_get_setting('show_documents_preview') === 'true') { $this->load_directories_preview = true; } } /** * @param array $personal_course_list */ public function return_exercise_block($personal_course_list) { $exercise_list = array(); if (!empty($personal_course_list)) { foreach ($personal_course_list as $course_item) { $course_code = $course_item['c']; $session_id = $course_item['id_session']; $exercises = ExerciseLib::get_exercises_to_be_taken( $course_code, $session_id ); foreach ($exercises as $exercise_item) { $exercise_item['course_code'] = $course_code; $exercise_item['session_id'] = $session_id; $exercise_item['tms'] = api_strtotime($exercise_item['end_time'], 'UTC'); $exercise_list[] = $exercise_item; } } if (!empty($exercise_list)) { $exercise_list = msort($exercise_list, 'tms'); $my_exercise = $exercise_list[0]; $url = Display::url( $my_exercise['title'], api_get_path(WEB_CODE_PATH).'exercise/overview.php?exerciseId='.$my_exercise['id'].'&cidReq='.$my_exercise['course_code'].'&id_session='.$my_exercise['session_id'] ); $this->tpl->assign('exercise_url', $url); $this->tpl->assign( 'exercise_end_date', api_convert_and_format_date($my_exercise['end_time'], DATE_FORMAT_SHORT) ); } } } /** * @param bool $show_slide * @return null|string */ public function return_announcements($show_slide = true) { $hideAnnouncements = api_get_setting('hide_global_announcements_when_not_connected'); $currentUserId = api_get_user_id(); if ($hideAnnouncements == 'true' && empty($currentUserId)) { return null; } $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : null; $announcement = intval($announcement); if (!api_is_anonymous() && $this->user_id) { $visibility = SystemAnnouncementManager::getCurrentUserVisibility(); if ($show_slide) { $announcements = SystemAnnouncementManager::displayAnnouncementsSlider( $visibility, $announcement ); } else { $announcements = SystemAnnouncementManager::displayAllAnnouncements( $visibility, $announcement ); } } else { if ($show_slide) { $announcements = SystemAnnouncementManager::displayAnnouncementsSlider( SystemAnnouncementManager::VISIBLE_GUEST, $announcement ); } else { $announcements = SystemAnnouncementManager::displayAllAnnouncements( SystemAnnouncementManager::VISIBLE_GUEST, $announcement ); } } return $announcements; } /** * Alias for the online_logout() function * @param bool $redirect Whether to ask online_logout to redirect to index.php or not * @param array $logoutInfo Information stored by local.inc.php before new context ['uid'=> x, 'cid'=>y, 'sid'=>z] */ public function logout($redirect = true, $logoutInfo = []) { online_logout($this->user_id, true); Event::courseLogout($logoutInfo); } /** * This function checks if there are courses that are open to the world in the platform course categories (=faculties) * * @param string $category * @return boolean */ public function category_has_open_courses($category) { $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true'; $main_course_table = Database::get_main_table(TABLE_MAIN_COURSE); $category = Database::escape_string($category); $sql_query = "SELECT * FROM $main_course_table WHERE category_code='$category'"; $sql_result = Database::query($sql_query); while ($course = Database::fetch_array($sql_result)) { if (!$setting_show_also_closed_courses) { if ((api_get_user_id() > 0 && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) { return true; //at least one open course } } else { if (isset($course['visibility'])) { return true; // At least one course (it does not matter weither it's open or not because $setting_show_also_closed_courses = true). } } } return false; } /** * @return null|string */ public function return_teacher_link() { $html = ''; $show_menu = false; if (!empty($this->user_id)) { // tabs that are deactivated are added here $show_menu = false; $show_create_link = false; $show_course_link = false; if (api_is_allowed_to_create_course()) { $show_menu = true; $show_course_link = true; $show_create_link = true; } else { if (api_get_setting('allow_students_to_browse_courses') === 'true') { $show_menu = true; $show_course_link = true; } if (api_is_allowed_to_create_course()) { $show_create_link = true; } } if ($show_menu && ($show_create_link || $show_course_link)) { $show_menu = true; } else { $show_menu = false; } } // My Account section if ($show_menu) { $html .= ''; } if (!empty($html)) { $html = self::show_right_block( get_lang('Courses'), $html, 'teacher_block', null, 'teachers', 'teachersCollapse' ); } return $html; } /** * Includes a created page * @return string */ public function return_home_page() { $userId = api_get_user_id(); // Including the page for the news $html = ''; if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) { $open = @(string) file_get_contents($this->home.$_GET['include']); $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); } else { // Hiding home top when user not connected. $hideTop = api_get_setting('hide_home_top_when_connected'); if ($hideTop == 'true' && !empty($userId)) { return $html; } if (!empty($_SESSION['user_language_choice'])) { $user_selected_language = $_SESSION['user_language_choice']; } elseif (!empty($_SESSION['_user']['language'])) { $user_selected_language = $_SESSION['_user']['language']; } else { $user_selected_language = api_get_setting('platformLanguage'); } $home_top_temp = ''; // Try language specific home if (file_exists($this->home.'home_top_'.$user_selected_language.'.html')) { $home_top_temp = file_get_contents($this->home.'home_top_'.$user_selected_language.'.html'); } // Try default language home if (empty($home_top_temp)) { if (file_exists($this->home.'home_top.html')) { $home_top_temp = file_get_contents($this->home.'home_top.html'); } else { if (file_exists($this->default_home.'home_top.html')) { $home_top_temp = file_get_contents($this->default_home.'home_top.html'); } } } if (trim($home_top_temp) == '' && api_is_platform_admin()) { $home_top_temp = '
'.get_lang('PortalHomepageDefaultIntroduction').'
'; } else { $home_top_temp = '
'.$home_top_temp.'
'; } $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp); $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); } return $html; } /** * @return string */ public function return_notice() { $user_selected_language = api_get_interface_language(); $html = ''; // Notice $home_notice = @(string) file_get_contents($this->home.'home_notice_'.$user_selected_language.'.html'); if (empty($home_notice)) { $home_notice = @(string) file_get_contents($this->home.'home_notice.html'); } if (!empty($home_notice)) { $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice))); $html = self::show_right_block( get_lang('Notice'), $home_notice, 'notice_block', null, 'notices', 'noticesCollapse' ); } return $html; } /** * @return string */ public function return_help() { $user_selected_language = api_get_interface_language(); $platformLanguage = api_get_setting('platformLanguage'); // Help section. /* Hide right menu "general" and other parts on anonymous right menu. */ if (!isset($user_selected_language)) { $user_selected_language = $platformLanguage; } $html = ''; $home_menu = @(string) file_get_contents($this->home.'home_menu_'.$user_selected_language.'.html'); if (!empty($home_menu)) { $home_menu_content = ''; $html .= self::show_right_block( get_lang('MenuGeneral'), $home_menu_content, 'help_block', null, 'helps', 'helpsCollapse' ); } return $html; } /** * Generate the block for show a panel with links to My Certificates and Certificates Search pages * @return array The HTML code for the panel */ public function returnSkillLinks() { $items = []; if (!api_is_anonymous() && api_get_configuration_value('hide_my_certificate_link') === false ) { $items[] = [ 'icon' => Display::return_icon('graduation.png', get_lang('MyCertificates')), 'link' => api_get_path(WEB_CODE_PATH).'gradebook/my_certificates.php', 'title' => get_lang('MyCertificates') ]; } if (api_get_setting('allow_public_certificates') == 'true') { $items[] = [ 'icon' => Display::return_icon('search_graduation.png', get_lang('Search')), 'link' => api_get_path(WEB_CODE_PATH).'gradebook/search.php', 'title' => get_lang('Search') ]; } if (Skill::isAllow(0, false)) { $items[] = [ 'icon' => Display::return_icon('skill-badges.png', get_lang('MySkills')), 'link' => api_get_path(WEB_CODE_PATH).'social/my_skills_report.php', 'title' => get_lang('MySkills') ]; $allowSkillsManagement = api_get_setting('allow_hr_skills_management') == 'true'; if (($allowSkillsManagement && api_is_drh()) || api_is_platform_admin()) { $items[] = [ 'icon' => Display::return_icon('edit-skill.png', get_lang('MySkills')), 'link' => api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php', 'title' => get_lang('ManageSkills') ]; } } return $items; } /** * Reacts on a failed login: * Displays an explanation with a link to the registration form. * * @version 1.0.1 */ public function handle_login_failed() { return $this->tpl->handleLoginFailed(); } /** * Display list of courses in a category. * (for anonymous users) * * @version 1.1 * @author Patrick Cool , Ghent University - refactoring and code cleaning * @author Julio Montoya , Beeznest template modifs */ public function return_courses_in_categories() { $result = ''; $stok = Security::get_token(); // Initialization. $user_identified = (api_get_user_id() > 0 && !api_is_anonymous()); $web_course_path = api_get_path(WEB_COURSE_PATH); $category = isset($_GET['category']) ? Database::escape_string($_GET['category']) : ''; $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true'; // Database table definitions. $main_course_table = Database::get_main_table(TABLE_MAIN_COURSE); $main_category_table = Database::get_main_table(TABLE_MAIN_CATEGORY); // Get list of courses in category $category. $sql = "SELECT * FROM $main_course_table cours WHERE category_code = '".$category."' ORDER BY title, UPPER(visual_code)"; // Showing only the courses of the current access_url_id. if (api_is_multiple_url_enabled()) { $url_access_id = api_get_current_access_url_id(); if ($url_access_id != -1) { $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); $sql = "SELECT * FROM $main_course_table as course INNER JOIN $tbl_url_rel_course as url_rel_course ON (url_rel_course.c_id = course.id) WHERE access_url_id = $url_access_id AND category_code = '".$category."' ORDER BY title, UPPER(visual_code)"; } } // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' $queryResult = Database::query($sql); while ($course_result = Database::fetch_array($queryResult)) { $course_list[] = $course_result; } $numRows = Database::num_rows($queryResult); // $setting_show_also_closed_courses if ($user_identified) { if ($setting_show_also_closed_courses) { $platform_visible_courses = ''; } else { $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )"; } } else { if ($setting_show_also_closed_courses) { $platform_visible_courses = ''; } else { $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )"; } } $sqlGetSubCatList = " SELECT t1.name, t1.code, t1.parent_id, t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse FROM $main_category_table t1 LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id LEFT JOIN $main_course_table t3 ON (t3.category_code = t1.code $platform_visible_courses) WHERE t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")." GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name"; // Showing only the category of courses of the current access_url_id if (api_is_multiple_url_enabled()) { $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY); $courseCategoryCondition = " INNER JOIN $table a ON (t1.id = a.course_category_id)"; $url_access_id = api_get_current_access_url_id(); if ($url_access_id != -1) { $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); $sqlGetSubCatList = " SELECT t1.name, t1.code, t1.parent_id, t1.children_count, COUNT(DISTINCT t3.code) AS nbCourse FROM $main_category_table t1 $courseCategoryCondition LEFT JOIN $main_category_table t2 ON t1.code = t2.parent_id LEFT JOIN $main_course_table t3 ON (t3.category_code = t1.code $platform_visible_courses) INNER JOIN $tbl_url_rel_course as url_rel_course ON (url_rel_course.c_id = t3.id) WHERE url_rel_course.access_url_id = $url_access_id AND t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")." GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name"; } } $resCats = Database::query($sqlGetSubCatList); $thereIsSubCat = false; if (Database::num_rows($resCats) > 0) { $htmlListCat = Display::page_header(get_lang('CatList')); $htmlListCat .= '"; } $result .= $htmlTitre; if ($thereIsSubCat) { $result .= $htmlListCat; } while ($categoryName = Database::fetch_array($resCats)) { $result .= '

'.$categoryName['name']."

\n"; } $courses_list_string = ''; $courses_shown = 0; if ($numRows > 0) { $courses_list_string .= Display::page_header(get_lang('CourseList')); $courses_list_string .= ""; } if ($courses_shown > 0) { // Only display the list of courses and categories if there was more than // 0 courses visible to the world (we're in the anonymous list here). $result .= $courses_list_string; } if ($category != '') { $result .= '

' .Display:: return_icon('back.png', get_lang('BackToHomePage')) .get_lang('BackToHomePage').'

'; } return $result; } /** * retrieves all the courses that the user has already subscribed to * @author Patrick Cool , Ghent University, Belgium * @param int $user_id : the id of the user * @return array an array containing all the information of the courses of the given user */ public function get_courses_of_user($user_id) { $table_course = Database::get_main_table(TABLE_MAIN_COURSE); $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); // Secondly we select the courses that are in a category (user_course_cat <> 0) // and sort these according to the sort of the category $user_id = intval($user_id); $sql = "SELECT course.code k, course.visual_code vc, course.subscribe subscr, course.unsubscribe unsubscr, course.title i, course.tutor_name t, course.directory dir, course_rel_user.status status, course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat FROM $table_course course, $table_course_user course_rel_user WHERE course.id = course_rel_user.c_id AND course_rel_user.user_id = '".$user_id."' AND course_rel_user.relation_type <> ".COURSE_RELATION_TYPE_RRHH." ORDER BY course_rel_user.sort ASC"; $result = Database::query($sql); $courses = array(); while ($row = Database::fetch_array($result)) { // We only need the database name of the course. $courses[$row['k']] = array( 'code' => $row['k'], 'visual_code' => $row['vc'], 'title' => $row['i'], 'directory' => $row['dir'], 'status' => $row['status'], 'tutor' => $row['t'], 'subscribe' => $row['subscr'], 'unsubscribe' => $row['unsubscr'], 'sort' => $row['sort'], 'user_course_category' => $row['user_course_cat'] ); } return $courses; } /** * @todo use the template system * @param $title * @param $content * @param string $id * @param array $params * @param string $idAccordion * @param string $idCollapse * @return string */ public function show_right_block( $title, $content, $id = '', $params = [], $idAccordion = '', $idCollapse = '' ) { $html = ''; if (!empty($idAccordion)) { $html .= '
'; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'.$content.'
'; $html .= '
'; } else { if (!empty($id)) { $params['id'] = $id; } $params['class'] = 'panel panel-default'; $html = null; if (!empty($title)) { $html .= '
'.$title.'
'; } $html .= '
'.$content.'
'; $html = Display::div($html, $params); } return $html; } /** * @todo use FormValidator * @return string */ public function return_search_block() { $html = ''; if (api_get_setting('search_enabled') == 'true') { $search_btn = get_lang('Search'); $search_content = '
'; $html .= self::show_right_block(get_lang('Search'), $search_content, 'search_block'); } return $html; } /** * @return string */ public function return_classes_block() { if (api_get_setting('show_groups_to_users') !== 'true') { return ''; } $usergroup = new UserGroup(); $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id()); $items = []; if (!empty($usergroup_list)) { foreach ($usergroup_list as $group_id) { $data = $usergroup->get($group_id); $items[] = [ 'link' => api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id'], 'title' => $data['name'] ]; } } if (api_is_platform_admin()) { $items[] = [ 'link' => api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add', 'title' => get_lang('AddClasses') ]; } $html = self::show_right_block( get_lang('Classes'), self::returnRightBlockItems($items), 'classes_block' ); return $html; } /** * @return string */ public function return_user_image_block() { $html = ''; if (!api_is_anonymous()) { $userPicture = UserManager::getUserPicture(api_get_user_id(), USER_IMAGE_SIZE_ORIGINAL); $content = null; if (api_get_setting('allow_social_tool') == 'true') { $content .= ' '; } else { $content .= ' '; } $html = self::show_right_block( null, $content, 'user_image_block', array('style' => 'text-align:center;') ); } return $html; } /** * @return array */ public function return_profile_block() { $userInfo = api_get_user_info(); $userId = api_get_user_id(); if (empty($userId)) { return; } $items = []; $userGroup = new UserGroup(); // @todo Add a platform setting to add the user image. if (api_get_setting('allow_message_tool') == 'true') { // New messages. $number_of_new_messages = MessageManager::getCountNewMessages(); // New contact invitations. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id( $userId ); // New group invitations sent by a moderator. $group_pending_invitations = $userGroup->get_groups_by_user( $userId, GROUP_USER_PERMISSION_PENDING_INVITATION, false ); $group_pending_invitations = count($group_pending_invitations); $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations; $cant_msg = Display::badge($number_of_new_messages); $link = ''; if (api_get_setting('allow_social_tool') == 'true') { $link = '?f=social'; } $items[] = [ 'class' => 'inbox-message-social', 'icon' => Display::return_icon('inbox.png', get_lang('Inbox')), 'link' => api_get_path(WEB_PATH).'main/messages/inbox.php'.$link, 'title' => get_lang('Inbox').$cant_msg ]; $items[] = [ 'class' => 'new-message-social', 'icon' => Display::return_icon('new-message.png', get_lang('Compose')), 'link' => api_get_path(WEB_PATH).'main/messages/new_message.php'.$link, 'title' => get_lang('Compose') ]; if (api_get_setting('allow_social_tool') == 'true') { $total_invitations = Display::badge($total_invitations); $items[] = [ 'class' => 'invitations-social', 'icon' => Display::return_icon('invitations.png', get_lang('PendingInvitations')), 'link' => api_get_path(WEB_PATH).'main/social/invitations.php', 'title' => get_lang('PendingInvitations').$total_invitations ]; } if (api_get_configuration_value('allow_my_files_link_in_homepage')) { if (api_get_setting('allow_my_files') !== 'false') { $items[] = [ 'class' => 'myfiles-social', 'icon' => Display::return_icon('sn-files.png', get_lang('Files')), 'link' => api_get_path(WEB_PATH).'main/social/myfiles.php', 'title' => get_lang('MyFiles') ]; } } } $items[] = [ 'class' => 'profile-social', 'icon' => Display::return_icon('edit-profile.png', get_lang('EditProfile')), 'link' => Display::getProfileEditionLink($userId), 'title' => get_lang('EditProfile') ]; if (api_get_configuration_value('show_link_request_hrm_user') && api_is_drh() ) { $label = get_lang('RequestLinkingToUser'); $items[] = [ 'icon' => Display::return_icon('new_group.png', $label), 'link' => api_get_path(WEB_CODE_PATH).'social/require_user_linking.php', 'title' => $label ]; } if (bbb::showGlobalConferenceLink($userInfo)) { $bbb = new bbb('', '', true, api_get_user_id()); $url = $bbb->getListingUrl(); $items[] = [ 'class' => 'video-conference', 'icon' => Display::return_icon( 'bbb.png', get_lang('VideoConference') ), 'link' => $url, 'title' => get_lang('VideoConference') ]; } return $items; } /** * @return array */ public function return_navigation_links() { $items = []; // Deleting the myprofile link. if (api_get_setting('allow_social_tool') == 'true') { unset($this->tpl->menu_navigation['myprofile']); } $hideMenu = api_get_configuration_value('hide_main_navigation_menu'); if ($hideMenu === true) { return ''; } // Main navigation section. // Tabs that are deactivated are added here. if (!empty($this->tpl->menu_navigation)) { //$content = '