user_portal.php 35 KB

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