user_portal.php 9.4 KB

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