user_portal.php 10.0 KB

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