legal.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. use \ChamiloSession as Session;
  3. // Language files that need to be included
  4. $language_file = array('create_course', 'course_info', 'admin');
  5. $cidReset = true;
  6. require_once '../inc/global.inc.php';
  7. $this_section = SECTION_COURSES;
  8. $course_code = isset($_REQUEST['course_code']) ? $_REQUEST['course_code'] : null;
  9. $session_id = isset($_REQUEST['session_id']) ? intval($_REQUEST['session_id']) : null;
  10. $user_id = api_get_user_id();
  11. if (empty($course_code)) {
  12. api_not_allowed();
  13. }
  14. $course_info = CourseManager::get_course_information($course_code);
  15. $courseId = $course_info['real_id'];
  16. $course_legal = $course_info['legal'];
  17. // Build the form
  18. $form = new FormValidator('legal', 'GET', api_get_self().'?course_code='.$course_code.'&session_id='.$session_id);
  19. $form->addElement('header', get_lang('CourseLegalAgreement'));
  20. $form->addElement('label', null, $course_legal);
  21. $form->addElement('hidden', 'course_code', $course_code);
  22. $form->addElement('hidden', 'session_id', $session_id);
  23. $form->addElement('checkbox', 'accept_legal', null, get_lang('AcceptLegal'));
  24. $form->addElement('style_submit_button', null, get_lang('Accept'), 'class="save"');
  25. $variable = 'accept_legal_'.$user_id.'_'.$course_info['real_id'].'_'.$session_id;
  26. if ($form->validate()) {
  27. $accept_legal = $form->exportValue('accept_legal');
  28. if ($accept_legal == 1) {
  29. CourseManager::save_user_legal($user_id, $course_info, $session_id);
  30. if (api_check_user_access_to_legal($course_info['visibility'])) {
  31. Session::write($variable, true);
  32. }
  33. }
  34. }
  35. $user_pass_open_course = false;
  36. if (api_check_user_access_to_legal($course_info['visibility']) && Session::read($variable)) {
  37. $user_pass_open_course = true;
  38. }
  39. $url = api_get_course_url($course_code, $session_id);
  40. if (empty($session_id)) {
  41. if (CourseManager::is_user_subscribed_in_course($user_id, $courseId) || api_check_user_access_to_legal($course_info['visibility'])) {
  42. $user_accepted_legal = CourseManager::is_user_accepted_legal($user_id, $course_info);
  43. if ($user_accepted_legal || $user_pass_open_course) {
  44. //Redirect to course home
  45. header('Location: '.$url);
  46. exit;
  47. }
  48. } else {
  49. api_not_allowed();
  50. }
  51. } else {
  52. if (api_is_platform_admin()) {
  53. header('Location: '.$url);
  54. }
  55. $user_session_status = SessionManager::get_user_status_in_course_session($user_id, $courseId, $session_id);
  56. if (isset($user_session_status) || api_check_user_access_to_legal($course_info['visibility'])) {
  57. $user_accepted_legal = CourseManager::is_user_accepted_legal($user_id, $course_info, $session_id);
  58. if ($user_accepted_legal || $user_pass_open_course) {
  59. //Redirect to course session home
  60. header('Location: '.$url);
  61. exit;
  62. }
  63. } else {
  64. api_not_allowed();
  65. }
  66. }
  67. Display :: display_header($nameTools);
  68. $form->display();
  69. Display :: display_footer();