banner.lib.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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 {
  55. // Link to my progress
  56. $navigation['session_my_progress']['url'] = api_get_path(WEB_CODE_PATH).'auth/my_progress.php';
  57. $navigation['session_my_progress']['title'] = get_lang('MyProgress');
  58. $navigation['session_my_progress']['key'] = 'my-progress';
  59. }
  60. // Social
  61. /*
  62. if (api_get_setting('allow_social_tool')=='true') {
  63. $navigation['social']['url'] = api_get_path(WEB_CODE_PATH).'social/home.php';
  64. // get count unread message and total invitations
  65. $count_unread_message = MessageManager::get_number_of_messages(true);
  66. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  67. $group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION,false);
  68. $group_pending_invitations = 0;
  69. if (!empty($group_pending_invitations )) {
  70. $group_pending_invitations = count($group_pending_invitations);
  71. }
  72. $total_invitations = intval($number_of_new_messages_of_friend) + $group_pending_invitations + intval($count_unread_message);
  73. $total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) :'');
  74. $navigation['social']['title'] = get_lang('SocialNetwork'). $total_invitations;
  75. }
  76. */
  77. // Social
  78. if (api_get_setting('allow_social_tool')=='true') {
  79. $navigation['social']['url'] = api_get_path(WEB_CODE_PATH).'social/home.php';
  80. $navigation['social']['title'] = get_lang('SocialNetwork');
  81. $navigation['social']['key'] = 'social-network';
  82. }
  83. // Dashboard
  84. if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
  85. $navigation['dashboard']['url'] = api_get_path(WEB_CODE_PATH).'dashboard/index.php';
  86. $navigation['dashboard']['title'] = get_lang('Dashboard');
  87. $navigation['dashboard']['key'] = 'dashboard';
  88. }
  89. // Reports
  90. /*
  91. if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
  92. $navigation['reports']['url'] = api_get_path(WEB_CODE_PATH).'reports/index.php';
  93. $navigation['reports']['title'] = get_lang('Reports');
  94. }*/
  95. // Custom Tabs See BT#7180
  96. $customTabs = getCustomTabs();
  97. if (!empty($customTabs)) {
  98. foreach ($customTabs as $tab) {
  99. if (api_get_setting($tab['variable'], $tab['subkey']) == 'true') {
  100. if (!empty($tab['comment']) && $tab['comment'] !== 'ShowTabsComment') {
  101. $navigation[$tab['subkey']]['url'] = $tab['comment'];
  102. // $tab['title'] value must be included in trad4all.inc.php
  103. $navigation[$tab['subkey']]['title'] = get_lang($tab['title']);
  104. $navigation[$tab['subkey']]['key'] = $tab['subkey'];
  105. }
  106. }
  107. }
  108. }
  109. // End Custom Tabs
  110. // Platform administration
  111. if (api_is_platform_admin(true)) {
  112. $navigation['platform_admin']['url'] = api_get_path(WEB_CODE_PATH).'admin/';
  113. $navigation['platform_admin']['title'] = get_lang('PlatformAdmin');
  114. $navigation['platform_admin']['key'] = 'admin';
  115. }
  116. return $navigation;
  117. }
  118. /**
  119. * This function returns the custom tabs
  120. *
  121. * @return array
  122. */
  123. function getCustomTabs() {
  124. $tableSettingsCurrent = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  125. $sql = "SELECT * FROM $tableSettingsCurrent
  126. WHERE variable = 'show_tabs' AND
  127. subkey like 'custom_tab_%'";
  128. $result = Database::query($sql);
  129. $customTabs = array();
  130. while ($row = Database::fetch_assoc($result)) {
  131. $customTabs[] = $row;
  132. }
  133. return $customTabs;
  134. }
  135. function return_logo($theme) {
  136. $_course = api_get_course_info();
  137. $html = '';
  138. $logo = api_get_path(SYS_CODE_PATH).'css/'.$theme.'/images/header-logo.png';
  139. $site_name = api_get_setting('siteName');
  140. if (file_exists($logo)) {
  141. $site_name = api_get_setting('Institution').' - '.$site_name;
  142. $html .= '<div id="logo">';
  143. $image_url = api_get_path(WEB_CSS_PATH).$theme.'/images/header-logo.png';
  144. $logo = Display::img($image_url, $site_name, array('title'=>$site_name));
  145. $html .= Display::url($logo, api_get_path(WEB_PATH).'index.php');
  146. $html .= '</div>';
  147. } else {
  148. $html .= '<a href="'.api_get_path(WEB_PATH).'index.php" target="_top">'.$site_name.'</a>';
  149. $iurl = api_get_setting('InstitutionUrl');
  150. $iname = api_get_setting('Institution');
  151. if (!empty($iname)) {
  152. $html .= '-&nbsp;<a href="'.$iurl.'" target="_top">'.$iname.'</a>';
  153. }
  154. // External link section a.k.a Department - Department URL
  155. if (isset($_course['extLink']) && $_course['extLink']['name'] != '') {
  156. $html .= '<span class="extLinkSeparator"> - </span>';
  157. if ($_course['extLink']['url'] != '') {
  158. $html .= '<a class="extLink" href="'.$_course['extLink']['url'].'" target="_top">';
  159. $html .= $_course['extLink']['name'];
  160. $html .= '</a>';
  161. } else {
  162. $html .= $_course['extLink']['name'];
  163. }
  164. }
  165. }
  166. /* // Course title section
  167. if (!empty($_cid) and $_cid != -1 and isset($_course)) {
  168. //Put the name of the course in the header
  169. $html .= '<div id="my_courses">';
  170. $html .= '</div>';
  171. } elseif (isset($nameTools) && $language_file != 'course_home') {
  172. //Put the name of the user-tools in the header
  173. if (!isset($user_id)) {
  174. //echo '<div id="my_courses"></div>';
  175. } elseif (!$noPHP_SELF) {
  176. $html .= '<div id="my_courses"><a href="'.api_get_self().'?'.api_get_cidreq(). '" target="_top">'.$nameTools.'</a></div>';
  177. } else {
  178. $html .= '<div id="my_courses">'.$nameTools.'</div>';
  179. }
  180. }*/
  181. return $html;
  182. }
  183. function return_notification_menu() {
  184. $_course = api_get_course_info();
  185. $course_id = api_get_course_id();
  186. $user_id = api_get_user_id();
  187. $html = '';
  188. 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)) {
  189. $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
  190. $number_online_in_course = 0;
  191. if(!empty($_course['id'])) {
  192. $number_online_in_course = who_is_online_in_this_course_count($user_id, api_get_setting('time_limit_whosonline'), $_course['id']);
  193. }
  194. // Display the who's online of the platform
  195. if ($number) {
  196. if ((api_get_setting('showonline', 'world') == 'true' AND !$user_id) OR (api_get_setting('showonline', 'users') == 'true' AND $user_id)) {
  197. $html .= '<li><a href="'.api_get_path(WEB_PATH).'whoisonline.php" target="_top" title="'.get_lang('UsersOnline').'" >'.
  198. Display::return_icon('user.png', get_lang('UsersOnline'), array(), ICON_SIZE_TINY).' '.$number.'</a></li>';
  199. }
  200. }
  201. // Display the who's online for the course
  202. if ($number_online_in_course) {
  203. if (is_array($_course) AND api_get_setting('showonline', 'course') == 'true' AND isset($_course['sysCode'])) {
  204. $html .= '<li><a href="'.api_get_path(WEB_PATH).'whoisonline.php?cidReq='.$_course['sysCode'].'" target="_top">'.
  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="_top">'.
  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. $navigation = array();
  225. $menu_navigation = array();
  226. $possible_tabs = get_tabs();
  227. // Campus Homepage
  228. if (api_get_setting('show_tabs', 'campus_homepage') == 'true') {
  229. $navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
  230. } else {
  231. $menu_navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
  232. }
  233. if (api_get_user_id() && !api_is_anonymous()) {
  234. // My Courses
  235. if (api_get_setting('show_tabs', 'my_courses') == 'true') {
  236. $navigation['mycourses'] = $possible_tabs['mycourses'];
  237. } else {
  238. $menu_navigation['mycourses'] = $possible_tabs['mycourses'];
  239. }
  240. // My Profile
  241. if (api_get_setting('show_tabs', 'my_profile') == 'true' && api_get_setting('allow_social_tool') != 'true') {
  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()) {
  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()) {
  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. $navigation = return_navigation_array();
  330. $navigation = $navigation['navigation'];
  331. // Displaying the tabs
  332. $lang = ''; //el for "Edit Language"
  333. if (!empty($_SESSION['user_language_choice'])) {
  334. $lang = $_SESSION['user_language_choice'];
  335. } elseif (!empty($_SESSION['_user']['language'])) {
  336. $lang = $_SESSION['_user']['language'];
  337. } else {
  338. $lang = get_setting('platformLanguage');
  339. }
  340. //Preparing home folder for multiple urls
  341. if (api_get_multiple_access_url()) {
  342. $access_url_id = api_get_current_access_url_id();
  343. if ($access_url_id != -1) {
  344. $url_info = api_get_access_url($access_url_id);
  345. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  346. $clean_url = replace_dangerous_char($url);
  347. $clean_url = str_replace('/', '-', $clean_url);
  348. $clean_url .= '/';
  349. $homep = api_get_path(SYS_PATH).'home/'.$clean_url; //homep for Home Path
  350. //we create the new dir for the new sites
  351. if (!is_dir($homep)) {
  352. mkdir($homep, api_get_permissions_for_new_directories());
  353. }
  354. }
  355. } else {
  356. $homep = api_get_path(SYS_PATH).'home/';
  357. }
  358. $ext = '.html';
  359. $menutabs = 'home_tabs';
  360. $mtloggedin = 'home_tabs_logged_in';
  361. $home_top = '';
  362. if (is_file($homep.$menutabs.'_'.$lang.$ext) && is_readable($homep.$menutabs.'_'.$lang.$ext)) {
  363. $home_top = @(string)file_get_contents($homep.$menutabs.'_'.$lang.$ext);
  364. } elseif (is_file($homep.$menutabs.$lang.$ext) && is_readable($homep.$menutabs.$lang.$ext)) {
  365. $home_top = @(string)file_get_contents($homep.$menutabs.$lang.$ext);
  366. } else {
  367. //$errorMsg = get_lang('HomePageFilesNotReadable');
  368. }
  369. $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
  370. $open = str_replace('{rel_path}',api_get_path(REL_PATH), $home_top);
  371. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  372. $open_mtloggedin = '';
  373. if (api_get_user_id() && !api_is_anonymous()) {
  374. if (is_file($homep.$mtloggedin.'_'.$lang.$ext) && is_readable($homep.$mtloggedin.'_'.$lang.$ext)) {
  375. $home_top = @(string)file_get_contents($homep.$mtloggedin.'_'.$lang.$ext);
  376. $home_top = str_replace('::private', '', $home_top);
  377. } elseif (is_file($homep.$mtloggedin.$lang.$ext) && is_readable($homep.$mtloggedin.$lang.$ext)) {
  378. $home_top = @(string)file_get_contents($homep.$mtloggedin.$lang.$ext);
  379. $home_top = str_replace('::private', '', $home_top);
  380. } else {
  381. //$errorMsg = get_lang('HomePageFilesNotReadable');
  382. }
  383. $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
  384. $open_mtloggedin = str_replace('{rel_path}',api_get_path(REL_PATH), $home_top);
  385. $open_mtloggedin = api_to_system_encoding($open_mtloggedin, api_detect_encoding(strip_tags($open_mtloggedin)));
  386. }
  387. $lis = '';
  388. if (!empty($open) OR !empty($open_mtloggedin)) {
  389. if (strpos($open.$open_mtloggedin, 'show_menu') === false) {
  390. if (api_is_anonymous()) {
  391. $navigation[SECTION_CAMPUS] = null;
  392. }
  393. } else {
  394. //$lis .= Display::tag('li', $open);
  395. if (api_get_user_id() && !api_is_anonymous()) {
  396. $lis .= $open_mtloggedin;
  397. } else {
  398. $lis .= $open;
  399. }
  400. }
  401. }
  402. if (count($navigation) > 0 || !empty($lis)) {
  403. $pre_lis = '';
  404. foreach ($navigation as $section => $navigation_info) {
  405. $key = (!empty($navigation_info['key'])?'tab-'.$navigation_info['key']:'');
  406. if (isset($GLOBALS['this_section'])) {
  407. $current = $section == $GLOBALS['this_section'] ? ' id="current" class="active '.$key.'" ' : ' class="'.$key.'"';
  408. } else {
  409. $current = '';
  410. }
  411. if (!empty($navigation_info['title'])) {
  412. $pre_lis .= '<li'.$current.'><a href="'.$navigation_info['url'].'" target="_top">'.$navigation_info['title'].'</a></li>';
  413. }
  414. }
  415. $lis = $pre_lis.$lis;
  416. }
  417. $menu = null;
  418. if (!empty($lis)) {
  419. $menu .= $lis;
  420. }
  421. return $menu;
  422. }
  423. function return_breadcrumb($interbreadcrumb, $language_file, $nameTools)
  424. {
  425. $session_id = api_get_session_id();
  426. $session_name = api_get_session_name($session_id);
  427. $_course = api_get_course_info();
  428. $user_id = api_get_user_id();
  429. $course_id = api_get_course_id();
  430. /* Plugins for banner section */
  431. $web_course_path = api_get_path(WEB_COURSE_PATH);
  432. /* If the user is a coach he can see the users who are logged in its session */
  433. $navigation = array();
  434. // part 1: Course Homepage. If we are in a course then the first breadcrumb is a link to the course homepage
  435. // hide_course_breadcrumb the parameter has been added to hide the name of the course, that appeared in the default $interbreadcrumb
  436. $session_name = cut($session_name, MAX_LENGTH_BREADCRUMB);
  437. $my_session_name = is_null($session_name) ? '' : '&nbsp;('.$session_name.')';
  438. if (!empty($_course) && !isset($_GET['hide_course_breadcrumb'])) {
  439. $navigation_item['url'] = $web_course_path . $_course['path'].'/index.php'.(!empty($session_id) ? '?id_session='.$session_id : '');
  440. $_course['name'] = api_htmlentities($_course['name']);
  441. $course_title = cut($_course['name'], MAX_LENGTH_BREADCRUMB);
  442. switch (api_get_setting('breadcrumbs_course_homepage')) {
  443. case 'get_lang':
  444. $navigation_item['title'] = Display::img(api_get_path(WEB_CSS_PATH).'home.png', get_lang('CourseHomepageLink')).' '.get_lang('CourseHomepageLink');
  445. break;
  446. case 'course_code':
  447. $navigation_item['title'] = Display::img(api_get_path(WEB_CSS_PATH).'home.png', $_course['official_code']).' '.$_course['official_code'];
  448. break;
  449. case 'session_name_and_course_title':
  450. $navigation_item['title'] = Display::img(api_get_path(WEB_CSS_PATH).'home.png', $_course['name'].$my_session_name).' '.$course_title.$my_session_name;
  451. break;
  452. default:
  453. if (api_get_session_id() != -1 ) {
  454. $navigation_item['title'] = Display::img(api_get_path(WEB_CSS_PATH).'home.png', $_course['name'].$my_session_name).' '.$course_title.$my_session_name;
  455. } else {
  456. $navigation_item['title'] = Display::img(api_get_path(WEB_CSS_PATH).'home.png', $_course['name']).' '.$course_title;
  457. }
  458. break;
  459. }
  460. /**
  461. * @todo could be useful adding the My courses in the breadcrumb
  462. $navigation_item_my_courses['title'] = get_lang('MyCourses');
  463. $navigation_item_my_courses['url'] = api_get_path(WEB_PATH).'user_portal.php';
  464. $navigation[] = $navigation_item_my_courses;
  465. */
  466. $navigation[] = $navigation_item;
  467. }
  468. /* part 2: Interbreadcrumbs. If there is an array $interbreadcrumb
  469. defined then these have to appear before the last breadcrumb
  470. (which is the tool itself)*/
  471. if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
  472. foreach ($interbreadcrumb as $breadcrumb_step) {
  473. if (isset($breadcrumb_step['type']) && $breadcrumb_step['type'] == 'right') {
  474. continue;
  475. }
  476. if ($breadcrumb_step['url'] != '#') {
  477. $sep = (strrchr($breadcrumb_step['url'], '?') ? '&amp;' : '?');
  478. $navigation_item['url'] = $breadcrumb_step['url'].$sep.api_get_cidreq();
  479. } else {
  480. $navigation_item['url'] = '#';
  481. }
  482. $navigation_item['title'] = $breadcrumb_step['name'];
  483. // titles for shared folders
  484. if ($breadcrumb_step['name'] == 'shared_folder') {
  485. $navigation_item['title'] = get_lang('UserFolders');
  486. } elseif(strstr($breadcrumb_step['name'], 'shared_folder_session_')) {
  487. $navigation_item['title'] = get_lang('UserFolders');
  488. } elseif(strstr($breadcrumb_step['name'], 'sf_user_')) {
  489. $userinfo = api_get_user_info(substr($breadcrumb_step['name'], 8));
  490. $navigation_item['title'] = $userinfo['complete_name'];
  491. } elseif($breadcrumb_step['name'] == 'chat_files') {
  492. $navigation_item['title'] = get_lang('ChatFiles');
  493. } elseif($breadcrumb_step['name'] == 'images') {
  494. $navigation_item['title'] = get_lang('Images');
  495. } elseif($breadcrumb_step['name'] == 'video') {
  496. $navigation_item['title'] = get_lang('Video');
  497. } elseif($breadcrumb_step['name'] == 'audio') {
  498. $navigation_item['title'] = get_lang('Audio');
  499. } elseif($breadcrumb_step['name'] == 'flash') {
  500. $navigation_item['title'] = get_lang('Flash');
  501. } elseif($breadcrumb_step['name'] == 'gallery') {
  502. $navigation_item['title'] = get_lang('Gallery');
  503. }
  504. //Fixes breadcrumb title now we applied the Security::remove_XSS and we cut the string depending of the MAX_LENGTH_BREADCRUMB value
  505. $navigation_item['title'] = cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
  506. $navigation_item['title'] = Security::remove_XSS($navigation_item['title']);
  507. $navigation[] = $navigation_item;
  508. }
  509. }
  510. $navigation_right = array();
  511. if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
  512. foreach ($interbreadcrumb as $breadcrumb_step) {
  513. if (isset($breadcrumb_step['type']) && $breadcrumb_step['type'] == 'right') {
  514. if ($breadcrumb_step['url'] != '#') {
  515. $sep = (strrchr($breadcrumb_step['url'], '?') ? '&amp;' : '?');
  516. $navigation_item['url'] = $breadcrumb_step['url'].$sep.api_get_cidreq();
  517. } else {
  518. $navigation_item['url'] = '#';
  519. }
  520. $breadcrumb_step['title'] = cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
  521. $breadcrumb_step['title'] = Security::remove_XSS($navigation_item['title']);
  522. $navigation_right[] = $breadcrumb_step;
  523. }
  524. }
  525. }
  526. // 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
  527. // is the same as the first part of the breadcrumbs (see part 1)
  528. if (isset($nameTools) && $language_file != 'course_home') { // TODO: This condition $language_file != 'course_home' might bring surprises.
  529. $navigation_item['url'] = '#';
  530. $navigation_item['title'] = $nameTools;
  531. $navigation[] = $navigation_item;
  532. }
  533. $final_navigation = array();
  534. $counter = 0;
  535. foreach ($navigation as $index => $navigation_info) {
  536. if (!empty($navigation_info['title'])) {
  537. if ($navigation_info['url'] == '#') {
  538. $final_navigation[$index] = $navigation_info['title'];
  539. } else {
  540. $final_navigation[$index] = '<a href="'.$navigation_info['url'].'" class="" target="_top">'.$navigation_info['title'].'</a>';
  541. }
  542. $counter++;
  543. }
  544. }
  545. $html = '';
  546. /* Part 4 . Show the teacher view/student view button at the right of the breadcrumb */
  547. $view_as_student_link = null;
  548. if ($user_id && isset($course_id)) {
  549. if ((api_is_course_admin() || api_is_platform_admin()) && api_get_setting('student_view_enabled') == 'true') {
  550. $view_as_student_link = api_display_tool_view_option();
  551. }
  552. }
  553. if (!empty($final_navigation)) {
  554. $lis = '';
  555. $i = 0;
  556. $final_navigation_count = count($final_navigation);
  557. if (!empty($final_navigation)) {
  558. // $home_link.= '<span class="divider">/</span>';
  559. if (!empty($home_link)) {
  560. $lis.= Display::tag('li', $home_link);
  561. }
  562. foreach ($final_navigation as $bread) {
  563. $bread_check = trim(strip_tags($bread));
  564. if (!empty($bread_check)) {
  565. if ($final_navigation_count-1 > $i) {
  566. $bread .= '<span class="divider">/</span>';
  567. }
  568. $lis.= Display::tag('li', $bread);
  569. $i++;
  570. }
  571. }
  572. } else {
  573. if (!empty($home_link)) {
  574. $lis.= Display::tag('li', $home_link);
  575. }
  576. }
  577. // View as student/teacher link
  578. if (!empty($view_as_student_link)) {
  579. $lis.= Display::tag('li', $view_as_student_link, array('id' => 'view_as_link','class' => 'pull-right'));
  580. }
  581. if (!empty($navigation_right)) {
  582. foreach($navigation_right as $item){
  583. $extra_class = isset($item['class']) ? $item['class'] : null;
  584. $lis.= Display::tag('li', $item['title'], array('class' => $extra_class.' pull-right'));
  585. }
  586. }
  587. if (!empty($lis)) {
  588. $html .= Display::tag('ul', $lis, array('class'=>'breadcrumb','style'=>'margin-top: 0'));
  589. }
  590. }
  591. return $html ;
  592. }