legal.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use \ChamiloSession as Session;
  4. $cidReset = true;
  5. ////require_once '../inc/global.inc.php';
  6. $this_section = SECTION_COURSES;
  7. $course_code = isset($_REQUEST['course_code']) ? $_REQUEST['course_code'] : null;
  8. $session_id = isset($_REQUEST['session_id']) ? intval($_REQUEST['session_id']) : null;
  9. $user_id = api_get_user_id();
  10. if (empty($course_code)) {
  11. api_not_allowed();
  12. }
  13. $course_info = CourseManager::get_course_information($course_code);
  14. $course_legal = $course_info['legal'];
  15. $enabled = api_get_plugin_setting('courselegal', 'tool_enable');
  16. $pluginExtra = null;
  17. $pluginLegal = false;
  18. if ($enabled == 'true') {
  19. $pluginLegal = true;
  20. require_once api_get_path(SYS_PLUGIN_PATH).'courselegal/config.php';
  21. $plugin = CourseLegalPlugin::create();
  22. $data = $plugin->getData($course_info['real_id'], $session_id);
  23. if (!empty($data)) {
  24. $course_legal = $data['content'];
  25. }
  26. $userData = $plugin->getUserAcceptedLegal(
  27. $user_id,
  28. $course_info['real_id'],
  29. $session_id
  30. );
  31. if (isset($_GET['web_agreement_link'])) {
  32. $plugin->saveUserMailLegal(
  33. $_GET['web_agreement_link'],
  34. $user_id,
  35. $course_info['real_id'],
  36. $session_id
  37. );
  38. }
  39. }
  40. // Build the form
  41. $form = new FormValidator('legal', 'GET', api_get_self().'?course_code='.$course_code.'&session_id='.$session_id);
  42. $pluginMessage = null;
  43. $hideForm = false;
  44. if ($pluginLegal && isset($userData) && !empty($userData)) {
  45. if ($userData['web_agreement'] == 1) {
  46. if (empty($userData['mail_agreement'])) {
  47. $pluginMessage = Display::return_message(
  48. $plugin->get_lang('YouNeedToConfirmYourAgreementCheckYourEmail')
  49. );
  50. $hideForm = true;
  51. }
  52. }
  53. }
  54. $form->addElement('header', get_lang('CourseLegalAgreement'));
  55. $form->addElement('label', null, $course_legal);
  56. if ($pluginLegal && !empty($plugin)) {
  57. $form->addElement('label', null, $plugin->getCurrentFile($course_info['real_id'], $session_id));
  58. }
  59. $form->addElement('hidden', 'course_code', $course_code);
  60. $form->addElement('hidden', 'session_id', $session_id);
  61. $form->addElement('checkbox', 'accept_legal', null, get_lang('AcceptLegal'));
  62. $form->addButtonSave(get_lang('Accept'));
  63. $variable = 'accept_legal_'.$user_id.'_'.$course_info['real_id'].'_'.$session_id;
  64. $url = api_get_course_url($course_code, $session_id);
  65. if ($form->validate()) {
  66. $accept_legal = $form->exportValue('accept_legal');
  67. if ($accept_legal == 1) {
  68. CourseManager::save_user_legal($user_id, $course_code, $session_id);
  69. if (api_check_user_access_to_legal($course_info['visibility'])) {
  70. Session::write($variable, true);
  71. }
  72. if ($pluginLegal) {
  73. header('Location:' .$url);
  74. exit;
  75. }
  76. }
  77. }
  78. $user_pass_open_course = false;
  79. if (api_check_user_access_to_legal($course_info['visibility']) && Session::read($variable)) {
  80. $user_pass_open_course = true;
  81. }
  82. if (empty($session_id)) {
  83. if (CourseManager::is_user_subscribed_in_course($user_id, $course_code) ||
  84. api_check_user_access_to_legal($course_info['visibility'])
  85. ) {
  86. $user_accepted_legal = CourseManager::is_user_accepted_legal(
  87. $user_id,
  88. $course_code
  89. );
  90. if ($user_accepted_legal || $user_pass_open_course) {
  91. //Redirect to course home
  92. header('Location: '.$url);
  93. exit;
  94. }
  95. } else {
  96. api_not_allowed();
  97. }
  98. } else {
  99. if (api_is_platform_admin()) {
  100. header('Location: '.$url);
  101. }
  102. $userStatus = SessionManager::get_user_status_in_session($user_id, $course_info['real_id'], $session_id);
  103. if (isset($userStatus) || api_check_user_access_to_legal($course_info['visibility'])) {
  104. $user_accepted_legal = CourseManager::is_user_accepted_legal(
  105. $user_id,
  106. $course_code,
  107. $session_id
  108. );
  109. if ($user_accepted_legal || $user_pass_open_course) {
  110. // Redirect to course session home.
  111. header('Location: '.$url);
  112. exit;
  113. }
  114. } else {
  115. api_not_allowed();
  116. }
  117. }
  118. Display :: display_header();
  119. echo $pluginMessage;
  120. if ($hideForm == false) {
  121. $form->display();
  122. }
  123. Display :: display_footer();