course_home.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. use Fhaculty\Graph\Graph;
  5. /**
  6. * HOME PAGE FOR EACH COURSE.
  7. *
  8. * This page, included in every course's index.php is the home
  9. * page. To make administration simple, the teacher edits his
  10. * course from the home page. Only the login detects that the
  11. * visitor is allowed to activate, deactivate home page links,
  12. * access to the teachers tools (statistics, edit forums...).
  13. *
  14. * Edit visibility of tools
  15. *
  16. * visibility = 1 - everybody
  17. * visibility = 0 - course admin (teacher) and platform admin
  18. *
  19. * Who can change visibility ?
  20. *
  21. * admin = 0 - course admin (teacher) and platform admin
  22. * admin = 1 - platform admin
  23. *
  24. * Show message to confirm that a tools must be hide from available tools
  25. *
  26. * visibility 0,1
  27. */
  28. $use_anonymous = true;
  29. require_once __DIR__.'/../inc/global.inc.php';
  30. $js = '<script>'.api_get_language_translate_html().'</script>';
  31. $htmlHeadXtra[] = $js;
  32. $htmlHeadXtra[] = '<script>
  33. /* option show/hide thematic-block */
  34. $(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. $(".make_visible_and_invisible").attr("href", "javascript:void(0);");
  46. $(".make_visible_and_invisible > img").click(function () {
  47. make_visible = "visible.png";
  48. make_invisible = "invisible.png";
  49. path_name = $(this).attr("src");
  50. list_path_name = path_name.split("/");
  51. image_link = list_path_name[list_path_name.length - 1];
  52. tool_id = $(this).attr("id");
  53. tool_info = tool_id.split("_");
  54. my_tool_id = tool_info[1];
  55. $("#id_normal_message").attr("class", "normal-message alert alert-success");
  56. $.ajax({
  57. contentType: "application/x-www-form-urlencoded",
  58. beforeSend: function(myObject) {
  59. $(".normal-message").show();
  60. $("#id_confirmation_message").hide();
  61. },
  62. type: "GET",
  63. url: "'.api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?'.api_get_cidreq().'&a=set_visibility",
  64. data: "id=" + my_tool_id + "&sent_http_request=1",
  65. success: function(data) {
  66. eval("var info=" + data);
  67. new_current_tool_image = info.image;
  68. new_current_view = "'.api_get_path('WEB_PUBLIC_PATH').'img/" + info.view;
  69. //eyes
  70. $("#" + tool_id).attr("src", new_current_view);
  71. //tool
  72. $("#toolimage_" + my_tool_id).attr("src", new_current_tool_image);
  73. //clase
  74. $("#tooldesc_" + my_tool_id).attr("class", info.tclass);
  75. $("#istooldesc_" + my_tool_id).attr("class", info.tclass);
  76. if (image_link == "visible.png") {
  77. $("#" + tool_id).attr("alt", "'.get_lang('Activate').'");
  78. $("#" + tool_id).attr("title", "'.get_lang('Activate').'");
  79. } else {
  80. $("#" + tool_id).attr("alt", "'.get_lang('Deactivate').'");
  81. $("#" + tool_id).attr("title", "'.get_lang('Deactivate').'");
  82. }
  83. if (info.message == "is_active") {
  84. message = "'.get_lang('ToolIsNowVisible').'";
  85. } else {
  86. message = "'.get_lang('ToolIsNowHidden').'";
  87. }
  88. $(".normal-message").hide();
  89. $("#id_confirmation_message").html(message);
  90. $("#id_confirmation_message").show();
  91. }
  92. });
  93. });
  94. });
  95. </script>';
  96. // The section for the tabs
  97. $this_section = SECTION_COURSES;
  98. $user_id = api_get_user_id();
  99. $course_code = api_get_course_id();
  100. $courseId = api_get_course_int_id();
  101. $sessionId = api_get_session_id();
  102. $show_message = '';
  103. if (api_is_invitee()) {
  104. $isInASession = $sessionId > 0;
  105. $isSubscribed = CourseManager::is_user_subscribed_in_course(
  106. $user_id,
  107. $course_code,
  108. $isInASession,
  109. $sessionId
  110. );
  111. if (!$isSubscribed) {
  112. api_not_allowed(true);
  113. }
  114. }
  115. // Deleting group session
  116. Session::erase('toolgroup');
  117. Session::erase('_gid');
  118. $isSpecialCourse = CourseManager::isSpecialCourse($courseId);
  119. if ($isSpecialCourse) {
  120. if (isset($_GET['autoreg']) && $_GET['autoreg'] == 1) {
  121. if (CourseManager::subscribeUser($user_id, $course_code, STUDENT)) {
  122. Session::write('is_allowed_in_course', true);
  123. }
  124. }
  125. }
  126. $action = !empty($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
  127. if ($action == 'subscribe') {
  128. if (Security::check_token('get')) {
  129. Security::clear_token();
  130. $result = CourseManager::autoSubscribeToCourse($course_code);
  131. if ($result) {
  132. if (CourseManager::is_user_subscribed_in_course($user_id, $course_code)) {
  133. Session::write('is_allowed_in_course', true);
  134. }
  135. }
  136. header('Location: '.api_get_self());
  137. exit;
  138. }
  139. }
  140. /* Is the user allowed here? */
  141. api_protect_course_script(true);
  142. /* STATISTICS */
  143. if (!isset($coursesAlreadyVisited[$course_code])) {
  144. Event::accessCourse();
  145. $coursesAlreadyVisited[$course_code] = 1;
  146. Session::write('coursesAlreadyVisited', $coursesAlreadyVisited);
  147. }
  148. $logInfo = [
  149. 'tool' => 'course-main',
  150. 'tool_id' => 0,
  151. 'tool_id_detail' => 0,
  152. 'action' => $action,
  153. 'info' => '',
  154. ];
  155. Event::registerLog($logInfo);
  156. /* Auto launch code */
  157. $autoLaunchWarning = '';
  158. $showAutoLaunchLpWarning = false;
  159. $course_id = api_get_course_int_id();
  160. $lpAutoLaunch = api_get_course_setting('enable_lp_auto_launch');
  161. $session_id = api_get_session_id();
  162. $allowAutoLaunchForCourseAdmins = api_is_platform_admin() || api_is_allowed_to_edit(true, true) || api_is_coach();
  163. if (!empty($lpAutoLaunch)) {
  164. if ($lpAutoLaunch == 2) {
  165. // LP list
  166. if ($allowAutoLaunchForCourseAdmins) {
  167. $showAutoLaunchLpWarning = true;
  168. } else {
  169. $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  170. if (!isset($_SESSION[$session_key])) {
  171. // Redirecting to the LP
  172. $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&id_session='.$session_id;
  173. $_SESSION[$session_key] = true;
  174. header("Location: $url");
  175. exit;
  176. }
  177. }
  178. } else {
  179. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  180. $condition = '';
  181. if (!empty($session_id)) {
  182. $condition = api_get_session_condition($session_id);
  183. $sql = "SELECT id FROM $lp_table
  184. WHERE c_id = $course_id AND autolaunch = 1 $condition
  185. LIMIT 1";
  186. $result = Database::query($sql);
  187. // If we found nothing in the session we just called the session_id = 0 autolaunch
  188. if (Database::num_rows($result) == 0) {
  189. $condition = '';
  190. }
  191. }
  192. $sql = "SELECT id FROM $lp_table
  193. WHERE c_id = $course_id AND autolaunch = 1 $condition
  194. LIMIT 1";
  195. $result = Database::query($sql);
  196. if (Database::num_rows($result) > 0) {
  197. $lp_data = Database::fetch_array($result, 'ASSOC');
  198. if (!empty($lp_data['id'])) {
  199. if ($allowAutoLaunchForCourseAdmins) {
  200. $showAutoLaunchLpWarning = true;
  201. } else {
  202. $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  203. if (!isset($_SESSION[$session_key])) {
  204. // Redirecting to the LP
  205. $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$lp_data['id'];
  206. $_SESSION[$session_key] = true;
  207. header("Location: $url");
  208. exit;
  209. }
  210. }
  211. }
  212. }
  213. }
  214. }
  215. if ($showAutoLaunchLpWarning) {
  216. $autoLaunchWarning = get_lang('The learning path auto-launch setting is ON. When learners enter this course, they will be automatically redirected to the learning path marked as auto-launch.');
  217. }
  218. $forumAutoLaunch = api_get_course_setting('enable_forum_auto_launch');
  219. if ($forumAutoLaunch == 1) {
  220. if ($allowAutoLaunchForCourseAdmins) {
  221. if (empty($autoLaunchWarning)) {
  222. $autoLaunchWarning = get_lang('The forum\'s auto-launch setting is on. Students will be redirected to the forum tool when entering this course.');
  223. }
  224. } else {
  225. $url = api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&id_session='.$session_id;
  226. header("Location: $url");
  227. exit;
  228. }
  229. }
  230. if (api_get_configuration_value('allow_exercise_auto_launch')) {
  231. $exerciseAutoLaunch = (int) api_get_course_setting('enable_exercise_auto_launch');
  232. if ($exerciseAutoLaunch == 2) {
  233. if ($allowAutoLaunchForCourseAdmins) {
  234. if (empty($autoLaunchWarning)) {
  235. $autoLaunchWarning = get_lang(
  236. 'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToTheExerciseList'
  237. );
  238. }
  239. } else {
  240. // Redirecting to the document
  241. $url = api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq().'&id_session='.$session_id;
  242. header("Location: $url");
  243. exit;
  244. }
  245. } elseif ($exerciseAutoLaunch == 1) {
  246. if ($allowAutoLaunchForCourseAdmins) {
  247. if (empty($autoLaunchWarning)) {
  248. $autoLaunchWarning = get_lang(
  249. 'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificExercise'
  250. );
  251. }
  252. } else {
  253. // Redirecting to an exercise
  254. $table = Database::get_course_table(TABLE_QUIZ_TEST);
  255. $condition = '';
  256. if (!empty($session_id)) {
  257. $condition = api_get_session_condition($session_id);
  258. $sql = "SELECT iid FROM $table
  259. WHERE c_id = $course_id AND autolaunch = 1 $condition
  260. LIMIT 1";
  261. $result = Database::query($sql);
  262. // If we found nothing in the session we just called the session_id = 0 autolaunch
  263. if (Database::num_rows($result) == 0) {
  264. $condition = '';
  265. }
  266. }
  267. $sql = "SELECT iid FROM $table
  268. WHERE c_id = $course_id AND autolaunch = 1 $condition
  269. LIMIT 1";
  270. $result = Database::query($sql);
  271. if (Database::num_rows($result) > 0) {
  272. $row = Database::fetch_array($result, 'ASSOC');
  273. $exerciseId = $row['iid'];
  274. $url = api_get_path(WEB_CODE_PATH).
  275. 'exercise/overview.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&id_session='.$session_id;
  276. header("Location: $url");
  277. exit;
  278. }
  279. }
  280. }
  281. }
  282. $documentAutoLaunch = api_get_course_setting('enable_document_auto_launch');
  283. if ($documentAutoLaunch == 1) {
  284. if ($allowAutoLaunchForCourseAdmins) {
  285. if (empty($autoLaunchWarning)) {
  286. $autoLaunchWarning = get_lang('The document auto-launch feature configuration is enabled. Learners will be automatically redirected to document tool.');
  287. }
  288. } else {
  289. // Redirecting to the document
  290. $url = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&id_session='.$session_id;
  291. header("Location: $url");
  292. exit;
  293. }
  294. }
  295. // Used in different pages
  296. $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  297. /* Introduction section (editable by course admins) */
  298. $content = Display::return_introduction_section(
  299. TOOL_COURSE_HOMEPAGE,
  300. [
  301. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
  302. 'CreateDocumentDir' => 'document/',
  303. 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/',
  304. ]
  305. );
  306. /* SWITCH TO A DIFFERENT HOMEPAGE VIEW
  307. the setting homepage_view is adjustable through
  308. the platform administration section */
  309. if (!empty($autoLaunchWarning)) {
  310. $show_message .= Display::return_message(
  311. $autoLaunchWarning,
  312. 'warning'
  313. );
  314. }
  315. /*$homePageView = api_get_setting('homepage_view');
  316. switch ($homePageView) {
  317. case 'activity':
  318. case 'activity_big':
  319. require 'activity.php';
  320. break;
  321. }*/
  322. require 'activity.php';
  323. // Get session-career diagram
  324. $diagram = '';
  325. $allow = api_get_configuration_value('allow_career_diagram');
  326. if ($allow === true) {
  327. $htmlHeadXtra[] = api_get_js('jsplumb2.js');
  328. $extra = new ExtraFieldValue('session');
  329. $value = $extra->get_values_by_handler_and_field_variable(
  330. api_get_session_id(),
  331. 'external_career_id'
  332. );
  333. if (!empty($value) && isset($value['value'])) {
  334. $careerId = $value['value'];
  335. $extraFieldValue = new ExtraFieldValue('career');
  336. $item = $extraFieldValue->get_item_id_from_field_variable_and_field_value(
  337. 'external_career_id',
  338. $careerId,
  339. false,
  340. false,
  341. false
  342. );
  343. if (!empty($item) && isset($item['item_id'])) {
  344. $careerId = $item['item_id'];
  345. $career = new Career();
  346. $careerInfo = $career->get($careerId);
  347. if (!empty($careerInfo)) {
  348. $extraFieldValue = new ExtraFieldValue('career');
  349. $item = $extraFieldValue->get_values_by_handler_and_field_variable(
  350. $careerId,
  351. 'career_diagram',
  352. false,
  353. false,
  354. false
  355. );
  356. if (!empty($item) && isset($item['value']) && !empty($item['value'])) {
  357. /** @var Graph $graph */
  358. $graph = UnserializeApi::unserialize(
  359. 'career',
  360. $item['value']
  361. );
  362. $diagram = Career::renderDiagram($careerInfo, $graph);
  363. }
  364. }
  365. }
  366. }
  367. }
  368. $content = '<div id="course_tools">'.$diagram.$content.'</div>';
  369. // Deleting the objects
  370. Session::erase('_gid');
  371. Session::erase('oLP');
  372. Session::erase('lpobject');
  373. api_remove_in_gradebook();
  374. Exercise::cleanSessionVariables();
  375. DocumentManager::removeGeneratedAudioTempFile();
  376. $tpl = new Template(null);
  377. $tpl->assign('message', $show_message);
  378. $tpl->assign('content', $content);
  379. // Direct login to course
  380. $tpl->assign('course_code', $course_code);
  381. $tpl->display_one_col_template();