course_home.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. // Name of the language file that needs to be included.
  31. $language_file = 'course_home';
  32. $use_anonymous = true;
  33. // Inlcuding the global initialization file.
  34. require dirname(__FILE__).'/../inc/global.inc.php';
  35. // Delete LP sessions - commented out after seeing that normal
  36. // users in their first learnpath step (1st SCO of a SCORM)
  37. // cannot have their data saved if they "Return to course homepage"
  38. // before any LMSFinish()
  39. //unset($_SESSION['oLP']);
  40. //unset($_SESSION['lpobject']);
  41. $htmlHeadXtra[] ='<script type="text/javascript">
  42. $(document).ready(function() {
  43. $(".make_visible_and_invisible").attr("href", "javascript:void(0);");
  44. $(".make_visible_and_invisible > img").click(function () {
  45. make_visible = "visible.gif";
  46. make_invisible = "invisible.gif";
  47. path_name = $(this).attr("src");
  48. list_path_name = path_name.split("/");
  49. image_link = list_path_name[list_path_name.length - 1];
  50. tool_id = $(this).attr("id");
  51. tool_info = tool_id.split("_");
  52. my_tool_id = tool_info[1];
  53. $.ajax({
  54. contentType: "application/x-www-form-urlencoded",
  55. beforeSend: function(objeto) {
  56. $(".normal-message").show();
  57. $("#id_confirmation_message").hide();
  58. },
  59. type: "GET",
  60. url: "'.api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?'.api_get_cidreq().'&a=set_visibility",
  61. data: "id=" + my_tool_id + "&sent_http_request=1",
  62. success: function(data) {
  63. eval("var info=" + data);
  64. new_current_tool_image = info.image;
  65. new_current_view = "'.api_get_path(WEB_IMG_PATH).'" + info.view;
  66. //eyes
  67. $("#" + tool_id).attr("src", new_current_view);
  68. //tool
  69. $("#toolimage_" + my_tool_id).attr("src", new_current_tool_image);
  70. //clase
  71. $("#tooldesc_" + my_tool_id).attr("class", info.tclass);
  72. $("#istooldesc_" + my_tool_id).attr("class", info.tclass);
  73. if (image_link == "visible.gif") {
  74. $("#" + tool_id).attr("alt", "'.get_lang('Activate', '').'");
  75. $("#" + tool_id).attr("title", "'.get_lang('Activate', '').'");
  76. } else {
  77. $("#" + tool_id).attr("alt", "'.get_lang('Deactivate', '').'");
  78. $("#" + tool_id).attr("title", "'.get_lang('Deactivate', '').'");
  79. }
  80. if (info.message == "is_active") {
  81. message = "'.get_lang('ToolIsNowVisible', '').'";
  82. } else {
  83. message = "'.get_lang('ToolIsNowHidden', '').'";
  84. }
  85. $(".normal-message").hide();
  86. $("#id_confirmation_message").html(message);
  87. $("#id_confirmation_message").show();
  88. }
  89. });
  90. });
  91. });
  92. /* toogle for post-it in course home */
  93. $(function() {
  94. $(".thematic-postit-head").click(function() {
  95. $(".thematic-postit-center").slideToggle("fast");
  96. });
  97. });
  98. </script>';
  99. if (!isset($cidReq)) {
  100. $cidReq = api_get_course_id(); // To provide compatibility with previous systems.
  101. global $error_msg,$error_no;
  102. $classError = 'init';
  103. $error_no[$classError][] = '2';
  104. $error_level[$classError][] = 'info';
  105. $error_msg[$classError][] = "[".__FILE__."][".__LINE__."] cidReq was missing $cidReq take $dbname;";
  106. }
  107. if (isset($_SESSION['_gid'])) {
  108. unset($_SESSION['_gid']);
  109. }
  110. // The section for the tabs
  111. $this_section = SECTION_COURSES;
  112. /* Constants */
  113. define('TOOL_PUBLIC', 'Public');
  114. define('TOOL_PUBLIC_BUT_HIDDEN', 'PublicButHide');
  115. define('TOOL_COURSE_ADMIN', 'courseAdmin');
  116. define('TOOL_PLATFORM_ADMIN', 'platformAdmin');
  117. define('TOOL_AUTHORING', 'toolauthoring');
  118. define('TOOL_INTERACTION', 'toolinteraction');
  119. define('TOOL_COURSE_PLUGIN', 'toolcourseplugin'); //all plugins that can be enabled in courses
  120. define('TOOL_ADMIN', 'tooladmin');
  121. define('TOOL_ADMIN_PLATFORM', 'tooladminplatform');
  122. //define('TOOL_ADMIN_PLATFORM_VISIBLE', 'tooladminplatformvisible');
  123. //define('TOOL_ADMIN_PLATFORM_INVISIBLE', 'tooladminplatforminvisible');
  124. //define('TOOL_ADMIN_COURS_INVISIBLE', 'tooladmincoursinvisible');
  125. define('TOOL_STUDENT_VIEW', 'toolstudentview');
  126. define('TOOL_ADMIN_VISIBLE', 'tooladminvisible');
  127. /* Virtual course support code */
  128. $user_id = api_get_user_id();
  129. $course_code = $_course['sysCode'];
  130. $course_info = Database::get_course_info($course_code);
  131. $return_result = CourseManager::determine_course_title_from_course_info($_user['user_id'], $course_info);
  132. $course_title = $return_result['title'];
  133. $course_code = $return_result['code'];
  134. $_course['name'] = $course_title;
  135. $_course['official_code'] = $course_code;
  136. api_session_unregister('toolgroup');
  137. $is_speacialcourse = CourseManager::is_special_course($course_code);
  138. if ($is_speacialcourse) {
  139. $autoreg = Security::remove_XSS($_GET['autoreg']);
  140. if ($autoreg == 1) {
  141. CourseManager::subscribe_user($user_id, $course_code, $status = STUDENT);
  142. }
  143. }
  144. /* Is the user allowed here? */
  145. if (!$is_allowed_in_course) {
  146. api_not_allowed(true);
  147. }
  148. /* Header */
  149. /* STATISTICS */
  150. if (!isset($coursesAlreadyVisited[$_cid])) {
  151. event_access_course();
  152. $coursesAlreadyVisited[$_cid] = 1;
  153. api_session_register('coursesAlreadyVisited');
  154. }
  155. /*Auto lunch code */
  156. $show_autolunch_lp_warning = false;
  157. $auto_lunch = api_get_course_setting('enable_lp_auto_launch');
  158. if (!empty($auto_lunch)) {
  159. $session_id = api_get_session_id();
  160. if ($auto_lunch == 2) { //LP list
  161. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  162. $show_autolunch_lp_warning = true;
  163. } else {
  164. $session_key = 'lp_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  165. if (!isset($_SESSION[$session_key])) {
  166. //redirecting to the LP
  167. $url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq().'&id_session='.$session_id;
  168. $_SESSION[$session_key] = true;
  169. header("Location: $url");
  170. exit;
  171. }
  172. }
  173. } else {
  174. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  175. $course_id = api_get_course_int_id();
  176. $condition = '';
  177. if (!empty($session_id)) {
  178. $condition = api_get_session_condition($session_id);
  179. $sql = "SELECT id FROM $lp_table WHERE c_id = $course_id AND autolunch = 1 $condition LIMIT 1";
  180. $result = Database::query($sql);
  181. //If we found nothing in the session we just called the session_id = 0 autolunch
  182. if (Database::num_rows($result) == 0) {
  183. $condition = '';
  184. } else {
  185. //great, there is an specific auto lunch for this session we leave the $condition
  186. }
  187. }
  188. $sql = "SELECT id FROM $lp_table WHERE autolunch = 1 $condition 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_autolunch_lp_warning = true;
  195. } else {
  196. $session_key = 'lp_autolunch_'.$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).'newscorm/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. $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  210. $temps = time();
  211. $reqdate = "&reqdate=$temps";
  212. /* MAIN CODE */
  213. //display course title for course home page (similar to toolname for tool pages)
  214. //echo '<h3>'.api_display_tool_title($nameTools) . '</h3>';
  215. /* Introduction section (editable by course admins) */
  216. $content = Display::return_introduction_section(TOOL_COURSE_HOMEPAGE, array(
  217. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
  218. 'CreateDocumentDir' => 'document/',
  219. 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/'
  220. )
  221. );
  222. /* SWITCH TO A DIFFERENT HOMEPAGE VIEW
  223. the setting homepage_view is adjustable through
  224. the platform administration section */
  225. require_once api_get_path(LIBRARY_PATH).'course_home.lib.php';
  226. if ($show_autolunch_lp_warning) {
  227. $show_message = Display::return_message(get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP'),'warning');
  228. }
  229. if (api_get_setting('homepage_view') == 'activity' || api_get_setting('homepage_view') == 'activity_big') {
  230. require 'activity.php';
  231. } elseif (api_get_setting('homepage_view') == '2column') {
  232. require '2column.php';
  233. } elseif (api_get_setting('homepage_view') == '3column') {
  234. require '3column.php';
  235. } elseif (api_get_setting('homepage_view') == 'vertical_activity') {
  236. require 'vertical_activity.php';
  237. }
  238. $tpl = new Template($tool_name);
  239. $tpl->assign('actions', $actions);
  240. $tpl->assign('message', $show_message);
  241. $tpl->assign('content', $content);
  242. $tpl->display_one_col_template();