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. var course_id = my_id.split("_")[2];
  176. var session_id = my_id.split("_")[3];
  177. //showing div
  178. $(".document_preview_container").hide();
  179. $("#document_result_" +course_id+"_" + session_id).show();
  180. //Loading
  181. var image = $("img", this);
  182. image.attr("src", "'.$close_icon.'");
  183. $.ajax({
  184. url: "'.$url.'",
  185. data: "course_id="+course_id+"&session_id="+session_id,
  186. success: function(return_value) {
  187. image.attr("src", "'.$folder_icon.'");
  188. $("#document_result_" +course_id+"_" + session_id).html(return_value);
  189. }
  190. });
  191. });
  192. });
  193. </script>';
  194. }
  195. Display :: display_header($nameTools);
  196. /* MAIN CODE */
  197. /* PERSONAL COURSE LIST */
  198. if (!isset ($maxValvas)) {
  199. $maxValvas = CONFVAL_maxValvasByCourse; // Maximum number of entries
  200. }
  201. if (!isset ($maxAgenda)) {
  202. $maxAgenda = CONFVAL_maxAgendaByCourse; // collected from each course
  203. }
  204. if (!isset ($maxCourse)) {
  205. $maxCourse = CONFVAL_maxTotalByCourse; // and displayed in summary.
  206. }
  207. $maxValvas = (int) $maxValvas;
  208. $maxAgenda = (int) $maxAgenda;
  209. $maxCourse = (int) $maxCourse; // 0 if invalid.
  210. if ($maxCourse > 0) {
  211. unset ($allentries); // We shall collect all summary$key1 entries in here:
  212. $toolsList['agenda']['name'] = get_lang('Agenda');
  213. $toolsList['agenda']['path'] = api_get_path(WEB_CODE_PATH).'calendar/agenda.php?cidReq=';
  214. $toolsList['valvas']['name'] = get_lang('Valvas');
  215. $toolsList['valvas']['path'] = api_get_path(WEB_CODE_PATH).'announcements/announcements.php?cidReq=';
  216. }
  217. echo '<div class="maincontent" id="maincontent">'; // Start of content for logged in users.
  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).'message.lib.php';
  528. require_once api_get_path(LIBRARY_PATH).'social.lib.php';
  529. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  530. // New messages.
  531. $number_of_new_messages = MessageManager::get_new_messages();
  532. // New contact invitations.
  533. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  534. // New group invitations sent by a moderator.
  535. $group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false);
  536. $group_pending_invitations = count($group_pending_invitations);
  537. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  538. $cant_msg = '';
  539. if ($number_of_new_messages > 0) {
  540. $cant_msg = ' ('.$number_of_new_messages.')';
  541. }
  542. $profile_content .= '<div class="clear"></div>';
  543. $profile_content .= '<div class="message-content"><ul class="menulist">';
  544. $link = '';
  545. if (api_get_setting('allow_social_tool') == 'true') {
  546. $link = '?f=social';
  547. }
  548. $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>';
  549. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'" class="message-body">'.get_lang('Compose').' </a></li>';
  550. if (api_get_setting('allow_social_tool') == 'true') {
  551. if ($total_invitations == 0) {
  552. $total_invitations = '';
  553. } else {
  554. $total_invitations = ' ('.$total_invitations.')';
  555. }
  556. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php" class="message-body">'.get_lang('PendingInvitations').' '.$total_invitations.' </a></li>';
  557. }
  558. $profile_content .= '</ul>';
  559. $profile_content .= '</div>';
  560. }
  561. echo '<div id="menu-wrapper">';
  562. //Profile content
  563. echo show_right_block(get_lang('Profile'), $profile_content);
  564. // My account section.
  565. if ($show_menu) {
  566. $my_account_content = '<ul class="menulist">';
  567. if ($show_create_link) {
  568. $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>';
  569. }
  570. if ($show_course_link) {
  571. if (!api_is_drh()) {
  572. $my_account_content .= '<li><a href="main/auth/courses.php">'.get_lang('CourseManagement').'</a></li>';
  573. if (api_get_setting('use_session_mode') == 'true') {
  574. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  575. $my_account_content .= '<li><a href="user_portal.php">'.get_lang('DisplayTrainingList').'</a></li>';
  576. } else {
  577. $my_account_content .= '<li><a href="user_portal.php?history=1">'.get_lang('HistoryTrainingSessions').'</a></li>';
  578. }
  579. }
  580. } else {
  581. $my_account_content .= '<li><a href="main/dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
  582. }
  583. }
  584. if ($show_digest_link) {
  585. $my_account_content .= Display :: display_digest($toolsList, $digest, $orderKey, $courses);
  586. }
  587. $my_account_content .= '</ul>';
  588. }
  589. if (!empty($my_account_content)) {
  590. echo show_right_block(get_lang('MenuUser'), $my_account_content);
  591. }
  592. // Deleting the myprofile link.
  593. if (api_get_setting('allow_social_tool') == 'true') {
  594. unset($menu_navigation['myprofile']);
  595. }
  596. // Main navigation section.
  597. // Tabs that are deactivated are added here.
  598. if (!empty($menu_navigation)) {
  599. $main_navigation_content .= '<ul class="menulist">';
  600. foreach ($menu_navigation as $section => $navigation_info) {
  601. $current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  602. $main_navigation_content .= '<li'.$current.'>';
  603. $main_navigation_content .= '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  604. $main_navigation_content .= '</li>';
  605. }
  606. $main_navigation_content .= '</ul>';
  607. echo show_right_block(get_lang('MainNavigation'), $main_navigation_content);
  608. }
  609. // Plugins for the my courses menu.
  610. if (isset($_plugins['mycourses_menu']) && is_array($_plugins['mycourses_menu'])) {
  611. ob_start();
  612. api_plugin('mycourses_menu');
  613. $plugin_content = ob_get_contents();
  614. ob_end_clean();
  615. echo show_right_block('', $plugin_content);
  616. }
  617. if (api_get_setting('allow_reservation') == 'true' && api_is_allowed_to_create_course()) {
  618. $booking_content .='<ul class="menulist">';
  619. $booking_content .='<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br />';
  620. $booking_content .='</ul>';
  621. echo show_right_block(get_lang('Booking'), $booking_content);
  622. }
  623. // Deleting the session_id.
  624. api_session_unregister('session_id');
  625. // Search textbox.
  626. if (api_get_setting('search_enabled') == 'true') {
  627. echo '<div class="searchbox">';
  628. $search_btn = get_lang('Search');
  629. $search_text_default = get_lang('YourTextHere');
  630. $search_content = '<br />
  631. <form action="main/search/" method="post">
  632. <input type="text" id="query" size="15" name="query" value="" />
  633. <button class="save" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button>
  634. </form></div>';
  635. echo show_right_block(get_lang('Search'), $search_content);
  636. }
  637. if (api_get_setting('show_groups_to_users') == 'true') {
  638. require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php';
  639. $usergroup = new Usergroup();
  640. $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
  641. $classes = '';
  642. if (!empty($usergroup_list)) {
  643. foreach($usergroup_list as $group_id) {
  644. $data = $usergroup->get($group_id);
  645. $data['name'] = Display::url($data['name'], api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id']);
  646. $classes .= Display::tag('li', $data['name']);
  647. }
  648. }
  649. if (api_is_platform_admin()) {
  650. $classes .= Display::tag('li', Display::url(get_lang('AddClasses') ,api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add'));
  651. }
  652. if (!empty($classes)) {
  653. $classes = Display::tag('ul', $classes, array('class'=>'menulist'));
  654. echo show_right_block(get_lang('Classes'), $classes);
  655. }
  656. }
  657. echo '</div>'; // End of menu wrapper
  658. function show_right_block($title, $content) {
  659. $html= '<div id="menu" class="menu">';
  660. $html.= '<div class="menusection">';
  661. $html.= '<span class="menusectioncaption">'.$title.'</span>';
  662. $html.= $content;
  663. $html.= '</div>';
  664. $html.= '</div>';
  665. return $html;
  666. }
  667. // Footer
  668. Display :: display_footer();