banner.lib.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  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. ///if (api_is_student()) {
  303. if (true) {
  304. $params = array('variable = ? AND subkey = ?' => ['status', 'studentfollowup']);
  305. $result = api_get_settings_params_simple($params);
  306. if (!empty($result) && $result['selected_value'] === 'installed') {
  307. $navigation['follow_up']['url'] = api_get_path(WEB_PLUGIN_PATH).'studentfollowup/posts.php';
  308. $navigation['follow_up']['title'] = get_lang('MyDossier');
  309. $navigation['follow_up']['key'] = 'homepage';
  310. $navigation['follow_up']['icon'] = 'homepage.png';
  311. }
  312. }
  313. // Administration
  314. if (api_is_platform_admin(true)) {
  315. if (api_get_setting('show_tabs', 'platform_administration') == 'true') {
  316. $navigation['platform_admin'] = $possible_tabs['platform_admin'];
  317. } else {
  318. $menu_navigation['platform_admin'] = $possible_tabs['platform_admin'];
  319. }
  320. }
  321. // Reports
  322. if (!empty($possible_tabs['reports'])) {
  323. if (api_get_setting('show_tabs', 'reports') == 'true') {
  324. if (
  325. (api_is_platform_admin() || api_is_drh() || api_is_session_admin())
  326. && Rights::hasRight('show_tabs:reports')
  327. ) {
  328. $navigation['reports'] = $possible_tabs['reports'];
  329. }
  330. } else {
  331. $menu_navigation['reports'] = $possible_tabs['reports'];
  332. }
  333. }
  334. // Custom tabs
  335. $customTabs = getCustomTabs();
  336. if (!empty($customTabs)) {
  337. foreach ($customTabs as $tab) {
  338. if (api_get_setting($tab['variable'], $tab['subkey']) == 'true' &&
  339. isset($possible_tabs[$tab['subkey']])
  340. ) {
  341. $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH)
  342. .$possible_tabs[$tab['subkey']]['url'];
  343. $navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
  344. } else {
  345. if (isset($possible_tabs[$tab['subkey']])) {
  346. $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH)
  347. .$possible_tabs[$tab['subkey']]['url'];
  348. $menu_navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
  349. }
  350. }
  351. }
  352. }
  353. } else {
  354. // Show custom tabs that are specifically marked as 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. /**
  380. * Return the navigation menu elements as a flat array
  381. * @return array
  382. */
  383. function menuArray()
  384. {
  385. $mainNavigation = return_navigation_array();
  386. unset($mainNavigation['possible_tabs']);
  387. unset($mainNavigation['menu_navigation']);
  388. //$navigation = $navigation['navigation'];
  389. // Get active language
  390. $lang = api_get_setting('platformLanguage');
  391. if (!empty($_SESSION['user_language_choice'])) {
  392. $lang = $_SESSION['user_language_choice'];
  393. } elseif (!empty($_SESSION['_user']['language'])) {
  394. $lang = $_SESSION['_user']['language'];
  395. }
  396. // Preparing home folder for multiple urls
  397. if (api_get_multiple_access_url()) {
  398. $access_url_id = api_get_current_access_url_id();
  399. if ($access_url_id != -1) {
  400. // If not a dead URL
  401. $urlInfo = api_get_access_url($access_url_id);
  402. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $urlInfo['url']));
  403. $cleanUrl = api_replace_dangerous_char($url);
  404. $cleanUrl = str_replace('/', '-', $cleanUrl);
  405. $cleanUrl .= '/';
  406. $homepath = api_get_path(SYS_HOME_PATH).$cleanUrl; //homep for Home Path
  407. //we create the new dir for the new sites
  408. if (!is_dir($homepath)) {
  409. mkdir($homepath, api_get_permissions_for_new_directories());
  410. }
  411. }
  412. } else {
  413. $homepath = api_get_path(SYS_HOME_PATH);
  414. }
  415. $ext = '.html';
  416. $menuTabs = 'home_tabs';
  417. $menuTabsLoggedIn = 'home_tabs_logged_in';
  418. $pageContent = '';
  419. // Get the extra page content, containing the links to add to the tabs
  420. if (is_file($homepath.$menuTabs.'_'.$lang.$ext) && is_readable($homepath.$menuTabs.'_'.$lang.$ext)) {
  421. $pageContent = @(string) file_get_contents($homepath.$menuTabs.'_'.$lang.$ext);
  422. } elseif (is_file($homepath.$menuTabs.$lang.$ext) && is_readable($homepath.$menuTabs.$lang.$ext)) {
  423. $pageContent = @(string) file_get_contents($homepath.$menuTabs.$lang.$ext);
  424. }
  425. // Sanitize page content
  426. $pageContent = api_to_system_encoding($pageContent, api_detect_encoding(strip_tags($pageContent)));
  427. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $pageContent);
  428. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  429. // Get the extra page content, containing the links to add to the tabs
  430. // that are only for users already logged in
  431. $openMenuTabsLoggedIn = '';
  432. if (api_get_user_id() && !api_is_anonymous()) {
  433. if (is_file($homepath.$menuTabsLoggedIn.'_'.$lang.$ext) && is_readable(
  434. $homepath.$menuTabsLoggedIn.'_'.$lang.$ext
  435. )
  436. ) {
  437. $pageContent = @(string) file_get_contents($homepath.$menuTabsLoggedIn.'_'.$lang.$ext);
  438. $pageContent = str_replace('::private', '', $pageContent);
  439. } elseif (is_file($homepath.$menuTabsLoggedIn.$lang.$ext) && is_readable(
  440. $homepath.$menuTabsLoggedIn.$lang.$ext
  441. )
  442. ) {
  443. $pageContent = @(string) file_get_contents($homepath.$menuTabsLoggedIn.$lang.$ext);
  444. $pageContent = str_replace('::private', '', $pageContent);
  445. }
  446. $pageContent = api_to_system_encoding($pageContent, api_detect_encoding(strip_tags($pageContent)));
  447. $openMenuTabsLoggedIn = str_replace('{rel_path}', api_get_path(REL_PATH), $pageContent);
  448. $openMenuTabsLoggedIn = api_to_system_encoding(
  449. $openMenuTabsLoggedIn,
  450. api_detect_encoding(strip_tags($openMenuTabsLoggedIn))
  451. );
  452. }
  453. if (!empty($open) || !empty($openMenuTabsLoggedIn)) {
  454. if (strpos($open.$openMenuTabsLoggedIn, 'show_menu') === false) {
  455. if (api_is_anonymous()) {
  456. $mainNavigation['navigation'][SECTION_CAMPUS] = null;
  457. }
  458. } else {
  459. $list = explode("\n", api_get_user_id() && !api_is_anonymous() ? $openMenuTabsLoggedIn : $open);
  460. foreach ($list as $link) {
  461. if (strpos($link, 'class="hide_menu"') !== false) {
  462. continue;
  463. }
  464. $matches = array();
  465. $match = preg_match('$href="([^"]*)" target="([^"]*)">([^<]*)</a>$', $link, $matches);
  466. if (!$match) {
  467. continue;
  468. }
  469. $mainNavigation['navigation'][$matches[3]] = array(
  470. 'url' => $matches[1],
  471. 'target' => $matches[2],
  472. 'title' => $matches[3],
  473. 'key' => 'page-'.str_replace(' ', '-', strtolower($matches[3])),
  474. );
  475. }
  476. }
  477. }
  478. if (count($mainNavigation['navigation']) > 0) {
  479. //$pre_lis = '';
  480. $activeSection = '';
  481. foreach ($mainNavigation['navigation'] as $section => $navigation_info) {
  482. $key = (!empty($navigation_info['key']) ? 'tab-'.$navigation_info['key'] : '');
  483. if (isset($GLOBALS['this_section'])) {
  484. $tempSection = $section;
  485. if ($section == 'social') {
  486. $tempSection = 'social-network';
  487. }
  488. if ($tempSection == $GLOBALS['this_section']) {
  489. $activeSection = $section;
  490. }
  491. // If we're on the index page and a specific extra link has been
  492. // loaded
  493. if ($GLOBALS['this_section'] == SECTION_CAMPUS) {
  494. if (!empty($_GET['include'])) {
  495. $name = str_replace(' ', '-', strtolower($navigation_info['title'])).'_'.$lang.$ext;
  496. if (strtolower($_GET['include']) == $name) {
  497. $activeSection = $section;
  498. }
  499. }
  500. }
  501. } else {
  502. $current = '';
  503. }
  504. $mainNavigation['navigation'][$section]['current'] = '';
  505. }
  506. if (!empty($activeSection)) {
  507. $mainNavigation['navigation'][$activeSection]['current'] = 'active';
  508. }
  509. }
  510. unset($mainNavigation['navigation']['myprofile']);
  511. return $mainNavigation['navigation'];
  512. }
  513. /**
  514. * Return the breadcrumb menu elements as an array of <li> items
  515. * @param array $interbreadcrumb The elements to add to the breadcrumb
  516. * @param string $language_file Deprecated
  517. * @param string $nameTools The name of the current tool (not linked)
  518. * @return string HTML string of <li> items
  519. */
  520. function return_breadcrumb($interbreadcrumb, $language_file, $nameTools)
  521. {
  522. /** @var \Chamilo\CoreBundle\Entity\Session $session */
  523. $session = Database::getManager()
  524. ->find('ChamiloCoreBundle:Session', api_get_session_id());
  525. $_course = api_get_course_info();
  526. $user_id = api_get_user_id();
  527. $course_id = 0;
  528. if (!empty($_course)) {
  529. $course_id = $_course['real_id'];
  530. }
  531. $additonalBlocks = '';
  532. /* Plugins for banner section */
  533. $web_course_path = api_get_path(WEB_COURSE_PATH);
  534. /* If the user is a coach he can see the users who are logged in its session */
  535. $navigation = array();
  536. // part 1: Course Homepage. If we are in a course then the first breadcrumb is a link to the course homepage
  537. // hide_course_breadcrumb the parameter has been added to hide the name of the course, that appeared in the default $interbreadcrumb
  538. $my_session_name = $session ? ' ('.cut($session->getName(), MAX_LENGTH_BREADCRUMB).')' : null;
  539. if (!empty($_course) && !isset($_GET['hide_course_breadcrumb'])) {
  540. $_course['name'] = api_htmlentities($_course['name']);
  541. $course_title = cut($_course['name'], MAX_LENGTH_BREADCRUMB);
  542. switch (api_get_setting('breadcrumbs_course_homepage')) {
  543. case 'get_lang':
  544. $itemTitle = Display::return_icon('home.png', get_lang('CourseHomepageLink'), [], ICON_SIZE_TINY);
  545. break;
  546. case 'course_code':
  547. $itemTitle = Display::return_icon('home.png', $_course['official_code'], [], ICON_SIZE_TINY)
  548. .' '.$_course['official_code'];
  549. break;
  550. case 'session_name_and_course_title':
  551. //no break
  552. default:
  553. $itemTitle = Display::return_icon('home.png', $_course['name'].$my_session_name, [], ICON_SIZE_TINY)
  554. .' '.$course_title.$my_session_name;
  555. if (
  556. $session && ($session->getDuration() && !api_is_allowed_to_edit())
  557. ) {
  558. $daysLeft = SessionManager::getDayLeftInSession(
  559. ['id' => $session->getId(), 'duration' => $session->getDuration()],
  560. $user_id
  561. );
  562. $additonalBlocks .= Display::return_message(
  563. sprintf(get_lang('SessionDurationXDaysLeft'), $daysLeft),
  564. 'information'
  565. );
  566. }
  567. break;
  568. }
  569. /**
  570. * @todo could be useful adding the My courses in the breadcrumb
  571. * $navigation_item_my_courses['title'] = get_lang('MyCourses');
  572. * $navigation_item_my_courses['url'] = api_get_path(WEB_PATH).'user_portal.php';
  573. * $navigation[] = $navigation_item_my_courses;
  574. */
  575. $navigation[] = [
  576. 'url' => $web_course_path.$_course['path'].'/index.php'.($session ? '?id_session='.$session->getId() : ''),
  577. 'title' => $itemTitle
  578. ];
  579. }
  580. /* part 2: Interbreadcrumbs. If there is an array $interbreadcrumb
  581. defined then these have to appear before the last breadcrumb
  582. (which is the tool itself)*/
  583. if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
  584. foreach ($interbreadcrumb as $breadcrumb_step) {
  585. if (isset($breadcrumb_step['type']) && $breadcrumb_step['type'] == 'right') {
  586. continue;
  587. }
  588. if ($breadcrumb_step['url'] != '#') {
  589. $sep = strrchr($breadcrumb_step['url'], '?') ? '&' : '?';
  590. $courseParams = strpos($breadcrumb_step['url'], 'cidReq') === false ? api_get_cidreq() : '';
  591. $navigation_item['url'] = $breadcrumb_step['url'].$sep.$courseParams;
  592. } else {
  593. $navigation_item['url'] = '#';
  594. }
  595. $navigation_item['title'] = $breadcrumb_step['name'];
  596. // titles for shared folders
  597. if ($breadcrumb_step['name'] == 'shared_folder') {
  598. $navigation_item['title'] = get_lang('UserFolders');
  599. } elseif (strstr($breadcrumb_step['name'], 'shared_folder_session_')) {
  600. $navigation_item['title'] = get_lang('UserFolders');
  601. } elseif (strstr($breadcrumb_step['name'], 'sf_user_')) {
  602. $userinfo = api_get_user_info(substr($breadcrumb_step['name'], 8));
  603. $navigation_item['title'] = $userinfo['complete_name'];
  604. } elseif ($breadcrumb_step['name'] == 'chat_files') {
  605. $navigation_item['title'] = get_lang('ChatFiles');
  606. } elseif ($breadcrumb_step['name'] == 'images') {
  607. $navigation_item['title'] = get_lang('Images');
  608. } elseif ($breadcrumb_step['name'] == 'video') {
  609. $navigation_item['title'] = get_lang('Video');
  610. } elseif ($breadcrumb_step['name'] == 'audio') {
  611. $navigation_item['title'] = get_lang('Audio');
  612. } elseif ($breadcrumb_step['name'] == 'flash') {
  613. $navigation_item['title'] = get_lang('Flash');
  614. } elseif ($breadcrumb_step['name'] == 'gallery') {
  615. $navigation_item['title'] = get_lang('Gallery');
  616. }
  617. // Fixes breadcrumb title now we applied the Security::remove_XSS and
  618. // we cut the string depending of the MAX_LENGTH_BREADCRUMB value
  619. $navigation_item['title'] = cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
  620. $navigation_item['title'] = Security::remove_XSS($navigation_item['title']);
  621. $navigation[] = $navigation_item;
  622. }
  623. }
  624. $navigation_right = array();
  625. if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
  626. foreach ($interbreadcrumb as $breadcrumb_step) {
  627. if (isset($breadcrumb_step['type']) && $breadcrumb_step['type'] == 'right') {
  628. if ($breadcrumb_step['url'] != '#') {
  629. $sep = (strrchr($breadcrumb_step['url'], '?') ? '&amp;' : '?');
  630. $navigation_item['url'] = $breadcrumb_step['url'].$sep.api_get_cidreq();
  631. } else {
  632. $navigation_item['url'] = '#';
  633. }
  634. $breadcrumb_step['title'] = cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
  635. $breadcrumb_step['title'] = Security::remove_XSS($navigation_item['title']);
  636. $navigation_right[] = $breadcrumb_step;
  637. }
  638. }
  639. }
  640. // part 3: The tool itself. If we are on the course homepage we do not want
  641. // to display the title of the course because this
  642. // is the same as the first part of the breadcrumbs (see part 1)
  643. if (isset($nameTools)) {
  644. $navigation_item['url'] = '#';
  645. $navigation_item['title'] = $nameTools;
  646. $navigation[] = $navigation_item;
  647. }
  648. $final_navigation = array();
  649. $counter = 0;
  650. foreach ($navigation as $index => $navigation_info) {
  651. if (!empty($navigation_info['title'])) {
  652. if ($navigation_info['url'] == '#') {
  653. $final_navigation[$index] = $navigation_info['title'];
  654. } else {
  655. $final_navigation[$index] = '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  656. }
  657. $counter++;
  658. }
  659. }
  660. $html = '';
  661. /* Part 4 . Show the teacher view/student view button at the right of the breadcrumb */
  662. $view_as_student_link = null;
  663. if ($user_id && isset($course_id)) {
  664. if ((
  665. api_is_course_admin() ||
  666. api_is_platform_admin() ||
  667. api_is_coach(null, null, false)
  668. ) &&
  669. api_get_setting('student_view_enabled') === 'true' && api_get_course_info()
  670. ) {
  671. $view_as_student_link = api_display_tool_view_option();
  672. // Only show link if LP can be editable
  673. /** @var learnpath $learnPath */
  674. $learnPath = Session::read('oLP');
  675. if (!empty($learnPath) && !empty($view_as_student_link)) {
  676. if ((int) $learnPath->get_lp_session_id() != (int) api_get_session_id()) {
  677. $view_as_student_link = '';
  678. }
  679. }
  680. }
  681. }
  682. if (!empty($final_navigation)) {
  683. $lis = '';
  684. $i = 0;
  685. $final_navigation_count = count($final_navigation);
  686. if (!empty($final_navigation)) {
  687. // $home_link.= '<span class="divider">/</span>';
  688. if (!empty($home_link)) {
  689. $lis .= Display::tag('li', $home_link);
  690. }
  691. foreach ($final_navigation as $bread) {
  692. $bread_check = trim(strip_tags($bread));
  693. if (!empty($bread_check)) {
  694. if ($final_navigation_count - 1 > $i) {
  695. $bread .= '';
  696. }
  697. $lis .= Display::tag('li', $bread, array('class' => 'active'));
  698. $i++;
  699. }
  700. }
  701. } else {
  702. if (!empty($home_link)) {
  703. $lis .= Display::tag('li', $home_link);
  704. }
  705. }
  706. // View as student/teacher link
  707. if (!empty($view_as_student_link)) {
  708. $html .= Display::tag('div', $view_as_student_link, array('id' => 'view_as_link', 'class' => 'pull-right'));
  709. }
  710. if (!empty($navigation_right)) {
  711. foreach ($navigation_right as $item) {
  712. $extra_class = isset($item['class']) ? $item['class'] : null;
  713. $lis .= Display::tag('li', $item['title'], array('class' => $extra_class.' pull-right'));
  714. }
  715. }
  716. if (!empty($lis)) {
  717. $html .= Display::tag('ul', $lis, array('class' => 'breadcrumb'));
  718. }
  719. }
  720. return $html.$additonalBlocks;
  721. }
  722. /**
  723. * Helper function to get the number of users online, using cache if available
  724. * @return int The number of users currently online
  725. */
  726. function getOnlineUsersCount()
  727. {
  728. $number = 0;
  729. $cacheAvailable = api_get_configuration_value('apc');
  730. if ($cacheAvailable === true) {
  731. $apcVar = api_get_configuration_value('apc_prefix').'my_campus_whoisonline_count_simple';
  732. if (apcu_exists($apcVar)) {
  733. $number = apcu_fetch($apcVar);
  734. } else {
  735. $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
  736. apcu_store($apcVar, $number, 15);
  737. }
  738. } else {
  739. $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
  740. }
  741. return $number;
  742. }
  743. /**
  744. * Helper function to get the number of users online in a course, using cache if available
  745. * @param int $userId The user ID
  746. * @param array $_course The course details
  747. * @return int The number of users currently online
  748. */
  749. function getOnlineUsersInCourseCount($userId, $_course)
  750. {
  751. $cacheAvailable = api_get_configuration_value('apc');
  752. $numberOnlineInCourse = 0;
  753. if (!empty($_course['id'])) {
  754. if ($cacheAvailable === true) {
  755. $apcVar = api_get_configuration_value('apc_prefix').'my_campus_whoisonline_count_simple_'.$_course['id'];
  756. if (apcu_exists($apcVar)) {
  757. $numberOnlineInCourse = apcu_fetch($apcVar);
  758. } else {
  759. $numberOnlineInCourse = who_is_online_in_this_course_count(
  760. $userId,
  761. api_get_setting('time_limit_whosonline'),
  762. $_course['id']
  763. );
  764. apcu_store(
  765. $apcVar,
  766. $numberOnlineInCourse,
  767. 15
  768. );
  769. }
  770. } else {
  771. $numberOnlineInCourse = who_is_online_in_this_course_count(
  772. $userId,
  773. api_get_setting('time_limit_whosonline'),
  774. $_course['id']
  775. );
  776. }
  777. }
  778. return $numberOnlineInCourse;
  779. }