course_home.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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. * @package chamilo.course_home
  29. */
  30. $use_anonymous = true;
  31. require_once __DIR__.'/../inc/global.inc.php';
  32. $js = '<script>'.api_get_language_translate_html().'</script>';
  33. $htmlHeadXtra[] = $js;
  34. $htmlHeadXtra[] = '<script>
  35. /* option show/hide thematic-block */
  36. $(function() {
  37. $("#thematic-show").click(function(){
  38. $(".btn-hide-thematic").hide();
  39. $(".btn-show-thematic").show(); //show using class
  40. $("#pross").fadeToggle(); //Not working collapse for Chrome
  41. });
  42. $("#thematic-hide").click(function(){
  43. $(".btn-show-thematic").hide(); //show using class
  44. $(".btn-hide-thematic").show();
  45. $("#pross").fadeToggle(); //Not working collapse for Chrome
  46. });
  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(myObject) {
  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. $user_id = api_get_user_id();
  101. $course_code = api_get_course_id();
  102. $courseId = api_get_course_int_id();
  103. $sessionId = api_get_session_id();
  104. $show_message = '';
  105. if (api_is_invitee()) {
  106. $isInASession = $sessionId > 0;
  107. $isSubscribed = CourseManager::is_user_subscribed_in_course(
  108. $user_id,
  109. $course_code,
  110. $isInASession,
  111. $sessionId
  112. );
  113. if (!$isSubscribed) {
  114. api_not_allowed(true);
  115. }
  116. }
  117. // Deleting group session
  118. Session::erase('toolgroup');
  119. Session::erase('_gid');
  120. $isSpecialCourse = CourseManager::isSpecialCourse($courseId);
  121. if ($isSpecialCourse) {
  122. if (isset($_GET['autoreg']) && $_GET['autoreg'] == 1) {
  123. if (CourseManager::subscribeUser($user_id, $course_code, STUDENT)) {
  124. Session::write('is_allowed_in_course', true);
  125. }
  126. }
  127. }
  128. $action = !empty($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
  129. if ($action == 'subscribe') {
  130. if (Security::check_token('get')) {
  131. Security::clear_token();
  132. $result = CourseManager::autoSubscribeToCourse($course_code);
  133. if ($result) {
  134. if (CourseManager::is_user_subscribed_in_course($user_id, $course_code)) {
  135. Session::write('is_allowed_in_course', true);
  136. }
  137. }
  138. header('Location: '.api_get_self());
  139. exit;
  140. }
  141. }
  142. /* Is the user allowed here? */
  143. api_protect_course_script(true);
  144. /* STATISTICS */
  145. if (!isset($coursesAlreadyVisited[$course_code])) {
  146. Event::accessCourse();
  147. $coursesAlreadyVisited[$course_code] = 1;
  148. Session::write('coursesAlreadyVisited', $coursesAlreadyVisited);
  149. }
  150. $logInfo = [
  151. 'tool' => 'course-main',
  152. 'tool_id' => 0,
  153. 'tool_id_detail' => 0,
  154. 'action' => $action,
  155. 'info' => '',
  156. ];
  157. Event::registerLog($logInfo);
  158. /* Auto launch code */
  159. $autoLaunchWarning = '';
  160. $showAutoLaunchLpWarning = false;
  161. $course_id = api_get_course_int_id();
  162. $lpAutoLaunch = api_get_course_setting('enable_lp_auto_launch');
  163. $session_id = api_get_session_id();
  164. $allowAutoLaunchForCourseAdmins = api_is_platform_admin() || api_is_allowed_to_edit(true, true) || api_is_coach();
  165. if (!empty($lpAutoLaunch)) {
  166. if ($lpAutoLaunch == 2) {
  167. // LP list
  168. if ($allowAutoLaunchForCourseAdmins) {
  169. $showAutoLaunchLpWarning = true;
  170. } else {
  171. $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  172. if (!isset($_SESSION[$session_key])) {
  173. // Redirecting to the LP
  174. $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&id_session='.$session_id;
  175. $_SESSION[$session_key] = true;
  176. header("Location: $url");
  177. exit;
  178. }
  179. }
  180. } else {
  181. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  182. $condition = '';
  183. if (!empty($session_id)) {
  184. $condition = api_get_session_condition($session_id);
  185. $sql = "SELECT id FROM $lp_table
  186. WHERE c_id = $course_id AND autolaunch = 1 $condition
  187. LIMIT 1";
  188. $result = Database::query($sql);
  189. // If we found nothing in the session we just called the session_id = 0 autolaunch
  190. if (Database::num_rows($result) == 0) {
  191. $condition = '';
  192. }
  193. }
  194. $sql = "SELECT id FROM $lp_table
  195. WHERE c_id = $course_id AND autolaunch = 1 $condition
  196. LIMIT 1";
  197. $result = Database::query($sql);
  198. if (Database::num_rows($result) > 0) {
  199. $lp_data = Database::fetch_array($result, 'ASSOC');
  200. if (!empty($lp_data['id'])) {
  201. if ($allowAutoLaunchForCourseAdmins) {
  202. $showAutoLaunchLpWarning = true;
  203. } else {
  204. $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  205. if (!isset($_SESSION[$session_key])) {
  206. // Redirecting to the LP
  207. $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$lp_data['id'];
  208. $_SESSION[$session_key] = true;
  209. header("Location: $url");
  210. exit;
  211. }
  212. }
  213. }
  214. }
  215. }
  216. }
  217. if ($showAutoLaunchLpWarning) {
  218. $autoLaunchWarning = get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP');
  219. }
  220. $forumAutoLaunch = api_get_course_setting('enable_forum_auto_launch');
  221. if ($forumAutoLaunch == 1) {
  222. if ($allowAutoLaunchForCourseAdmins) {
  223. if (empty($autoLaunchWarning)) {
  224. $autoLaunchWarning = get_lang('TheForumAutoLaunchSettingIsOnStudentsWillBeRedirectToTheForumTool');
  225. }
  226. } else {
  227. $url = api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&id_session='.$session_id;
  228. header("Location: $url");
  229. exit;
  230. }
  231. }
  232. if (api_get_configuration_value('allow_exercise_auto_launch')) {
  233. $exerciseAutoLaunch = (int) api_get_course_setting('enable_exercise_auto_launch');
  234. if ($exerciseAutoLaunch == 2) {
  235. if ($allowAutoLaunchForCourseAdmins) {
  236. if (empty($autoLaunchWarning)) {
  237. $autoLaunchWarning = get_lang(
  238. 'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToTheExerciseList'
  239. );
  240. }
  241. } else {
  242. // Redirecting to the document
  243. $url = api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq().'&id_session='.$session_id;
  244. header("Location: $url");
  245. exit;
  246. }
  247. } elseif ($exerciseAutoLaunch == 1) {
  248. if ($allowAutoLaunchForCourseAdmins) {
  249. if (empty($autoLaunchWarning)) {
  250. $autoLaunchWarning = get_lang(
  251. 'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificExercise'
  252. );
  253. }
  254. } else {
  255. // Redirecting to an exercise
  256. $table = Database::get_course_table(TABLE_QUIZ_TEST);
  257. $condition = '';
  258. if (!empty($session_id)) {
  259. $condition = api_get_session_condition($session_id);
  260. $sql = "SELECT iid FROM $table
  261. WHERE c_id = $course_id AND autolaunch = 1 $condition
  262. LIMIT 1";
  263. $result = Database::query($sql);
  264. // If we found nothing in the session we just called the session_id = 0 autolaunch
  265. if (Database::num_rows($result) == 0) {
  266. $condition = '';
  267. }
  268. }
  269. $sql = "SELECT iid FROM $table
  270. WHERE c_id = $course_id AND autolaunch = 1 $condition
  271. LIMIT 1";
  272. $result = Database::query($sql);
  273. if (Database::num_rows($result) > 0) {
  274. $row = Database::fetch_array($result, 'ASSOC');
  275. $exerciseId = $row['iid'];
  276. $url = api_get_path(WEB_CODE_PATH).
  277. 'exercise/overview.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&id_session='.$session_id;
  278. header("Location: $url");
  279. exit;
  280. }
  281. }
  282. }
  283. }
  284. $documentAutoLaunch = api_get_course_setting('enable_document_auto_launch');
  285. if ($documentAutoLaunch == 1) {
  286. if ($allowAutoLaunchForCourseAdmins) {
  287. if (empty($autoLaunchWarning)) {
  288. $autoLaunchWarning = get_lang('TheDocumentAutoLaunchSettingIsOnStudentsWillBeRedirectToTheDocumentTool');
  289. }
  290. } else {
  291. // Redirecting to the document
  292. $url = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&id_session='.$session_id;
  293. header("Location: $url");
  294. exit;
  295. }
  296. }
  297. // Used in different pages
  298. $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  299. /* Introduction section (editable by course admins) */
  300. $content = Display::return_introduction_section(
  301. TOOL_COURSE_HOMEPAGE,
  302. [
  303. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
  304. 'CreateDocumentDir' => 'document/',
  305. 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/',
  306. ]
  307. );
  308. /* SWITCH TO A DIFFERENT HOMEPAGE VIEW
  309. the setting homepage_view is adjustable through
  310. the platform administration section */
  311. if (!empty($autoLaunchWarning)) {
  312. $show_message .= Display::return_message(
  313. $autoLaunchWarning,
  314. 'warning'
  315. );
  316. }
  317. $homePageView = api_get_setting('homepage_view');
  318. switch ($homePageView) {
  319. case 'activity':
  320. case 'activity_big':
  321. require 'activity.php';
  322. break;
  323. case '2column':
  324. require '2column.php';
  325. break;
  326. case '3column':
  327. require '3column.php';
  328. break;
  329. case 'vertical_activity':
  330. require 'vertical_activity.php';
  331. break;
  332. }
  333. // Get session-career diagram
  334. $diagram = '';
  335. $allow = api_get_configuration_value('allow_career_diagram');
  336. if ($allow === true) {
  337. $htmlHeadXtra[] = api_get_js('jsplumb2.js');
  338. $extra = new ExtraFieldValue('session');
  339. $value = $extra->get_values_by_handler_and_field_variable(
  340. api_get_session_id(),
  341. 'external_career_id'
  342. );
  343. if (!empty($value) && isset($value['value'])) {
  344. $careerId = $value['value'];
  345. $extraFieldValue = new ExtraFieldValue('career');
  346. $item = $extraFieldValue->get_item_id_from_field_variable_and_field_value(
  347. 'external_career_id',
  348. $careerId,
  349. false,
  350. false,
  351. false
  352. );
  353. if (!empty($item) && isset($item['item_id'])) {
  354. $careerId = $item['item_id'];
  355. $career = new Career();
  356. $careerInfo = $career->get($careerId);
  357. if (!empty($careerInfo)) {
  358. $extraFieldValue = new ExtraFieldValue('career');
  359. $item = $extraFieldValue->get_values_by_handler_and_field_variable(
  360. $careerId,
  361. 'career_diagram',
  362. false,
  363. false,
  364. false
  365. );
  366. if (!empty($item) && isset($item['value']) && !empty($item['value'])) {
  367. /** @var Graph $graph */
  368. $graph = UnserializeApi::unserialize(
  369. 'career',
  370. $item['value']
  371. );
  372. $diagram = Career::renderDiagram($careerInfo, $graph);
  373. }
  374. }
  375. }
  376. }
  377. }
  378. $content = '<div id="course_tools">'.$diagram.$content.'</div>';
  379. // Deleting the objects
  380. Session::erase('_gid');
  381. Session::erase('oLP');
  382. Session::erase('lpobject');
  383. api_remove_in_gradebook();
  384. Exercise::cleanSessionVariables();
  385. DocumentManager::removeGeneratedAudioTempFile();
  386. $tpl = new Template(null);
  387. $tpl->assign('message', $show_message);
  388. $tpl->assign('content', $content);
  389. // Direct login to course
  390. $tpl->assign('course_code', $course_code);
  391. $tpl->display_one_col_template();