course_home.php 9.9 KB

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