banner.lib.php 37 KB

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