banner.lib.php 37 KB

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