user_portal.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  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. // Plugins for the my courses main area.
  217. echo '<div id="plugin-mycourses_main">';
  218. api_plugin('mycourses_main');
  219. echo '</div>';
  220. /* System Announcements */
  221. /*
  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(), $load_dirs);
  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, $load_dirs);
  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('folder_blue.png', get_lang('SessionCategory'), array('width'=>'48px', 'align' => 'absmiddle'));
  459. if (api_is_platform_admin()) {
  460. 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>';
  461. }
  462. echo '<span id="session_category_title">';
  463. echo $category['details']['name'];
  464. echo '</span>';
  465. echo '<span style="padding-left: 10px; font-size: 90%; font-weight: normal;">';
  466. if ($category['details']['date_end'] != '0000-00-00') {
  467. printf(get_lang('FromDateXToDateY'),$category['details']['date_start'],$category['details']['date_end']);
  468. }
  469. echo '</span></div>';
  470. echo $html_sessions;
  471. echo '</div>';
  472. }
  473. }
  474. }
  475. }
  476. }
  477. echo '</div>'; // End of content main-section
  478. // Register whether full admin or null admin course
  479. // by course through an array dbname x user status.
  480. api_session_register('status');
  481. /* RIGHT MENU */
  482. $show_menu = false;
  483. $show_create_link = false;
  484. $show_course_link = false;
  485. $show_digest_link = false;
  486. $display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
  487. if ($display_add_course_link) {
  488. $show_menu = true;
  489. $show_create_link = true;
  490. }
  491. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  492. $show_menu = true;
  493. $show_course_link = true;
  494. } else {
  495. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  496. $show_menu = true;
  497. $show_course_link = true;
  498. }
  499. }
  500. if (isset($toolsList) && is_array($toolsList) && isset($digest)) {
  501. $show_digest_link = true;
  502. $show_menu = true;
  503. }
  504. //Always show the user image
  505. $img_array = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', true, true);
  506. $no_image = false;
  507. if ($img_array['file'] == 'unknown.jpg') {
  508. $no_image = true;
  509. }
  510. $img_array = UserManager::get_picture_user(api_get_user_id(), $img_array['file'], 50, USER_IMAGE_SIZE_MEDIUM, ' width="90" height="90" ');
  511. $profile_content = '<div id="social_widget">';
  512. $profile_content .= '<div id="social_widget_image">';
  513. if (api_get_setting('allow_social_tool') == 'true') {
  514. if (!$no_image) {
  515. $profile_content .='<a href="'.api_get_path(WEB_PATH).'main/social/home.php"><img src="'.$img_array['file'].'" '.$img_array['style'].' border="1"></a>';
  516. } else {
  517. $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>';
  518. }
  519. } else {
  520. $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>';
  521. }
  522. $profile_content .= ' </div></div>';
  523. // @todo Add a platform setting to add the user image.
  524. if (api_get_setting('allow_message_tool') == 'true') {
  525. require_once api_get_path(LIBRARY_PATH).'message.lib.php';
  526. require_once api_get_path(LIBRARY_PATH).'social.lib.php';
  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();