user_portal.php 34 KB

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