banner.lib.php 34 KB

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