banner.lib.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  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. /**
  132. *
  133. * @param string $theme
  134. */
  135. function return_logo($theme)
  136. {
  137. $_course = api_get_course_info();
  138. $html = '';
  139. $logoBase = api_get_path(SYS_CSS_PATH).'themes/'.$theme.'/images/header-logo.';
  140. $customLogoBase = api_get_path(SYS_PUBLIC_PATH).'css/themes/'.$theme.'/images/header-logo-custom.';
  141. $customLogo = '';
  142. $siteName = api_get_setting('siteName');
  143. $attributes = array(
  144. 'title' => $siteName,
  145. 'class' => 'img-responsive',
  146. 'id' => 'header-logo'
  147. );
  148. $testServer = api_get_setting('server_type');
  149. if ($testServer == 'test' && is_file($logoBase . 'svg')) {
  150. $logo = $logoBase . 'svg';
  151. $attributes['width'] = '245';
  152. $attributes['height'] = '68';
  153. $imageUrl = api_get_path(WEB_CSS_PATH).'themes/'.$theme.'/images/header-logo.svg';
  154. } else {
  155. $logo = $logoBase . 'png';
  156. $customLogo = $customLogoBase . 'png';
  157. $imageUrl = api_get_path(WEB_CSS_PATH).'themes/'.$theme.'/images/header-logo.png';
  158. $customImageUrl = api_get_path(WEB_CSS_PATH).'themes/'.$theme.'/images/header-logo-custom.png';
  159. }
  160. if (file_exists($customLogo)) {
  161. $siteName = api_get_setting('Institution').' - '.$siteName;
  162. $customLogo = Display::img(
  163. $customImageUrl,
  164. $siteName,
  165. $attributes
  166. );
  167. $html .= Display::url($customLogo, api_get_path(WEB_PATH).'index.php');
  168. } elseif (file_exists($logo)) {
  169. $siteName = api_get_setting('Institution').' - '.$siteName;
  170. $logo = Display::img(
  171. $imageUrl,
  172. $siteName,
  173. $attributes
  174. );
  175. $html .= Display::url($logo, api_get_path(WEB_PATH).'index.php');
  176. } else {
  177. $html .= '<a href="'.api_get_path(WEB_PATH).'index.php" target="_top">'.$siteName.'</a>';
  178. $iurl = api_get_setting('InstitutionUrl');
  179. $iname = api_get_setting('Institution');
  180. if (!empty($iname)) {
  181. $html .= '-&nbsp;<a href="'.$iurl.'" target="_top">'.$iname.'</a>';
  182. }
  183. // External link section a.k.a Department - Department URL
  184. if (isset($_course['extLink']) && $_course['extLink']['name'] != '') {
  185. $html .= '<span class="extLinkSeparator"> - </span>';
  186. if ($_course['extLink']['url'] != '') {
  187. $html .= '<a class="extLink" href="'.$_course['extLink']['url'].'" target="_top">';
  188. $html .= $_course['extLink']['name'];
  189. $html .= '</a>';
  190. } else {
  191. $html .= $_course['extLink']['name'];
  192. }
  193. }
  194. }
  195. return $html;
  196. }
  197. function return_notification_menu()
  198. {
  199. $_course = api_get_course_info();
  200. $course_id = 0;
  201. if (!empty($_course)) {
  202. $course_id = $_course['code'];
  203. }
  204. $user_id = api_get_user_id();
  205. $html = '';
  206. if ((api_get_setting('showonline', 'world') == 'true' && !$user_id) ||
  207. (api_get_setting('showonline', 'users') == 'true' && $user_id) ||
  208. (api_get_setting('showonline', 'course') == 'true' && $user_id && $course_id)
  209. ) {
  210. $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
  211. $number_online_in_course = 0;
  212. if (!empty($_course['id'])) {
  213. $number_online_in_course = who_is_online_in_this_course_count(
  214. $user_id,
  215. api_get_setting('time_limit_whosonline'),
  216. $_course['id']
  217. );
  218. }
  219. // Display the who's online of the platform
  220. if ($number) {
  221. if ((api_get_setting('showonline', 'world') == 'true' && !$user_id) ||
  222. (api_get_setting('showonline', 'users') == 'true' && $user_id)
  223. ) {
  224. $html .= '<li><a href="'.api_get_path(WEB_PATH).'whoisonline.php" target="_self" title="'.get_lang('UsersOnline').'" >'.
  225. Display::return_icon('user.png', get_lang('UsersOnline'), array(), ICON_SIZE_TINY).' '.$number.'</a></li>';
  226. }
  227. }
  228. // Display the who's online for the course
  229. if ($number_online_in_course) {
  230. if (is_array($_course) &&
  231. api_get_setting('showonline', 'course') == 'true' &&
  232. isset($_course['sysCode'])
  233. ) {
  234. $html .= '<li><a href="'.api_get_path(WEB_PATH).'whoisonline.php?cidReq='.$_course['sysCode'].'" target="_self">'.
  235. Display::return_icon('course.png', get_lang('UsersOnline').' '.get_lang('InThisCourse'), array(), ICON_SIZE_TINY).' '.$number_online_in_course.' </a></li>';
  236. }
  237. }
  238. //if (api_get_setting('showonline', 'session') == 'true') {
  239. // Display the who's online for the session
  240. if (isset($user_id) && api_get_session_id() != 0) {
  241. $html .= '<li><a href="'.api_get_path(WEB_PATH).'whoisonlinesession.php?id_coach='.$user_id.'&amp;referer='.urlencode($_SERVER['REQUEST_URI']).'" target="_self">'.
  242. Display::return_icon('session.png', get_lang('UsersConnectedToMySessions'), array(), ICON_SIZE_TINY).' </a></li>';
  243. }
  244. //}
  245. }
  246. return $html;
  247. }
  248. function return_navigation_array()
  249. {
  250. $navigation = array();
  251. $menu_navigation = array();
  252. $possible_tabs = get_tabs();
  253. // Campus Homepage
  254. if (api_get_setting('show_tabs', 'campus_homepage') == 'true') {
  255. $navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
  256. } else {
  257. $menu_navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
  258. }
  259. if (api_get_user_id() && !api_is_anonymous()) {
  260. // My Courses
  261. if (api_get_setting('show_tabs', 'my_courses') == 'true') {
  262. $navigation['mycourses'] = $possible_tabs['mycourses'];
  263. } else {
  264. $menu_navigation['mycourses'] = $possible_tabs['mycourses'];
  265. }
  266. // My Profile
  267. if (api_get_setting('show_tabs', 'my_profile') == 'true' &&
  268. api_get_setting('allow_social_tool') != 'true'
  269. ) {
  270. $navigation['myprofile'] = $possible_tabs['myprofile'];
  271. } else {
  272. $menu_navigation['myprofile'] = $possible_tabs['myprofile'];
  273. }
  274. // My Agenda
  275. if (api_get_setting('show_tabs', 'my_agenda') == 'true') {
  276. $navigation['myagenda'] = $possible_tabs['myagenda'];
  277. } else {
  278. $menu_navigation['myagenda'] = $possible_tabs['myagenda'];
  279. }
  280. // Gradebook
  281. if (api_get_setting('gradebook_enable') == 'true') {
  282. if (api_get_setting('show_tabs', 'my_gradebook') == 'true') {
  283. $navigation['mygradebook'] = $possible_tabs['mygradebook'];
  284. } else{
  285. $menu_navigation['mygradebook'] = $possible_tabs['mygradebook'];
  286. }
  287. }
  288. // Reporting
  289. if (api_get_setting('show_tabs', 'reporting') == 'true') {
  290. if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin() || api_is_student_boss()) {
  291. $navigation['session_my_space'] = $possible_tabs['session_my_space'];
  292. } else {
  293. $navigation['session_my_space'] = $possible_tabs['session_my_progress'];
  294. }
  295. } else {
  296. if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin() || api_is_student_boss()) {
  297. $menu_navigation['session_my_space'] = $possible_tabs['session_my_space'];
  298. } else {
  299. $menu_navigation['session_my_space'] = $possible_tabs['session_my_progress'];
  300. }
  301. }
  302. // Social Networking
  303. if (api_get_setting('show_tabs', 'social') == 'true') {
  304. if (api_get_setting('allow_social_tool') == 'true') {
  305. $navigation['social'] = isset($possible_tabs['social']) ? $possible_tabs['social'] : null;
  306. }
  307. } else{
  308. $menu_navigation['social'] = isset($possible_tabs['social']) ? $possible_tabs['social'] : null;
  309. }
  310. // Dashboard
  311. if (api_get_setting('show_tabs', 'dashboard') == 'true') {
  312. if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
  313. $navigation['dashboard'] = isset($possible_tabs['dashboard']) ? $possible_tabs['dashboard'] : null;
  314. }
  315. } else{
  316. $menu_navigation['dashboard'] = isset($possible_tabs['dashboard']) ? $possible_tabs['dashboard'] : null;
  317. }
  318. // Administration
  319. if (api_is_platform_admin(true)) {
  320. if (api_get_setting('show_tabs', 'platform_administration') == 'true') {
  321. $navigation['platform_admin'] = $possible_tabs['platform_admin'];
  322. } else {
  323. $menu_navigation['platform_admin'] = $possible_tabs['platform_admin'];
  324. }
  325. }
  326. // Reports
  327. if (!empty($possible_tabs['reports'])) {
  328. if (api_get_setting('show_tabs', 'reports') == 'true') {
  329. if ((api_is_platform_admin() || api_is_drh() || api_is_session_admin()) && Rights::hasRight('show_tabs:reports')) {
  330. $navigation['reports'] = $possible_tabs['reports'];
  331. }
  332. } else {
  333. $menu_navigation['reports'] = $possible_tabs['reports'];
  334. }
  335. }
  336. // Custom tabs
  337. $customTabs = getCustomTabs();
  338. if (!empty($customTabs)) {
  339. foreach ($customTabs as $tab) {
  340. if (api_get_setting($tab['variable'], $tab['subkey']) == 'true' &&
  341. isset($possible_tabs[$tab['subkey']])
  342. ) {
  343. $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH).$possible_tabs[$tab['subkey']]['url'];
  344. $navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
  345. } else {
  346. if (isset($possible_tabs[$tab['subkey']])) {
  347. $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH).$possible_tabs[$tab['subkey']]['url'];
  348. $menu_navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
  349. }
  350. }
  351. }
  352. }
  353. }else{
  354. // Custom tabs public
  355. $customTabs = getCustomTabs();
  356. if (!empty($customTabs)) {
  357. foreach ($customTabs as $tab) {
  358. if (api_get_setting($tab['variable'], $tab['subkey']) == 'true' &&
  359. isset($possible_tabs[$tab['subkey']]) &&
  360. api_get_plugin_setting(strtolower(str_replace('Tabs', '', $tab['subkeytext'])), 'public_main_menu_tab') == 'true'
  361. ) {
  362. $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH).$possible_tabs[$tab['subkey']]['url'];
  363. $navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
  364. } else {
  365. if (isset($possible_tabs[$tab['subkey']])) {
  366. $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH).$possible_tabs[$tab['subkey']]['url'];
  367. $menu_navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
  368. }
  369. }
  370. }
  371. }
  372. }
  373. return array(
  374. 'menu_navigation' => $menu_navigation,
  375. 'navigation' => $navigation,
  376. 'possible_tabs' => $possible_tabs,
  377. );
  378. }
  379. function return_menu()
  380. {
  381. $navigation = return_navigation_array();
  382. $navigation = $navigation['navigation'];
  383. // Displaying the tabs
  384. $lang = api_get_setting('platformLanguage');
  385. if (!empty($_SESSION['user_language_choice'])) {
  386. $lang = $_SESSION['user_language_choice'];
  387. } elseif (!empty($_SESSION['_user']['language'])) {
  388. $lang = $_SESSION['_user']['language'];
  389. }
  390. // Preparing home folder for multiple urls
  391. if (api_get_multiple_access_url()) {
  392. $access_url_id = api_get_current_access_url_id();
  393. if ($access_url_id != -1) {
  394. $url_info = api_get_access_url($access_url_id);
  395. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  396. $clean_url = api_replace_dangerous_char($url);
  397. $clean_url = str_replace('/', '-', $clean_url);
  398. $clean_url .= '/';
  399. $homep = api_get_path(SYS_APP_PATH).'home/'.$clean_url; //homep for Home Path
  400. //we create the new dir for the new sites
  401. if (!is_dir($homep)) {
  402. mkdir($homep, api_get_permissions_for_new_directories());
  403. }
  404. }
  405. } else {
  406. $homep = api_get_path(SYS_APP_PATH).'home/';
  407. }
  408. $ext = '.html';
  409. $menutabs = 'home_tabs';
  410. $mtloggedin = 'home_tabs_logged_in';
  411. $home_top = '';
  412. if (is_file($homep.$menutabs.'_'.$lang.$ext) && is_readable($homep.$menutabs.'_'.$lang.$ext)) {
  413. $home_top = @(string)file_get_contents($homep.$menutabs.'_'.$lang.$ext);
  414. } elseif (is_file($homep.$menutabs.$lang.$ext) && is_readable($homep.$menutabs.$lang.$ext)) {
  415. $home_top = @(string)file_get_contents($homep.$menutabs.$lang.$ext);
  416. } else {
  417. //$errorMsg = get_lang('HomePageFilesNotReadable');
  418. }
  419. $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
  420. $open = str_replace('{rel_path}',api_get_path(REL_PATH), $home_top);
  421. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  422. $open_mtloggedin = '';
  423. if (api_get_user_id() && !api_is_anonymous()) {
  424. if (is_file($homep.$mtloggedin.'_'.$lang.$ext) && is_readable($homep.$mtloggedin.'_'.$lang.$ext)) {
  425. $home_top = @(string)file_get_contents($homep.$mtloggedin.'_'.$lang.$ext);
  426. $home_top = str_replace('::private', '', $home_top);
  427. } elseif (is_file($homep.$mtloggedin.$lang.$ext) && is_readable($homep.$mtloggedin.$lang.$ext)) {
  428. $home_top = @(string)file_get_contents($homep.$mtloggedin.$lang.$ext);
  429. $home_top = str_replace('::private', '', $home_top);
  430. } else {
  431. //$errorMsg = get_lang('HomePageFilesNotReadable');
  432. }
  433. $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
  434. $open_mtloggedin = str_replace('{rel_path}',api_get_path(REL_PATH), $home_top);
  435. $open_mtloggedin = api_to_system_encoding($open_mtloggedin, api_detect_encoding(strip_tags($open_mtloggedin)));
  436. }
  437. $lis = '';
  438. if (!empty($open) OR !empty($open_mtloggedin)) {
  439. if (strpos($open.$open_mtloggedin, 'show_menu') === false) {
  440. if (api_is_anonymous()) {
  441. $navigation[SECTION_CAMPUS] = null;
  442. }
  443. } else {
  444. if (api_get_user_id() && !api_is_anonymous()) {
  445. $lis .= $open_mtloggedin;
  446. } else {
  447. $lis .= $open;
  448. }
  449. }
  450. }
  451. if (count($navigation) > 0 || !empty($lis)) {
  452. $pre_lis = '';
  453. foreach ($navigation as $section => $navigation_info) {
  454. $key = (!empty($navigation_info['key'])?'tab-'.$navigation_info['key']:'');
  455. if (isset($GLOBALS['this_section'])) {
  456. $current = $section == $GLOBALS['this_section'] ? ' id="current" class="active '.$key.'" ' : ' class="'.$key.'"';
  457. } else {
  458. $current = '';
  459. }
  460. if (!empty($navigation_info['title'])) {
  461. $pre_lis .= '<li'.$current.'><a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a></li>';
  462. }
  463. }
  464. $lis = $pre_lis.$lis;
  465. }
  466. $menu = null;
  467. if (!empty($lis)) {
  468. $menu .= $lis;
  469. }
  470. return $menu;
  471. }
  472. /**
  473. * @param string $nameTools
  474. */
  475. function return_breadcrumb($interbreadcrumb, $language_file, $nameTools)
  476. {
  477. $session_id = api_get_session_id();
  478. $session_name = api_get_session_name($session_id);
  479. $_course = api_get_course_info();
  480. $user_id = api_get_user_id();
  481. $course_id = 0;
  482. if (!empty($_course)) {
  483. $course_id = $_course['real_id'];
  484. }
  485. /* Plugins for banner section */
  486. $web_course_path = api_get_path(WEB_COURSE_PATH);
  487. /* If the user is a coach he can see the users who are logged in its session */
  488. $navigation = array();
  489. // part 1: Course Homepage. If we are in a course then the first breadcrumb is a link to the course homepage
  490. // hide_course_breadcrumb the parameter has been added to hide the name of the course, that appeared in the default $interbreadcrumb
  491. $session_name = cut($session_name, MAX_LENGTH_BREADCRUMB);
  492. $my_session_name = is_null($session_name) ? '' : '&nbsp;('.$session_name.')';
  493. if (!empty($_course) && !isset($_GET['hide_course_breadcrumb'])) {
  494. $navigation_item['url'] = $web_course_path . $_course['path'].'/index.php'.(!empty($session_id) ? '?id_session='.$session_id : '');
  495. $_course['name'] = api_htmlentities($_course['name']);
  496. $course_title = cut($_course['name'], MAX_LENGTH_BREADCRUMB);
  497. switch (api_get_setting('breadcrumbs_course_homepage')) {
  498. case 'get_lang':
  499. $navigation_item['title'] = Display::img(api_get_path(WEB_IMG_PATH).'home.png', get_lang('CourseHomepageLink')).' '.get_lang('CourseHomepageLink');
  500. break;
  501. case 'course_code':
  502. $navigation_item['title'] = Display::img(api_get_path(WEB_IMG_PATH).'home.png', $_course['official_code']).' '.$_course['official_code'];
  503. break;
  504. case 'session_name_and_course_title':
  505. $navigation_item['title'] = Display::img(api_get_path(WEB_IMG_PATH).'home.png', $_course['name'].$my_session_name).' '.$course_title.$my_session_name;
  506. break;
  507. default:
  508. if (api_get_session_id() != -1 ) {
  509. $navigation_item['title'] = Display::img(api_get_path(WEB_IMG_PATH).'home.png', $_course['name'].$my_session_name).' '.$course_title.$my_session_name;
  510. } else {
  511. $navigation_item['title'] = Display::img(api_get_path(WEB_IMG_PATH).'home.png', $_course['name']).' '.$course_title;
  512. }
  513. break;
  514. }
  515. /**
  516. * @todo could be useful adding the My courses in the breadcrumb
  517. $navigation_item_my_courses['title'] = get_lang('MyCourses');
  518. $navigation_item_my_courses['url'] = api_get_path(WEB_PATH).'user_portal.php';
  519. $navigation[] = $navigation_item_my_courses;
  520. */
  521. $navigation[] = $navigation_item;
  522. }
  523. /* part 2: Interbreadcrumbs. If there is an array $interbreadcrumb
  524. defined then these have to appear before the last breadcrumb
  525. (which is the tool itself)*/
  526. if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
  527. foreach ($interbreadcrumb as $breadcrumb_step) {
  528. if (isset($breadcrumb_step['type']) && $breadcrumb_step['type'] == 'right') {
  529. continue;
  530. }
  531. if ($breadcrumb_step['url'] != '#') {
  532. $sep = (strrchr($breadcrumb_step['url'], '?') ? '&amp;' : '?');
  533. $navigation_item['url'] = $breadcrumb_step['url'].$sep.api_get_cidreq();
  534. } else {
  535. $navigation_item['url'] = '#';
  536. }
  537. $navigation_item['title'] = $breadcrumb_step['name'];
  538. // titles for shared folders
  539. if ($breadcrumb_step['name'] == 'shared_folder') {
  540. $navigation_item['title'] = get_lang('UserFolders');
  541. } elseif(strstr($breadcrumb_step['name'], 'shared_folder_session_')) {
  542. $navigation_item['title'] = get_lang('UserFolders');
  543. } elseif(strstr($breadcrumb_step['name'], 'sf_user_')) {
  544. $userinfo = api_get_user_info(substr($breadcrumb_step['name'], 8));
  545. $navigation_item['title'] = $userinfo['complete_name'];
  546. } elseif($breadcrumb_step['name'] == 'chat_files') {
  547. $navigation_item['title'] = get_lang('ChatFiles');
  548. } elseif($breadcrumb_step['name'] == 'images') {
  549. $navigation_item['title'] = get_lang('Images');
  550. } elseif($breadcrumb_step['name'] == 'video') {
  551. $navigation_item['title'] = get_lang('Video');
  552. } elseif($breadcrumb_step['name'] == 'audio') {
  553. $navigation_item['title'] = get_lang('Audio');
  554. } elseif($breadcrumb_step['name'] == 'flash') {
  555. $navigation_item['title'] = get_lang('Flash');
  556. } elseif($breadcrumb_step['name'] == 'gallery') {
  557. $navigation_item['title'] = get_lang('Gallery');
  558. }
  559. // Fixes breadcrumb title now we applied the Security::remove_XSS and
  560. // we cut the string depending of the MAX_LENGTH_BREADCRUMB value
  561. $navigation_item['title'] = cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
  562. $navigation_item['title'] = Security::remove_XSS($navigation_item['title']);
  563. $navigation[] = $navigation_item;
  564. }
  565. }
  566. $navigation_right = array();
  567. if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
  568. foreach ($interbreadcrumb as $breadcrumb_step) {
  569. if (isset($breadcrumb_step['type']) && $breadcrumb_step['type'] == 'right') {
  570. if ($breadcrumb_step['url'] != '#') {
  571. $sep = (strrchr($breadcrumb_step['url'], '?') ? '&amp;' : '?');
  572. $navigation_item['url'] = $breadcrumb_step['url'].$sep.api_get_cidreq();
  573. } else {
  574. $navigation_item['url'] = '#';
  575. }
  576. $breadcrumb_step['title'] = cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
  577. $breadcrumb_step['title'] = Security::remove_XSS($navigation_item['title']);
  578. $navigation_right[] = $breadcrumb_step;
  579. }
  580. }
  581. }
  582. // part 3: The tool itself. If we are on the course homepage we do not want
  583. // to display the title of the course because this
  584. // is the same as the first part of the breadcrumbs (see part 1)
  585. if (isset($nameTools)) {
  586. $navigation_item['url'] = '#';
  587. $navigation_item['title'] = $nameTools;
  588. $navigation[] = $navigation_item;
  589. }
  590. $final_navigation = array();
  591. $counter = 0;
  592. foreach ($navigation as $index => $navigation_info) {
  593. if (!empty($navigation_info['title'])) {
  594. if ($navigation_info['url'] == '#') {
  595. $final_navigation[$index] = $navigation_info['title'];
  596. } else {
  597. $final_navigation[$index] = '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  598. }
  599. $counter++;
  600. }
  601. }
  602. $html = '';
  603. /* Part 4 . Show the teacher view/student view button at the right of the breadcrumb */
  604. $view_as_student_link = null;
  605. if ($user_id && isset($course_id)) {
  606. if ((api_is_course_admin() || api_is_platform_admin() || api_is_coach(null, null, false)) && api_get_setting('student_view_enabled') == 'true') {
  607. $view_as_student_link = api_display_tool_view_option();
  608. }
  609. }
  610. if (!empty($final_navigation)) {
  611. $lis = '';
  612. $i = 0;
  613. $final_navigation_count = count($final_navigation);
  614. if (!empty($final_navigation)) {
  615. // $home_link.= '<span class="divider">/</span>';
  616. if (!empty($home_link)) {
  617. $lis.= Display::tag('li', $home_link);
  618. }
  619. foreach ($final_navigation as $bread) {
  620. $bread_check = trim(strip_tags($bread));
  621. if (!empty($bread_check)) {
  622. if ($final_navigation_count-1 > $i) {
  623. $bread .= '';
  624. }
  625. $lis.= Display::tag('li', $bread,array('class'=>'active'));
  626. $i++;
  627. }
  628. }
  629. } else {
  630. if (!empty($home_link)) {
  631. $lis.= Display::tag('li', $home_link);
  632. }
  633. }
  634. // View as student/teacher link
  635. $view = null;
  636. if (!empty($view_as_student_link)) {
  637. $view .= Display::tag('div', $view_as_student_link, array('id' => 'view_as_link','class' => 'pull-right'));
  638. }
  639. if (!empty($navigation_right)) {
  640. foreach($navigation_right as $item){
  641. $extra_class = isset($item['class']) ? $item['class'] : null;
  642. $lis.= Display::tag('li', $item['title'], array('class' => $extra_class.' pull-right'));
  643. }
  644. }
  645. if (!empty($lis)) {
  646. $html .= $view;
  647. $html .= Display::tag('ul', $lis, array('class'=>'breadcrumb'));
  648. }
  649. }
  650. return $html;
  651. }