From ed7b80c7ba671c78497ec11d4fd8b62d42d8b77e Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 31 Mar 2020 14:47:17 +0200 Subject: [PATCH] Add option to redirect to course home in the catalog: Setting: course_catalog_settings.redirect_after_subscription --- main/auth/courses.php | 33 ++++++++++++++++++++--------- main/install/configuration.dist.php | 3 ++- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/main/auth/courses.php b/main/auth/courses.php index 5707bc1d7c..c28f22cbe4 100755 --- a/main/auth/courses.php +++ b/main/auth/courses.php @@ -64,6 +64,24 @@ $currentUrl = api_get_path(WEB_CODE_PATH).'auth/courses.php?category_code='.$cat $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_configuration_value('course_catalog_settings'); +if (!empty($settings)) { + if (isset($settings['link_settings'])) { + $courseCatalogSettings = $settings['link_settings']; + } + if (isset($settings['redirect_after_subscription'])) { + $redirectAfterSubscription = $settings['redirect_after_subscription']; + } +} + + switch ($action) { case 'unsubscribe': // We are unsubscribing from a course (=Unsubscribe from course). @@ -86,7 +104,12 @@ switch ($action) { } $courseCodeToSubscribe = isset($_GET['course_code']) ? Security::remove_XSS($_GET['course_code']) : ''; if (Security::check_token('get')) { + $courseInfo = api_get_course_info($courseCodeToSubscribe); CourseManager::autoSubscribeToCourse($courseCodeToSubscribe); + if ('course_home' === $redirectAfterSubscription) { + header('Location: '.$courseInfo['course_public_url']); + exit; + } header('Location: '.api_get_self()); exit; } @@ -387,16 +410,6 @@ switch ($action) { $courseUrl = api_get_path(WEB_COURSE_PATH); $hideRating = api_get_configuration_value('hide_course_rating'); - $courseCatalogSettings = [ - 'info_url' => 'course_description_popup', - 'title_url' => 'course_home', - 'image_url' => 'course_about', - ]; - - $settings = api_get_configuration_value('course_catalog_settings'); - if (!empty($settings) && isset($settings['link_settings'])) { - $courseCatalogSettings = $settings['link_settings']; - } if (!empty($courses)) { foreach ($courses as &$course) { diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index bacd2b6f16..939360dc94 100755 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -1434,7 +1434,8 @@ ALTER TABLE notification_event ADD COLUMN event_id INT NULL; 'info_url' => 'course_description_popup', // course description popup page 'title_url' => 'course_home', // Course home URL 'image_url' => 'course_about', // Course about URL - ], + ] + 'redirect_after_subscription' => 'course_home', // or 'course_catalog' to stay in the page ];*/ // KEEP THIS AT THE END