diff --git a/index.php b/index.php index 0ed26c2a58..e1e40e6e73 100755 --- a/index.php +++ b/index.php @@ -149,6 +149,20 @@ if (!isset($_REQUEST['include'])) { } } $announcements_block = $controller->return_announcements(); + + if (api_get_configuration_value('course_catalog_display_in_home') + && ('true' === api_get_setting('course_catalog_published') || !api_is_anonymous()) + ) { + $userCanViewPage = CoursesAndSessionsCatalog::userCanView(); + + if (CoursesAndSessionsCatalog::is(CATALOG_SESSIONS)) { + $announcements_block .= $userCanViewPage ? CoursesAndSessionsCatalog::sessionList(true) : ''; + } else { + $announcements_block .= $userCanViewPage + ? CoursesAndSessionsCatalog::displayCoursesList('display_courses', '', '', true) + : ''; + } + } } if (api_get_configuration_value('show_hot_sessions') === true) { $hotSessions = SessionManager::getHotSessions(); diff --git a/main/inc/lib/CoursesAndSessionsCatalog.class.php b/main/inc/lib/CoursesAndSessionsCatalog.class.php index 3cb6670cde..49d64ad381 100644 --- a/main/inc/lib/CoursesAndSessionsCatalog.class.php +++ b/main/inc/lib/CoursesAndSessionsCatalog.class.php @@ -1136,8 +1136,9 @@ class CoursesAndSessionsCatalog return Display::url( Display::returnFontAwesomeIcon('check').' '.$title, - api_get_self().'?action='.$action.'&sec_token='.$stok. - '&course_code='.$course['code'].'&search_term='.$search_term.'&category_code='.$categoryCode, + api_get_path(WEB_CODE_PATH).'auth/courses.php' + .'?action='.$action.'&sec_token='.$stok + .'&course_code='.$course['code'].'&search_term='.$search_term.'&category_code='.$categoryCode, ['class' => 'btn btn-success btn-sm', 'title' => $title, 'aria-label' => $title] ); } @@ -1160,7 +1161,8 @@ class CoursesAndSessionsCatalog $categoryCode = Security::remove_XSS($categoryCode); $sessionId = (int) $sessionId; - $url = api_get_self().'?action=unsubscribe&sec_token='.$stok.'&sid='.$sessionId.'&course_code='.$course['code']. + $url = api_get_path(WEB_CODE_PATH).'auth/courses.php' + .'?action=unsubscribe&sec_token='.$stok.'&sid='.$sessionId.'&course_code='.$course['code']. '&search_term='.$search_term.'&category_code='.$categoryCode; return Display::url( @@ -1326,7 +1328,7 @@ class CoursesAndSessionsCatalog /** * Return Session catalog rendered view. */ - public static function sessionList() + public static function sessionList(bool $returnHtml = false): ?string { $date = $_POST['date'] ?? ''; $limit = self::getLimitArray(); @@ -1363,8 +1365,14 @@ class CoursesAndSessionsCatalog $tpl->get_template('catalog/session_catalog.tpl') ); + if ($returnHtml) { + return $templateContent; + } + $tpl->assign('content', $templateContent); $tpl->display_one_col_template(); + + return null; } /** @@ -1442,7 +1450,7 @@ class CoursesAndSessionsCatalog $headers = []; if (self::showCourses()) { $headers[] = [ - 'url' => api_get_self(), + 'url' => api_get_path(WEB_CODE_PATH).'auth/courses.php', 'content' => get_lang('CourseManagement'), ]; } @@ -1830,7 +1838,7 @@ class CoursesAndSessionsCatalog $categoryCode = !empty($categoryCode) ? Security::remove_XSS($categoryCode) : 'ALL'; // Start URL with params - $pageUrl = api_get_self(). + $pageUrl = api_get_path(WEB_CODE_PATH).'auth/courses.php'. '?action='.$action. '&search_term='.$searchTerm. '&keyword='.$keyword. @@ -1880,7 +1888,7 @@ class CoursesAndSessionsCatalog } if ('course_home' !== $redirectAfterSubscription) { - return api_get_self(); + return api_get_path(WEB_CODE_PATH).'auth/courses.php'; } if (api_get_configuration_value('catalog_course_subscription_in_user_s_session')) { @@ -1897,8 +1905,12 @@ class CoursesAndSessionsCatalog /** * @throws Exception */ - public static function displayCoursesList(string $action, string $searchTerm, string $categoryCode) - { + public static function displayCoursesList( + string $action = '', + string $searchTerm = '', + string $categoryCode = '', + bool $returnHtml = false + ): ?string { $settings = api_get_configuration_value('course_catalog_settings'); $courseCatalogSettings = [ @@ -2226,8 +2238,14 @@ class CoursesAndSessionsCatalog $template->get_template('catalog/course_catalog.tpl') ); + if ($returnHtml) { + return $templateContent; + } + $template->assign('content', $templateContent); $template->display_one_col_template(); + + return null; } public static function userCanView(): bool diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index 0cf528abce..35a3319ecd 100755 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -1649,6 +1649,9 @@ $_configuration['course_catalog_settings'] = [ ]; */ +// Display the course catalog in home page +//$_configuration['course_catalog_display_in_home'] = false; + // Page "My Courses" shows specific course extra fields (CourseManager::getExtraFieldsToBePresented) /*$_configuration['my_course_course_extrafields_to_be_presented'] = [ 'fields' => ['mots_cles', 'duree_en_min', 'format'], diff --git a/main/template/default/catalog/session_catalog.tpl b/main/template/default/catalog/session_catalog.tpl index 8e174f5d2d..d8a77d8ada 100644 --- a/main/template/default/catalog/session_catalog.tpl +++ b/main/template/default/catalog/session_catalog.tpl @@ -11,7 +11,7 @@
{% if catalog_settings.sessions.by_title %}
-
+
- +
@@ -47,7 +47,7 @@ {% if catalog_settings.sessions.by_tag %}
- +