user_portal.php 34 KB

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