course_home.php 10 KB

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