course_home.php 11 KB

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