user_portal.php 10 KB

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