user_portal.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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, true);
  203. if (empty($courses_tree[0]) && count($courses_tree) == 1) {
  204. $courses_tree = null;
  205. }
  206. } else {
  207. $courses_tree = UserManager::get_sessions_by_category(api_get_user_id(), true, false, true);
  208. }
  209. if (!empty($courses_tree)) {
  210. foreach ($courses_tree as $cat => $sessions) {
  211. $courses_tree[$cat]['details'] = SessionManager::get_session_category($cat);
  212. if ($cat == 0) {
  213. $courses_tree[$cat]['courses'] = CourseManager::get_courses_list_by_user_id(api_get_user_id(), false);
  214. }
  215. $courses_tree[$cat]['sessions'] = array_flip(array_flip($sessions));
  216. if (count($courses_tree[$cat]['sessions']) > 0) {
  217. foreach ($courses_tree[$cat]['sessions'] as $k => $s_id) {
  218. $courses_tree[$cat]['sessions'][$k] = array('details' => SessionManager::fetch($s_id));
  219. $courses_tree[$cat]['sessions'][$k]['courses'] = UserManager::get_courses_list_by_session(api_get_user_id(), $s_id);
  220. }
  221. }
  222. }
  223. }
  224. $list = '';
  225. foreach ($personal_course_list as $my_course) {
  226. $thisCourseDbName = $my_course['db'];
  227. $thisCourseSysCode = $my_course['k'];
  228. $thisCoursePublicCode = $my_course['c'];
  229. $thisCoursePath = $my_course['d'];
  230. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  231. $dbname = $my_course['k'];
  232. $status = array();
  233. $status[$dbname] = $my_course['s'];
  234. $nbDigestEntries = 0; // Number of entries already collected.
  235. if ($maxCourse < $maxValvas) {
  236. $maxValvas = $maxCourse;
  237. }
  238. if ($maxCourse > 0) {
  239. $courses[$thisCourseSysCode]['coursePath'] = $thisCoursePath;
  240. $courses[$thisCourseSysCode]['courseCode'] = $thisCoursePublicCode;
  241. }
  242. /* Announcements */
  243. $course_database = $my_course['db'];
  244. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  245. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'announcements/announcements.php' AND visibility = 1";
  246. $result = Database::query($query);
  247. // Collect from announcements, but only if tool is visible for the course.
  248. if ($result && $maxValvas > 0 && Database::num_rows($result) > 0) {
  249. // Search announcements table.
  250. // Take the entries listed at the top of advalvas/announcements tool.
  251. $course_announcement_table = Database::get_course_table(TABLE_ANNOUNCEMENT);
  252. $sqlGetLastAnnouncements = "SELECT end_date publicationDate, content
  253. FROM ".$course_announcement_table;
  254. switch (CONFVAL_limitPreviewTo) {
  255. case SCRIPTVAL_NewEntriesOfTheDay :
  256. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date('Y m d')."'";
  257. break;
  258. case SCRIPTVAL_NoTimeLimit :
  259. break;
  260. case SCRIPTVAL_NewEntriesOfTheDayOfLastLogin :
  261. // take care mysql -> DATE_FORMAT(time,format) php -> date(format,date)
  262. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date('Y m d', $_user['lastLogin'])."'";
  263. }
  264. $sqlGetLastAnnouncements .= "ORDER BY end_date DESC LIMIT ".$maxValvas;
  265. $resGetLastAnnouncements = Database::query($sqlGetLastAnnouncements);
  266. if ($resGetLastAnnouncements) {
  267. while ($annoncement = Database::fetch_array($resGetLastAnnouncements)) {
  268. $keyTools = 'valvas';
  269. $keyTime = $annoncement['publicationDate'];
  270. $keyCourse = $thisCourseSysCode;
  271. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = @htmlspecialchars(api_substr(strip_tags($annoncement['content']), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  272. $nbDigestEntries ++; // summary has same order as advalvas
  273. }
  274. }
  275. }
  276. /* Agenda */
  277. $course_database = $my_course['db'];
  278. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST, $course_database);
  279. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'calendar/agenda.php' AND visibility = 1";
  280. $result = Database::query($query);
  281. $thisAgenda = $maxCourse - $nbDigestEntries; // New max entries for agenda.
  282. if ($maxAgenda < $thisAgenda) {
  283. $thisAgenda = $maxAgenda;
  284. }
  285. // Collect from agenda, but only if tool is visible for the course.
  286. if ($result && $thisAgenda > 0 && Database::num_rows($result) > 0) {
  287. $tableCal = $courseTablePrefix.$thisCourseDbName.$_configuration['db_glue'].'calendar_event';
  288. $sqlGetNextAgendaEvent = "SELECT start_date, title content, start_time
  289. FROM $tableCal
  290. WHERE start_date >= CURDATE()
  291. ORDER BY start_date, start_time
  292. LIMIT $maxAgenda";
  293. $resGetNextAgendaEvent = Database::query($sqlGetNextAgendaEvent);
  294. if ($resGetNextAgendaEvent) {
  295. while ($agendaEvent = Database::fetch_array($resGetNextAgendaEvent)) {
  296. $keyTools = 'agenda';
  297. $keyTime = $agendaEvent['start_date'];
  298. $keyCourse = $thisCourseSysCode;
  299. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = @htmlspecialchars(api_substr(strip_tags($agendaEvent['content']), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  300. $nbDigestEntries ++; // Summary has same order as advalvas.
  301. }
  302. }
  303. }
  304. /*
  305. Digest Display
  306. Take collected data and display it.
  307. */
  308. } // End while mycourse...
  309. }
  310. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  311. echo Display::tag('h2', get_lang('HistoryTrainingSession'));
  312. //if (empty($courses_tree[0]['sessions'])){
  313. if (empty($courses_tree)){
  314. echo get_lang('YouDoNotHaveAnySessionInItsHistory');
  315. }
  316. }
  317. if (is_array($courses_tree)) {
  318. foreach ($courses_tree as $key => $category) {
  319. if ($key == 0) {
  320. // Sessions and courses that are not in a session category.
  321. if (!isset($_GET['history'])) {
  322. // If we're not in the history view...
  323. CourseManager :: display_special_courses(api_get_user_id());
  324. CourseManager :: display_courses(api_get_user_id());
  325. }
  326. // Independent sessions.
  327. foreach ($category['sessions'] as $session) {
  328. // Don't show empty sessions.
  329. if (count($session['courses']) < 1) { continue; }
  330. // Courses inside the current session.
  331. $date_session_start = $session['details']['date_start'];
  332. $days_access_before_beginning = $session['details']['nb_days_access_before_beginning'] * 24 * 3600;
  333. $session_now = time();
  334. $html_courses_session = '';
  335. $count_courses_session = 0;
  336. foreach ($session['courses'] as $course) {
  337. $is_coach_course = api_is_coach($session['details']['id'], $course['code']);
  338. $allowed_time = 0;
  339. if ($date_session_start != '0000-00-00') {
  340. if ($is_coach_course) {
  341. $allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
  342. } else {
  343. $allowed_time = api_strtotime($date_session_start);
  344. }
  345. }
  346. if ($session_now > $allowed_time) { //read only and accesible
  347. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  348. $c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item',true);
  349. //$c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item',($session['details']['visibility']==3?false:true));
  350. $html_courses_session .= $c[1];
  351. }
  352. $count_courses_session++;
  353. }
  354. }
  355. if ($count_courses_session > 0) {
  356. echo '<div class="userportal-session-item"><ul class="session_box">';
  357. echo '<li class="session_box_title" id="session_'.$session['details']['id'].'" >';
  358. echo Display::return_icon('window_list.png', get_lang('Expand').'/'.get_lang('Hide'), array('width' => '48px', 'align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  359. $s = Display :: get_session_title_box($session['details']['id']);
  360. $extra_info = (!empty($s['coach']) ? $s['coach'].' | ' : '').$s['dates'];
  361. /*if ($session['details']['visibility'] == 3) {
  362. $session_link = $s['title'];
  363. } else {*/
  364. $session_link = Display::tag('a',$s['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/?session_id='.$session['details']['id']));
  365. //}
  366. echo Display::tag('span',$session_link. ' </span> <span style="padding-left: 10px; font-size: 90%; font-weight: normal;">'.$extra_info);
  367. if (api_is_platform_admin()) {
  368. 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>';
  369. }
  370. echo '</li>';
  371. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  372. echo $html_courses_session;
  373. }
  374. echo '</ul></div>';
  375. }
  376. }
  377. } else {
  378. // All sessions included in.
  379. if (!empty($category['details'])) {
  380. $count_courses_session = 0;
  381. $html_sessions = '';
  382. foreach ($category['sessions'] as $session) {
  383. // Don't show empty sessions.
  384. if (count($session['courses']) < 1) { continue; }
  385. $date_session_start = $session['details']['date_start'];
  386. $days_access_before_beginning = $session['details']['nb_days_access_before_beginning'] * 24 * 3600;
  387. $session_now = time();
  388. $html_courses_session = '';
  389. $count = 0;
  390. foreach ($session['courses'] as $course) {
  391. $is_coach_course = api_is_coach($session['details']['id'], $course['code']);
  392. if ($is_coach_course) {
  393. $allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
  394. } else {
  395. $allowed_time = api_strtotime($date_session_start);
  396. }
  397. if ($session_now > $allowed_time) {
  398. $c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item');
  399. $html_courses_session .= $c[1];
  400. $count_courses_session++;
  401. $count++;
  402. }
  403. }
  404. if ($count > 0) {
  405. $s = Display :: get_session_title_box($session['details']['id']);
  406. $html_sessions .= '<ul class="sub_session_box" id="session_'.$session['details']['id'].'">';
  407. $html_sessions .= '<li class="sub_session_box_title" id="session_'.$session['details']['id'].'">';
  408. //$html_sessions .= Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  409. $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'])) . ' ';
  410. $session_link = Display::tag('a',$s['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/?session_id='.$session['details']['id']));
  411. $html_sessions .= '<span>' . $session_link. ' </span> ';
  412. $html_sessions .= '<span style="padding-left: 10px; font-size: 90%; font-weight: normal;">';
  413. $html_sessions .= (!empty($s['coach']) ? $s['coach'].' | ' : '').$s['dates'];
  414. $html_sessions .= '</span>';
  415. if (api_is_platform_admin()) {
  416. $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>';
  417. }
  418. $html_sessions .= '</li>';
  419. $html_sessions .= $html_courses_session;
  420. $html_sessions .= '</ul>';
  421. }
  422. }
  423. if ($count_courses_session > 0) {
  424. echo '<div class="userportal-session-category-item" id="session_category_'.$category['details']['id'].'">';
  425. echo '<div class="session_category_title_box" id="session_category_title_box_'.$category['details']['id'].'" style="color: #555555;">';
  426. //echo Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'category_img_'.$category['details']['id']));
  427. echo Display::return_icon('folder_blue.png', get_lang('SessionCategory'), array('width'=>'48px', 'align' => 'absmiddle'));
  428. if (api_is_platform_admin()) {
  429. 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>';
  430. }
  431. echo '<span id="session_category_title">';
  432. echo $category['details']['name'];
  433. echo '</span>';
  434. echo '<span style="padding-left: 10px; font-size: 90%; font-weight: normal;">';
  435. if ($category['details']['date_end'] != '0000-00-00') {
  436. printf(get_lang('FromDateXToDateY'),$category['details']['date_start'],$category['details']['date_end']);
  437. }
  438. echo '</span></div>';
  439. echo $html_sessions;
  440. echo '</div>';
  441. }
  442. }
  443. }
  444. }
  445. }
  446. echo '</div>'; // End of content main-section
  447. // Register whether full admin or null admin course
  448. // by course through an array dbname x user status.
  449. api_session_register('status');
  450. /* RIGHT MENU */
  451. $show_menu = false;
  452. $show_create_link = false;
  453. $show_course_link = false;
  454. $show_digest_link = false;
  455. $display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
  456. if ($display_add_course_link) {
  457. $show_menu = true;
  458. $show_create_link = true;
  459. }
  460. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  461. $show_menu = true;
  462. $show_course_link = true;
  463. } else {
  464. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  465. $show_menu = true;
  466. $show_course_link = true;
  467. }
  468. }
  469. if (isset($toolsList) && is_array($toolsList) && isset($digest)) {
  470. $show_digest_link = true;
  471. $show_menu = true;
  472. }
  473. //Always show the user image
  474. $img_array = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', true, true);
  475. $no_image = false;
  476. if ($img_array['file'] == 'unknown.jpg') {
  477. $no_image = true;
  478. }
  479. $img_array = UserManager::get_picture_user(api_get_user_id(), $img_array['file'], 50, USER_IMAGE_SIZE_MEDIUM, ' width="90" height="90" ');
  480. $profile_content = '<div id="social_widget">';
  481. $profile_content .= '<div id="social_widget_image">';
  482. if (api_get_setting('allow_social_tool') == 'true') {
  483. if (!$no_image) {
  484. $profile_content .='<a href="'.api_get_path(WEB_PATH).'main/social/home.php"><img src="'.$img_array['file'].'" '.$img_array['style'].' border="1"></a>';
  485. } else {
  486. $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>';
  487. }
  488. } else {
  489. $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>';
  490. }
  491. $profile_content .= ' </div></div>';
  492. // @todo Add a platform setting to add the user image.
  493. if (api_get_setting('allow_message_tool') == 'true') {
  494. require_once api_get_path(LIBRARY_PATH).'message.lib.php';
  495. require_once api_get_path(LIBRARY_PATH).'social.lib.php';
  496. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  497. // New messages.
  498. $number_of_new_messages = MessageManager::get_new_messages();
  499. // New contact invitations.
  500. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  501. // New group invitations sent by a moderator.
  502. $group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false);
  503. $group_pending_invitations = count($group_pending_invitations);
  504. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  505. $cant_msg = '';
  506. if ($number_of_new_messages > 0) {
  507. $cant_msg = ' ('.$number_of_new_messages.')';
  508. }
  509. $profile_content .= '<div class="clear"></div>';
  510. $profile_content .= '<div class="message-content"><ul class="menulist">';
  511. $link = '';
  512. if (api_get_setting('allow_social_tool') == 'true') {
  513. $link = '?f=social';
  514. }
  515. $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>';
  516. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'" class="message-body">'.get_lang('Compose').' </a></li>';
  517. if (api_get_setting('allow_social_tool') == 'true') {
  518. if ($total_invitations == 0) {
  519. $total_invitations = '';
  520. } else {
  521. $total_invitations = ' ('.$total_invitations.')';
  522. }
  523. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php" class="message-body">'.get_lang('PendingInvitations').' '.$total_invitations.' </a></li>';
  524. }
  525. $profile_content .= '</ul>';
  526. $profile_content .= '</div>';
  527. }
  528. echo '<div id="menu-wrapper">';
  529. //Profile content
  530. echo show_right_block(get_lang('Profile'), $profile_content);
  531. // My account section.
  532. if ($show_menu) {
  533. $my_account_content = '<ul class="menulist">';
  534. if ($show_create_link) {
  535. $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>';
  536. }
  537. if ($show_course_link) {
  538. if (!api_is_drh()) {
  539. $my_account_content .= '<li><a href="main/auth/courses.php">'.get_lang('CourseManagement').'</a></li>';
  540. if (api_get_setting('use_session_mode') == 'true') {
  541. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  542. $my_account_content .= '<li><a href="user_portal.php">'.get_lang('DisplayTrainingList').'</a></li>';
  543. } else {
  544. $my_account_content .= '<li><a href="user_portal.php?history=1">'.get_lang('HistoryTrainingSessions').'</a></li>';
  545. }
  546. }
  547. } else {
  548. $my_account_content .= '<li><a href="main/dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
  549. }
  550. }
  551. if ($show_digest_link) {
  552. $my_account_content .= Display :: display_digest($toolsList, $digest, $orderKey, $courses);
  553. }
  554. $my_account_content .= '</ul>';
  555. }
  556. if (!empty($my_account_content)) {
  557. echo show_right_block(get_lang('MenuUser'), $my_account_content);
  558. }
  559. // Deleting the myprofile link.
  560. if (api_get_setting('allow_social_tool') == 'true') {
  561. unset($menu_navigation['myprofile']);
  562. }
  563. // Main navigation section.
  564. // Tabs that are deactivated are added here.
  565. if (!empty($menu_navigation)) {
  566. $main_navigation_content .= '<ul class="menulist">';
  567. foreach ($menu_navigation as $section => $navigation_info) {
  568. $current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  569. $main_navigation_content .= '<li'.$current.'>';
  570. $main_navigation_content .= '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  571. $main_navigation_content .= '</li>';
  572. }
  573. $main_navigation_content .= '</ul>';
  574. echo show_right_block(get_lang('MainNavigation'), $main_navigation_content);
  575. }
  576. // Plugins for the my courses menu.
  577. if (isset($_plugins['mycourses_menu']) && is_array($_plugins['mycourses_menu'])) {
  578. ob_start();
  579. api_plugin('mycourses_menu');
  580. $plugin_content = ob_get_contents();
  581. ob_end_clean();
  582. echo show_right_block('', $plugin_content);
  583. }
  584. if (api_get_setting('allow_reservation') == 'true' && api_is_allowed_to_create_course()) {
  585. $booking_content .='<ul class="menulist">';
  586. $booking_content .='<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br />';
  587. $booking_content .='</ul>';
  588. echo show_right_block(get_lang('Booking'), $booking_content);
  589. }
  590. // Deleting the session_id.
  591. api_session_unregister('session_id');
  592. // Search textbox.
  593. if (api_get_setting('search_enabled') == 'true') {
  594. echo '<div class="searchbox">';
  595. $search_btn = get_lang('Search');
  596. $search_text_default = get_lang('YourTextHere');
  597. $search_content = '<br />
  598. <form action="main/search/" method="post">
  599. <input type="text" id="query" size="15" name="query" value="" />
  600. <button class="save" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button>
  601. </form></div>';
  602. echo show_right_block(get_lang('Search'), $search_content);
  603. }
  604. if (api_get_setting('show_groups_to_users') == 'true') {
  605. require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php';
  606. $usergroup = new Usergroup();
  607. $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
  608. $classes = '';
  609. if (!empty($usergroup_list)) {
  610. foreach($usergroup_list as $group_id) {
  611. $data = $usergroup->get($group_id);
  612. $data['name'] = Display::url($data['name'], api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id']);
  613. $classes .= Display::tag('li', $data['name']);
  614. }
  615. }
  616. if (api_is_platform_admin()) {
  617. $classes .= Display::tag('li', Display::url(get_lang('AddClasses') ,api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add'));
  618. }
  619. if (!empty($classes)) {
  620. $classes = Display::tag('ul', $classes, array('class'=>'menulist'));
  621. echo show_right_block(get_lang('Classes'), $classes);
  622. }
  623. }
  624. echo '</div>'; // End of menu wrapper
  625. function show_right_block($title, $content) {
  626. $html= '<div id="menu" class="menu">';
  627. $html.= '<div class="menusection">';
  628. $html.= '<span class="menusectioncaption">'.$title.'</span>';
  629. $html.= $content;
  630. $html.= '</div>';
  631. $html.= '</div>';
  632. return $html;
  633. }
  634. // Footer
  635. Display :: display_footer();