banner.lib.php 33 KB

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