api_get_path(WEB_CODE_PATH).'auth/courses.php', 'name' => get_lang('CourseManagement'), ]; } $interbreadcrumb[] = ['url' => '#', 'name' => $nameTools]; } $auth = new Auth(); $userId = api_get_user_id(); $currentUrl = api_get_path(WEB_CODE_PATH).'auth/courses.php?category_code='.$categoryCode.'&search_term='.$searchTerm; $content = ''; $toolTitle = get_lang('CourseCatalog'); $courseCatalogSettings = [ 'info_url' => 'course_description_popup', 'title_url' => 'course_home', 'image_url' => 'course_about', ]; $redirectAfterSubscription = 'course_home'; $settings = api_get_setting('course.course_catalog_settings', true); // By default all extra fields are shown (visible and filterable) $extraFieldsInSearchForm = []; $extraFieldsInCourseBlock = []; if (!empty($settings)) { if (isset($settings['link_settings'])) { $courseCatalogSettings = $settings['link_settings']; } if (isset($settings['redirect_after_subscription'])) { $redirectAfterSubscription = $settings['redirect_after_subscription']; } if (isset($settings['extra_fields_in_search_form'])) { $extraFieldsInSearchForm = $settings['extra_fields_in_search_form']; } if (isset($settings['extra_fields_in_course_block'])) { $extraFieldsInCourseBlock = $settings['extra_fields_in_course_block']; } } switch ($action) { case 'unsubscribe': // We are unsubscribing from a course (=Unsubscribe from course). if (!empty($_GET['sec_token']) && $ctok == $_GET['sec_token']) { $result = $auth->remove_user_from_course($_GET['course_code']); if ($result) { Display::addFlash( Display::return_message(get_lang('YouAreNowUnsubscribed')) ); } } header('Location: '.$currentUrl); exit; break; case 'subscribe_course': $courseCodeToSubscribe = isset($_GET['course_code']) ? Security::remove_XSS($_GET['course_code']) : ''; if (api_is_anonymous()) { header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php?c='.$courseCodeToSubscribe); exit; } if (Security::check_token('get')) { $courseInfo = api_get_course_info($courseCodeToSubscribe); CourseManager::autoSubscribeToCourse($courseCodeToSubscribe); if ('course_home' === $redirectAfterSubscription) { $redirectionTarget = $courseInfo['course_public_url']; if ('true' === api_get_setting('session.catalog_course_subscription_in_user_s_session')) { $user = api_get_user_entity(api_get_user_id()); if ($user) { foreach ($user->getCurrentlyAccessibleSessions() as $session) { $redirectionTarget = $redirectionTarget.'?id_session='.$session->getId(); break; } } } header('Location: '.$redirectionTarget); exit; } header('Location: '.api_get_self()); exit; } break; case 'subscribe_course_validation': $toolTitle = get_lang('Subscribe'); $courseCodeToSubscribe = isset($_GET['course_code']) ? Security::remove_XSS($_GET['course_code']) : ''; $courseInfo = api_get_course_info($courseCodeToSubscribe); if (empty($courseInfo)) { header('Location: '.api_get_self()); exit; } $message = get_lang('CourseRequiresPassword').' '; $message .= $courseInfo['title'].' ('.$courseInfo['visual_code'].') '; $action = api_get_self().'?action=subscribe_course_validation&sec_token='. Security::getTokenFromSession().'&course_code='.$courseInfo['code']; $form = new FormValidator( 'subscribe_user_with_password', 'post', $action ); $form->addHeader($message); $form->addElement('hidden', 'sec_token', Security::getTokenFromSession()); $form->addElement('hidden', 'subscribe_user_with_password', $courseInfo['code']); $form->addElement('text', 'course_registration_code'); $form->addButtonSave(get_lang('SubmitRegistrationCode')); $content = $form->returnForm(); if ($form->validate()) { if (sha1($_POST['course_registration_code']) === $courseInfo['registration_code']) { CourseManager::autoSubscribeToCourse($_POST['subscribe_user_with_password']); if ('course_home' === $redirectAfterSubscription) { $redirectionTarget = $courseInfo['course_public_url']; if ('true' === api_get_setting('session.catalog_course_subscription_in_user_s_session')) { $user = api_get_user_entity(api_get_user_id()); if ($user) { foreach ($user->getCurrentlyAccessibleSessions() as $session) { $redirectionTarget = $redirectionTarget.'?id_session='.$session->getId(); break; } } } header('Location: '.$redirectionTarget); exit; } header('Location: '.api_get_self()); exit; } else { Display::addFlash(Display::return_message(get_lang('CourseRegistrationCodeIncorrect')), 'warning'); header('Location: '.$action); exit; } } break; case 'subscribe': if (!$userCanViewPage) { api_not_allowed(true); } header('Location: '.api_get_self()); exit; break; case 'display_random_courses': case 'display_courses': case 'search_course': if (!$userCanViewPage) { api_not_allowed(true); } $settings = CoursesAndSessionsCatalog::getCatalogSearchSettings(); $form = new FormValidator('search', 'get', '', null, null, FormValidator::LAYOUT_GRID); $form->addHidden('action', 'search_course'); if (isset($settings['courses']) && true === $settings['courses']['by_title']) { $form->addText('search_term', get_lang('Title')); } $select = $form->addSelect( 'category_code', get_lang('CourseCategories'), [], ['placeholder' => get_lang('SelectAnOption')] ); $defaults = []; $listCategories = CoursesAndSessionsCatalog::getCourseCategoriesTree(); foreach ($listCategories as $category) { $countCourse = (int) $category['number_courses']; if (empty($countCourse)) { continue; } $categoryCodeItem = Security::remove_XSS($category['code']); $categoryName = Security::remove_XSS($category['name']); $level = $category['level']; $separate = ''; if ($level > 0) { $separate = str_repeat('--', $level); } $select->addOption($separate.' '.$categoryName.' ('.$countCourse.')', $categoryCodeItem); } $jqueryReadyContent = ''; if ($allowExtraFields) { $extraField = new ExtraField('course'); $onlyFields = []; $returnParams = $extraField->addElements($form, null, [], true, false, $extraFieldsInSearchForm); $jqueryReadyContent = $returnParams['jquery_ready_content']; } $sortKeySelect = $form->addSelect( 'sortKeys', get_lang('SortKeys'), CoursesAndSessionsCatalog::courseSortOptions(), ['multiple' => true] ); $sortKeys = isset($_REQUEST['sortKeys']) ? Security::remove_XSS($_REQUEST['sortKeys']) : ''; $defaults['sortKeys'] = $sortKeys; $defaults['search_term'] = $searchTerm; $defaults['category_code'] = $categoryCode; $conditions = []; $fields = []; if ('display_random_courses' === $action) { // Random value is used instead limit filter $courses = CoursesAndSessionsCatalog::getCoursesInCategory(null, 12); $countCoursesInCategory = count($courses); } else { $values = $_REQUEST; if ($allowExtraFields) { $extraResult = $extraField->processExtraFieldSearch($values, $form, 'course', 'AND'); $conditions = $extraResult['condition']; $fields = $extraResult['fields']; $defaults = $extraResult['defaults']; $defaults['sortKeys'] = $sortKeys; $defaults['search_term'] = $searchTerm; $defaults['category_code'] = $categoryCode; } $courses = CoursesAndSessionsCatalog::searchAndSortCourses( $categoryCode, $searchTerm, $limit, true, $conditions, $sortKeySelect->getValue() ); $countCoursesInCategory = CourseCategory::countCoursesInCategory( $categoryCode, $searchTerm, true, $conditions ); } $showCourses = CoursesAndSessionsCatalog::showCourses(); $showSessions = CoursesAndSessionsCatalog::showSessions(); $pageCurrent = isset($_GET['pageCurrent']) ? (int) $_GET['pageCurrent'] : 1; $pageLength = isset($_GET['pageLength']) ? (int) $_GET['pageLength'] : CoursesAndSessionsCatalog::PAGE_LENGTH; $pageTotal = (int) ceil($countCoursesInCategory / $pageLength); $url = CoursesAndSessionsCatalog::getCatalogUrl(1, $pageLength, 'ALL', 'search_course', $fields); $urlNoExtraFields = CoursesAndSessionsCatalog::getCatalogUrl(1, $pageLength, 'ALL', 'search_course'); $urlNoCategory = CoursesAndSessionsCatalog::getCatalogUrl(1, $pageLength, '', 'search_course', $fields); $urlNoCategory = str_replace('&category_code=ALL', '', $urlNoCategory); $form->setAttribute('action', $url); // getting all the courses to which the user is subscribed to $user_courses = CourseManager::getCoursesByUserCourseCategory($userId); $user_coursecodes = []; // we need only the course codes as these will be used to match against the courses of the category if ('' != $user_courses) { foreach ($user_courses as $key => $value) { $user_coursecodes[] = $value['code']; } } if (api_is_drh()) { $coursesDrh = CourseManager::get_courses_followed_by_drh($userId); foreach ($coursesDrh as $course) { $user_coursecodes[] = $course['code']; } } $catalogShowCoursesSessions = 0; $showCoursesSessions = (int) api_get_setting('catalog_show_courses_sessions'); if ($showCoursesSessions > 0) { $catalogShowCoursesSessions = $showCoursesSessions; } $catalogPagination = ''; if ($pageTotal > 1) { $catalogPagination = CoursesAndSessionsCatalog::getCatalogPagination( $pageCurrent, $pageLength, $pageTotal, $categoryCode, $action, $fields, $sortKeySelect->getValue() ); } $userInfo = api_get_user_info(); $extraDate = ''; if ($showSessions) { $extraDate = " $('#date').datepicker({ dateFormat: 'yy-mm-dd' });"; } $htmlHeadXtra[] = " "; $stok = Security::get_token(); $content = CoursesAndSessionsCatalog::getTabList(1); $content .= '