user_portal.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. * @todo rewrite code to separate display, logic, database code
  11. * @package chamilo.main
  12. * @todo Shouldn't the SCRIPTVAL_ and CONFVAL_ constant be moved to the config page? Has anybody any idea what the are used for?
  13. * If these are really configuration settings then we can add those to the dokeos config settings.
  14. * @todo move display_courses and some other functions to a more appripriate place course.lib.php or user.lib.php
  15. * @todo use api_get_path instead of $rootAdminWeb
  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. /**
  20. * INIT SECTION
  21. */
  22. // Language files that should be included.
  23. $language_file = array('courses', 'index','admin');
  24. $cidReset = true; /* Flag forcing the 'current course' reset,
  25. as we're not inside a course anymore */
  26. if (isset($_SESSION['this_section']))
  27. unset($_SESSION['this_section']); // For HTML editor repository.
  28. /* Included libraries */
  29. require_once './main/inc/global.inc.php';
  30. require_once api_get_path(LIBRARY_PATH).'userportal.lib.php';
  31. api_block_anonymous_users(); // Only users who are logged in can proceed.
  32. /* Constants and CONFIGURATION parameters */
  33. //$load_dirs = api_get_setting('courses_list_document_dynamic_dropdown');
  34. $load_dirs = true;
  35. // This is the main function to get the course list.
  36. $personal_course_list = UserManager::get_personal_session_course_list(api_get_user_id());
  37. // Check if a user is enrolled only in one course for going directly to the course after the login.
  38. if (api_get_setting('go_to_course_after_login') == 'true') {
  39. $my_session_list = array();
  40. $count_of_courses_no_sessions = 0;
  41. $count_of_courses_with_sessions = 0;
  42. foreach($personal_course_list as $course) {
  43. if (!empty($course['id_session'])) {
  44. $my_session_list[$course['id_session']] = true;
  45. $count_of_courses_with_sessions++;
  46. } else {
  47. $count_of_courses_no_sessions++;
  48. }
  49. }
  50. $count_of_sessions = count($my_session_list);
  51. //echo $count_of_sessions.' '.$count_of_courses_with_sessions.' '.$count_of_courses_no_sessions;
  52. //!isset($_SESSION['coursesAlreadyVisited'])
  53. if ($count_of_sessions == 1 && $count_of_courses_no_sessions == 0) {
  54. $key = array_keys($personal_course_list);
  55. $course_info = $personal_course_list[$key[0]];
  56. $course_directory = $course_info['d'];
  57. $id_session = isset($course_info['id_session']) ? $course_info['id_session'] : 0;
  58. $url = api_get_path(WEB_CODE_PATH).'session/?session_id='.$id_session;
  59. header('location:'.$url);
  60. exit;
  61. }
  62. if (!isset($_SESSION['coursesAlreadyVisited']) && $count_of_sessions == 0 && $count_of_courses_no_sessions == 1) {
  63. $key = array_keys($personal_course_list);
  64. $course_info = $personal_course_list[$key[0]];
  65. $course_directory = $course_info['d'];
  66. $id_session = isset($course_info['id_session']) ? $course_info['id_session'] : 0;
  67. $url = api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$id_session;
  68. header('location:'.$url);
  69. exit;
  70. }
  71. /*
  72. if (api_get_setting('hide_courses_in_sessions') == 'true') {
  73. //Check sessions
  74. $session_list = array();
  75. $only_session_id = 0;
  76. foreach($personal_course_list as $course_item) {
  77. $session_list[$course_item['id_session']] = $course_item;
  78. $only_session_id = $course_item['id_session'];
  79. }
  80. if (count($session_list) == 1 && !empty($only_session_id)) {
  81. header('Location:'.api_get_path(WEB_CODE_PATH).'session/?session_id='.$session_list[$only_session_id]['id_session']);
  82. }
  83. }
  84. */
  85. }
  86. /*
  87. $nosession = false;
  88. if (api_get_setting('use_session_mode') == 'true' && !$nosession) {
  89. $display_actives = !isset($_GET['inactives']);
  90. }*/
  91. $nameTools = get_lang('MyCourses');
  92. $this_section = SECTION_COURSES;
  93. /* Check configuration parameters integrity */
  94. /*
  95. if (CONFVAL_showExtractInfo != SCRIPTVAL_UnderCourseList and $orderKey[0] != 'keyCourse') {
  96. // CONFVAL_showExtractInfo must be SCRIPTVAL_UnderCourseList to accept $orderKey[0] != 'keyCourse'
  97. if (DEBUG || api_is_platform_admin()){ // Show bug if admin. Else force a new order.
  98. die('
  99. <strong>config error:'.__FILE__.'</strong><br />
  100. set
  101. <ul>
  102. <li>
  103. CONFVAL_showExtractInfo = SCRIPTVAL_UnderCourseList
  104. (actually : '.CONFVAL_showExtractInfo.')
  105. </li>
  106. </ul>
  107. or
  108. <ul>
  109. <li>
  110. $orderKey[0] != \'keyCourse\'
  111. (actually : '.$orderKey[0].')
  112. </li>
  113. </ul>');
  114. } else {
  115. $orderKey = array('keyCourse', 'keyTools', 'keyTime');
  116. }
  117. }*/
  118. /*
  119. Header
  120. Include the HTTP, HTML headers plus the top banner.
  121. */
  122. if ($load_dirs) {
  123. $url = api_get_path(WEB_AJAX_PATH).'document.ajax.php?a=document_preview';
  124. $folder_icon = api_get_path(WEB_IMG_PATH).'icons/22/folder.png';
  125. $close_icon = api_get_path(WEB_IMG_PATH).'loading1.gif';
  126. $htmlHeadXtra[] = '<script type="text/javascript">
  127. $(document).ready( function() {
  128. $(".document_preview_container").hide();
  129. $(".document_preview").click(function() {
  130. var my_id = this.id;
  131. var course_id = my_id.split("_")[2];
  132. var session_id = my_id.split("_")[3];
  133. //showing div
  134. $(".document_preview_container").hide();
  135. $("#document_result_" +course_id+"_" + session_id).show();
  136. //Loading
  137. var image = $("img", this);
  138. image.attr("src", "'.$close_icon.'");
  139. $.ajax({
  140. url: "'.$url.'",
  141. data: "course_id="+course_id+"&session_id="+session_id,
  142. success: function(return_value) {
  143. image.attr("src", "'.$folder_icon.'");
  144. $("#document_result_" +course_id+"_" + session_id).html(return_value);
  145. }
  146. });
  147. });
  148. });
  149. </script>';
  150. }
  151. Display :: display_header($nameTools);
  152. /* MAIN CODE */
  153. $index = new IndexManager($nameTools, false);
  154. echo '<div class="maincontent" id="maincontent">'; // Start of content for logged in users.
  155. // Plugins for the my courses main area.
  156. echo $index->return_courses_main_plugin();
  157. // Main courses and session list
  158. echo $index->return_courses_and_sessions($personal_course_list);
  159. echo '</div>'; // End of content main-section
  160. // Register whether full admin or null admin course by course through an array dbname x user status.
  161. api_session_register('status');
  162. /* RIGHT MENU */
  163. echo '<div id="menu-wrapper">';
  164. //Profile content
  165. echo $index->return_profile_block();
  166. echo $index->return_account_block();
  167. echo $index->return_navigation_course_links($menu_navigation);
  168. echo $index->return_plugin_courses_block();
  169. echo $index->return_reservation_block();
  170. echo $index->return_search_block();
  171. echo $index->return_classes_block();
  172. echo '</div>'; // End of menu wrapper
  173. // Deleting the session_id.
  174. api_session_unregister('session_id');
  175. // Footer
  176. Display :: display_footer();