123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- use \ChamiloSession as Session;
- // Language files that need to be included
- $language_file = array('create_course', 'course_info', 'admin');
- $cidReset = true;
- require_once '../inc/global.inc.php';
- $this_section = SECTION_COURSES;
- $course_code = isset($_REQUEST['course_code']) ? $_REQUEST['course_code'] : null;
- $session_id = isset($_REQUEST['session_id']) ? intval($_REQUEST['session_id']) : null;
- $user_id = api_get_user_id();
- if (empty($course_code)) {
- api_not_allowed();
- }
- $course_info = CourseManager::get_course_information($course_code);
- $courseId = $course_info['real_id'];
- $course_legal = $course_info['legal'];
- // Build the form
- $form = new FormValidator('legal', 'GET', api_get_self().'?course_code='.$course_code.'&session_id='.$session_id);
- $form->addElement('header', get_lang('CourseLegalAgreement'));
- $form->addElement('label', null, $course_legal);
- $form->addElement('hidden', 'course_code', $course_code);
- $form->addElement('hidden', 'session_id', $session_id);
- $form->addElement('checkbox', 'accept_legal', null, get_lang('AcceptLegal'));
- $form->addElement('style_submit_button', null, get_lang('Accept'), 'class="save"');
- $variable = 'accept_legal_'.$user_id.'_'.$course_info['real_id'].'_'.$session_id;
- if ($form->validate()) {
- $accept_legal = $form->exportValue('accept_legal');
- if ($accept_legal == 1) {
- CourseManager::save_user_legal($user_id, $course_info, $session_id);
- if (api_check_user_access_to_legal($course_info['visibility'])) {
- Session::write($variable, true);
- }
- }
- }
- $user_pass_open_course = false;
- if (api_check_user_access_to_legal($course_info['visibility']) && Session::read($variable)) {
- $user_pass_open_course = true;
- }
- $url = api_get_course_url($course_code, $session_id);
- if (empty($session_id)) {
- if (CourseManager::is_user_subscribed_in_course($user_id, $courseId) || api_check_user_access_to_legal($course_info['visibility'])) {
- $user_accepted_legal = CourseManager::is_user_accepted_legal($user_id, $course_info);
- if ($user_accepted_legal || $user_pass_open_course) {
- //Redirect to course home
- header('Location: '.$url);
- exit;
- }
- } else {
- api_not_allowed();
- }
- } else {
- if (api_is_platform_admin()) {
- header('Location: '.$url);
- }
- $user_session_status = SessionManager::get_user_status_in_course_session($user_id, $courseId, $session_id);
- if (isset($user_session_status) || api_check_user_access_to_legal($course_info['visibility'])) {
- $user_accepted_legal = CourseManager::is_user_accepted_legal($user_id, $course_info, $session_id);
- if ($user_accepted_legal || $user_pass_open_course) {
- //Redirect to course session home
- header('Location: '.$url);
- exit;
- }
- } else {
- api_not_allowed();
- }
- }
- Display :: display_header($nameTools);
- $form->display();
- Display :: display_footer();
|