course_home.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. HOME PAGE FOR EACH COURSE
  6. *
  7. * This page, included in every course's index.php is the home
  8. * page. To make administration simple, the teacher edits his
  9. * course from the home page. Only the login detects that the
  10. * visitor is allowed to activate, deactivate home page links,
  11. * access to the teachers tools (statistics, edit forums...).
  12. *
  13. * Edit visibility of tools
  14. *
  15. * visibility = 1 - everybody
  16. * visibility = 0 - course admin (teacher) and platform admin
  17. *
  18. * Who can change visibility ?
  19. *
  20. * admin = 0 - course admin (teacher) and platform admin
  21. * admin = 1 - platform admin
  22. *
  23. * Show message to confirm that a tools must be hide from available tools
  24. *
  25. * visibility 0,1
  26. *
  27. *
  28. * @package chamilo.course_home
  29. */
  30. $use_anonymous = true;
  31. require_once __DIR__.'/../inc/global.inc.php';
  32. // Delete LP sessions - commented out after seeing that normal
  33. // users in their first learnpath step (1st SCO of a SCORM)
  34. // cannot have their data saved if they "Return to course homepage"
  35. // before any LMSFinish()
  36. //unset($_SESSION['oLP']);
  37. //unset($_SESSION['lpobject']);
  38. $htmlHeadXtra[] ='<script>
  39. /* option show/hide thematic-block */
  40. $(document).ready(function(){
  41. $("#thematic-show").click(function(){
  42. $(".btn-hide-thematic").hide();
  43. $(".btn-show-thematic").show(); //show using class
  44. $("#pross").fadeToggle(); //Not working collapse for Chrome
  45. });
  46. $("#thematic-hide").click(function(){
  47. $(".btn-show-thematic").hide(); //show using class
  48. $(".btn-hide-thematic").show();
  49. $("#pross").fadeToggle(); //Not working collapse for Chrome
  50. });
  51. });
  52. $(document).ready(function() {
  53. $(".make_visible_and_invisible").attr("href", "javascript:void(0);");
  54. $(".make_visible_and_invisible > img").click(function () {
  55. make_visible = "visible.gif";
  56. make_invisible = "invisible.gif";
  57. path_name = $(this).attr("src");
  58. list_path_name = path_name.split("/");
  59. image_link = list_path_name[list_path_name.length - 1];
  60. tool_id = $(this).attr("id");
  61. tool_info = tool_id.split("_");
  62. my_tool_id = tool_info[1];
  63. $("#id_normal_message").attr("class", "normal-message alert alert-success");
  64. $.ajax({
  65. contentType: "application/x-www-form-urlencoded",
  66. beforeSend: function(objeto) {
  67. $(".normal-message").show();
  68. $("#id_confirmation_message").hide();
  69. },
  70. type: "GET",
  71. url: "'.api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?'.api_get_cidreq().'&a=set_visibility",
  72. data: "id=" + my_tool_id + "&sent_http_request=1",
  73. success: function(data) {
  74. eval("var info=" + data);
  75. new_current_tool_image = info.image;
  76. new_current_view = "'.api_get_path(WEB_IMG_PATH).'" + info.view;
  77. //eyes
  78. $("#" + tool_id).attr("src", new_current_view);
  79. //tool
  80. $("#toolimage_" + my_tool_id).attr("src", new_current_tool_image);
  81. //clase
  82. $("#tooldesc_" + my_tool_id).attr("class", info.tclass);
  83. $("#istooldesc_" + my_tool_id).attr("class", info.tclass);
  84. if (image_link == "visible.gif") {
  85. $("#" + tool_id).attr("alt", "'.get_lang('Activate', '').'");
  86. $("#" + tool_id).attr("title", "'.get_lang('Activate', '').'");
  87. } else {
  88. $("#" + tool_id).attr("alt", "'.get_lang('Deactivate', '').'");
  89. $("#" + tool_id).attr("title", "'.get_lang('Deactivate', '').'");
  90. }
  91. if (info.message == "is_active") {
  92. message = "'.get_lang('ToolIsNowVisible', '').'";
  93. } else {
  94. message = "'.get_lang('ToolIsNowHidden', '').'";
  95. }
  96. $(".normal-message").hide();
  97. $("#id_confirmation_message").html(message);
  98. $("#id_confirmation_message").show();
  99. }
  100. });
  101. });
  102. });
  103. </script>';
  104. // The section for the tabs
  105. $this_section = SECTION_COURSES;
  106. $user_id = api_get_user_id();
  107. $course_code = api_get_course_id();
  108. $courseId = api_get_course_int_id();
  109. $sessionId = api_get_session_id();
  110. $show_message = '';
  111. if (api_is_invitee()) {
  112. $isInASession = $sessionId > 0;
  113. $isSubscribed = CourseManager::is_user_subscribed_in_course(
  114. $user_id,
  115. $course_code,
  116. $isInASession,
  117. $sessionId
  118. );
  119. if (!$isSubscribed) {
  120. api_not_allowed(true);
  121. }
  122. }
  123. //Deleting group session
  124. Session::erase('toolgroup');
  125. Session::erase('_gid');
  126. $isSpecialCourse = CourseManager::isSpecialCourse($courseId);
  127. if ($isSpecialCourse) {
  128. if (isset($_GET['autoreg'])) {
  129. $autoRegistration = Security::remove_XSS($_GET['autoreg']);
  130. if ($autoRegistration == 1) {
  131. if (CourseManager::subscribe_user($user_id, $course_code, STUDENT)) {
  132. Session::write('is_allowed_in_course', true);
  133. }
  134. }
  135. }
  136. }
  137. if (isset($_GET['action']) && $_GET['action'] == 'subscribe') {
  138. if (Security::check_token('get')) {
  139. Security::clear_token();
  140. $auth = new Auth();
  141. $msg = $auth->subscribe_user($course_code);
  142. if (CourseManager::is_user_subscribed_in_course($user_id, $course_code)) {
  143. Session::write('is_allowed_in_course', true);
  144. }
  145. if (!empty($msg)) {
  146. $show_message .= Display::return_message(
  147. get_lang($msg['message']),
  148. 'info',
  149. false
  150. );
  151. }
  152. }
  153. }
  154. /* Is the user allowed here? */
  155. api_protect_course_script(true);
  156. /* STATISTICS */
  157. if (!isset($coursesAlreadyVisited[$course_code])) {
  158. Event::accessCourse();
  159. $coursesAlreadyVisited[$course_code] = 1;
  160. Session::write('coursesAlreadyVisited', $coursesAlreadyVisited);
  161. }
  162. /*Auto launch code */
  163. $show_autolaunch_lp_warning = false;
  164. $auto_launch = api_get_course_setting('enable_lp_auto_launch');
  165. $session_id = api_get_session_id();
  166. if (!empty($auto_launch)) {
  167. if ($auto_launch == 2) { //LP list
  168. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  169. $show_autolaunch_lp_warning = true;
  170. } else {
  171. $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  172. if (!isset($_SESSION[$session_key])) {
  173. //redirecting to the LP
  174. $url = api_get_path(WEB_CODE_PATH) . 'lp/lp_controller.php?' . api_get_cidreq() . '&id_session=' . $session_id;
  175. $_SESSION[$session_key] = true;
  176. header("Location: $url");
  177. exit;
  178. }
  179. }
  180. } else {
  181. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  182. $course_id = api_get_course_int_id();
  183. $condition = '';
  184. if (!empty($session_id)) {
  185. $condition = api_get_session_condition($session_id);
  186. $sql = "SELECT id FROM $lp_table
  187. WHERE c_id = $course_id AND autolaunch = 1 $condition
  188. LIMIT 1";
  189. $result = Database::query($sql);
  190. //If we found nothing in the session we just called the session_id = 0 autolaunch
  191. if (Database::num_rows($result) == 0) {
  192. $condition = '';
  193. } else {
  194. //great, there is an specific auto launch for this session we leave the $condition
  195. }
  196. }
  197. $sql = "SELECT id FROM $lp_table
  198. WHERE c_id = $course_id AND autolaunch = 1 $condition
  199. LIMIT 1";
  200. $result = Database::query($sql);
  201. if (Database::num_rows($result) > 0) {
  202. $lp_data = Database::fetch_array($result,'ASSOC');
  203. if (!empty($lp_data['id'])) {
  204. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  205. $show_autolaunch_lp_warning = true;
  206. } else {
  207. $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  208. if (!isset($_SESSION[$session_key])) {
  209. //redirecting to the LP
  210. $url = api_get_path(WEB_CODE_PATH) . 'lp/lp_controller.php?' . api_get_cidreq() . '&action=view&lp_id=' . $lp_data['id'];
  211. $_SESSION[$session_key] = true;
  212. header("Location: $url");
  213. exit;
  214. }
  215. }
  216. }
  217. }
  218. }
  219. }
  220. $forumAutoLaunch = api_get_course_setting('enable_forum_auto_launch');
  221. if ($forumAutoLaunch == 1) {
  222. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  223. Display::addFlash(Display::return_message(
  224. get_lang('TheForumAutoLaunchSettingIsOnStudentsWillBeRedirectToTheForumTool'),
  225. 'warning'
  226. ));
  227. } else {
  228. //$forumKey = 'forum_auto_launch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  229. //if (!isset($_SESSION[$forumKey])) {
  230. //redirecting to the LP
  231. $url = api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&id_session='.$session_id;
  232. // $_SESSION[$forumKey] = true;
  233. header("Location: $url");
  234. exit;
  235. //}
  236. }
  237. }
  238. $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  239. $temps = time();
  240. $reqdate = "&reqdate=$temps";
  241. $content = Display::return_introduction_section(
  242. TOOL_COURSE_HOMEPAGE,
  243. array(
  244. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
  245. 'CreateDocumentDir' => 'document/',
  246. 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/',
  247. )
  248. );
  249. /* SWITCH TO A DIFFERENT HOMEPAGE VIEW
  250. the setting homepage_view is adjustable through
  251. the platform administration section */
  252. if ($show_autolaunch_lp_warning) {
  253. $show_message .= Display::return_message(
  254. get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP'),
  255. 'warning'
  256. );
  257. }
  258. if (api_get_setting('course.homepage_view') == 'activity' ||
  259. api_get_setting('course.homepage_view') == 'activity_big'
  260. ) {
  261. require 'activity.php';
  262. } elseif (api_get_setting('course.homepage_view') == '2column') {
  263. require '2column.php';
  264. } elseif (api_get_setting('course.homepage_view') == '3column') {
  265. require '3column.php';
  266. } elseif (api_get_setting('course.homepage_view') == 'vertical_activity') {
  267. require 'vertical_activity.php';
  268. }
  269. $content = '<div id="course_tools">'.$content.'</div>';
  270. $tpl = new Template(null);
  271. $tpl->assign('message', $show_message);
  272. $tpl->assign('content', $content);
  273. // Direct login to course
  274. $tpl->assign('course_code', $course_code);
  275. $tpl->display_one_col_template();
  276. // Deleting the objects
  277. Session::erase('_gid');
  278. Session::erase('oLP');
  279. Session::erase('lpobject');
  280. api_remove_in_gradebook();
  281. DocumentManager::removeGeneratedAudioTempFile();