user_portal.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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. // Don't change these settings
  23. define('SCRIPTVAL_No', 0);
  24. define('SCRIPTVAL_InCourseList', 1);
  25. define('SCRIPTVAL_UnderCourseList', 2);
  26. define('SCRIPTVAL_Both', 3);
  27. define('SCRIPTVAL_NewEntriesOfTheDay', 4);
  28. define('SCRIPTVAL_NewEntriesOfTheDayOfLastLogin', 5);
  29. define('SCRIPTVAL_NoTimeLimit', 6);
  30. // End 'don't change' section
  31. // Language files that should be included.
  32. $language_file = array('courses', 'index','admin');
  33. $cidReset = true; /* Flag forcing the 'current course' reset,
  34. as we're not inside a course anymore */
  35. if (isset($_SESSION['this_section']))
  36. unset($_SESSION['this_section']); // For HTML editor repository.
  37. /* Included libraries */
  38. require_once './main/inc/global.inc.php';
  39. $libpath = api_get_path(LIBRARY_PATH);
  40. require_once $libpath.'course.lib.php';
  41. require_once $libpath.'system_announcements.lib.php';
  42. require_once $libpath.'groupmanager.lib.php';
  43. require_once $libpath.'usermanager.lib.php';
  44. require_once 'main/survey/survey.lib.php';
  45. require_once $libpath.'sessionmanager.lib.php';
  46. api_block_anonymous_users(); // Only users who are logged in can proceed.
  47. /* Table definitions */
  48. // Database table definitions.
  49. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  50. $main_admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  51. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  52. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  53. $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  54. /* Constants and CONFIGURATION parameters */
  55. // ---- Course list options ----
  56. define('CONFVAL_showCourseLangIfNotSameThatPlatform', true);
  57. // Preview of course content
  58. // to disable all: set CONFVAL_maxTotalByCourse = 0
  59. // to enable all: set e.g. CONFVAL_maxTotalByCourse = 5
  60. // by default disabled since what's new icons are better (see function display_digest() )
  61. define('CONFVAL_maxValvasByCourse', 2); // Maximum number of entries
  62. define('CONFVAL_maxAgendaByCourse', 2); // collected from each course
  63. define('CONFVAL_maxTotalByCourse', 0); // and displayed in summary.
  64. define('CONFVAL_NB_CHAR_FROM_CONTENT', 80);
  65. // Order to sort data
  66. $orderKey = array('keyTools', 'keyTime', 'keyCourse'); // default "best" Choice
  67. //$orderKey = array('keyTools', 'keyCourse', 'keyTime');
  68. //$orderKey = array('keyCourse', 'keyTime', 'keyTools');
  69. //$orderKey = array('keyCourse', 'keyTools', 'keyTime');
  70. define('CONFVAL_showExtractInfo', SCRIPTVAL_UnderCourseList);
  71. // SCRIPTVAL_InCourseList // best choice if $orderKey[0] == 'keyCourse'
  72. // SCRIPTVAL_UnderCourseList // best choice
  73. // SCRIPTVAL_Both // probably only for debug
  74. //define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatShort'));
  75. define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatLong'));
  76. //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NewEntriesOfTheDay);
  77. //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NoTimeLimit);
  78. define("CONFVAL_limitPreviewTo", SCRIPTVAL_NewEntriesOfTheDayOfLastLogin);
  79. //$load_dirs = api_get_setting('courses_list_document_dynamic_dropdown');
  80. $load_dirs = true;
  81. // This is the main function to get the course list.
  82. $personal_course_list = UserManager::get_personal_session_course_list(api_get_user_id());
  83. // Check if a user is enrolled only in one course for going directly to the course after the login.
  84. if (api_get_setting('go_to_course_after_login') == 'true') {
  85. $my_session_list = array();
  86. $count_of_courses_no_sessions = 0;
  87. $count_of_courses_with_sessions = 0;
  88. foreach($personal_course_list as $course) {
  89. if (!empty($course['id_session'])) {
  90. $my_session_list[$course['id_session']] = true;
  91. $count_of_courses_with_sessions++;
  92. } else {
  93. $count_of_courses_no_sessions++;
  94. }
  95. }
  96. $count_of_sessions = count($my_session_list);
  97. //echo $count_of_sessions.' '.$count_of_courses_with_sessions.' '.$count_of_courses_no_sessions;
  98. //!isset($_SESSION['coursesAlreadyVisited'])
  99. if ($count_of_sessions == 1 && $count_of_courses_no_sessions == 0) {
  100. $key = array_keys($personal_course_list);
  101. $course_info = $personal_course_list[$key[0]];
  102. $course_directory = $course_info['d'];
  103. $id_session = isset($course_info['id_session']) ? $course_info['id_session'] : 0;
  104. $url = api_get_path(WEB_CODE_PATH).'session/?session_id='.$id_session;
  105. header('location:'.$url);
  106. exit;
  107. }
  108. if (!isset($_SESSION['coursesAlreadyVisited']) && $count_of_sessions == 0 && $count_of_courses_no_sessions == 1) {
  109. $key = array_keys($personal_course_list);
  110. $course_info = $personal_course_list[$key[0]];
  111. $course_directory = $course_info['d'];
  112. $id_session = isset($course_info['id_session']) ? $course_info['id_session'] : 0;
  113. $url = api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$id_session;
  114. header('location:'.$url);
  115. exit;
  116. }
  117. /*
  118. if (api_get_setting('hide_courses_in_sessions') == 'true') {
  119. //Check sessions
  120. $session_list = array();
  121. $only_session_id = 0;
  122. foreach($personal_course_list as $course_item) {
  123. $session_list[$course_item['id_session']] = $course_item;
  124. $only_session_id = $course_item['id_session'];
  125. }
  126. if (count($session_list) == 1 && !empty($only_session_id)) {
  127. header('Location:'.api_get_path(WEB_CODE_PATH).'session/?session_id='.$session_list[$only_session_id]['id_session']);
  128. }
  129. }
  130. */
  131. }
  132. $nosession = false;
  133. if (api_get_setting('use_session_mode') == 'true' && !$nosession) {
  134. $display_actives = !isset($_GET['inactives']);
  135. }
  136. $nameTools = get_lang('MyCourses');
  137. $this_section = SECTION_COURSES;
  138. /* Check configuration parameters integrity */
  139. if (CONFVAL_showExtractInfo != SCRIPTVAL_UnderCourseList and $orderKey[0] != 'keyCourse') {
  140. // CONFVAL_showExtractInfo must be SCRIPTVAL_UnderCourseList to accept $orderKey[0] != 'keyCourse'
  141. if (DEBUG || api_is_platform_admin()){ // Show bug if admin. Else force a new order.
  142. die('
  143. <strong>config error:'.__FILE__.'</strong><br />
  144. set
  145. <ul>
  146. <li>
  147. CONFVAL_showExtractInfo = SCRIPTVAL_UnderCourseList
  148. (actually : '.CONFVAL_showExtractInfo.')
  149. </li>
  150. </ul>
  151. or
  152. <ul>
  153. <li>
  154. $orderKey[0] != \'keyCourse\'
  155. (actually : '.$orderKey[0].')
  156. </li>
  157. </ul>');
  158. } else {
  159. $orderKey = array('keyCourse', 'keyTools', 'keyTime');
  160. }
  161. }
  162. /*
  163. Header
  164. Include the HTTP, HTML headers plus the top banner.
  165. */
  166. if ($load_dirs) {
  167. $url = api_get_path(WEB_AJAX_PATH).'document.ajax.php?a=document_preview';
  168. $folder_icon = api_get_path(WEB_IMG_PATH).'icons/22/folder.png';
  169. $close_icon = api_get_path(WEB_IMG_PATH).'loading1.gif';
  170. $htmlHeadXtra[] = '<script type="text/javascript">
  171. $(document).ready( function() {
  172. $(".document_preview_container").hide();
  173. $(".document_preview").click(function() {
  174. var my_id = this.id;
  175. course_id = my_id.split("_")[2];
  176. //showing div
  177. $(".document_preview_container").hide();
  178. $("#document_result_" +course_id).show();
  179. //Loading
  180. var image = $("img", this);
  181. image.attr("src", "'.$close_icon.'");
  182. $.ajax({
  183. url: "'.$url.'",
  184. data: "course_id="+course_id,
  185. success: function(return_value) {
  186. image.attr("src", "'.$folder_icon.'");
  187. $("#document_result_" +course_id).html(return_value);
  188. },
  189. });
  190. });
  191. });
  192. </script>';
  193. }
  194. Display :: display_header($nameTools);
  195. /* MAIN CODE */
  196. /* PERSONAL COURSE LIST */
  197. if (!isset ($maxValvas)) {
  198. $maxValvas = CONFVAL_maxValvasByCourse; // Maximum number of entries
  199. }
  200. if (!isset ($maxAgenda)) {
  201. $maxAgenda = CONFVAL_maxAgendaByCourse; // collected from each course
  202. }
  203. if (!isset ($maxCourse)) {
  204. $maxCourse = CONFVAL_maxTotalByCourse; // and displayed in summary.
  205. }
  206. $maxValvas = (int) $maxValvas;
  207. $maxAgenda = (int) $maxAgenda;
  208. $maxCourse = (int) $maxCourse; // 0 if invalid.
  209. if ($maxCourse > 0) {
  210. unset ($allentries); // We shall collect all summary$key1 entries in here:
  211. $toolsList['agenda']['name'] = get_lang('Agenda');
  212. $toolsList['agenda']['path'] = api_get_path(WEB_CODE_PATH).'calendar/agenda.php?cidReq=';
  213. $toolsList['valvas']['name'] = get_lang('Valvas');
  214. $toolsList['valvas']['path'] = api_get_path(WEB_CODE_PATH).'announcements/announcements.php?cidReq=';
  215. }
  216. echo '<div class="maincontent" id="maincontent">'; // Start of content for logged in users.
  217. // Plugins for the my courses main area.
  218. echo '<div id="plugin-mycourses_main">';
  219. api_plugin('mycourses_main');
  220. echo '</div>';
  221. /* System Announcements */
  222. $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : -1;
  223. $visibility = api_is_allowed_to_create_course() ? VISIBLE_TEACHER : VISIBLE_STUDENT;
  224. SystemAnnouncementManager :: display_announcements($visibility, $announcement);
  225. if (!empty ($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/',$_GET['include'])) {
  226. include './home/'.$_GET['include'];
  227. $pageIncluded = true;
  228. } else {
  229. /* DISPLAY COURSES */
  230. // Compose a structured array of session categories, sessions and courses
  231. // for the current user.
  232. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  233. $courses_tree = UserManager::get_sessions_by_category(api_get_user_id(), true, true, true);
  234. if (empty($courses_tree[0]) && count($courses_tree) == 1) {
  235. $courses_tree = null;
  236. }
  237. } else {
  238. $courses_tree = UserManager::get_sessions_by_category(api_get_user_id(), true, false, true);
  239. }
  240. if (!empty($courses_tree)) {
  241. foreach ($courses_tree as $cat => $sessions) {
  242. $courses_tree[$cat]['details'] = SessionManager::get_session_category($cat);
  243. if ($cat == 0) {
  244. $courses_tree[$cat]['courses'] = CourseManager::get_courses_list_by_user_id(api_get_user_id(), false);
  245. }
  246. $courses_tree[$cat]['sessions'] = array_flip(array_flip($sessions));
  247. if (count($courses_tree[$cat]['sessions']) > 0) {
  248. foreach ($courses_tree[$cat]['sessions'] as $k => $s_id) {
  249. $courses_tree[$cat]['sessions'][$k] = array('details' => SessionManager::fetch($s_id));
  250. $courses_tree[$cat]['sessions'][$k]['courses'] = UserManager::get_courses_list_by_session(api_get_user_id(), $s_id);
  251. }
  252. }
  253. }
  254. }
  255. $list = '';
  256. foreach ($personal_course_list as $my_course) {
  257. $thisCourseDbName = $my_course['db'];
  258. $thisCourseSysCode = $my_course['k'];
  259. $thisCoursePublicCode = $my_course['c'];
  260. $thisCoursePath = $my_course['d'];
  261. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  262. $dbname = $my_course['k'];
  263. $status = array();
  264. $status[$dbname] = $my_course['s'];
  265. $nbDigestEntries = 0; // Number of entries already collected.
  266. if ($maxCourse < $maxValvas) {
  267. $maxValvas = $maxCourse;
  268. }
  269. if ($maxCourse > 0) {
  270. $courses[$thisCourseSysCode]['coursePath'] = $thisCoursePath;
  271. $courses[$thisCourseSysCode]['courseCode'] = $thisCoursePublicCode;
  272. }
  273. /* Announcements */
  274. $course_database = $my_course['db'];
  275. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  276. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'announcements/announcements.php' AND visibility = 1";
  277. $result = Database::query($query);
  278. // Collect from announcements, but only if tool is visible for the course.
  279. if ($result && $maxValvas > 0 && Database::num_rows($result) > 0) {
  280. // Search announcements table.
  281. // Take the entries listed at the top of advalvas/announcements tool.
  282. $course_announcement_table = Database::get_course_table(TABLE_ANNOUNCEMENT);
  283. $sqlGetLastAnnouncements = "SELECT end_date publicationDate, content
  284. FROM ".$course_announcement_table;
  285. switch (CONFVAL_limitPreviewTo) {
  286. case SCRIPTVAL_NewEntriesOfTheDay :
  287. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date('Y m d')."'";
  288. break;
  289. case SCRIPTVAL_NoTimeLimit :
  290. break;
  291. case SCRIPTVAL_NewEntriesOfTheDayOfLastLogin :
  292. // take care mysql -> DATE_FORMAT(time,format) php -> date(format,date)
  293. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date('Y m d', $_user['lastLogin'])."'";
  294. }
  295. $sqlGetLastAnnouncements .= "ORDER BY end_date DESC LIMIT ".$maxValvas;
  296. $resGetLastAnnouncements = Database::query($sqlGetLastAnnouncements);
  297. if ($resGetLastAnnouncements) {
  298. while ($annoncement = Database::fetch_array($resGetLastAnnouncements)) {
  299. $keyTools = 'valvas';
  300. $keyTime = $annoncement['publicationDate'];
  301. $keyCourse = $thisCourseSysCode;
  302. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = @htmlspecialchars(api_substr(strip_tags($annoncement['content']), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  303. $nbDigestEntries ++; // summary has same order as advalvas
  304. }
  305. }
  306. }
  307. /* Agenda */
  308. $course_database = $my_course['db'];
  309. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST, $course_database);
  310. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'calendar/agenda.php' AND visibility = 1";
  311. $result = Database::query($query);
  312. $thisAgenda = $maxCourse - $nbDigestEntries; // New max entries for agenda.
  313. if ($maxAgenda < $thisAgenda) {
  314. $thisAgenda = $maxAgenda;
  315. }
  316. // Collect from agenda, but only if tool is visible for the course.
  317. if ($result && $thisAgenda > 0 && Database::num_rows($result) > 0) {
  318. $tableCal = $courseTablePrefix.$thisCourseDbName.$_configuration['db_glue'].'calendar_event';
  319. $sqlGetNextAgendaEvent = "SELECT start_date, title content, start_time
  320. FROM $tableCal
  321. WHERE start_date >= CURDATE()
  322. ORDER BY start_date, start_time
  323. LIMIT $maxAgenda";
  324. $resGetNextAgendaEvent = Database::query($sqlGetNextAgendaEvent);
  325. if ($resGetNextAgendaEvent) {
  326. while ($agendaEvent = Database::fetch_array($resGetNextAgendaEvent)) {
  327. $keyTools = 'agenda';
  328. $keyTime = $agendaEvent['start_date'];
  329. $keyCourse = $thisCourseSysCode;
  330. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = @htmlspecialchars(api_substr(strip_tags($agendaEvent['content']), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  331. $nbDigestEntries ++; // Summary has same order as advalvas.
  332. }
  333. }
  334. }
  335. /*
  336. Digest Display
  337. Take collected data and display it.
  338. */
  339. } // End while mycourse...
  340. }
  341. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  342. echo Display::tag('h2', get_lang('HistoryTrainingSession'));
  343. //if (empty($courses_tree[0]['sessions'])){
  344. if (empty($courses_tree)){
  345. echo get_lang('YouDoNotHaveAnySessionInItsHistory');
  346. }
  347. }
  348. if (is_array($courses_tree)) {
  349. foreach ($courses_tree as $key => $category) {
  350. if ($key == 0) {
  351. // Sessions and courses that are not in a session category.
  352. if (!isset($_GET['history'])) {
  353. // If we're not in the history view...
  354. CourseManager :: display_special_courses(api_get_user_id());
  355. CourseManager :: display_courses(api_get_user_id(), $load_dirs);
  356. }
  357. // Independent sessions.
  358. foreach ($category['sessions'] as $session) {
  359. // Don't show empty sessions.
  360. if (count($session['courses']) < 1) { continue; }
  361. // Courses inside the current session.
  362. $date_session_start = $session['details']['date_start'];
  363. $days_access_before_beginning = $session['details']['nb_days_access_before_beginning'] * 24 * 3600;
  364. $session_now = time();
  365. $html_courses_session = '';
  366. $count_courses_session = 0;
  367. foreach ($session['courses'] as $course) {
  368. $is_coach_course = api_is_coach($session['details']['id'], $course['code']);
  369. $allowed_time = 0;
  370. if ($date_session_start != '0000-00-00') {
  371. if ($is_coach_course) {
  372. $allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
  373. } else {
  374. $allowed_time = api_strtotime($date_session_start);
  375. }
  376. }
  377. if ($session_now > $allowed_time) { //read only and accesible
  378. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  379. $c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item',true);
  380. //$c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item',($session['details']['visibility']==3?false:true));
  381. $html_courses_session .= $c[1];
  382. }
  383. $count_courses_session++;
  384. }
  385. }
  386. if ($count_courses_session > 0) {
  387. echo '<div class="userportal-session-item"><ul class="session_box">';
  388. echo '<li class="session_box_title" id="session_'.$session['details']['id'].'" >';
  389. echo Display::return_icon('window_list.png', get_lang('Expand').'/'.get_lang('Hide'), array('width' => '48px', 'align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  390. $s = Display :: get_session_title_box($session['details']['id']);
  391. $extra_info = (!empty($s['coach']) ? $s['coach'].' | ' : '').$s['dates'];
  392. /*if ($session['details']['visibility'] == 3) {
  393. $session_link = $s['title'];
  394. } else {*/
  395. $session_link = Display::tag('a',$s['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/?session_id='.$session['details']['id']));
  396. //}
  397. echo Display::tag('span',$session_link. ' </span> <span style="padding-left: 10px; font-size: 90%; font-weight: normal;">'.$extra_info);
  398. if (api_is_platform_admin()) {
  399. echo '<div style="float:right;"><a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session['details']['id'].'">'.
  400. Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),22).'</a></div>';
  401. }
  402. echo '</li>';
  403. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  404. echo $html_courses_session;
  405. }
  406. echo '</ul></div>';
  407. }
  408. }
  409. } else {
  410. // All sessions included in.
  411. if (!empty($category['details'])) {
  412. $count_courses_session = 0;
  413. $html_sessions = '';
  414. foreach ($category['sessions'] as $session) {
  415. // Don't show empty sessions.
  416. if (count($session['courses']) < 1) { continue; }
  417. $date_session_start = $session['details']['date_start'];
  418. $days_access_before_beginning = $session['details']['nb_days_access_before_beginning'] * 24 * 3600;
  419. $session_now = time();
  420. $html_courses_session = '';
  421. $count = 0;
  422. foreach ($session['courses'] as $course) {
  423. $is_coach_course = api_is_coach($session['details']['id'], $course['code']);
  424. if ($is_coach_course) {
  425. $allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
  426. } else {
  427. $allowed_time = api_strtotime($date_session_start);
  428. }
  429. if ($session_now > $allowed_time) {
  430. $c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item');
  431. $html_courses_session .= $c[1];
  432. $count_courses_session++;
  433. $count++;
  434. }
  435. }
  436. if ($count > 0) {
  437. $s = Display :: get_session_title_box($session['details']['id']);
  438. $html_sessions .= '<ul class="sub_session_box" id="session_'.$session['details']['id'].'">';
  439. $html_sessions .= '<li class="sub_session_box_title" id="session_'.$session['details']['id'].'">';
  440. //$html_sessions .= Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  441. $html_sessions .= Display::return_icon('window_list.png', get_lang('Expand').'/'.get_lang('Hide'), array('width' => '48px', 'align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  442. $session_link = Display::tag('a',$s['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/?session_id='.$session['details']['id']));
  443. $html_sessions .= '<span>' . $session_link. ' </span> ';
  444. $html_sessions .= '<span style="padding-left: 10px; font-size: 90%; font-weight: normal;">';
  445. $html_sessions .= (!empty($s['coach']) ? $s['coach'].' | ' : '').$s['dates'];
  446. $html_sessions .= '</span>';
  447. if (api_is_platform_admin()) {
  448. $html_sessions .= '<div style="float: right;"><a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session['details']['id'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),22).'</a></div>';
  449. }
  450. $html_sessions .= '</li>';
  451. $html_sessions .= $html_courses_session;
  452. $html_sessions .= '</ul>';
  453. }
  454. }
  455. if ($count_courses_session > 0) {
  456. echo '<div class="userportal-session-category-item" id="session_category_'.$category['details']['id'].'">';
  457. echo '<div class="session_category_title_box" id="session_category_title_box_'.$category['details']['id'].'" style="color: #555555;">';
  458. //echo Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'category_img_'.$category['details']['id']));
  459. echo Display::return_icon('folder_blue.png', get_lang('SessionCategory'), array('width'=>'48px', 'align' => 'absmiddle'));
  460. if (api_is_platform_admin()) {
  461. echo'<div style="float: right;"><a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$category['details']['id'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array(),22).'</a></div>';
  462. }
  463. echo '<span id="session_category_title">';
  464. echo $category['details']['name'];
  465. echo '</span>';
  466. echo '<span style="padding-left: 10px; font-size: 90%; font-weight: normal;">';
  467. if ($category['details']['date_end'] != '0000-00-00') {
  468. printf(get_lang('FromDateXToDateY'),$category['details']['date_start'],$category['details']['date_end']);
  469. }
  470. echo '</span></div>';
  471. echo $html_sessions;
  472. echo '</div>';
  473. }
  474. }
  475. }
  476. }
  477. }
  478. echo '</div>'; // End of content main-section
  479. // Register whether full admin or null admin course
  480. // by course through an array dbname x user status.
  481. api_session_register('status');
  482. /* RIGHT MENU */
  483. $show_menu = false;
  484. $show_create_link = false;
  485. $show_course_link = false;
  486. $show_digest_link = false;
  487. $display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
  488. if ($display_add_course_link) {
  489. $show_menu = true;
  490. $show_create_link = true;
  491. }
  492. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  493. $show_menu = true;
  494. $show_course_link = true;
  495. } else {
  496. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  497. $show_menu = true;
  498. $show_course_link = true;
  499. }
  500. }
  501. if (isset($toolsList) && is_array($toolsList) && isset($digest)) {
  502. $show_digest_link = true;
  503. $show_menu = true;
  504. }
  505. //Always show the user image
  506. $img_array = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', true, true);
  507. $no_image = false;
  508. if ($img_array['file'] == 'unknown.jpg') {
  509. $no_image = true;
  510. }
  511. $img_array = UserManager::get_picture_user(api_get_user_id(), $img_array['file'], 50, USER_IMAGE_SIZE_MEDIUM, ' width="90" height="90" ');
  512. $profile_content = '<div id="social_widget">';
  513. $profile_content .= '<div id="social_widget_image">';
  514. if (api_get_setting('allow_social_tool') == 'true') {
  515. if (!$no_image) {
  516. $profile_content .='<a href="'.api_get_path(WEB_PATH).'main/social/home.php"><img src="'.$img_array['file'].'" '.$img_array['style'].' border="1"></a>';
  517. } else {
  518. $profile_content .='<a href="'.api_get_path(WEB_PATH).'main/auth/profile.php"><img title="'.get_lang('EditProfile').'" src="'.$img_array['file'].'" '.$img_array['style'].' border="1"></a>';
  519. }
  520. } else {
  521. $profile_content .='<a href="'.api_get_path(WEB_PATH).'main/auth/profile.php"><img title="'.get_lang('EditProfile').'" src="'.$img_array['file'].'" '.$img_array['style'].' border="1"></a>';
  522. }
  523. $profile_content .= ' </div></div>';
  524. // @todo Add a platform setting to add the user image.
  525. if (api_get_setting('allow_message_tool') == 'true') {
  526. require_once api_get_path(LIBRARY_PATH).'message.lib.php';
  527. require_once api_get_path(LIBRARY_PATH).'social.lib.php';
  528. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  529. // New messages.
  530. $number_of_new_messages = MessageManager::get_new_messages();
  531. // New contact invitations.
  532. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  533. // New group invitations sent by a moderator.
  534. $group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false);
  535. $group_pending_invitations = count($group_pending_invitations);
  536. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  537. $cant_msg = '';
  538. if ($number_of_new_messages > 0) {
  539. $cant_msg = ' ('.$number_of_new_messages.')';
  540. }
  541. $profile_content .= '<div class="clear"></div>';
  542. $profile_content .= '<div class="message-content"><ul class="menulist">';
  543. $link = '';
  544. if (api_get_setting('allow_social_tool') == 'true') {
  545. $link = '?f=social';
  546. }
  547. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php'.$link.'" class="message-body">'.get_lang('Inbox').$cant_msg.' </a></li>';
  548. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'" class="message-body">'.get_lang('Compose').' </a></li>';
  549. if (api_get_setting('allow_social_tool') == 'true') {
  550. if ($total_invitations == 0) {
  551. $total_invitations = '';
  552. } else {
  553. $total_invitations = ' ('.$total_invitations.')';
  554. }
  555. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php" class="message-body">'.get_lang('PendingInvitations').' '.$total_invitations.' </a></li>';
  556. }
  557. $profile_content .= '</ul>';
  558. $profile_content .= '</div>';
  559. }
  560. echo '<div id="menu-wrapper">';
  561. //Profile content
  562. echo show_right_block(get_lang('Profile'), $profile_content);
  563. // My account section.
  564. if ($show_menu) {
  565. $my_account_content = '<ul class="menulist">';
  566. if ($show_create_link) {
  567. $my_account_content .= '<li><a href="main/create_course/add_course.php">'.(api_get_setting('course_validation') == 'true' ? get_lang('CreateCourseRequest') : get_lang('CourseCreate')).'</a></li>';
  568. }
  569. if ($show_course_link) {
  570. if (!api_is_drh()) {
  571. $my_account_content .= '<li><a href="main/auth/courses.php">'.get_lang('CourseManagement').'</a></li>';
  572. if (api_get_setting('use_session_mode') == 'true') {
  573. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  574. $my_account_content .= '<li><a href="user_portal.php">'.get_lang('DisplayTrainingList').'</a></li>';
  575. } else {
  576. $my_account_content .= '<li><a href="user_portal.php?history=1">'.get_lang('HistoryTrainingSessions').'</a></li>';
  577. }
  578. }
  579. } else {
  580. $my_account_content .= '<li><a href="main/dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
  581. }
  582. }
  583. if ($show_digest_link) {
  584. $my_account_content .= Display :: display_digest($toolsList, $digest, $orderKey, $courses);
  585. }
  586. $my_account_content .= '</ul>';
  587. }
  588. if (!empty($my_account_content)) {
  589. echo show_right_block(get_lang('MenuUser'), $my_account_content);
  590. }
  591. // Deleting the myprofile link.
  592. if (api_get_setting('allow_social_tool') == 'true') {
  593. unset($menu_navigation['myprofile']);
  594. }
  595. // Main navigation section.
  596. // Tabs that are deactivated are added here.
  597. if (!empty($menu_navigation)) {
  598. $main_navigation_content .= '<ul class="menulist">';
  599. foreach ($menu_navigation as $section => $navigation_info) {
  600. $current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  601. $main_navigation_content .= '<li'.$current.'>';
  602. $main_navigation_content .= '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  603. $main_navigation_content .= '</li>';
  604. }
  605. $main_navigation_content .= '</ul>';
  606. echo show_right_block(get_lang('MainNavigation'), $main_navigation_content);
  607. }
  608. // Plugins for the my courses menu.
  609. if (isset($_plugins['mycourses_menu']) && is_array($_plugins['mycourses_menu'])) {
  610. ob_start();
  611. api_plugin('mycourses_menu');
  612. $plugin_content = ob_get_contents();
  613. ob_end_clean();
  614. echo show_right_block('', $plugin_content);
  615. }
  616. if (api_get_setting('allow_reservation') == 'true' && api_is_allowed_to_create_course()) {
  617. $booking_content .='<ul class="menulist">';
  618. $booking_content .='<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br />';
  619. $booking_content .='</ul>';
  620. echo show_right_block(get_lang('Booking'), $booking_content);
  621. }
  622. // Deleting the session_id.
  623. api_session_unregister('session_id');
  624. // Search textbox.
  625. if (api_get_setting('search_enabled') == 'true') {
  626. echo '<div class="searchbox">';
  627. $search_btn = get_lang('Search');
  628. $search_text_default = get_lang('YourTextHere');
  629. $search_content = '<br />
  630. <form action="main/search/" method="post">
  631. <input type="text" id="query" size="15" name="query" value="" />
  632. <button class="save" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button>
  633. </form></div>';
  634. echo show_right_block(get_lang('Search'), $search_content);
  635. }
  636. if (api_get_setting('show_groups_to_users') == 'true') {
  637. require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php';
  638. $usergroup = new Usergroup();
  639. $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
  640. $classes = '';
  641. if (!empty($usergroup_list)) {
  642. foreach($usergroup_list as $group_id) {
  643. $data = $usergroup->get($group_id);
  644. $data['name'] = Display::url($data['name'], api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id']);
  645. $classes .= Display::tag('li', $data['name']);
  646. }
  647. }
  648. if (api_is_platform_admin()) {
  649. $classes .= Display::tag('li', Display::url(get_lang('AddClasses') ,api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add'));
  650. }
  651. if (!empty($classes)) {
  652. $classes = Display::tag('ul', $classes, array('class'=>'menulist'));
  653. echo show_right_block(get_lang('Classes'), $classes);
  654. }
  655. }
  656. echo '</div>'; // End of menu wrapper
  657. function show_right_block($title, $content) {
  658. $html= '<div id="menu" class="menu">';
  659. $html.= '<div class="menusection">';
  660. $html.= '<span class="menusectioncaption">'.$title.'</span>';
  661. $html.= $content;
  662. $html.= '</div>';
  663. $html.= '</div>';
  664. return $html;
  665. }
  666. // Footer
  667. Display :: display_footer();