user_portal.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This is the index file displayed when a user is logged in on Chamilo.
  6. *
  7. * It displays:
  8. * - personal course list
  9. * - menu bar
  10. * Search for CONFIGURATION parameters to modify settings
  11. *
  12. * @package chamilo.main
  13. *
  14. * @todo Shouldn't the CONFVAL_ constant be moved to the config page? Has anybody any idea what the are used for?
  15. * If these are really configuration settings then we can add those to the dokeos config settings.
  16. * @todo check for duplication of functions with index.php (user_portal.php is orginally a copy of index.php)
  17. * @todo display_digest, shouldn't this be removed and be made into an extension?
  18. */
  19. /* Flag forcing the 'current course' reset, as we're not inside a course anymore */
  20. $cidReset = true;
  21. // For HTML editor repository.
  22. if (isset($_SESSION['this_section'])) {
  23. unset($_SESSION['this_section']);
  24. }
  25. /* Included libraries */
  26. require_once './main/inc/global.inc.php';
  27. $this_section = SECTION_COURSES;
  28. api_block_anonymous_users(); // Only users who are logged in can proceed.
  29. $userId = api_get_user_id();
  30. /* Constants and CONFIGURATION parameters */
  31. $load_dirs = api_get_setting('show_documents_preview');
  32. $displayMyCourseViewBySessionLink = api_get_setting('my_courses_view_by_session') === 'true';
  33. $nameTools = get_lang('MyCourses');
  34. $loadHistory = isset($_GET['history']) && intval($_GET['history']) == 1 ? true : false;
  35. // Load course notification by ajax
  36. $loadNotificationsByAjax = api_get_configuration_value('user_portal_load_notification_by_ajax');
  37. if ($loadNotificationsByAjax) {
  38. $htmlHeadXtra[] = '<script>
  39. $(function() {
  40. $(".course_notification").each(function(index) {
  41. var div = $(this);
  42. var id = $(this).attr("id");
  43. var idList = id.split("_");
  44. var courseId = idList[1];
  45. var sessionId = idList[2];
  46. var status = idList[3];
  47. $.ajax({
  48. type: "GET",
  49. url: "'.api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=get_notification&course_id="+courseId+"&session_id="+sessionId+"&status="+status,
  50. success: function(data) {
  51. div.append(data);
  52. }
  53. });
  54. });
  55. });
  56. </script>';
  57. }
  58. /*
  59. Header
  60. Include the HTTP, HTML headers plus the top banner.
  61. */
  62. if ($load_dirs) {
  63. $url = api_get_path(WEB_AJAX_PATH).'document.ajax.php?a=document_preview';
  64. $folder_icon = api_get_path(WEB_IMG_PATH).'icons/22/folder.png';
  65. $close_icon = api_get_path(WEB_IMG_PATH).'loading1.gif';
  66. $htmlHeadXtra[] = '<script>
  67. $(document).ready(function() {
  68. $(".document_preview_container").hide();
  69. $(".document_preview").click(function() {
  70. var my_id = this.id;
  71. var course_id = my_id.split("_")[2];
  72. var session_id = my_id.split("_")[3];
  73. //showing div
  74. $(".document_preview_container").hide();
  75. $("#document_result_" +course_id+"_" + session_id).show();
  76. // Loading
  77. var image = $("img", this);
  78. image.attr("src", "'.$close_icon.'");
  79. $.ajax({
  80. url: "'.$url.'",
  81. data: "course_id="+course_id+"&session_id="+session_id,
  82. success: function(return_value) {
  83. image.attr("src", "'.$folder_icon.'");
  84. $("#document_result_" +course_id+"_" + session_id).html(return_value);
  85. }
  86. });
  87. });
  88. });
  89. </script>';
  90. }
  91. if ($displayMyCourseViewBySessionLink) {
  92. $htmlHeadXtra[] = '
  93. <script>
  94. userId = '.$userId.'
  95. $(document).ready(function() {
  96. changeMyCoursesView($.cookie("defaultMyCourseView" + userId));
  97. });
  98. /**
  99. * Keep in cookie the last teacher view for the My Courses Tab. default view, or view by session
  100. * @param inView
  101. */
  102. function changeMyCoursesView(inView) {
  103. $.cookie("defaultMyCourseView"+userId, inView, { expires: 365 });
  104. if (inView == '.IndexManager::VIEW_BY_SESSION.') {
  105. $("#viewBySession").addClass("btn-primary");
  106. $("#viewByDefault").removeClass("btn-primary");
  107. } else {
  108. $("#viewByDefault").addClass("btn-primary");
  109. $("#viewBySession").removeClass("btn-primary");
  110. }
  111. }
  112. </script>';
  113. }
  114. $myCourseListAsCategory = api_get_configuration_value('my_courses_list_as_category');
  115. $controller = new IndexManager(get_lang('MyCourses'));
  116. if (!$myCourseListAsCategory) {
  117. // Main courses and session list
  118. if (isset($_COOKIE['defaultMyCourseView'.$userId]) &&
  119. $_COOKIE['defaultMyCourseView'.$userId] == IndexManager::VIEW_BY_SESSION &&
  120. $displayMyCourseViewBySessionLink
  121. ) {
  122. $courseAndSessions = $controller->returnCoursesAndSessionsViewBySession($userId);
  123. IndexManager::setDefaultMyCourseView(IndexManager::VIEW_BY_SESSION, $userId);
  124. } else {
  125. $courseAndSessions = $controller->returnCoursesAndSessions($userId, true, null, true, $loadHistory);
  126. IndexManager::setDefaultMyCourseView(IndexManager::VIEW_BY_DEFAULT, $userId);
  127. }
  128. // if teacher, session coach or admin, display the button to change te course view
  129. if ($displayMyCourseViewBySessionLink &&
  130. (
  131. api_is_drh() ||
  132. api_is_session_general_coach() ||
  133. api_is_platform_admin() ||
  134. api_is_session_admin() ||
  135. api_is_teacher()
  136. )
  137. ) {
  138. $courseAndSessions['html'] = "
  139. <div class='view-by-session-link'>
  140. <div class='btn-group pull-right'>
  141. <a class='btn btn-default' id='viewByDefault' href='user_portal.php'
  142. onclick='changeMyCoursesView(\"".IndexManager::VIEW_BY_DEFAULT."\")'>
  143. ".get_lang('MyCoursesDefaultView')."
  144. </a>
  145. <a class='btn btn-default' id='viewBySession' href='user_portal.php'
  146. onclick='changeMyCoursesView(\"".IndexManager::VIEW_BY_SESSION."\")'>
  147. ".get_lang('MyCoursesSessionView')."
  148. </a>
  149. </div>
  150. </div>
  151. <br /><br />
  152. ".$courseAndSessions['html'];
  153. }
  154. } else {
  155. $categoryCode = isset($_GET['category']) ? $_GET['category'] : '';
  156. if (!$categoryCode) {
  157. $courseAndSessions = $controller->returnCourseCategoryListFromUser($userId);
  158. } else {
  159. $courseAndSessions = $controller->returnCoursesAndSessions(
  160. $userId,
  161. false,
  162. $categoryCode,
  163. true,
  164. $loadHistory
  165. );
  166. $getCategory = CourseCategory::getCategory($categoryCode);
  167. $controller->tpl->assign('category', $getCategory);
  168. }
  169. }
  170. // Check if a user is enrolled only in one course for going directly to the course after the login.
  171. if (api_get_setting('go_to_course_after_login') == 'true') {
  172. $count_of_sessions = $courseAndSessions['session_count'];
  173. $count_of_courses_no_sessions = $courseAndSessions['course_count'];
  174. // User is subscribe in 1 session and 0 courses.
  175. if ($count_of_sessions == 1 && $count_of_courses_no_sessions == 0) {
  176. $sessions = SessionManager::get_sessions_by_user($userId);
  177. if (isset($sessions[0])) {
  178. $sessionInfo = $sessions[0];
  179. // Session only has 1 course.
  180. if (isset($sessionInfo['courses']) &&
  181. count($sessionInfo['courses']) == 1
  182. ) {
  183. $courseCode = $sessionInfo['courses'][0]['code'];
  184. $courseInfo = api_get_course_info_by_id($sessionInfo['courses'][0]['real_id']);
  185. $courseUrl = $courseInfo['course_public_url'].'?id_session='.$sessionInfo['session_id'];
  186. header('Location:'.$courseUrl);
  187. exit;
  188. }
  189. // Session has many courses.
  190. if (isset($sessionInfo['session_id'])) {
  191. $url = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$sessionInfo['session_id'];
  192. header('Location:'.$url);
  193. exit;
  194. }
  195. }
  196. }
  197. // User is subscribed to 1 course.
  198. if (!isset($_SESSION['coursesAlreadyVisited']) &&
  199. $count_of_sessions == 0 &&
  200. $count_of_courses_no_sessions == 1
  201. ) {
  202. $courses = CourseManager::get_courses_list_by_user_id($userId);
  203. if (!empty($courses) && isset($courses[0]) && isset($courses[0]['code'])) {
  204. $courseInfo = api_get_course_info_by_id($courses[0]['real_id']);
  205. if (!empty($courseInfo)) {
  206. $courseUrl = $courseInfo['course_public_url'];
  207. header('Location:'.$courseUrl);
  208. exit;
  209. }
  210. }
  211. }
  212. }
  213. // Show the chamilo mascot
  214. if (empty($courseAndSessions['html']) && !isset($_GET['history'])) {
  215. $controller->tpl->assign(
  216. 'welcome_to_course_block',
  217. $controller->return_welcome_to_course_block()
  218. );
  219. }
  220. $controller->tpl->assign('content', $courseAndSessions['html']);
  221. // Display the Site Use Cookie Warning Validation
  222. $useCookieValidation = api_get_setting('cookie_warning');
  223. if ($useCookieValidation === 'true') {
  224. if (isset($_POST['acceptCookies'])) {
  225. api_set_site_use_cookie_warning_cookie();
  226. } else {
  227. if (!api_site_use_cookie_warning_cookie_exist()) {
  228. if (Template::isToolBarDisplayedForUser()) {
  229. $controller->tpl->assign('toolBarDisplayed', true);
  230. } else {
  231. $controller->tpl->assign('toolBarDisplayed', false);
  232. }
  233. $controller->tpl->assign('displayCookieUsageWarning', true);
  234. }
  235. }
  236. }
  237. //check for flash and message
  238. $sniff_notification = '';
  239. $some_activex = isset($_SESSION['sniff_check_some_activex']) ? $_SESSION['sniff_check_some_activex'] : null;
  240. $some_plugins = isset($_SESSION['sniff_check_some_plugins']) ? $_SESSION['sniff_check_some_plugins'] : null;
  241. if (!empty($some_activex) || !empty($some_plugins)) {
  242. if (!preg_match("/flash_yes/", $some_activex) && !preg_match("/flash_yes/", $some_plugins)) {
  243. $sniff_notification = Display::return_message(get_lang('NoFlash'), 'warning', true);
  244. //js verification - To annoying of redirecting every time the page
  245. $controller->tpl->assign('sniff_notification', $sniff_notification);
  246. }
  247. }
  248. $controller->tpl->assign('profile_block', $controller->return_profile_block());
  249. $controller->tpl->assign('user_image_block', $controller->return_user_image_block());
  250. $controller->tpl->assign('course_block', $controller->return_course_block());
  251. $controller->tpl->assign('navigation_course_links', $controller->return_navigation_links());
  252. $controller->tpl->assign('search_block', $controller->return_search_block());
  253. $controller->tpl->assign('notice_block', $controller->return_notice());
  254. $controller->tpl->assign('classes_block', $controller->returnClassesBlock());
  255. $controller->tpl->assign('skills_block', $controller->returnSkillLinks());
  256. $historyClass = '';
  257. if (!empty($_GET['history'])) {
  258. $historyClass = 'courses-history';
  259. }
  260. $controller->tpl->assign('course_history_page', $historyClass);
  261. if ($myCourseListAsCategory) {
  262. $controller->tpl->assign('header', get_lang('MyCourses'));
  263. }
  264. $controller->setGradeBookDependencyBar($userId);
  265. $controller->tpl->display_two_col_template();
  266. // Deleting the session_id.
  267. Session::erase('session_id');
  268. Session::erase('studentview');
  269. api_remove_in_gradebook();