course_home.php 9.4 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
  36. unset($_SESSION['oLP']);
  37. unset($_SESSION['lpobject']);
  38. $htmlHeadXtra[] ='<script type="text/javascript">
  39. $(document).ready(function() {
  40. $(".make_visible_and_invisible").attr("href", "javascript:void(0);");
  41. $(".make_visible_and_invisible > img").click(function () {
  42. make_visible = "visible.gif";
  43. make_invisible = "invisible.gif";
  44. path_name = $(this).attr("src");
  45. list_path_name = path_name.split("/");
  46. image_link = list_path_name[list_path_name.length - 1];
  47. tool_id = $(this).attr("id");
  48. tool_info = tool_id.split("_");
  49. my_tool_id = tool_info[1];
  50. $.ajax({
  51. contentType: "application/x-www-form-urlencoded",
  52. beforeSend: function(objeto) {
  53. $(".normal-message").show();
  54. $("#id_confirmation_message").hide();
  55. },
  56. type: "GET",
  57. url: "'.api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=set_visibility",
  58. data: "id=" + my_tool_id + "&sent_http_request=1",
  59. success: function(data) {
  60. eval("var info=" + data);
  61. new_current_tool_image = info.image;
  62. new_current_view = "'.api_get_path(WEB_IMG_PATH).'" + info.view;
  63. //eyes
  64. $("#" + tool_id).attr("src", new_current_view);
  65. //tool
  66. $("#toolimage_" + my_tool_id).attr("src", new_current_tool_image);
  67. //clase
  68. $("#tooldesc_" + my_tool_id).attr("class", info.tclass);
  69. $("#istooldesc_" + my_tool_id).attr("class", info.tclass);
  70. if (image_link == "visible.gif") {
  71. $("#" + tool_id).attr("alt", "'.get_lang('Activate', '').'");
  72. $("#" + tool_id).attr("title", "'.get_lang('Activate', '').'");
  73. } else {
  74. $("#" + tool_id).attr("alt", "'.get_lang('Deactivate', '').'");
  75. $("#" + tool_id).attr("title", "'.get_lang('Deactivate', '').'");
  76. }
  77. if (info.message == "is_active") {
  78. message = "'.get_lang('ToolIsNowVisible', '').'";
  79. } else {
  80. message = "'.get_lang('ToolIsNowHidden', '').'";
  81. }
  82. $(".normal-message").hide();
  83. $("#id_confirmation_message").html(message);
  84. $("#id_confirmation_message").show();
  85. }
  86. });
  87. });
  88. });
  89. /* toogle for post-it in course home */
  90. $(function() {
  91. $(".thematic-postit-head").click(function() {
  92. $(".thematic-postit-center").slideToggle("normal");
  93. });
  94. });
  95. </script>';
  96. if (!isset($cidReq)) {
  97. $cidReq = api_get_course_id(); // To provide compatibility with previous systems.
  98. global $error_msg,$error_no;
  99. $classError = 'init';
  100. $error_no[$classError][] = '2';
  101. $error_level[$classError][] = 'info';
  102. $error_msg[$classError][] = "[".__FILE__."][".__LINE__."] cidReq was Missing $cidReq take $dbname;";
  103. }
  104. if (isset($_SESSION['_gid'])) {
  105. unset($_SESSION['_gid']);
  106. }
  107. // The section for the tabs
  108. $this_section = SECTION_COURSES;
  109. // Libraries
  110. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  111. /* Constants */
  112. define('TOOL_PUBLIC', 'Public');
  113. define('TOOL_PUBLIC_BUT_HIDDEN', 'PublicButHide');
  114. define('TOOL_COURSE_ADMIN', 'courseAdmin');
  115. define('TOOL_PLATFORM_ADMIN', 'platformAdmin');
  116. define('TOOL_AUTHORING', 'toolauthoring');
  117. define('TOOL_INTERACTION', 'toolinteraction');
  118. define('TOOL_COURSE_PLUGIN', 'toolcourseplugin'); //all plugins that can be enabled in courses
  119. define('TOOL_ADMIN', 'tooladmin');
  120. define('TOOL_ADMIN_PLATEFORM', 'tooladminplatform');
  121. //define('TOOL_ADMIN_PLATFORM_VISIBLE', 'tooladminplatformvisible');
  122. //define('TOOL_ADMIN_PLATFORM_INVISIBLE', 'tooladminplatforminvisible');
  123. //define('TOOL_ADMIN_COURS_INVISIBLE', 'tooladmincoursinvisible');
  124. define('TOOL_STUDENT_VIEW', 'toolstudentview');
  125. define('TOOL_ADMIN_VISIBLE', 'tooladminvisible');
  126. /* Virtual course support code */
  127. $user_id = api_get_user_id();
  128. $course_code = $_course['sysCode'];
  129. $course_info = Database::get_course_info($course_code);
  130. $return_result = CourseManager::determine_course_title_from_course_info($_user['user_id'], $course_info);
  131. $course_title = $return_result['title'];
  132. $course_code = $return_result['code'];
  133. $_course['name'] = $course_title;
  134. $_course['official_code'] = $course_code;
  135. api_session_unregister('toolgroup');
  136. $is_speacialcourse = CourseManager::is_special_course($course_code);
  137. if ($is_speacialcourse){
  138. $autoreg = Security::remove_XSS($_GET['autoreg']);
  139. if ($autoreg == 1) {
  140. CourseManager::subscribe_user($user_id, $course_code, $status = STUDENT);
  141. }
  142. }
  143. /* Is the user allowed here? */
  144. if (!$is_allowed_in_course) {
  145. api_not_allowed(true);
  146. }
  147. /* Header */
  148. /* STATISTICS */
  149. if (!isset($coursesAlreadyVisited[$_cid])) {
  150. event_access_course();
  151. $coursesAlreadyVisited[$_cid] = 1;
  152. api_session_register('coursesAlreadyVisited');
  153. }
  154. /*Auto lunch code */
  155. $show_autolunch_lp_warning = false;
  156. $auto_lunch = api_get_course_setting('enable_lp_auto_launch');
  157. if (!empty($auto_lunch)) {
  158. $session_id = api_get_session_id();
  159. if ($auto_lunch == 2) { //LP list
  160. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  161. $show_autolunch_lp_warning = true;
  162. } else {
  163. $session_key = 'lp_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  164. if (!isset($_SESSION[$session_key])) {
  165. //redirecting to the LP
  166. $url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq().'&id_session='.$session_id;
  167. $_SESSION[$session_key] = true;
  168. header("Location: $url");
  169. exit;
  170. }
  171. }
  172. } else {
  173. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  174. $condition = '';
  175. if (!empty($session_id)) {
  176. $condition = api_get_session_condition($session_id);
  177. $sql = "SELECT id FROM $lp_table WHERE autolunch = 1 $condition LIMIT 1";
  178. $result = Database::query($sql);
  179. //If we found nothing in the session we just called the session_id = 0 autolunch
  180. if (Database::num_rows($result) == 0) {
  181. $condition = '';
  182. } else {
  183. //great, there is an specific auto lunch for this session we leave the $condition
  184. }
  185. }
  186. $sql = "SELECT id FROM $lp_table WHERE autolunch = 1 $condition LIMIT 1";
  187. $result = Database::query($sql);
  188. if (Database::num_rows($result) > 0) {
  189. $lp_data = Database::fetch_array($result,'ASSOC');
  190. if (!empty($lp_data['id'])) {
  191. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  192. $show_autolunch_lp_warning = true;
  193. } else {
  194. $session_key = 'lp_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  195. if (!isset($_SESSION[$session_key])) {
  196. //redirecting to the LP
  197. $url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$lp_data['id'];
  198. $_SESSION[$session_key] = true;
  199. header("Location: $url");
  200. exit;
  201. }
  202. }
  203. }
  204. }
  205. }
  206. }
  207. Display::display_header(null, 'Home');
  208. $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  209. $temps = time();
  210. $reqdate = "&reqdate=$temps";
  211. /* MAIN CODE */
  212. //display course title for course home page (similar to toolname for tool pages)
  213. //echo '<h3>'.api_display_tool_title($nameTools) . '</h3>';
  214. /* Introduction section
  215. (editable by course admins) */
  216. Display::display_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. if ($show_autolunch_lp_warning) {
  226. Display::display_warning_message(get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP'));
  227. }
  228. if (api_get_setting('homepage_view') == 'activity' || api_get_setting('homepage_view') == 'activity_big') {
  229. require 'activity.php';
  230. } elseif (api_get_setting('homepage_view') == '2column') {
  231. require '2column.php';
  232. } elseif (api_get_setting('homepage_view') == '3column') {
  233. require '3column.php';
  234. } elseif (api_get_setting('homepage_view') == 'vertical_activity') {
  235. require 'vertical_activity.php';
  236. }
  237. /* FOOTER */
  238. Display::display_footer();