course_home.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. // Inlcuding the global initialization file.
  35. require 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. $htmlHeadXtra[] ='<script>
  43. $(document).ready(function() {
  44. $(".make_visible_and_invisible").attr("href", "javascript:void(0);");
  45. $(".make_visible_and_invisible > img").click(function () {
  46. make_visible = "visible.gif";
  47. make_invisible = "invisible.gif";
  48. path_name = $(this).attr("src");
  49. list_path_name = path_name.split("/");
  50. image_link = list_path_name[list_path_name.length - 1];
  51. tool_id = $(this).attr("id");
  52. tool_info = tool_id.split("_");
  53. my_tool_id = tool_info[1];
  54. $.ajax({
  55. contentType: "application/x-www-form-urlencoded",
  56. beforeSend: function(objeto) {
  57. $(".normal-message").show();
  58. $("#id_confirmation_message").hide();
  59. },
  60. type: "GET",
  61. url: "'.api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?'.api_get_cidreq().'&a=set_visibility",
  62. data: "id=" + my_tool_id + "&sent_http_request=1",
  63. success: function(data) {
  64. eval("var info=" + data);
  65. new_current_tool_image = info.image;
  66. new_current_view = "'.api_get_path(WEB_IMG_PATH).'" + info.view;
  67. //eyes
  68. $("#" + tool_id).attr("src", new_current_view);
  69. //tool
  70. $("#toolimage_" + my_tool_id).attr("src", new_current_tool_image);
  71. //clase
  72. $("#tooldesc_" + my_tool_id).attr("class", info.tclass);
  73. $("#istooldesc_" + my_tool_id).attr("class", info.tclass);
  74. if (image_link == "visible.gif") {
  75. $("#" + tool_id).attr("alt", "'.get_lang('Activate', '').'");
  76. $("#" + tool_id).attr("title", "'.get_lang('Activate', '').'");
  77. } else {
  78. $("#" + tool_id).attr("alt", "'.get_lang('Deactivate', '').'");
  79. $("#" + tool_id).attr("title", "'.get_lang('Deactivate', '').'");
  80. }
  81. if (info.message == "is_active") {
  82. message = "'.get_lang('ToolIsNowVisible', '').'";
  83. } else {
  84. message = "'.get_lang('ToolIsNowHidden', '').'";
  85. }
  86. $(".normal-message").hide();
  87. $("#id_confirmation_message").html(message);
  88. $("#id_confirmation_message").show();
  89. }
  90. });
  91. });
  92. });
  93. /* toogle for post-it in course home */
  94. $(function() {
  95. $(".thematic-postit-head").click(function() {
  96. $(".thematic-postit-center").slideToggle("fast");
  97. });
  98. });
  99. </script>';
  100. // The section for the tabs
  101. $this_section = SECTION_COURSES;
  102. /* Constants */
  103. define('TOOL_PUBLIC', 'Public');
  104. define('TOOL_PUBLIC_BUT_HIDDEN', 'PublicButHide');
  105. define('TOOL_COURSE_ADMIN', 'courseAdmin');
  106. define('TOOL_PLATFORM_ADMIN', 'platformAdmin');
  107. define('TOOL_AUTHORING', 'toolauthoring');
  108. define('TOOL_INTERACTION', 'toolinteraction');
  109. define('TOOL_COURSE_PLUGIN', 'toolcourseplugin'); //all plugins that can be enabled in courses
  110. define('TOOL_ADMIN', 'tooladmin');
  111. define('TOOL_ADMIN_PLATFORM', 'tooladminplatform');
  112. define('TOOL_STUDENT_VIEW', 'toolstudentview');
  113. define('TOOL_ADMIN_VISIBLE', 'tooladminvisible');
  114. $user_id = api_get_user_id();
  115. $course_code = api_get_course_id();
  116. $show_message = '';
  117. //Deleting group session
  118. Session::erase('toolgroup');
  119. Session::erase('_gid');
  120. $is_speacialcourse = CourseManager::is_special_course($course_code);
  121. if ($is_speacialcourse) {
  122. $autoreg = Security::remove_XSS($_GET['autoreg']);
  123. if ($autoreg == 1) {
  124. CourseManager::subscribe_user($user_id, $course_code, $status = STUDENT);
  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 (!empty($msg)) {
  133. $show_message .= Display::return_message(get_lang($msg));
  134. }
  135. }
  136. }
  137. /* Is the user allowed here? */
  138. api_protect_course_script(true);
  139. /* STATISTICS */
  140. if (!isset($coursesAlreadyVisited[$course_code])) {
  141. event_access_course();
  142. $coursesAlreadyVisited[$course_code] = 1;
  143. Session::write('coursesAlreadyVisited', $coursesAlreadyVisited);
  144. }
  145. /*Auto launch code */
  146. $show_autolunch_lp_warning = false;
  147. $auto_launch = api_get_course_setting('enable_lp_auto_launch');
  148. if (!empty($auto_launch)) {
  149. $session_id = api_get_session_id();
  150. if ($auto_launch == 2) { //LP list
  151. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  152. $show_autolunch_lp_warning = true;
  153. } else {
  154. $session_key = 'lp_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  155. if (!isset($_SESSION[$session_key])) {
  156. //redirecting to the LP
  157. $url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq().'&id_session='.$session_id;
  158. $_SESSION[$session_key] = true;
  159. header("Location: $url");
  160. exit;
  161. }
  162. }
  163. } else {
  164. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  165. $course_id = api_get_course_int_id();
  166. $condition = '';
  167. if (!empty($session_id)) {
  168. $condition = api_get_session_condition($session_id);
  169. $sql = "SELECT id FROM $lp_table WHERE c_id = $course_id AND autolunch = 1 $condition LIMIT 1";
  170. $result = Database::query($sql);
  171. //If we found nothing in the session we just called the session_id = 0 autolunch
  172. if (Database::num_rows($result) == 0) {
  173. $condition = '';
  174. } else {
  175. //great, there is an specific auto lunch for this session we leave the $condition
  176. }
  177. }
  178. $sql = "SELECT id FROM $lp_table WHERE c_id = $course_id AND autolunch = 1 $condition LIMIT 1";
  179. $result = Database::query($sql);
  180. if (Database::num_rows($result) > 0) {
  181. $lp_data = Database::fetch_array($result,'ASSOC');
  182. if (!empty($lp_data['id'])) {
  183. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  184. $show_autolunch_lp_warning = true;
  185. } else {
  186. $session_key = 'lp_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  187. if (!isset($_SESSION[$session_key])) {
  188. //redirecting to the LP
  189. $url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$lp_data['id'];
  190. $_SESSION[$session_key] = true;
  191. header("Location: $url");
  192. exit;
  193. }
  194. }
  195. }
  196. }
  197. }
  198. }
  199. $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  200. $temps = time();
  201. $reqdate = "&reqdate=$temps";
  202. /* MAIN CODE */
  203. /* Introduction section (editable by course admins) */
  204. $content = Display::return_introduction_section(TOOL_COURSE_HOMEPAGE, array(
  205. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
  206. 'CreateDocumentDir' => 'document/',
  207. 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/'
  208. ));
  209. /* SWITCH TO A DIFFERENT HOMEPAGE VIEW
  210. the setting homepage_view is adjustable through
  211. the platform administration section */
  212. if ($show_autolunch_lp_warning) {
  213. $show_message .= Display::return_message(get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP'),'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. $tpl = new Template(null);
  226. $tpl->assign('message', $show_message);
  227. $tpl->assign('content', $content);
  228. $tpl->display_one_col_template();
  229. Session::erase('_gid');