course_home.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. use \ChamiloSession as Session;
  30. // Name of the language file that needs to be included.
  31. $language_file = array('course_home', 'courses');
  32. $use_anonymous = true;
  33. // Inlcuding the global initialization file.
  34. require_once 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>
  42. /* option show/hide thematic-block */
  43. $(document).ready(function(){
  44. $("#thematic-show").click(function(){
  45. $(".btn-hide-thematic").hide();
  46. $(".btn-show-thematic").show(); //show using class
  47. $("#pross").fadeToggle(); //Not working collapse for Chrome
  48. });
  49. $("#thematic-hide").click(function(){
  50. $(".btn-show-thematic").hide(); //show using class
  51. $(".btn-hide-thematic").show();
  52. $("#pross").fadeToggle(); //Not working collapse for Chrome
  53. });
  54. });
  55. $(document).ready(function() {
  56. $(".make_visible_and_invisible").attr("href", "javascript:void(0);");
  57. $(".make_visible_and_invisible > img").click(function () {
  58. make_visible = "visible.gif";
  59. make_invisible = "invisible.gif";
  60. path_name = $(this).attr("src");
  61. list_path_name = path_name.split("/");
  62. image_link = list_path_name[list_path_name.length - 1];
  63. tool_id = $(this).attr("id");
  64. tool_info = tool_id.split("_");
  65. my_tool_id = tool_info[1];
  66. $.ajax({
  67. contentType: "application/x-www-form-urlencoded",
  68. beforeSend: function(objeto) {
  69. $(".normal-message").show();
  70. $("#id_confirmation_message").hide();
  71. },
  72. type: "GET",
  73. url: "'.api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?'.api_get_cidreq().'&a=set_visibility",
  74. data: "id=" + my_tool_id + "&sent_http_request=1",
  75. success: function(data) {
  76. eval("var info=" + data);
  77. new_current_tool_image = info.image;
  78. new_current_view = "'.api_get_path(WEB_IMG_PATH).'" + info.view;
  79. //eyes
  80. $("#" + tool_id).attr("src", new_current_view);
  81. //tool
  82. $("#toolimage_" + my_tool_id).attr("src", new_current_tool_image);
  83. //clase
  84. $("#tooldesc_" + my_tool_id).attr("class", info.tclass);
  85. $("#istooldesc_" + my_tool_id).attr("class", info.tclass);
  86. if (image_link == "visible.gif") {
  87. $("#" + tool_id).attr("alt", "'.get_lang('Activate', '').'");
  88. $("#" + tool_id).attr("title", "'.get_lang('Activate', '').'");
  89. } else {
  90. $("#" + tool_id).attr("alt", "'.get_lang('Deactivate', '').'");
  91. $("#" + tool_id).attr("title", "'.get_lang('Deactivate', '').'");
  92. }
  93. if (info.message == "is_active") {
  94. message = "'.get_lang('ToolIsNowVisible', '').'";
  95. } else {
  96. message = "'.get_lang('ToolIsNowHidden', '').'";
  97. }
  98. $(".normal-message").hide();
  99. $("#id_confirmation_message").html(message);
  100. $("#id_confirmation_message").show();
  101. }
  102. });
  103. });
  104. });
  105. </script>';
  106. // The section for the tabs
  107. $this_section = SECTION_COURSES;
  108. /* Constants */
  109. define('TOOL_PUBLIC', 'Public');
  110. define('TOOL_PUBLIC_BUT_HIDDEN', 'PublicButHide');
  111. define('TOOL_COURSE_ADMIN', 'courseAdmin');
  112. define('TOOL_PLATFORM_ADMIN', 'platformAdmin');
  113. define('TOOL_AUTHORING', 'toolauthoring');
  114. define('TOOL_INTERACTION', 'toolinteraction');
  115. define('TOOL_COURSE_PLUGIN', 'toolcourseplugin'); //all plugins that can be enabled in courses
  116. define('TOOL_ADMIN', 'tooladmin');
  117. define('TOOL_ADMIN_PLATFORM', 'tooladminplatform');
  118. define('TOOL_DRH', 'tool_drh');
  119. define('TOOL_STUDENT_VIEW', 'toolstudentview');
  120. define('TOOL_ADMIN_VISIBLE', 'tooladminvisible');
  121. $user_id = api_get_user_id();
  122. $course_code = api_get_course_id();
  123. $show_message = '';
  124. // Deleting group session
  125. Session::erase('toolgroup');
  126. Session::erase('_gid');
  127. $is_speacialcourse = CourseManager::is_special_course($course_code);
  128. if ($is_speacialcourse) {
  129. $autoreg = Security::remove_XSS($_GET['autoreg']);
  130. if ($autoreg == 1) {
  131. if (CourseManager::subscribe_user($user_id, $course_code, $status = STUDENT)) {
  132. Session::write('is_allowed_in_course', true);
  133. }
  134. }
  135. }
  136. if (isset($_GET['action']) && $_GET['action'] == 'subscribe') {
  137. if (Security::check_token('get')) {
  138. Security::clear_token();
  139. $auth = new Auth();
  140. $msg = $auth->subscribe_user($course_code);
  141. if (!empty($msg)) {
  142. $show_message .= Display::return_message(get_lang($msg));
  143. }
  144. }
  145. }
  146. /* Is the user allowed here? */
  147. api_protect_course_script(true);
  148. /* STATISTICS */
  149. if (!isset($coursesAlreadyVisited[$course_code])) {
  150. event_access_course();
  151. $coursesAlreadyVisited[$course_code] = 1;
  152. Session::write('coursesAlreadyVisited', $coursesAlreadyVisited);
  153. }
  154. /*Auto launch code */
  155. $show_autolunch_lp_warning = false;
  156. $auto_launch = api_get_course_setting('enable_lp_auto_launch');
  157. if (!empty($auto_launch)) {
  158. $session_id = api_get_session_id();
  159. if ($auto_launch == 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. $course_id = api_get_course_int_id();
  175. $condition = '';
  176. if (!empty($session_id)) {
  177. $condition = api_get_session_condition($session_id);
  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 we found nothing in the session we just called the session_id = 0 autolunch
  181. if (Database::num_rows($result) == 0) {
  182. $condition = '';
  183. } else {
  184. //great, there is an specific auto lunch for this session we leave the $condition
  185. }
  186. }
  187. $sql = "SELECT id FROM $lp_table WHERE c_id = $course_id AND autolunch = 1 $condition 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_autolunch_lp_warning = true;
  194. } else {
  195. $session_key = 'lp_autolunch_'.$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).'newscorm/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. $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  209. $temps = time();
  210. $reqdate = "&reqdate=$temps";
  211. /* MAIN CODE */
  212. /* Introduction section (editable by course admins) */
  213. $content = Display::return_introduction_section(TOOL_COURSE_HOMEPAGE, array(
  214. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
  215. 'CreateDocumentDir' => 'document/',
  216. 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/'
  217. )
  218. );
  219. /* SWITCH TO A DIFFERENT HOMEPAGE VIEW
  220. the setting homepage_view is adjustable through
  221. the platform administration section */
  222. if ($show_autolunch_lp_warning) {
  223. $show_message .= Display::return_message(
  224. get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP'),
  225. 'warning'
  226. );
  227. }
  228. if (api_get_setting('homepage_view') == 'activity' ||
  229. api_get_setting('homepage_view') == 'activity_big'
  230. ) {
  231. require 'activity.php';
  232. } elseif (api_get_setting('homepage_view') == '2column') {
  233. require '2column.php';
  234. } elseif (api_get_setting('homepage_view') == '3column') {
  235. require '3column.php';
  236. } elseif (api_get_setting('homepage_view') == 'vertical_activity') {
  237. require 'vertical_activity.php';
  238. }
  239. $content = '<div id="course_tools">'.$content.'</div>';
  240. $tpl = new Template(null);
  241. $tpl->assign('message', $show_message);
  242. $tpl->assign('content', $content);
  243. // Direct login to course
  244. $tpl->assign('course_code', $course_code);
  245. $tpl->display_one_col_template();
  246. Session::erase('_gid');
  247. // Deleting the objects
  248. Session::erase('oLP');
  249. Session::erase('lpobject');
  250. DocumentManager::removeGeneratedAudioTempFile();