user_portal.php 11 KB

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