user_portal.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This is the index file displayed when a user is logged in on Chamilo.
  6. *
  7. * It displays:
  8. * - personal course list
  9. * - menu bar
  10. * Search for CONFIGURATION parameters to modify settings
  11. *
  12. * @package chamilo.main
  13. *
  14. * @todo Shouldn't the CONFVAL_ constant be moved to the config page? Has anybody any idea what the are used for?
  15. * If these are really configuration settings then we can add those to the dokeos config settings.
  16. * @todo check for duplication of functions with index.php (user_portal.php is orginally a copy of index.php)
  17. * @todo display_digest, shouldn't this be removed and be made into an extension?
  18. */
  19. /* Flag forcing the 'current course' reset, as we're not inside a course anymore */
  20. $cidReset = true;
  21. // For HTML editor repository.
  22. if (isset($_SESSION['this_section'])) {
  23. unset($_SESSION['this_section']);
  24. }
  25. /* Included libraries */
  26. require_once './main/inc/global.inc.php';
  27. $this_section = SECTION_COURSES;
  28. api_block_anonymous_users(); // Only users who are logged in can proceed.
  29. $logInfo = [
  30. 'tool' => SECTION_COURSES,
  31. 'tool_id' => 0,
  32. 'tool_id_detail' => 0,
  33. 'action' => '',
  34. 'info' => '',
  35. ];
  36. Event::registerLog($logInfo);
  37. $userId = api_get_user_id();
  38. $collapsable = api_get_configuration_value('allow_user_session_collapsable');
  39. if ($collapsable) {
  40. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
  41. $sessionId = isset($_REQUEST['session_id']) ? $_REQUEST['session_id'] : '';
  42. $value = isset($_REQUEST['value']) ? (int) $_REQUEST['value'] : '';
  43. switch ($action) {
  44. case 'collapse_session':
  45. if (!empty($sessionId)) {
  46. $userRelSession = SessionManager::getUserSession($userId, $sessionId);
  47. if ($userRelSession) {
  48. $table = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  49. $sql = "UPDATE $table SET collapsed = $value WHERE id = ".$userRelSession['id'];
  50. Database::query($sql);
  51. Display::addFlash(Display::return_message(get_lang('Updated')));
  52. }
  53. header('Location: user_portal.php');
  54. exit;
  55. }
  56. break;
  57. }
  58. }
  59. /* Constants and CONFIGURATION parameters */
  60. $load_dirs = api_get_setting('show_documents_preview');
  61. $displayMyCourseViewBySessionLink = api_get_setting('my_courses_view_by_session') === 'true';
  62. $nameTools = get_lang('MyCourses');
  63. $loadHistory = isset($_GET['history']) && intval($_GET['history']) == 1 ? true : false;
  64. // Load course notification by ajax
  65. $loadNotificationsByAjax = api_get_configuration_value('user_portal_load_notification_by_ajax');
  66. if ($loadNotificationsByAjax) {
  67. $htmlHeadXtra[] = '<script>
  68. $(function() {
  69. $(".course_notification").each(function(index) {
  70. var div = $(this);
  71. var id = $(this).attr("id");
  72. var idList = id.split("_");
  73. var courseId = idList[1];
  74. var sessionId = idList[2];
  75. var status = idList[3];
  76. $.ajax({
  77. type: "GET",
  78. url: "'.api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=get_notification&course_id="+courseId+"&session_id="+sessionId+"&status="+status,
  79. success: function(data) {
  80. div.append(data);
  81. }
  82. });
  83. });
  84. });
  85. </script>';
  86. }
  87. /*
  88. Header
  89. Include the HTTP, HTML headers plus the top banner.
  90. */
  91. if ($load_dirs) {
  92. $url = api_get_path(WEB_AJAX_PATH).'document.ajax.php?a=document_preview';
  93. $folder_icon = api_get_path(WEB_IMG_PATH).'icons/22/folder.png';
  94. $close_icon = api_get_path(WEB_IMG_PATH).'loading1.gif';
  95. $htmlHeadXtra[] = '<script>
  96. $(document).ready(function() {
  97. $(".document_preview_container").hide();
  98. $(".document_preview").click(function() {
  99. var my_id = this.id;
  100. var course_id = my_id.split("_")[2];
  101. var session_id = my_id.split("_")[3];
  102. //showing div
  103. $(".document_preview_container").hide();
  104. $("#document_result_" +course_id+"_" + session_id).show();
  105. // Loading
  106. var image = $("img", this);
  107. image.attr("src", "'.$close_icon.'");
  108. $.ajax({
  109. url: "'.$url.'",
  110. data: "course_id="+course_id+"&session_id="+session_id,
  111. success: function(return_value) {
  112. image.attr("src", "'.$folder_icon.'");
  113. $("#document_result_" +course_id+"_" + session_id).html(return_value);
  114. }
  115. });
  116. });
  117. });
  118. </script>';
  119. }
  120. if ($displayMyCourseViewBySessionLink) {
  121. $htmlHeadXtra[] = '
  122. <script>
  123. userId = '.$userId.'
  124. $(document).ready(function() {
  125. changeMyCoursesView($.cookie("defaultMyCourseView" + userId));
  126. });
  127. /**
  128. * Keep in cookie the last teacher view for the My Courses Tab. default view, or view by session
  129. * @param inView
  130. */
  131. function changeMyCoursesView(inView) {
  132. $.cookie("defaultMyCourseView"+userId, inView, { expires: 365 });
  133. if (inView == '.IndexManager::VIEW_BY_SESSION.') {
  134. $("#viewBySession").addClass("btn-primary");
  135. $("#viewByDefault").removeClass("btn-primary");
  136. } else {
  137. $("#viewByDefault").addClass("btn-primary");
  138. $("#viewBySession").removeClass("btn-primary");
  139. }
  140. }
  141. </script>';
  142. }
  143. $myCourseListAsCategory = api_get_configuration_value('my_courses_list_as_category');
  144. $controller = new IndexManager(get_lang('MyCourses'));
  145. if (!$myCourseListAsCategory) {
  146. // Main courses and session list
  147. if (isset($_COOKIE['defaultMyCourseView'.$userId]) &&
  148. $_COOKIE['defaultMyCourseView'.$userId] == IndexManager::VIEW_BY_SESSION &&
  149. $displayMyCourseViewBySessionLink
  150. ) {
  151. $courseAndSessions = $controller->returnCoursesAndSessionsViewBySession($userId);
  152. IndexManager::setDefaultMyCourseView(IndexManager::VIEW_BY_SESSION, $userId);
  153. } else {
  154. $courseAndSessions = $controller->returnCoursesAndSessions($userId, true, null, true, $loadHistory);
  155. IndexManager::setDefaultMyCourseView(IndexManager::VIEW_BY_DEFAULT, $userId);
  156. }
  157. // if teacher, session coach or admin, display the button to change te course view
  158. if ($displayMyCourseViewBySessionLink &&
  159. (
  160. api_is_drh() ||
  161. api_is_session_general_coach() ||
  162. api_is_platform_admin() ||
  163. api_is_session_admin() ||
  164. api_is_teacher()
  165. )
  166. ) {
  167. $courseAndSessions['html'] = "
  168. <div class='view-by-session-link'>
  169. <div class='btn-group pull-right'>
  170. <a class='btn btn-default' id='viewByDefault' href='user_portal.php'
  171. onclick='changeMyCoursesView(\"".IndexManager::VIEW_BY_DEFAULT."\")'>
  172. ".get_lang('MyCoursesDefaultView')."
  173. </a>
  174. <a class='btn btn-default' id='viewBySession' href='user_portal.php'
  175. onclick='changeMyCoursesView(\"".IndexManager::VIEW_BY_SESSION."\")'>
  176. ".get_lang('MyCoursesSessionView')."
  177. </a>
  178. </div>
  179. </div>
  180. <br /><br />
  181. ".$courseAndSessions['html'];
  182. }
  183. } else {
  184. $categoryCode = isset($_GET['category']) ? $_GET['category'] : '';
  185. if (!$categoryCode) {
  186. $courseAndSessions = $controller->returnCourseCategoryListFromUser($userId);
  187. } else {
  188. $courseAndSessions = $controller->returnCoursesAndSessions(
  189. $userId,
  190. false,
  191. $categoryCode,
  192. true,
  193. $loadHistory
  194. );
  195. $getCategory = CourseCategory::getCategory($categoryCode);
  196. $controller->tpl->assign('category', $getCategory);
  197. }
  198. }
  199. // Check if a user is enrolled only in one course for going directly to the course after the login.
  200. if (api_get_setting('go_to_course_after_login') == 'true') {
  201. $count_of_sessions = $courseAndSessions['session_count'];
  202. $count_of_courses_no_sessions = $courseAndSessions['course_count'];
  203. // User is subscribe in 1 session and 0 courses.
  204. if ($count_of_sessions == 1 && $count_of_courses_no_sessions == 0) {
  205. $sessions = SessionManager::get_sessions_by_user($userId);
  206. if (isset($sessions[0])) {
  207. $sessionInfo = $sessions[0];
  208. // Session only has 1 course.
  209. if (isset($sessionInfo['courses']) &&
  210. count($sessionInfo['courses']) == 1
  211. ) {
  212. $courseCode = $sessionInfo['courses'][0]['code'];
  213. $courseInfo = api_get_course_info_by_id($sessionInfo['courses'][0]['real_id']);
  214. $courseUrl = $courseInfo['course_public_url'].'?id_session='.$sessionInfo['session_id'];
  215. header('Location:'.$courseUrl);
  216. exit;
  217. }
  218. // Session has many courses.
  219. if (isset($sessionInfo['session_id'])) {
  220. $url = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$sessionInfo['session_id'];
  221. header('Location:'.$url);
  222. exit;
  223. }
  224. }
  225. }
  226. // User is subscribed to 1 course.
  227. if (!isset($_SESSION['coursesAlreadyVisited']) &&
  228. $count_of_sessions == 0 &&
  229. $count_of_courses_no_sessions == 1
  230. ) {
  231. $courses = CourseManager::get_courses_list_by_user_id($userId);
  232. if (!empty($courses) && isset($courses[0]) && isset($courses[0]['code'])) {
  233. $courseInfo = api_get_course_info_by_id($courses[0]['real_id']);
  234. if (!empty($courseInfo)) {
  235. $courseUrl = $courseInfo['course_public_url'];
  236. header('Location:'.$courseUrl);
  237. exit;
  238. }
  239. }
  240. }
  241. }
  242. // Show the chamilo mascot
  243. if (empty($courseAndSessions['html']) && !isset($_GET['history'])) {
  244. $controller->tpl->assign(
  245. 'welcome_to_course_block',
  246. $controller->return_welcome_to_course_block()
  247. );
  248. }
  249. $controller->tpl->assign('content', $courseAndSessions['html']);
  250. // Display the Site Use Cookie Warning Validation
  251. $useCookieValidation = api_get_setting('cookie_warning');
  252. if ($useCookieValidation === 'true') {
  253. if (isset($_POST['acceptCookies'])) {
  254. api_set_site_use_cookie_warning_cookie();
  255. } else {
  256. if (!api_site_use_cookie_warning_cookie_exist()) {
  257. if (Template::isToolBarDisplayedForUser()) {
  258. $controller->tpl->assign('toolBarDisplayed', true);
  259. } else {
  260. $controller->tpl->assign('toolBarDisplayed', false);
  261. }
  262. $controller->tpl->assign('displayCookieUsageWarning', true);
  263. }
  264. }
  265. }
  266. //check for flash and message
  267. $sniff_notification = '';
  268. $some_activex = isset($_SESSION['sniff_check_some_activex']) ? $_SESSION['sniff_check_some_activex'] : null;
  269. $some_plugins = isset($_SESSION['sniff_check_some_plugins']) ? $_SESSION['sniff_check_some_plugins'] : null;
  270. if (!empty($some_activex) || !empty($some_plugins)) {
  271. if (!preg_match("/flash_yes/", $some_activex) && !preg_match("/flash_yes/", $some_plugins)) {
  272. $sniff_notification = Display::return_message(get_lang('NoFlash'), 'warning', true);
  273. //js verification - To annoying of redirecting every time the page
  274. $controller->tpl->assign('sniff_notification', $sniff_notification);
  275. }
  276. }
  277. $diagnosisComplete = true;
  278. if (api_is_student()) {
  279. $extraFieldValue = new ExtraFieldValue('user');
  280. $diagnosisComplete = $extraFieldValue->get_values_by_handler_and_field_variable(
  281. api_get_user_id(),
  282. 'diagnosis_completed'
  283. );
  284. if ($diagnosisComplete === false ||
  285. is_array($diagnosisComplete) && empty($diagnosisComplete['value'])
  286. ) {
  287. $url = api_get_path(WEB_PATH).'search.php';
  288. $link = Display::url($url, $url);
  289. Display::addFlash(
  290. Display::return_message(
  291. sprintf(get_lang('DoDiagnosisNow'), $link),
  292. 'normal',
  293. false
  294. )
  295. );
  296. }
  297. }
  298. // ofaj
  299. $diagnosis = '';
  300. if (api_is_drh() || api_is_student_boss()) {
  301. $diagnosis = Display::url(get_lang('DiagnosisManagement'), api_get_path(WEB_PATH).'load_search.php').'<br />';
  302. $diagnosis .= Display::url(get_lang('DiagnosticForm'), api_get_path(WEB_PATH).'search.php');
  303. } else {
  304. if (api_is_student()) {
  305. if ($diagnosisComplete === false ||
  306. is_array($diagnosisComplete) && empty($diagnosisComplete['value'])
  307. ) {
  308. $diagnosis = Display::url(
  309. get_lang('DiagnosticForm'),
  310. api_get_path(WEB_PATH).'search.php'
  311. );
  312. }
  313. }
  314. }
  315. $block = '';
  316. if (!empty($diagnosis)) {
  317. $block .= $controller->showRightBlock(
  318. get_lang('Diagnostic'),
  319. '<ul class="list-group"><li class="list-group-item">'.$diagnosis.'</li></ul>',
  320. 'diagnosis_block',
  321. null,
  322. 'diagnosis',
  323. 'diagnosisCollapse'
  324. );
  325. }
  326. $controller->tpl->assign('diagnosis_block', $block);
  327. $controller->tpl->assign('profile_block', $controller->return_profile_block());
  328. $controller->tpl->assign('user_image_block', $controller->return_user_image_block());
  329. // Ofaj
  330. //$controller->tpl->assign('course_block', $controller->return_course_block());
  331. //$controller->tpl->assign('navigation_course_links', $controller->return_navigation_links());
  332. //$controller->tpl->assign('search_block', $controller->return_search_block());
  333. $controller->tpl->assign('notice_block', $controller->return_notice());
  334. //$controller->tpl->assign('classes_block', $controller->returnClassesBlock());
  335. $controller->tpl->assign('skills_block', $controller->returnSkillLinks());
  336. $historyClass = '';
  337. if (!empty($_GET['history'])) {
  338. $historyClass = 'courses-history';
  339. }
  340. $controller->tpl->assign('course_history_page', $historyClass);
  341. if ($myCourseListAsCategory) {
  342. $controller->tpl->assign('header', get_lang('MyCourses'));
  343. }
  344. $controller->setGradeBookDependencyBar($userId);
  345. $controller->tpl->display_two_col_template();
  346. // Deleting the session_id.
  347. Session::erase('session_id');
  348. Session::erase('id_session');
  349. Session::erase('studentview');
  350. api_remove_in_gradebook();