course_home.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. HOME PAGE FOR EACH COURSE
  5. *
  6. * This page, included in every course's index.php is the home
  7. * page. To make administration simple, the teacher edits his
  8. * course from the home page. Only the login detects that the
  9. * visitor is allowed to activate, deactivate home page links,
  10. * access to the teachers tools (statistics, edit forums...).
  11. *
  12. * Edit visibility of tools
  13. *
  14. * visibility = 1 - everybody
  15. * visibility = 0 - course admin (teacher) and platform admin
  16. *
  17. * Who can change visibility ?
  18. *
  19. * admin = 0 - course admin (teacher) and platform admin
  20. * admin = 1 - platform admin
  21. *
  22. * Show message to confirm that a tools must be hide from available tools
  23. *
  24. * visibility 0,1
  25. *
  26. *
  27. * @package chamilo.course_home
  28. */
  29. /* INIT SECTION */
  30. use \ChamiloSession as Session;
  31. // Name of the language file that needs to be included.
  32. $language_file = array('course_home','courses');
  33. $use_anonymous = true;
  34. // Including the global initialization file.
  35. require_once dirname(__FILE__).'/../inc/global.inc.php';
  36. // Delete LP sessions - commented out after seeing that normal
  37. // users in their first learnpath step (1st SCO of a SCORM)
  38. // cannot have their data saved if they "Return to course homepage"
  39. // before any LMSFinish()
  40. //unset($_SESSION['oLP']);
  41. //unset($_SESSION['lpobject']);
  42. // The section for the tabs
  43. $this_section = SECTION_COURSES;
  44. /* Constants */
  45. define('TOOL_PUBLIC', 'Public');
  46. define('TOOL_PUBLIC_BUT_HIDDEN', 'PublicButHide');
  47. define('TOOL_COURSE_ADMIN', 'courseAdmin');
  48. define('TOOL_PLATFORM_ADMIN', 'platformAdmin');
  49. define('TOOL_AUTHORING', 'toolauthoring');
  50. define('TOOL_INTERACTION', 'toolinteraction');
  51. define('TOOL_COURSE_PLUGIN', 'toolcourseplugin'); //all plugins that can be enabled in courses
  52. define('TOOL_ADMIN', 'tooladmin');
  53. define('TOOL_ADMIN_PLATFORM', 'tooladminplatform');
  54. define('TOOL_STUDENT_VIEW', 'toolstudentview');
  55. define('TOOL_ADMIN_VISIBLE', 'tooladminvisible');
  56. $user_id = api_get_user_id();
  57. $show_message = '';
  58. //Deleting group session
  59. Session::erase('toolgroup');
  60. Session::erase('_gid');
  61. $is_specialcourse = CourseManager::is_special_course($course_code);
  62. if ($is_specialcourse) {
  63. $autoreg = isset($_GET['autoreg']) ? Security::remove_XSS($_GET['autoreg']) : null;
  64. if ($autoreg == 1) {
  65. CourseManager::subscribe_user($user_id, $course_code, $status = STUDENT);
  66. }
  67. }
  68. if (isset($_GET['action']) && $_GET['action'] == 'subscribe') {
  69. if (Security::check_token('get')) {
  70. Security::clear_token();
  71. $auth = new AuthLib();
  72. $msg = $auth->subscribe_user($course_code);
  73. if (!empty($msg)) {
  74. $show_message .= Display::return_message(get_lang($msg));
  75. }
  76. }
  77. }
  78. /* Is the user allowed here? */
  79. api_protect_course_script(true);
  80. /* STATISTICS */
  81. if (!isset($coursesAlreadyVisited[$course_code])) {
  82. event_access_course();
  83. $coursesAlreadyVisited[$course_code] = 1;
  84. Session::write('coursesAlreadyVisited', $coursesAlreadyVisited);
  85. }
  86. $show_autolaunch_exercise_warning = false;
  87. // Exercise auto-launch
  88. $auto_launch = api_get_course_setting('enable_exercise_auto_launch');
  89. if (!empty($auto_launch)) {
  90. $session_id = api_get_session_id();
  91. //Exercise list
  92. if ($auto_launch == 2) {
  93. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  94. $show_autolaunch_exercise_warning = true;
  95. } else {
  96. $session_key = 'exercise_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  97. if (!isset($_SESSION[$session_key])) {
  98. //redirecting to the Exercise
  99. $url = api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&id_session='.$session_id;
  100. Session::write($session_key, true);
  101. //$_SESSION[$session_key] = true;
  102. header("Location: $url");
  103. exit;
  104. }
  105. }
  106. } else {
  107. $table = Database::get_course_table(TABLE_QUIZ_TEST);
  108. $course_id = api_get_course_int_id();
  109. $condition = '';
  110. if (!empty($session_id)) {
  111. $condition = api_get_session_condition($session_id);
  112. $sql = "SELECT iid FROM $table WHERE c_id = $course_id AND autolaunch = 1 $condition LIMIT 1";
  113. $result = Database::query($sql);
  114. //If we found nothing in the session we just called the session_id = 0 autolaunch
  115. if (Database::num_rows($result) == 0) {
  116. $condition = '';
  117. } else {
  118. //great, there is an specific auto lunch for this session we leave the $condition
  119. }
  120. }
  121. $sql = "SELECT iid FROM $table WHERE c_id = $course_id AND autolaunch = 1 $condition LIMIT 1";
  122. $result = Database::query($sql);
  123. if (Database::num_rows($result) > 0) {
  124. $data = Database::fetch_array($result,'ASSOC');
  125. if (!empty($data['iid'])) {
  126. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  127. $show_autolaunch_exercise_warning = true;
  128. } else {
  129. $session_key = 'exercise_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  130. if (!isset($_SESSION[$session_key])) {
  131. //redirecting to the LP
  132. $url = api_get_path(WEB_CODE_PATH).'exercice/overview.php?'.api_get_cidreq().'&exerciseId='.$data['iid'];
  133. //$_SESSION[$session_key] = true;
  134. Session::write($session_key, true);
  135. header("Location: $url");
  136. exit;
  137. }
  138. }
  139. }
  140. }
  141. }
  142. }
  143. /* Auto launch code */
  144. $show_autolaunch_lp_warning = false;
  145. $auto_launch = api_get_course_setting('enable_lp_auto_launch');
  146. if (!empty($auto_launch)) {
  147. $session_id = api_get_session_id();
  148. //LP list
  149. if ($auto_launch == 2) {
  150. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  151. $show_autolaunch_lp_warning = true;
  152. } else {
  153. $session_key = 'lp_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  154. if (!isset($_SESSION[$session_key])) {
  155. //redirecting to the LP
  156. $url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq().'&id_session='.$session_id;
  157. //$_SESSION[$session_key] = true;
  158. Session::write($session_key, true);
  159. header("Location: $url");
  160. exit;
  161. }
  162. }
  163. } else {
  164. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  165. $course_id = api_get_course_int_id();
  166. $condition = '';
  167. if (!empty($session_id)) {
  168. $condition = api_get_session_condition($session_id);
  169. $sql = "SELECT id FROM $lp_table WHERE c_id = $course_id AND autolunch = 1 $condition LIMIT 1";
  170. $result = Database::query($sql);
  171. //If we found nothing in the session we just called the session_id = 0 autolunch
  172. if (Database::num_rows($result) == 0) {
  173. $condition = '';
  174. } else {
  175. //great, there is an specific auto lunch for this session we leave the $condition
  176. }
  177. }
  178. $sql = "SELECT id FROM $lp_table WHERE c_id = $course_id AND autolunch = 1 $condition LIMIT 1";
  179. $result = Database::query($sql);
  180. if (Database::num_rows($result) > 0) {
  181. $lp_data = Database::fetch_array($result,'ASSOC');
  182. if (!empty($lp_data['id'])) {
  183. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  184. $show_autolaunch_lp_warning = true;
  185. } else {
  186. $session_key = 'lp_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  187. if (!isset($_SESSION[$session_key])) {
  188. //redirecting to the LP
  189. $url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$lp_data['id'];
  190. //$_SESSION[$session_key] = true;
  191. Session::write($session_key, true);
  192. header("Location: $url");
  193. exit;
  194. }
  195. }
  196. }
  197. }
  198. }
  199. }
  200. $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  201. $temps = time();
  202. $reqdate = "&reqdate=$temps";
  203. /* MAIN CODE */
  204. /* Introduction section (editable by course admins) */
  205. $content = Display::return_introduction_section(TOOL_COURSE_HOMEPAGE, array(
  206. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
  207. 'CreateDocumentDir' => 'document/',
  208. 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/'
  209. ));
  210. /* SWITCH TO A DIFFERENT HOMEPAGE VIEW
  211. the setting homepage_view is adjustable through
  212. the platform administration section */
  213. if ($show_autolaunch_lp_warning) {
  214. $show_message .= Display::return_message(get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP'),'warning');
  215. }
  216. if ($show_autolaunch_exercise_warning) {
  217. $show_message .= Display::return_message(get_lang('TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificExercise'),'warning');
  218. }
  219. if (api_get_setting('homepage_view') == 'activity' || api_get_setting('homepage_view') == 'activity_big') {
  220. require 'activity.php';
  221. } elseif (api_get_setting('homepage_view') == '2column') {
  222. require '2column.php';
  223. } elseif (api_get_setting('homepage_view') == '3column') {
  224. require '3column.php';
  225. } elseif (api_get_setting('homepage_view') == 'vertical_activity') {
  226. require 'vertical_activity.php';
  227. }
  228. $content = '<div id="course_tools">'.$content.'</div>';
  229. Session::erase('_gid');
  230. return array('content' => $content, 'message' => $show_message);