banner.lib.php 28 KB

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