user_portal.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. use Doctrine\Common\Collections\Criteria;
  5. /**
  6. * This is the index file displayed when a user is logged in on Chamilo.
  7. *
  8. * It displays:
  9. * - personal course list
  10. * - menu bar
  11. * Search for CONFIGURATION parameters to modify settings
  12. * @package chamilo.main
  13. * @todo Shouldn't the CONFVAL_ constant be moved to the config page? Has anybody any idea what the are used for?
  14. * If these are really configuration settings then we can add those to the dokeos config settings.
  15. * @todo check for duplication of functions with index.php (user_portal.php is orginally a copy of index.php)
  16. * @todo display_digest, shouldn't this be removed and be made into an extension?
  17. */
  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. }
  24. /* Included libraries */
  25. require_once './main/inc/global.inc.php';
  26. $this_section = SECTION_COURSES;
  27. api_block_anonymous_users(); // Only users who are logged in can proceed.
  28. $userId = api_get_user_id();
  29. /* Constants and CONFIGURATION parameters */
  30. $load_dirs = api_get_setting('show_documents_preview');
  31. $displayMyCourseViewBySessionLink = api_get_setting('my_courses_view_by_session') === 'true';
  32. $nameTools = get_lang('MyCourses');
  33. // Load course notification by ajax
  34. $loadNotificationsByAjax = api_get_configuration_value('user_portal_load_notification_by_ajax');
  35. if ($loadNotificationsByAjax) {
  36. $htmlHeadXtra[] = '<script>
  37. $(function() {
  38. $(".course_notification").each(function(index) {
  39. var div = $(this);
  40. var id = $(this).attr("id");
  41. var idList = id.split("_");
  42. var courseId = idList[1];
  43. var sessionId = idList[2];
  44. var status = idList[3];
  45. $.ajax({
  46. type: "GET",
  47. url: "'.api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=get_notification&course_id="+courseId+"&session_id="+sessionId+"&status="+status,
  48. success: function(data) {
  49. div.append(data);
  50. }
  51. });
  52. });
  53. });
  54. </script>';
  55. }
  56. /*
  57. Header
  58. Include the HTTP, HTML headers plus the top banner.
  59. */
  60. if ($load_dirs) {
  61. $url = api_get_path(WEB_AJAX_PATH).'document.ajax.php?a=document_preview';
  62. $folder_icon = api_get_path(WEB_IMG_PATH).'icons/22/folder.png';
  63. $close_icon = api_get_path(WEB_IMG_PATH).'loading1.gif';
  64. $htmlHeadXtra[] = '<script>
  65. $(document).ready(function() {
  66. $(".document_preview_container").hide();
  67. $(".document_preview").click(function() {
  68. var my_id = this.id;
  69. var course_id = my_id.split("_")[2];
  70. var session_id = my_id.split("_")[3];
  71. //showing div
  72. $(".document_preview_container").hide();
  73. $("#document_result_" +course_id+"_" + session_id).show();
  74. // Loading
  75. var image = $("img", this);
  76. image.attr("src", "'.$close_icon.'");
  77. $.ajax({
  78. url: "'.$url.'",
  79. data: "course_id="+course_id+"&session_id="+session_id,
  80. success: function(return_value) {
  81. image.attr("src", "'.$folder_icon.'");
  82. $("#document_result_" +course_id+"_" + session_id).html(return_value);
  83. }
  84. });
  85. });
  86. });
  87. </script>';
  88. }
  89. if ($displayMyCourseViewBySessionLink) {
  90. $htmlHeadXtra[] = '
  91. <script>
  92. userId = '.$userId.'
  93. $(document).ready(function() {
  94. changeMyCoursesView($.cookie("defaultMyCourseView" + userId));
  95. });
  96. /**
  97. * Keep in cookie the last teacher view for the My Courses Tab. default view, or view by session
  98. * @param inView
  99. */
  100. function changeMyCoursesView(inView) {
  101. $.cookie("defaultMyCourseView"+userId, inView, { expires: 365 });
  102. if (inView == '.IndexManager::VIEW_BY_SESSION.') {
  103. $("#viewBySession").addClass("btn-primary");
  104. $("#viewByDefault").removeClass("btn-primary");
  105. } else {
  106. $("#viewByDefault").addClass("btn-primary");
  107. $("#viewBySession").removeClass("btn-primary");
  108. }
  109. }
  110. </script>';
  111. }
  112. $myCourseListAsCategory = api_get_configuration_value('my_courses_list_as_category');
  113. $controller = new IndexManager(get_lang('MyCourses'));
  114. if (!$myCourseListAsCategory) {
  115. // Main courses and session list
  116. if (isset($_COOKIE['defaultMyCourseView'.$userId]) &&
  117. $_COOKIE['defaultMyCourseView'.$userId] == IndexManager::VIEW_BY_SESSION &&
  118. $displayMyCourseViewBySessionLink
  119. ) {
  120. $courseAndSessions = $controller->returnCoursesAndSessionsViewBySession($userId);
  121. IndexManager::setDefaultMyCourseView(IndexManager::VIEW_BY_SESSION, $userId);
  122. } else {
  123. $courseAndSessions = $controller->returnCoursesAndSessions($userId);
  124. IndexManager::setDefaultMyCourseView(IndexManager::VIEW_BY_DEFAULT, $userId);
  125. }
  126. // if teacher, session coach or admin, display the button to change te course view
  127. if ($displayMyCourseViewBySessionLink &&
  128. (
  129. api_is_drh() ||
  130. api_is_session_general_coach() ||
  131. api_is_platform_admin() ||
  132. api_is_session_admin() ||
  133. api_is_teacher()
  134. )
  135. ) {
  136. $courseAndSessions['html'] = "
  137. <div class='view-by-session-link'>
  138. <div class='btn-group pull-right'>
  139. <a class='btn btn-default' id='viewByDefault' href='user_portal.php'
  140. onclick='changeMyCoursesView(\"".IndexManager::VIEW_BY_DEFAULT."\")'>
  141. ".get_lang('MyCoursesDefaultView')."
  142. </a>
  143. <a class='btn btn-default' id='viewBySession' href='user_portal.php'
  144. onclick='changeMyCoursesView(\"".IndexManager::VIEW_BY_SESSION."\")'>
  145. ".get_lang('MyCoursesSessionView')."
  146. </a>
  147. </div>
  148. </div>
  149. <br /><br />
  150. ".$courseAndSessions['html'];
  151. }
  152. } else {
  153. $categoryCode = isset($_GET['category']) ? $_GET['category'] : '';
  154. if (!$categoryCode) {
  155. $courseAndSessions = $controller->returnCourseCategoryListFromUser($userId);
  156. } else {
  157. $courseAndSessions = $controller->returnCoursesAndSessions(
  158. $userId,
  159. false,
  160. $categoryCode
  161. );
  162. $getCategory = CourseCategory::getCategory($categoryCode);
  163. $controller->tpl->assign('category', $getCategory);
  164. }
  165. }
  166. // Check if a user is enrolled only in one course for going directly to the course after the login.
  167. if (api_get_setting('go_to_course_after_login') == 'true') {
  168. $count_of_sessions = $courseAndSessions['session_count'];
  169. $count_of_courses_no_sessions = $courseAndSessions['course_count'];
  170. // User is subscribe in 1 session and 0 courses.
  171. if ($count_of_sessions == 1 && $count_of_courses_no_sessions == 0) {
  172. $sessions = SessionManager::get_sessions_by_user($userId);
  173. if (isset($sessions[0])) {
  174. $sessionInfo = $sessions[0];
  175. // Session only has 1 course.
  176. if (isset($sessionInfo['courses']) &&
  177. count($sessionInfo['courses']) == 1
  178. ) {
  179. $courseCode = $sessionInfo['courses'][0]['code'];
  180. $courseInfo = api_get_course_info_by_id($sessionInfo['courses'][0]['real_id']);
  181. $courseUrl = $courseInfo['course_public_url'].'?id_session='.$sessionInfo['session_id'];
  182. header('Location:'.$courseUrl);
  183. exit;
  184. }
  185. // Session has many courses.
  186. if (isset($sessionInfo['session_id'])) {
  187. $url = api_get_path(WEB_CODE_PATH).'session/?session_id='.$sessionInfo['session_id'];
  188. header('Location:'.$url);
  189. exit;
  190. }
  191. }
  192. }
  193. // User is subscribed to 1 course.
  194. if (!isset($_SESSION['coursesAlreadyVisited']) &&
  195. $count_of_sessions == 0 &&
  196. $count_of_courses_no_sessions == 1
  197. ) {
  198. $courses = CourseManager::get_courses_list_by_user_id(
  199. $userId
  200. );
  201. if (!empty($courses) && isset($courses[0]) && isset($courses[0]['code'])) {
  202. $courseInfo = api_get_course_info_by_id($courses[0]['real_id']);
  203. if (!empty($courseInfo)) {
  204. $courseUrl = $courseInfo['course_public_url'];
  205. header('Location:'.$courseUrl);
  206. exit;
  207. }
  208. }
  209. }
  210. }
  211. // Show the chamilo mascot
  212. if (empty($courseAndSessions['html']) && !isset($_GET['history'])) {
  213. $controller->tpl->assign(
  214. 'welcome_to_course_block',
  215. $controller->return_welcome_to_course_block()
  216. );
  217. }
  218. $controller->tpl->assign('content', $courseAndSessions['html']);
  219. // Display the Site Use Cookie Warning Validation
  220. $useCookieValidation = api_get_setting('cookie_warning');
  221. if ($useCookieValidation === 'true') {
  222. if (isset($_POST['acceptCookies'])) {
  223. api_set_site_use_cookie_warning_cookie();
  224. } else {
  225. if (!api_site_use_cookie_warning_cookie_exist()) {
  226. if (Template::isToolBarDisplayedForUser()) {
  227. $controller->tpl->assign('toolBarDisplayed', true);
  228. } else {
  229. $controller->tpl->assign('toolBarDisplayed', false);
  230. }
  231. $controller->tpl->assign('displayCookieUsageWarning', true);
  232. }
  233. }
  234. }
  235. //check for flash and message
  236. $sniff_notification = '';
  237. $some_activex = isset($_SESSION['sniff_check_some_activex']) ? $_SESSION['sniff_check_some_activex'] : null;
  238. $some_plugins = isset($_SESSION['sniff_check_some_plugins']) ? $_SESSION['sniff_check_some_plugins'] : null;
  239. if (!empty($some_activex) || !empty($some_plugins)) {
  240. if (!preg_match("/flash_yes/", $some_activex) && !preg_match("/flash_yes/", $some_plugins)) {
  241. $sniff_notification = Display::return_message(get_lang('NoFlash'), 'warning', true);
  242. //js verification - To annoying of redirecting every time the page
  243. $controller->tpl->assign('sniff_notification', $sniff_notification);
  244. }
  245. }
  246. $diagnosisComplete = true;
  247. if (api_is_student()) {
  248. $extraFieldValue = new ExtraFieldValue('user');
  249. $diagnosisComplete = $extraFieldValue->get_values_by_handler_and_field_variable(
  250. api_get_user_id(),
  251. 'diagnosis_completed'
  252. );
  253. if ($diagnosisComplete === false ||
  254. is_array($diagnosisComplete) && empty($diagnosisComplete['value'])
  255. ) {
  256. $url = api_get_path(WEB_PATH).'search.php';
  257. $link = Display::url($url, $url);
  258. Display::addFlash(
  259. Display::return_message(
  260. sprintf(get_lang('DoDiagnosisNow'), $link),
  261. 'normal',
  262. false
  263. )
  264. );
  265. }
  266. }
  267. // ofaj
  268. $diagnosis = '';
  269. if (api_is_drh() || api_is_student_boss()) {
  270. $diagnosis = Display::url(get_lang('DiagnosisManagement'), api_get_path(WEB_PATH).'load_search.php').'<br />';
  271. $diagnosis .= Display::url(get_lang('DiagnosticForm'), api_get_path(WEB_PATH).'search.php');
  272. } else {
  273. if (api_is_student()) {
  274. if ($diagnosisComplete === false ||
  275. is_array($diagnosisComplete) && empty($diagnosisComplete['value'])
  276. ) {
  277. $diagnosis = Display::url(
  278. get_lang('DiagnosticForm'),
  279. api_get_path(WEB_PATH).'search.php'
  280. );
  281. }
  282. }
  283. }
  284. $block = '';
  285. if (!empty($diagnosis)) {
  286. $block .= $controller->show_right_block(
  287. get_lang('Diagnostic'),
  288. $diagnosis,
  289. 'diagnosis_block',
  290. null,
  291. 'diagnosis',
  292. 'diagnosisCollapse'
  293. );
  294. }
  295. $controller->tpl->assign('diagnosis_block', $block);
  296. $controller->tpl->assign('profile_block', $controller->return_profile_block());
  297. $controller->tpl->assign('user_image_block', $controller->return_user_image_block());
  298. $controller->tpl->assign('course_block', $controller->return_course_block());
  299. $controller->tpl->assign('navigation_course_links', $controller->return_navigation_links());
  300. $controller->tpl->assign('search_block', $controller->return_search_block());
  301. $controller->tpl->assign('classes_block', $controller->return_classes_block());
  302. $controller->tpl->assign('skills_block', $controller->returnSkillLinks());
  303. $historyClass = '';
  304. if (!empty($_GET['history'])) {
  305. $historyClass = 'courses-history';
  306. }
  307. $controller->tpl->assign('course_history_page', $historyClass);
  308. if ($myCourseListAsCategory) {
  309. $controller->tpl->assign('header', get_lang('MyCourses'));
  310. }
  311. $allow = api_get_configuration_value('gradebook_dependency');
  312. if ($allow) {
  313. $courseAndSessions = $controller->returnCoursesAndSessions(
  314. $userId,
  315. false,
  316. '',
  317. false
  318. );
  319. $courseList = api_get_configuration_value('gradebook_dependency_mandatory_courses');
  320. $courseList = isset($courseList['courses']) ? $courseList['courses'] : [];
  321. $mandatoryCourse = [];
  322. if (!empty($courseList)) {
  323. foreach ($courseList as $courseId) {
  324. $courseInfo = api_get_course_info_by_id($courseId);
  325. $mandatoryCourse[] = $courseInfo['code'];
  326. }
  327. }
  328. // @todo improve calls of course info
  329. $subscribedCourses = !empty($courseAndSessions['courses']) ? $courseAndSessions['courses'] : [];
  330. $mainCategoryList = [];
  331. foreach ($subscribedCourses as $courseInfo) {
  332. $courseCode = $courseInfo['code'];
  333. $categories = Category::load(null, null, $courseCode);
  334. /** @var Category $category */
  335. $category = !empty($categories[0]) ? $categories[0] : [];
  336. if (!empty($category)) {
  337. $mainCategoryList[] = $category;
  338. }
  339. }
  340. $result = [];
  341. $result20 = 0;
  342. $result80 = 0;
  343. $countCoursesPassedNoDependency = 0;
  344. /** @var Category $category */
  345. foreach ($mainCategoryList as $category) {
  346. $userFinished = Category::userFinishedCourse(
  347. $userId,
  348. $category,
  349. true
  350. );
  351. if ($userFinished) {
  352. if (in_array($category->get_course_code(), $mandatoryCourse)) {
  353. if ($result20 < 20) {
  354. $result20 += 10;
  355. }
  356. } else {
  357. $countCoursesPassedNoDependency++;
  358. if ($result80 < 80) {
  359. $result80 += 10;
  360. }
  361. }
  362. }
  363. }
  364. $finalResult = $result20 + $result80;
  365. $gradeBookList = api_get_configuration_value('gradebook_badge_sidebar');
  366. $gradeBookList = isset($gradeBookList['gradebooks']) ? $gradeBookList['gradebooks'] : [];
  367. $badgeList = [];
  368. foreach ($gradeBookList as $id) {
  369. $categories = Category::load($id);
  370. /** @var Category $category */
  371. $category = !empty($categories[0]) ? $categories[0] : [];
  372. $badgeList[$id]['name'] = $category->get_name();
  373. $badgeList[$id]['finished'] = false;
  374. $badgeList[$id]['skills'] = [];
  375. if (!empty($category)) {
  376. $minToValidate = $category->getMinimumToValidate();
  377. $dependencies = $category->getCourseListDependency();
  378. $countDependenciesPassed = 0;
  379. foreach ($dependencies as $courseId) {
  380. $courseInfo = api_get_course_info_by_id($courseId);
  381. $courseCode = $courseInfo['code'];
  382. $categories = Category::load(null, null, $courseCode);
  383. $subCategory = !empty($categories[0]) ? $categories[0] : null;
  384. if (!empty($subCategory)) {
  385. $score = Category::userFinishedCourse(
  386. $userId,
  387. $subCategory,
  388. true
  389. );
  390. if ($score) {
  391. $countDependenciesPassed++;
  392. }
  393. }
  394. }
  395. $userFinished =
  396. $countDependenciesPassed == count($dependencies) &&
  397. $countCoursesPassedNoDependency >= $minToValidate
  398. ;
  399. if ($userFinished) {
  400. $badgeList[$id]['finished'] = true;
  401. }
  402. $objSkill = new Skill();
  403. $skills = $category->get_skills();
  404. $skillList = [];
  405. foreach ($skills as $skill) {
  406. $skillList[] = $objSkill->get($skill['id']);
  407. }
  408. $badgeList[$id]['skills'] = $skillList;
  409. }
  410. }
  411. $controller->tpl->assign(
  412. 'grade_book_sidebar',
  413. true
  414. );
  415. $controller->tpl->assign(
  416. 'grade_book_progress',
  417. $finalResult
  418. );
  419. $controller->tpl->assign('grade_book_badge_list', $badgeList);
  420. /*if ($finalScore > 0) {
  421. $finalScore = (int) $finalScore / count($total);
  422. if ($finalScore == 100) {
  423. $completed = true;
  424. }
  425. }*/
  426. }
  427. $controller->tpl->display_two_col_template();
  428. // Deleting the session_id.
  429. Session::erase('session_id');
  430. Session::erase('studentview');
  431. api_remove_in_gradebook();