banner.lib.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Code
  5. * @todo use globals or parameters or add this file in the template
  6. * @package chamilo.include
  7. */
  8. /**
  9. * Determines the possible tabs (=sections) that are available.
  10. * This function is used when creating the tabs in the third header line and
  11. * all the sections that do not appear there (as determined by the
  12. * platform admin on the Dokeos configuration settings page)
  13. * will appear in the right hand menu that appears on several other pages
  14. * @return array containing all the possible tabs
  15. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  16. */
  17. function get_tabs($courseId = null)
  18. {
  19. $_course = api_get_course_info($courseId);
  20. $navigation = array();
  21. // Campus Homepage
  22. $navigation[SECTION_CAMPUS]['url'] = api_get_path(WEB_PATH).'index.php';
  23. $navigation[SECTION_CAMPUS]['title'] = get_lang('CampusHomepage');
  24. $navigation[SECTION_CAMPUS]['key'] = 'homepage';
  25. // My Courses
  26. if (api_is_allowed_to_create_course()) {
  27. // Link to my courses for teachers
  28. $navigation['mycourses']['url'] = api_get_path(WEB_PATH).'user_portal.php?nosession=true';
  29. } else {
  30. // Link to my courses for students
  31. $navigation['mycourses']['url'] = api_get_path(WEB_PATH).'user_portal.php';
  32. }
  33. $navigation['mycourses']['title'] = get_lang('MyCourses');
  34. $navigation['mycourses']['key'] = 'my-course';
  35. // My Profile
  36. $navigation['myprofile']['url'] = api_get_path(WEB_CODE_PATH).'auth/profile.php'.(!empty($_course['path']) ? '?coursePath='.$_course['path'].'&amp;courseCode='.$_course['official_code'] : '' );
  37. $navigation['myprofile']['title'] = get_lang('ModifyProfile');
  38. $navigation['myprofile']['key'] = 'profile';
  39. // Link to my agenda
  40. $navigation['myagenda']['url'] = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type=personal';
  41. $navigation['myagenda']['title'] = get_lang('MyAgenda');
  42. $navigation['myagenda']['key'] = 'agenda';
  43. // Gradebook
  44. if (api_get_setting('gradebook_enable') == 'true') {
  45. $navigation['mygradebook']['url'] = api_get_path(WEB_CODE_PATH).'gradebook/gradebook.php'.(!empty($_course['path']) ? '?coursePath='.$_course['path'].'&amp;courseCode='.$_course['official_code'] : '' );
  46. $navigation['mygradebook']['title'] = get_lang('MyGradebook');
  47. $navigation['mygradebook']['key'] = 'gradebook';
  48. }
  49. // Reporting
  50. if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin()) {
  51. // Link to my space
  52. $navigation['session_my_space']['url'] = api_get_path(WEB_CODE_PATH).'mySpace/'.(api_is_drh()?'session.php':'');
  53. $navigation['session_my_space']['title'] = get_lang('MySpace');
  54. $navigation['session_my_space']['key'] = 'my-space';
  55. } else if (api_is_student_boss()) {
  56. $navigation['session_my_space']['url'] = api_get_path(WEB_CODE_PATH) . 'mySpace/student.php';
  57. $navigation['session_my_space']['title'] = get_lang('MySpace');
  58. $navigation['session_my_space']['key'] = 'my-space';
  59. } else {
  60. $navigation['session_my_progress']['url'] = api_get_path(WEB_CODE_PATH);
  61. // Link to my progress
  62. switch (api_get_setting('gamification_mode')) {
  63. case 1:
  64. $navigation['session_my_progress']['url'] .= 'gamification/my_progress.php';
  65. break;
  66. default:
  67. $navigation['session_my_progress']['url'] .= 'auth/my_progress.php';
  68. }
  69. $navigation['session_my_progress']['title'] = get_lang('MyProgress');
  70. $navigation['session_my_progress']['key'] = 'my-progress';
  71. }
  72. // Social
  73. if (api_get_setting('allow_social_tool')=='true') {
  74. $navigation['social']['url'] = api_get_path(WEB_CODE_PATH).'social/home.php';
  75. $navigation['social']['title'] = get_lang('SocialNetwork');
  76. $navigation['social']['key'] = 'social-network';
  77. }
  78. // Dashboard
  79. if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
  80. $navigation['dashboard']['url'] = api_get_path(WEB_CODE_PATH).'dashboard/index.php';
  81. $navigation['dashboard']['title'] = get_lang('Dashboard');
  82. $navigation['dashboard']['key'] = 'dashboard';
  83. }
  84. // Reports
  85. /*
  86. if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
  87. $navigation['reports']['url'] = api_get_path(WEB_CODE_PATH).'reports/index.php';
  88. $navigation['reports']['title'] = get_lang('Reports');
  89. }*/
  90. // Custom Tabs See BT#7180
  91. $customTabs = getCustomTabs();
  92. if (!empty($customTabs)) {
  93. foreach ($customTabs as $tab) {
  94. if (api_get_setting($tab['variable'], $tab['subkey']) == 'true') {
  95. if (!empty($tab['comment']) && $tab['comment'] !== 'ShowTabsComment') {
  96. $navigation[$tab['subkey']]['url'] = $tab['comment'];
  97. // $tab['title'] value must be included in trad4all.inc.php
  98. $navigation[$tab['subkey']]['title'] = get_lang($tab['title']);
  99. $navigation[$tab['subkey']]['key'] = $tab['subkey'];
  100. }
  101. }
  102. }
  103. }
  104. // End Custom Tabs
  105. // Platform administration
  106. if (api_is_platform_admin(true)) {
  107. $navigation['platform_admin']['url'] = api_get_path(WEB_CODE_PATH).'admin/';
  108. $navigation['platform_admin']['title'] = get_lang('PlatformAdmin');
  109. $navigation['platform_admin']['key'] = 'admin';
  110. }
  111. return $navigation;
  112. }
  113. /**
  114. * This function returns the custom tabs
  115. *
  116. * @return array
  117. */
  118. function getCustomTabs()
  119. {
  120. $tableSettingsCurrent = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  121. $sql = "SELECT * FROM $tableSettingsCurrent
  122. WHERE variable = 'show_tabs' AND
  123. subkey like 'custom_tab_%'";
  124. $result = Database::query($sql);
  125. $customTabs = array();
  126. while ($row = Database::fetch_assoc($result)) {
  127. $customTabs[] = $row;
  128. }
  129. return $customTabs;
  130. }
  131. function return_logo($theme)
  132. {
  133. $_course = api_get_course_info();
  134. $html = '';
  135. $logo = api_get_path(SYS_CSS_PATH).'themes/'.$theme.'/images/header-logo.png';
  136. $site_name = api_get_setting('siteName');
  137. if (file_exists($logo)) {
  138. $site_name = api_get_setting('Institution').' - '.$site_name;
  139. $image_url = api_get_path(WEB_CSS_PATH).'themes/'.$theme.'/images/header-logo.png';
  140. $logo = Display::img(
  141. $image_url,
  142. $site_name,
  143. array('title' => $site_name, 'class' => 'img-responsive')
  144. );
  145. $html .= Display::url($logo, api_get_path(WEB_PATH).'index.php');
  146. } else {
  147. $html .= '<a href="'.api_get_path(WEB_PATH).'index.php" target="_top">'.$site_name.'</a>';
  148. $iurl = api_get_setting('InstitutionUrl');
  149. $iname = api_get_setting('Institution');
  150. if (!empty($iname)) {
  151. $html .= '-&nbsp;<a href="'.$iurl.'" target="_top">'.$iname.'</a>';
  152. }
  153. // External link section a.k.a Department - Department URL
  154. if (isset($_course['extLink']) && $_course['extLink']['name'] != '') {
  155. $html .= '<span class="extLinkSeparator"> - </span>';
  156. if ($_course['extLink']['url'] != '') {
  157. $html .= '<a class="extLink" href="'.$_course['extLink']['url'].'" target="_top">';
  158. $html .= $_course['extLink']['name'];
  159. $html .= '</a>';
  160. } else {
  161. $html .= $_course['extLink']['name'];
  162. }
  163. }
  164. }
  165. return $html;
  166. }
  167. function return_notification_menu()
  168. {
  169. $_course = api_get_course_info();
  170. $course_id = 0;
  171. if (!empty($_course)) {
  172. $course_id = $_course['code'];
  173. }
  174. $user_id = api_get_user_id();
  175. $html = '';
  176. if ((api_get_setting('showonline', 'world') == 'true' && !$user_id) ||
  177. (api_get_setting('showonline', 'users') == 'true' && $user_id) ||
  178. (api_get_setting('showonline', 'course') == 'true' && $user_id && $course_id)
  179. ) {
  180. $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
  181. $number_online_in_course = 0;
  182. if (!empty($_course['id'])) {
  183. $number_online_in_course = who_is_online_in_this_course_count(
  184. $user_id,
  185. api_get_setting('time_limit_whosonline'),
  186. $_course['id']
  187. );
  188. }
  189. // Display the who's online of the platform
  190. if ($number) {
  191. if ((api_get_setting('showonline', 'world') == 'true' && !$user_id) ||
  192. (api_get_setting('showonline', 'users') == 'true' && $user_id)
  193. ) {
  194. $html .= '<li><a href="'.api_get_path(WEB_PATH).'whoisonline.php" target="_self" title="'.get_lang('UsersOnline').'" >'.
  195. Display::return_icon('user.png', get_lang('UsersOnline'), array(), ICON_SIZE_TINY).' '.$number.'</a></li>';
  196. }
  197. }
  198. // Display the who's online for the course
  199. if ($number_online_in_course) {
  200. if (is_array($_course) &&
  201. api_get_setting('showonline', 'course') == 'true' &&
  202. isset($_course['sysCode'])
  203. ) {
  204. $html .= '<li><a href="'.api_get_path(WEB_PATH).'whoisonline.php?cidReq='.$_course['sysCode'].'" target="_self">'.
  205. Display::return_icon('course.png', get_lang('UsersOnline').' '.get_lang('InThisCourse'), array(), ICON_SIZE_TINY).' '.$number_online_in_course.' </a></li>';
  206. }
  207. }
  208. //if (api_get_setting('showonline', 'session') == 'true') {
  209. // Display the who's online for the session
  210. if (isset($user_id) && api_get_session_id() != 0) {
  211. $html .= '<li><a href="'.api_get_path(WEB_PATH).'whoisonlinesession.php?id_coach='.$user_id.'&amp;referer='.urlencode($_SERVER['REQUEST_URI']).'" target="_self">'.
  212. Display::return_icon('session.png', get_lang('UsersConnectedToMySessions'), array(), ICON_SIZE_TINY).' </a></li>';
  213. }
  214. //}
  215. }
  216. if (api_get_setting('accessibility_font_resize') == 'true') {
  217. $html .= '<li class="resize_font">';
  218. $html .= '<span class="decrease_font" title="'.get_lang('DecreaseFontSize').'">A</span> <span class="reset_font" title="'.get_lang('ResetFontSize').'">A</span> <span class="increase_font" title="'.get_lang('IncreaseFontSize').'">A</span>';
  219. $html .= '</li>';
  220. }
  221. return $html;
  222. }
  223. function return_navigation_array()
  224. {
  225. $navigation = array();
  226. $menu_navigation = array();
  227. $possible_tabs = get_tabs();
  228. // Campus Homepage
  229. if (api_get_setting('show_tabs', 'campus_homepage') == 'true') {
  230. $navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
  231. } else {
  232. $menu_navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
  233. }
  234. if (api_get_user_id() && !api_is_anonymous()) {
  235. // My Courses
  236. if (api_get_setting('show_tabs', 'my_courses') == 'true') {
  237. $navigation['mycourses'] = $possible_tabs['mycourses'];
  238. } else {
  239. $menu_navigation['mycourses'] = $possible_tabs['mycourses'];
  240. }
  241. // My Profile
  242. if (api_get_setting('show_tabs', 'my_profile') == 'true' &&
  243. api_get_setting('allow_social_tool') != 'true'
  244. ) {
  245. $navigation['myprofile'] = $possible_tabs['myprofile'];
  246. } else {
  247. $menu_navigation['myprofile'] = $possible_tabs['myprofile'];
  248. }
  249. // My Agenda
  250. if (api_get_setting('show_tabs', 'my_agenda') == 'true') {
  251. $navigation['myagenda'] = $possible_tabs['myagenda'];
  252. } else {
  253. $menu_navigation['myagenda'] = $possible_tabs['myagenda'];
  254. }
  255. // Gradebook
  256. if (api_get_setting('gradebook_enable') == 'true') {
  257. if (api_get_setting('show_tabs', 'my_gradebook') == 'true') {
  258. $navigation['mygradebook'] = $possible_tabs['mygradebook'];
  259. } else{
  260. $menu_navigation['mygradebook'] = $possible_tabs['mygradebook'];
  261. }
  262. }
  263. // Reporting
  264. if (api_get_setting('show_tabs', 'reporting') == 'true') {
  265. if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin() || api_is_student_boss()) {
  266. $navigation['session_my_space'] = $possible_tabs['session_my_space'];
  267. } else {
  268. $navigation['session_my_space'] = $possible_tabs['session_my_progress'];
  269. }
  270. } else {
  271. if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin() || api_is_student_boss()) {
  272. $menu_navigation['session_my_space'] = $possible_tabs['session_my_space'];
  273. } else {
  274. $menu_navigation['session_my_space'] = $possible_tabs['session_my_progress'];
  275. }
  276. }
  277. // Social Networking
  278. if (api_get_setting('show_tabs', 'social') == 'true') {
  279. if (api_get_setting('allow_social_tool') == 'true') {
  280. $navigation['social'] = isset($possible_tabs['social']) ? $possible_tabs['social'] : null;
  281. }
  282. } else{
  283. $menu_navigation['social'] = isset($possible_tabs['social']) ? $possible_tabs['social'] : null;
  284. }
  285. // Dashboard
  286. if (api_get_setting('show_tabs', 'dashboard') == 'true') {
  287. if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
  288. $navigation['dashboard'] = isset($possible_tabs['dashboard']) ? $possible_tabs['dashboard'] : null;
  289. }
  290. } else{
  291. $menu_navigation['dashboard'] = isset($possible_tabs['dashboard']) ? $possible_tabs['dashboard'] : null;
  292. }
  293. // Administration
  294. if (api_is_platform_admin(true)) {
  295. if (api_get_setting('show_tabs', 'platform_administration') == 'true') {
  296. $navigation['platform_admin'] = $possible_tabs['platform_admin'];
  297. } else {
  298. $menu_navigation['platform_admin'] = $possible_tabs['platform_admin'];
  299. }
  300. }
  301. // Reports
  302. if (!empty($possible_tabs['reports'])) {
  303. if (api_get_setting('show_tabs', 'reports') == 'true') {
  304. if ((api_is_platform_admin() || api_is_drh() || api_is_session_admin()) && Rights::hasRight('show_tabs:reports')) {
  305. $navigation['reports'] = $possible_tabs['reports'];
  306. }
  307. } else {
  308. $menu_navigation['reports'] = $possible_tabs['reports'];
  309. }
  310. }
  311. // Custom tabs
  312. $customTabs = getCustomTabs();
  313. if (!empty($customTabs)) {
  314. foreach ($customTabs as $tab) {
  315. if (api_get_setting($tab['variable'], $tab['subkey']) == 'true' &&
  316. isset($possible_tabs[$tab['subkey']])
  317. ) {
  318. $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH).$possible_tabs[$tab['subkey']]['url'];
  319. $navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
  320. } else {
  321. if (isset($possible_tabs[$tab['subkey']])) {
  322. $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH).$possible_tabs[$tab['subkey']]['url'];
  323. $menu_navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
  324. }
  325. }
  326. }
  327. }
  328. }
  329. return array(
  330. 'menu_navigation' => $menu_navigation,
  331. 'navigation' => $navigation,
  332. 'possible_tabs' => $possible_tabs,
  333. );
  334. }
  335. function return_menu()
  336. {
  337. $navigation = return_navigation_array();
  338. $navigation = $navigation['navigation'];
  339. // Displaying the tabs
  340. $lang = api_get_setting('platformLanguage');
  341. if (!empty($_SESSION['user_language_choice'])) {
  342. $lang = $_SESSION['user_language_choice'];
  343. } elseif (!empty($_SESSION['_user']['language'])) {
  344. $lang = $_SESSION['_user']['language'];
  345. }
  346. // Preparing home folder for multiple urls
  347. if (api_get_multiple_access_url()) {
  348. $access_url_id = api_get_current_access_url_id();
  349. if ($access_url_id != -1) {
  350. $url_info = api_get_access_url($access_url_id);
  351. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  352. $clean_url = api_replace_dangerous_char($url);
  353. $clean_url = str_replace('/', '-', $clean_url);
  354. $clean_url .= '/';
  355. $homep = api_get_path(SYS_APP_PATH).'home/'.$clean_url; //homep for Home Path
  356. //we create the new dir for the new sites
  357. if (!is_dir($homep)) {
  358. mkdir($homep, api_get_permissions_for_new_directories());
  359. }
  360. }
  361. } else {
  362. $homep = api_get_path(SYS_APP_PATH).'home/';
  363. }
  364. $ext = '.html';
  365. $menutabs = 'home_tabs';
  366. $mtloggedin = 'home_tabs_logged_in';
  367. $home_top = '';
  368. if (is_file($homep.$menutabs.'_'.$lang.$ext) && is_readable($homep.$menutabs.'_'.$lang.$ext)) {
  369. $home_top = @(string)file_get_contents($homep.$menutabs.'_'.$lang.$ext);
  370. } elseif (is_file($homep.$menutabs.$lang.$ext) && is_readable($homep.$menutabs.$lang.$ext)) {
  371. $home_top = @(string)file_get_contents($homep.$menutabs.$lang.$ext);
  372. } else {
  373. //$errorMsg = get_lang('HomePageFilesNotReadable');
  374. }
  375. $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
  376. $open = str_replace('{rel_path}',api_get_path(REL_PATH), $home_top);
  377. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  378. $open_mtloggedin = '';
  379. if (api_get_user_id() && !api_is_anonymous()) {
  380. if (is_file($homep.$mtloggedin.'_'.$lang.$ext) && is_readable($homep.$mtloggedin.'_'.$lang.$ext)) {
  381. $home_top = @(string)file_get_contents($homep.$mtloggedin.'_'.$lang.$ext);
  382. $home_top = str_replace('::private', '', $home_top);
  383. } elseif (is_file($homep.$mtloggedin.$lang.$ext) && is_readable($homep.$mtloggedin.$lang.$ext)) {
  384. $home_top = @(string)file_get_contents($homep.$mtloggedin.$lang.$ext);
  385. $home_top = str_replace('::private', '', $home_top);
  386. } else {
  387. //$errorMsg = get_lang('HomePageFilesNotReadable');
  388. }
  389. $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
  390. $open_mtloggedin = str_replace('{rel_path}',api_get_path(REL_PATH), $home_top);
  391. $open_mtloggedin = api_to_system_encoding($open_mtloggedin, api_detect_encoding(strip_tags($open_mtloggedin)));
  392. }
  393. $lis = '';
  394. if (!empty($open) OR !empty($open_mtloggedin)) {
  395. if (strpos($open.$open_mtloggedin, 'show_menu') === false) {
  396. if (api_is_anonymous()) {
  397. $navigation[SECTION_CAMPUS] = null;
  398. }
  399. } else {
  400. if (api_get_user_id() && !api_is_anonymous()) {
  401. $lis .= $open_mtloggedin;
  402. } else {
  403. $lis .= $open;
  404. }
  405. }
  406. }
  407. if (count($navigation) > 0 || !empty($lis)) {
  408. $pre_lis = '';
  409. foreach ($navigation as $section => $navigation_info) {
  410. $key = (!empty($navigation_info['key'])?'tab-'.$navigation_info['key']:'');
  411. if (isset($GLOBALS['this_section'])) {
  412. $current = $section == $GLOBALS['this_section'] ? ' id="current" class="active '.$key.'" ' : ' class="'.$key.'"';
  413. } else {
  414. $current = '';
  415. }
  416. if (!empty($navigation_info['title'])) {
  417. $pre_lis .= '<li'.$current.'><a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a></li>';
  418. }
  419. }
  420. $lis = $pre_lis.$lis;
  421. }
  422. $menu = null;
  423. if (!empty($lis)) {
  424. $menu .= $lis;
  425. }
  426. return $menu;
  427. }
  428. function return_breadcrumb($interbreadcrumb, $language_file, $nameTools)
  429. {
  430. $session_id = api_get_session_id();
  431. $session_name = api_get_session_name($session_id);
  432. $_course = api_get_course_info();
  433. $user_id = api_get_user_id();
  434. $course_id = 0;
  435. if (!empty($_course)) {
  436. $course_id = $_course['real_id'];
  437. }
  438. /* Plugins for banner section */
  439. $web_course_path = api_get_path(WEB_COURSE_PATH);
  440. /* If the user is a coach he can see the users who are logged in its session */
  441. $navigation = array();
  442. // part 1: Course Homepage. If we are in a course then the first breadcrumb is a link to the course homepage
  443. // hide_course_breadcrumb the parameter has been added to hide the name of the course, that appeared in the default $interbreadcrumb
  444. $session_name = cut($session_name, MAX_LENGTH_BREADCRUMB);
  445. $my_session_name = is_null($session_name) ? '' : '&nbsp;('.$session_name.')';
  446. if (!empty($_course) && !isset($_GET['hide_course_breadcrumb'])) {
  447. $navigation_item['url'] = $web_course_path . $_course['path'].'/index.php'.(!empty($session_id) ? '?id_session='.$session_id : '');
  448. $_course['name'] = api_htmlentities($_course['name']);
  449. $course_title = cut($_course['name'], MAX_LENGTH_BREADCRUMB);
  450. switch (api_get_setting('breadcrumbs_course_homepage')) {
  451. case 'get_lang':
  452. $navigation_item['title'] = Display::img(api_get_path(WEB_IMG_PATH).'home.png', get_lang('CourseHomepageLink')).' '.get_lang('CourseHomepageLink');
  453. break;
  454. case 'course_code':
  455. $navigation_item['title'] = Display::img(api_get_path(WEB_IMG_PATH).'home.png', $_course['official_code']).' '.$_course['official_code'];
  456. break;
  457. case 'session_name_and_course_title':
  458. $navigation_item['title'] = Display::img(api_get_path(WEB_IMG_PATH).'home.png', $_course['name'].$my_session_name).' '.$course_title.$my_session_name;
  459. break;
  460. default:
  461. if (api_get_session_id() != -1 ) {
  462. $navigation_item['title'] = Display::img(api_get_path(WEB_IMG_PATH).'home.png', $_course['name'].$my_session_name).' '.$course_title.$my_session_name;
  463. } else {
  464. $navigation_item['title'] = Display::img(api_get_path(WEB_IMG_PATH).'home.png', $_course['name']).' '.$course_title;
  465. }
  466. break;
  467. }
  468. /**
  469. * @todo could be useful adding the My courses in the breadcrumb
  470. $navigation_item_my_courses['title'] = get_lang('MyCourses');
  471. $navigation_item_my_courses['url'] = api_get_path(WEB_PATH).'user_portal.php';
  472. $navigation[] = $navigation_item_my_courses;
  473. */
  474. $navigation[] = $navigation_item;
  475. }
  476. /* part 2: Interbreadcrumbs. If there is an array $interbreadcrumb
  477. defined then these have to appear before the last breadcrumb
  478. (which is the tool itself)*/
  479. if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
  480. foreach ($interbreadcrumb as $breadcrumb_step) {
  481. if (isset($breadcrumb_step['type']) && $breadcrumb_step['type'] == 'right') {
  482. continue;
  483. }
  484. if ($breadcrumb_step['url'] != '#') {
  485. $sep = (strrchr($breadcrumb_step['url'], '?') ? '&amp;' : '?');
  486. $navigation_item['url'] = $breadcrumb_step['url'].$sep.api_get_cidreq();
  487. } else {
  488. $navigation_item['url'] = '#';
  489. }
  490. $navigation_item['title'] = $breadcrumb_step['name'];
  491. // titles for shared folders
  492. if ($breadcrumb_step['name'] == 'shared_folder') {
  493. $navigation_item['title'] = get_lang('UserFolders');
  494. } elseif(strstr($breadcrumb_step['name'], 'shared_folder_session_')) {
  495. $navigation_item['title'] = get_lang('UserFolders');
  496. } elseif(strstr($breadcrumb_step['name'], 'sf_user_')) {
  497. $userinfo = api_get_user_info(substr($breadcrumb_step['name'], 8));
  498. $navigation_item['title'] = $userinfo['complete_name'];
  499. } elseif($breadcrumb_step['name'] == 'chat_files') {
  500. $navigation_item['title'] = get_lang('ChatFiles');
  501. } elseif($breadcrumb_step['name'] == 'images') {
  502. $navigation_item['title'] = get_lang('Images');
  503. } elseif($breadcrumb_step['name'] == 'video') {
  504. $navigation_item['title'] = get_lang('Video');
  505. } elseif($breadcrumb_step['name'] == 'audio') {
  506. $navigation_item['title'] = get_lang('Audio');
  507. } elseif($breadcrumb_step['name'] == 'flash') {
  508. $navigation_item['title'] = get_lang('Flash');
  509. } elseif($breadcrumb_step['name'] == 'gallery') {
  510. $navigation_item['title'] = get_lang('Gallery');
  511. }
  512. // Fixes breadcrumb title now we applied the Security::remove_XSS and
  513. // we cut the string depending of the MAX_LENGTH_BREADCRUMB value
  514. $navigation_item['title'] = cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
  515. $navigation_item['title'] = Security::remove_XSS($navigation_item['title']);
  516. $navigation[] = $navigation_item;
  517. }
  518. }
  519. $navigation_right = array();
  520. if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
  521. foreach ($interbreadcrumb as $breadcrumb_step) {
  522. if (isset($breadcrumb_step['type']) && $breadcrumb_step['type'] == 'right') {
  523. if ($breadcrumb_step['url'] != '#') {
  524. $sep = (strrchr($breadcrumb_step['url'], '?') ? '&amp;' : '?');
  525. $navigation_item['url'] = $breadcrumb_step['url'].$sep.api_get_cidreq();
  526. } else {
  527. $navigation_item['url'] = '#';
  528. }
  529. $breadcrumb_step['title'] = cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
  530. $breadcrumb_step['title'] = Security::remove_XSS($navigation_item['title']);
  531. $navigation_right[] = $breadcrumb_step;
  532. }
  533. }
  534. }
  535. // part 3: The tool itself. If we are on the course homepage we do not want
  536. // to display the title of the course because this
  537. // is the same as the first part of the breadcrumbs (see part 1)
  538. if (isset($nameTools)) {
  539. $navigation_item['url'] = '#';
  540. $navigation_item['title'] = $nameTools;
  541. $navigation[] = $navigation_item;
  542. }
  543. $final_navigation = array();
  544. $counter = 0;
  545. foreach ($navigation as $index => $navigation_info) {
  546. if (!empty($navigation_info['title'])) {
  547. if ($navigation_info['url'] == '#') {
  548. $final_navigation[$index] = $navigation_info['title'];
  549. } else {
  550. $final_navigation[$index] = '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  551. }
  552. $counter++;
  553. }
  554. }
  555. $html = '';
  556. /* Part 4 . Show the teacher view/student view button at the right of the breadcrumb */
  557. $view_as_student_link = null;
  558. if ($user_id && isset($course_id)) {
  559. if ((api_is_course_admin() || api_is_platform_admin()) && api_get_setting('student_view_enabled') == 'true') {
  560. $view_as_student_link = api_display_tool_view_option();
  561. }
  562. }
  563. if (!empty($final_navigation)) {
  564. $lis = '';
  565. $i = 0;
  566. $final_navigation_count = count($final_navigation);
  567. if (!empty($final_navigation)) {
  568. // $home_link.= '<span class="divider">/</span>';
  569. if (!empty($home_link)) {
  570. $lis.= Display::tag('li', $home_link);
  571. }
  572. foreach ($final_navigation as $bread) {
  573. $bread_check = trim(strip_tags($bread));
  574. if (!empty($bread_check)) {
  575. if ($final_navigation_count-1 > $i) {
  576. $bread .= '';
  577. }
  578. $lis.= Display::tag('li', $bread,array('class'=>'active'));
  579. $i++;
  580. }
  581. }
  582. } else {
  583. if (!empty($home_link)) {
  584. $lis.= Display::tag('li', $home_link);
  585. }
  586. }
  587. // View as student/teacher link
  588. $view = null;
  589. if (!empty($view_as_student_link)) {
  590. $view .= Display::tag('div', $view_as_student_link, array('id' => 'view_as_link','class' => 'pull-right'));
  591. }
  592. if (!empty($navigation_right)) {
  593. foreach($navigation_right as $item){
  594. $extra_class = isset($item['class']) ? $item['class'] : null;
  595. $lis.= Display::tag('li', $item['title'], array('class' => $extra_class.' pull-right'));
  596. }
  597. }
  598. if (!empty($lis)) {
  599. $html .= $view;
  600. $html .= Display::tag('ul', $lis, array('class'=>'breadcrumb'));
  601. }
  602. }
  603. return $html;
  604. }