course_home.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. use ChamiloSession as Session;
  30. $use_anonymous = true;
  31. require_once dirname(__FILE__).'/../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. if (!empty($auto_launch)) {
  166. $session_id = api_get_session_id();
  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).'newscorm/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).'newscorm/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. $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  221. $temps = time();
  222. $reqdate = "&reqdate=$temps";
  223. /* MAIN CODE */
  224. /* Introduction section (editable by course admins) */
  225. $content = Display::return_introduction_section(TOOL_COURSE_HOMEPAGE, array(
  226. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
  227. 'CreateDocumentDir' => 'document/',
  228. 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/'
  229. )
  230. );
  231. /* SWITCH TO A DIFFERENT HOMEPAGE VIEW
  232. the setting homepage_view is adjustable through
  233. the platform administration section */
  234. if ($show_autolaunch_lp_warning) {
  235. $show_message .= Display::return_message(
  236. get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP'),
  237. 'warning'
  238. );
  239. }
  240. if (api_get_setting('homepage_view') == 'activity' ||
  241. api_get_setting('homepage_view') == 'activity_big'
  242. ) {
  243. require 'activity.php';
  244. } elseif (api_get_setting('homepage_view') == '2column') {
  245. require '2column.php';
  246. } elseif (api_get_setting('homepage_view') == '3column') {
  247. require '3column.php';
  248. } elseif (api_get_setting('homepage_view') == 'vertical_activity') {
  249. require 'vertical_activity.php';
  250. }
  251. $content = '<div id="course_tools">'.$content.'</div>';
  252. $tpl = new Template(null);
  253. $tpl->assign('message', $show_message);
  254. $tpl->assign('content', $content);
  255. // Direct login to course
  256. $tpl->assign('course_code', $course_code);
  257. $tpl->display_one_col_template();
  258. // Deleting the objects
  259. Session::erase('_gid');
  260. Session::erase('oLP');
  261. Session::erase('lpobject');
  262. api_remove_in_gradebook();
  263. DocumentManager::removeGeneratedAudioTempFile();