course_home.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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. * @package chamilo.course_home
  28. */
  29. $use_anonymous = true;
  30. require_once __DIR__.'/../inc/global.inc.php';
  31. $htmlHeadXtra[] = '<script>
  32. /* option show/hide thematic-block */
  33. $(document).ready(function(){
  34. $("#thematic-show").click(function(){
  35. $(".btn-hide-thematic").hide();
  36. $(".btn-show-thematic").show(); //show using class
  37. $("#pross").fadeToggle(); //Not working collapse for Chrome
  38. });
  39. $("#thematic-hide").click(function(){
  40. $(".btn-show-thematic").hide(); //show using class
  41. $(".btn-hide-thematic").show();
  42. $("#pross").fadeToggle(); //Not working collapse for Chrome
  43. });
  44. $(".make_visible_and_invisible").attr("href", "javascript:void(0);");
  45. $(".make_visible_and_invisible > img").click(function () {
  46. make_visible = "visible.gif";
  47. make_invisible = "invisible.gif";
  48. path_name = $(this).attr("src");
  49. list_path_name = path_name.split("/");
  50. image_link = list_path_name[list_path_name.length - 1];
  51. tool_id = $(this).attr("id");
  52. tool_info = tool_id.split("_");
  53. my_tool_id = tool_info[1];
  54. $("#id_normal_message").attr("class", "normal-message alert alert-success");
  55. $.ajax({
  56. contentType: "application/x-www-form-urlencoded",
  57. beforeSend: function(myObject) {
  58. $(".normal-message").show();
  59. $("#id_confirmation_message").hide();
  60. },
  61. type: "GET",
  62. url: "'.api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?'.api_get_cidreq().'&a=set_visibility",
  63. data: "id=" + my_tool_id + "&sent_http_request=1",
  64. success: function(data) {
  65. eval("var info=" + data);
  66. new_current_tool_image = info.image;
  67. new_current_view = "'.api_get_path(WEB_IMG_PATH).'" + info.view;
  68. //eyes
  69. $("#" + tool_id).attr("src", new_current_view);
  70. //tool
  71. $("#toolimage_" + my_tool_id).attr("src", new_current_tool_image);
  72. //clase
  73. $("#tooldesc_" + my_tool_id).attr("class", info.tclass);
  74. $("#istooldesc_" + my_tool_id).attr("class", info.tclass);
  75. if (image_link == "visible.gif") {
  76. $("#" + tool_id).attr("alt", "'.get_lang('Activate', '').'");
  77. $("#" + tool_id).attr("title", "'.get_lang('Activate', '').'");
  78. } else {
  79. $("#" + tool_id).attr("alt", "'.get_lang('Deactivate', '').'");
  80. $("#" + tool_id).attr("title", "'.get_lang('Deactivate', '').'");
  81. }
  82. if (info.message == "is_active") {
  83. message = "'.get_lang('ToolIsNowVisible', '').'";
  84. } else {
  85. message = "'.get_lang('ToolIsNowHidden', '').'";
  86. }
  87. $(".normal-message").hide();
  88. $("#id_confirmation_message").html(message);
  89. $("#id_confirmation_message").show();
  90. }
  91. });
  92. });
  93. });
  94. </script>';
  95. // The section for the tabs
  96. $this_section = SECTION_COURSES;
  97. $user_id = api_get_user_id();
  98. $course_code = api_get_course_id();
  99. $courseId = api_get_course_int_id();
  100. $sessionId = api_get_session_id();
  101. $show_message = '';
  102. if (api_is_invitee()) {
  103. $isInASession = $sessionId > 0;
  104. $isSubscribed = CourseManager::is_user_subscribed_in_course(
  105. $user_id,
  106. $course_code,
  107. $isInASession,
  108. $sessionId
  109. );
  110. if (!$isSubscribed) {
  111. api_not_allowed(true);
  112. }
  113. }
  114. // Deleting group session
  115. Session::erase('toolgroup');
  116. Session::erase('_gid');
  117. $isSpecialCourse = CourseManager::isSpecialCourse($courseId);
  118. if ($isSpecialCourse) {
  119. if (isset($_GET['autoreg']) && $_GET['autoreg'] == 1) {
  120. if (CourseManager::subscribe_user($user_id, $course_code, STUDENT)) {
  121. Session::write('is_allowed_in_course', true);
  122. }
  123. }
  124. }
  125. if (isset($_GET['action']) && $_GET['action'] == 'subscribe') {
  126. if (Security::check_token('get')) {
  127. Security::clear_token();
  128. $auth = new Auth();
  129. $msg = $auth->subscribe_user($course_code);
  130. if (CourseManager::is_user_subscribed_in_course($user_id, $course_code)) {
  131. Session::write('is_allowed_in_course', true);
  132. }
  133. if (!empty($msg)) {
  134. $show_message .= Display::return_message(
  135. get_lang($msg['message']),
  136. 'info',
  137. false
  138. );
  139. }
  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. /*Auto launch code */
  151. $autoLaunchWarning = '';
  152. $showAutoLaunchLpWarning = false;
  153. $course_id = api_get_course_int_id();
  154. $lpAutoLaunch = api_get_course_setting('enable_lp_auto_launch');
  155. $session_id = api_get_session_id();
  156. if (!empty($lpAutoLaunch)) {
  157. if ($lpAutoLaunch == 2) {
  158. // LP list
  159. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  160. $showAutoLaunchLpWarning = true;
  161. } else {
  162. $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  163. if (!isset($_SESSION[$session_key])) {
  164. // Redirecting to the LP
  165. $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&id_session='.$session_id;
  166. $_SESSION[$session_key] = true;
  167. header("Location: $url");
  168. exit;
  169. }
  170. }
  171. } else {
  172. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  173. $condition = '';
  174. if (!empty($session_id)) {
  175. $condition = api_get_session_condition($session_id);
  176. $sql = "SELECT id FROM $lp_table
  177. WHERE c_id = $course_id AND autolaunch = 1 $condition
  178. LIMIT 1";
  179. $result = Database::query($sql);
  180. // If we found nothing in the session we just called the session_id = 0 autolaunch
  181. if (Database::num_rows($result) == 0) {
  182. $condition = '';
  183. }
  184. }
  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 (Database::num_rows($result) > 0) {
  190. $lp_data = Database::fetch_array($result, 'ASSOC');
  191. if (!empty($lp_data['id'])) {
  192. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  193. $showAutoLaunchLpWarning = true;
  194. } else {
  195. $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  196. if (!isset($_SESSION[$session_key])) {
  197. //redirecting to the LP
  198. $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$lp_data['id'];
  199. $_SESSION[$session_key] = true;
  200. header("Location: $url");
  201. exit;
  202. }
  203. }
  204. }
  205. }
  206. }
  207. }
  208. if ($showAutoLaunchLpWarning) {
  209. $autoLaunchWarning = get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP');
  210. }
  211. $forumAutoLaunch = api_get_course_setting('enable_forum_auto_launch');
  212. if ($forumAutoLaunch == 1) {
  213. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  214. if (empty($autoLaunchWarning)) {
  215. $autoLaunchWarning = get_lang('TheForumAutoLaunchSettingIsOnStudentsWillBeRedirectToTheForumTool');
  216. }
  217. } else {
  218. $url = api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&id_session='.$session_id;
  219. header("Location: $url");
  220. exit;
  221. }
  222. }
  223. if (api_get_configuration_value('allow_exercise_auto_launch')) {
  224. $exerciseAutoLaunch = (int) api_get_course_setting('enable_exercise_auto_launch');
  225. if ($exerciseAutoLaunch == 2) {
  226. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  227. if (empty($autoLaunchWarning)) {
  228. $autoLaunchWarning = get_lang(
  229. 'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToTheExerciseList'
  230. );
  231. }
  232. } else {
  233. // Redirecting to the document
  234. $url = api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq().'&id_session='.$session_id;
  235. header("Location: $url");
  236. exit;
  237. }
  238. } elseif ($exerciseAutoLaunch == 1) {
  239. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  240. if (empty($autoLaunchWarning)) {
  241. $autoLaunchWarning = get_lang(
  242. 'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificExercise'
  243. );
  244. }
  245. } else {
  246. // Redirecting to an exercise
  247. $table = Database::get_course_table(TABLE_QUIZ_TEST);
  248. $condition = '';
  249. if (!empty($session_id)) {
  250. $condition = api_get_session_condition($session_id);
  251. $sql = "SELECT iid FROM $table
  252. WHERE c_id = $course_id AND autolaunch = 1 $condition
  253. LIMIT 1";
  254. $result = Database::query($sql);
  255. // If we found nothing in the session we just called the session_id = 0 autolaunch
  256. if (Database::num_rows($result) == 0) {
  257. $condition = '';
  258. }
  259. }
  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 (Database::num_rows($result) > 0) {
  265. $row = Database::fetch_array($result, 'ASSOC');
  266. $exerciseId = $row['iid'];
  267. $url = api_get_path(WEB_CODE_PATH).
  268. 'exercise/overview.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&id_session='.$session_id;
  269. header("Location: $url");
  270. exit;
  271. }
  272. }
  273. }
  274. }
  275. $documentAutoLaunch = api_get_course_setting('enable_document_auto_launch');
  276. if ($documentAutoLaunch == 1) {
  277. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  278. if (empty($autoLaunchWarning)) {
  279. $autoLaunchWarning = get_lang('TheDocumentAutoLaunchSettingIsOnStudentsWillBeRedirectToTheDocumentTool');
  280. }
  281. } else {
  282. // Redirecting to the document
  283. $url = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&id_session='.$session_id;
  284. header("Location: $url");
  285. exit;
  286. }
  287. }
  288. $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  289. $temps = time();
  290. $reqdate = "&reqdate=$temps";
  291. /* Introduction section (editable by course admins) */
  292. $content = Display::return_introduction_section(
  293. TOOL_COURSE_HOMEPAGE,
  294. [
  295. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
  296. 'CreateDocumentDir' => 'document/',
  297. 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/',
  298. ]
  299. );
  300. /* SWITCH TO A DIFFERENT HOMEPAGE VIEW
  301. the setting homepage_view is adjustable through
  302. the platform administration section */
  303. if (!empty($autoLaunchWarning)) {
  304. $show_message .= Display::return_message(
  305. $autoLaunchWarning,
  306. 'warning'
  307. );
  308. }
  309. if (api_get_setting('homepage_view') === 'activity' ||
  310. api_get_setting('homepage_view') === 'activity_big'
  311. ) {
  312. require 'activity.php';
  313. } elseif (api_get_setting('homepage_view') === '2column') {
  314. require '2column.php';
  315. } elseif (api_get_setting('homepage_view') === '3column') {
  316. require '3column.php';
  317. } elseif (api_get_setting('homepage_view') === 'vertical_activity') {
  318. require 'vertical_activity.php';
  319. }
  320. // Get session-career diagram
  321. $diagram = '';
  322. $allow = api_get_configuration_value('allow_career_diagram');
  323. if ($allow === true) {
  324. $htmlHeadXtra[] = api_get_js('jsplumb2.js');
  325. $extra = new ExtraFieldValue('session');
  326. $value = $extra->get_values_by_handler_and_field_variable(
  327. api_get_session_id(),
  328. 'external_career_id'
  329. );
  330. if (!empty($value) && isset($value['value'])) {
  331. $careerId = $value['value'];
  332. $extraFieldValue = new ExtraFieldValue('career');
  333. $item = $extraFieldValue->get_item_id_from_field_variable_and_field_value(
  334. 'external_career_id',
  335. $careerId,
  336. false,
  337. false,
  338. false
  339. );
  340. if (!empty($item) && isset($item['item_id'])) {
  341. $careerId = $item['item_id'];
  342. $career = new Career();
  343. $careerInfo = $career->get($careerId);
  344. if (!empty($careerInfo)) {
  345. $extraFieldValue = new ExtraFieldValue('career');
  346. $item = $extraFieldValue->get_values_by_handler_and_field_variable(
  347. $careerId,
  348. 'career_diagram',
  349. false,
  350. false,
  351. false
  352. );
  353. if (!empty($item) && isset($item['value']) && !empty($item['value'])) {
  354. $graph = unserialize($item['value']);
  355. $diagram = Career::renderDiagram($careerInfo, $graph);
  356. }
  357. }
  358. }
  359. }
  360. }
  361. $content = '<div id="course_tools">'.$diagram.$content.'</div>';
  362. // Deleting the objects
  363. Session::erase('_gid');
  364. Session::erase('oLP');
  365. Session::erase('lpobject');
  366. api_remove_in_gradebook();
  367. DocumentManager::removeGeneratedAudioTempFile();
  368. $tpl = new Template(null);
  369. $tpl->assign('message', $show_message);
  370. $tpl->assign('content', $content);
  371. // Direct login to course
  372. $tpl->assign('course_code', $course_code);
  373. $tpl->display_one_col_template();