banner.lib.php 27 KB

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