user_portal.php 9.7 KB

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