course_home.php 9.9 KB

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