PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/main/course_home/course_home.php

https://bitbucket.org/hanutimes/hanutimes
PHP | 256 lines | 168 code | 30 blank | 58 comment | 54 complexity | 0bbc7184b9a123cbb79e1c30f10a0475 MD5 | raw file
  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[$session_key] = true;
  101. header("Location: $url");
  102. exit;
  103. }
  104. }
  105. } else {
  106. $table = Database::get_course_table(TABLE_QUIZ_TEST);
  107. $course_id = api_get_course_int_id();
  108. $condition = '';
  109. if (!empty($session_id)) {
  110. $condition = api_get_session_condition($session_id);
  111. $sql = "SELECT iid FROM $table WHERE c_id = $course_id AND autolaunch = 1 $condition LIMIT 1";
  112. $result = Database::query($sql);
  113. //If we found nothing in the session we just called the session_id = 0 autolaunch
  114. if (Database::num_rows($result) == 0) {
  115. $condition = '';
  116. } else {
  117. //great, there is an specific auto lunch for this session we leave the $condition
  118. }
  119. }
  120. $sql = "SELECT iid FROM $table WHERE c_id = $course_id AND autolaunch = 1 $condition LIMIT 1";
  121. $result = Database::query($sql);
  122. if (Database::num_rows($result) > 0) {
  123. $data = Database::fetch_array($result,'ASSOC');
  124. if (!empty($data['iid'])) {
  125. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  126. $show_autolaunch_exercise_warning = true;
  127. } else {
  128. $session_key = 'exercise_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  129. if (!isset($_SESSION[$session_key])) {
  130. //redirecting to the LP
  131. $url = api_get_path(WEB_CODE_PATH).'exercice/overview.php?'.api_get_cidreq().'&exerciseId='.$data['iid'];
  132. $_SESSION[$session_key] = true;
  133. header("Location: $url");
  134. exit;
  135. }
  136. }
  137. }
  138. }
  139. }
  140. }
  141. /* Auto launch code */
  142. $show_autolaunch_lp_warning = false;
  143. $auto_launch = api_get_course_setting('enable_lp_auto_launch');
  144. if (!empty($auto_launch)) {
  145. $session_id = api_get_session_id();
  146. //LP list
  147. if ($auto_launch == 2) {
  148. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  149. $show_autolaunch_lp_warning = true;
  150. } else {
  151. $session_key = 'lp_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  152. if (!isset($_SESSION[$session_key])) {
  153. //redirecting to the LP
  154. $url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq().'&id_session='.$session_id;
  155. $_SESSION[$session_key] = true;
  156. header("Location: $url");
  157. exit;
  158. }
  159. }
  160. } else {
  161. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  162. $course_id = api_get_course_int_id();
  163. $condition = '';
  164. if (!empty($session_id)) {
  165. $condition = api_get_session_condition($session_id);
  166. $sql = "SELECT id FROM $lp_table WHERE c_id = $course_id AND autolunch = 1 $condition LIMIT 1";
  167. $result = Database::query($sql);
  168. //If we found nothing in the session we just called the session_id = 0 autolunch
  169. if (Database::num_rows($result) == 0) {
  170. $condition = '';
  171. } else {
  172. //great, there is an specific auto lunch for this session we leave the $condition
  173. }
  174. }
  175. $sql = "SELECT id FROM $lp_table WHERE c_id = $course_id AND autolunch = 1 $condition LIMIT 1";
  176. $result = Database::query($sql);
  177. if (Database::num_rows($result) > 0) {
  178. $lp_data = Database::fetch_array($result,'ASSOC');
  179. if (!empty($lp_data['id'])) {
  180. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  181. $show_autolaunch_lp_warning = true;
  182. } else {
  183. $session_key = 'lp_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  184. if (!isset($_SESSION[$session_key])) {
  185. //redirecting to the LP
  186. $url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$lp_data['id'];
  187. $_SESSION[$session_key] = true;
  188. header("Location: $url");
  189. exit;
  190. }
  191. }
  192. }
  193. }
  194. }
  195. }
  196. $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  197. $temps = time();
  198. $reqdate = "&reqdate=$temps";
  199. /* MAIN CODE */
  200. /* Introduction section (editable by course admins) */
  201. $content = Display::return_introduction_section(TOOL_COURSE_HOMEPAGE, array(
  202. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
  203. 'CreateDocumentDir' => 'document/',
  204. 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/'
  205. ));
  206. /* SWITCH TO A DIFFERENT HOMEPAGE VIEW
  207. the setting homepage_view is adjustable through
  208. the platform administration section */
  209. if ($show_autolaunch_lp_warning) {
  210. $show_message .= Display::return_message(get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP'),'warning');
  211. }
  212. if ($show_autolaunch_exercise_warning) {
  213. $show_message .= Display::return_message(get_lang('TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificExercise'),'warning');
  214. }
  215. if (api_get_setting('homepage_view') == 'activity' || api_get_setting('homepage_view') == 'activity_big') {
  216. require 'activity.php';
  217. } elseif (api_get_setting('homepage_view') == '2column') {
  218. require '2column.php';
  219. } elseif (api_get_setting('homepage_view') == '3column') {
  220. require '3column.php';
  221. } elseif (api_get_setting('homepage_view') == 'vertical_activity') {
  222. require 'vertical_activity.php';
  223. }
  224. $content = '<div id="course_tools">'.$content.'</div>';
  225. Session::erase('_gid');
  226. return array('content' => $content, 'message' => $show_message);