course_home.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. $htmlHeadXtra[] ='<script>
  33. /* option show/hide thematic-block */
  34. $(document).ready(function(){
  35. $("#thematic-show").click(function(){
  36. $(".btn-hide-thematic").hide();
  37. $(".btn-show-thematic").show(); //show using class
  38. $("#pross").fadeToggle(); //Not working collapse for Chrome
  39. });
  40. $("#thematic-hide").click(function(){
  41. $(".btn-show-thematic").hide(); //show using class
  42. $(".btn-hide-thematic").show();
  43. $("#pross").fadeToggle(); //Not working collapse for Chrome
  44. });
  45. });
  46. $(document).ready(function() {
  47. $(".make_visible_and_invisible").attr("href", "javascript:void(0);");
  48. $(".make_visible_and_invisible > img").click(function () {
  49. make_visible = "visible.gif";
  50. make_invisible = "invisible.gif";
  51. path_name = $(this).attr("src");
  52. list_path_name = path_name.split("/");
  53. image_link = list_path_name[list_path_name.length - 1];
  54. tool_id = $(this).attr("id");
  55. tool_info = tool_id.split("_");
  56. my_tool_id = tool_info[1];
  57. $("#id_normal_message").attr("class", "normal-message alert alert-success");
  58. $.ajax({
  59. contentType: "application/x-www-form-urlencoded",
  60. beforeSend: function(objeto) {
  61. $(".normal-message").show();
  62. $("#id_confirmation_message").hide();
  63. },
  64. type: "GET",
  65. url: "'.api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?'.api_get_cidreq().'&a=set_visibility",
  66. data: "id=" + my_tool_id + "&sent_http_request=1",
  67. success: function(data) {
  68. eval("var info=" + data);
  69. new_current_tool_image = info.image;
  70. new_current_view = "'.api_get_path(WEB_IMG_PATH).'" + info.view;
  71. //eyes
  72. $("#" + tool_id).attr("src", new_current_view);
  73. //tool
  74. $("#toolimage_" + my_tool_id).attr("src", new_current_tool_image);
  75. //clase
  76. $("#tooldesc_" + my_tool_id).attr("class", info.tclass);
  77. $("#istooldesc_" + my_tool_id).attr("class", info.tclass);
  78. if (image_link == "visible.gif") {
  79. $("#" + tool_id).attr("alt", "'.get_lang('Activate', '').'");
  80. $("#" + tool_id).attr("title", "'.get_lang('Activate', '').'");
  81. } else {
  82. $("#" + tool_id).attr("alt", "'.get_lang('Deactivate', '').'");
  83. $("#" + tool_id).attr("title", "'.get_lang('Deactivate', '').'");
  84. }
  85. if (info.message == "is_active") {
  86. message = "'.get_lang('ToolIsNowVisible', '').'";
  87. } else {
  88. message = "'.get_lang('ToolIsNowHidden', '').'";
  89. }
  90. $(".normal-message").hide();
  91. $("#id_confirmation_message").html(message);
  92. $("#id_confirmation_message").show();
  93. }
  94. });
  95. });
  96. });
  97. </script>';
  98. // The section for the tabs
  99. $this_section = SECTION_COURSES;
  100. $user_id = api_get_user_id();
  101. $course_code = api_get_course_id();
  102. $courseId = api_get_course_int_id();
  103. $sessionId = api_get_session_id();
  104. $show_message = '';
  105. if (api_is_invitee()) {
  106. $isInASession = $sessionId > 0;
  107. $isSubscribed = CourseManager::is_user_subscribed_in_course(
  108. $user_id,
  109. $course_code,
  110. $isInASession,
  111. $sessionId
  112. );
  113. if (!$isSubscribed) {
  114. api_not_allowed(true);
  115. }
  116. }
  117. // Deleting group session
  118. Session::erase('toolgroup');
  119. Session::erase('_gid');
  120. $isSpecialCourse = CourseManager::isSpecialCourse($courseId);
  121. if ($isSpecialCourse) {
  122. if (isset($_GET['autoreg']) && $_GET['autoreg'] == 1) {
  123. if (CourseManager::subscribe_user($user_id, $course_code, STUDENT)) {
  124. Session::write('is_allowed_in_course', true);
  125. }
  126. }
  127. }
  128. if (isset($_GET['action']) && $_GET['action'] == 'subscribe') {
  129. if (Security::check_token('get')) {
  130. Security::clear_token();
  131. $auth = new Auth();
  132. $msg = $auth->subscribe_user($course_code);
  133. if (CourseManager::is_user_subscribed_in_course($user_id, $course_code)) {
  134. Session::write('is_allowed_in_course', true);
  135. }
  136. if (!empty($msg)) {
  137. $show_message .= Display::return_message(
  138. get_lang($msg['message']),
  139. 'info',
  140. false
  141. );
  142. }
  143. }
  144. }
  145. /* Is the user allowed here? */
  146. api_protect_course_script(true);
  147. /* STATISTICS */
  148. if (!isset($coursesAlreadyVisited[$course_code])) {
  149. Event::accessCourse();
  150. $coursesAlreadyVisited[$course_code] = 1;
  151. Session::write('coursesAlreadyVisited', $coursesAlreadyVisited);
  152. }
  153. /*Auto launch code */
  154. $show_autolaunch_lp_warning = false;
  155. $auto_launch = api_get_course_setting('enable_lp_auto_launch');
  156. $session_id = api_get_session_id();
  157. if (!empty($auto_launch)) {
  158. if ($auto_launch == 2) { //LP list
  159. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  160. $show_autolaunch_lp_warning = true;
  161. } else {
  162. $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  163. if (!isset($_SESSION[$session_key])) {
  164. //redirecting to the LP
  165. $url = api_get_path(WEB_CODE_PATH) . 'lp/lp_controller.php?' . api_get_cidreq() . '&id_session=' . $session_id;
  166. $_SESSION[$session_key] = true;
  167. header("Location: $url");
  168. exit;
  169. }
  170. }
  171. } else {
  172. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  173. $course_id = api_get_course_int_id();
  174. $condition = '';
  175. if (!empty($session_id)) {
  176. $condition = api_get_session_condition($session_id);
  177. $sql = "SELECT id FROM $lp_table
  178. WHERE c_id = $course_id AND autolaunch = 1 $condition
  179. LIMIT 1";
  180. $result = Database::query($sql);
  181. // If we found nothing in the session we just called the session_id = 0 autolaunch
  182. if (Database::num_rows($result) == 0) {
  183. $condition = '';
  184. }
  185. }
  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 (Database::num_rows($result) > 0) {
  191. $lp_data = Database::fetch_array($result, 'ASSOC');
  192. if (!empty($lp_data['id'])) {
  193. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  194. $show_autolaunch_lp_warning = true;
  195. } else {
  196. $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  197. if (!isset($_SESSION[$session_key])) {
  198. //redirecting to the LP
  199. $url = api_get_path(WEB_CODE_PATH) . 'lp/lp_controller.php?' . api_get_cidreq() . '&action=view&lp_id=' . $lp_data['id'];
  200. $_SESSION[$session_key] = true;
  201. header("Location: $url");
  202. exit;
  203. }
  204. }
  205. }
  206. }
  207. }
  208. }
  209. $forumAutoLaunch = api_get_course_setting('enable_forum_auto_launch');
  210. if ($forumAutoLaunch == 1) {
  211. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  212. Display::addFlash(Display::return_message(
  213. get_lang('TheForumAutoLaunchSettingIsOnStudentsWillBeRedirectToTheForumTool'),
  214. 'warning'
  215. ));
  216. } else {
  217. //$forumKey = 'forum_auto_launch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  218. //if (!isset($_SESSION[$forumKey])) {
  219. //redirecting to the LP
  220. $url = api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&id_session='.$session_id;
  221. // $_SESSION[$forumKey] = true;
  222. header("Location: $url");
  223. exit;
  224. //}
  225. }
  226. }
  227. $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  228. $temps = time();
  229. $reqdate = "&reqdate=$temps";
  230. /* MAIN CODE */
  231. /* Introduction section (editable by course admins) */
  232. $content = Display::return_introduction_section(
  233. TOOL_COURSE_HOMEPAGE,
  234. array(
  235. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
  236. 'CreateDocumentDir' => 'document/',
  237. 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/',
  238. )
  239. );
  240. /* SWITCH TO A DIFFERENT HOMEPAGE VIEW
  241. the setting homepage_view is adjustable through
  242. the platform administration section */
  243. if ($show_autolaunch_lp_warning) {
  244. $show_message .= Display::return_message(
  245. get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP'),
  246. 'warning'
  247. );
  248. }
  249. if (api_get_setting('homepage_view') === 'activity' || api_get_setting('homepage_view') === 'activity_big') {
  250. require 'activity.php';
  251. } elseif (api_get_setting('homepage_view') === '2column') {
  252. require '2column.php';
  253. } elseif (api_get_setting('homepage_view') === '3column') {
  254. require '3column.php';
  255. } elseif (api_get_setting('homepage_view') === 'vertical_activity') {
  256. require 'vertical_activity.php';
  257. }
  258. $content = '<div id="course_tools">'.$content.'</div>';
  259. $tpl = new Template(null);
  260. $tpl->assign('message', $show_message);
  261. $tpl->assign('content', $content);
  262. // Direct login to course
  263. $tpl->assign('course_code', $course_code);
  264. $tpl->display_one_col_template();
  265. // Deleting the objects
  266. Session::erase('_gid');
  267. Session::erase('oLP');
  268. Session::erase('lpobject');
  269. api_remove_in_gradebook();
  270. DocumentManager::removeGeneratedAudioTempFile();