banner.lib.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  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. if ($access === true) {
  203. $profileList = api_get_configuration_value('allow_online_users_by_status');
  204. if (!empty($profileList) && isset($profileList['status'])) {
  205. $userInfo = api_get_user_info();
  206. if ($userInfo['is_admin']) {
  207. $userInfo['status'] = PLATFORM_ADMIN;
  208. }
  209. $profileList = $profileList['status'];
  210. $access = false;
  211. if (in_array($userInfo['status'], $profileList)) {
  212. $access = true;
  213. }
  214. }
  215. }
  216. return $access;
  217. }
  218. /**
  219. * Return HTML string of a list as <li> items.
  220. *
  221. * @return string
  222. */
  223. function returnNotificationMenu()
  224. {
  225. $courseInfo = api_get_course_info();
  226. $user_id = api_get_user_id();
  227. $sessionId = api_get_session_id();
  228. $html = '';
  229. if (accessToWhoIsOnline()) {
  230. $number = getOnlineUsersCount();
  231. $number_online_in_course = getOnlineUsersInCourseCount($user_id, $courseInfo);
  232. // Display the who's online of the platform
  233. if ($number &&
  234. (api_get_setting('showonline', 'world') == 'true' && !$user_id) ||
  235. (api_get_setting('showonline', 'users') == 'true' && $user_id)
  236. ) {
  237. $html .= '<li class="user-online"><a href="'.api_get_path(WEB_PATH).'whoisonline.php" target="_self" title="'
  238. .get_lang('UsersOnline').'" >'
  239. .Display::return_icon('user.png', get_lang('UsersOnline'), [], ICON_SIZE_TINY)
  240. .' '.$number.'</a></li>';
  241. }
  242. // Display the who's online for the course
  243. if ($number_online_in_course &&
  244. (
  245. is_array($courseInfo) &&
  246. api_get_setting('showonline', 'course') == 'true' && isset($courseInfo['sysCode'])
  247. )
  248. ) {
  249. $html .= '<li class="user-online-course"><a href="'.api_get_path(WEB_PATH).'whoisonline.php?cidReq='.$courseInfo['sysCode']
  250. .'" target="_self">'
  251. .Display::return_icon('course.png', get_lang('UsersOnline').' '.get_lang('InThisCourse'), [], ICON_SIZE_TINY)
  252. .' '.$number_online_in_course.' </a></li>';
  253. }
  254. if (!empty($sessionId)) {
  255. $allow = api_is_platform_admin(true) ||
  256. api_is_coach($sessionId, null, false) ||
  257. SessionManager::isUserSubscribedAsStudent($sessionId, api_get_user_id());
  258. if ($allow) {
  259. $numberOnlineInSession = getOnlineUsersInSessionCount($sessionId);
  260. $html .= '<li class="user-online-session">
  261. <a href="'.api_get_path(WEB_PATH).'whoisonlinesession.php" target="_self">'
  262. .Display::return_icon('session.png', get_lang('UsersConnectedToMySessions'), [], ICON_SIZE_TINY)
  263. .' '.$numberOnlineInSession.'</a></li>';
  264. }
  265. }
  266. }
  267. return $html;
  268. }
  269. /**
  270. * Return an array with different navigation mennu elements.
  271. *
  272. * @return array [menu_navigation[], navigation[], possible_tabs[]]
  273. */
  274. function return_navigation_array()
  275. {
  276. $navigation = [];
  277. $menu_navigation = [];
  278. $possible_tabs = get_tabs();
  279. // Campus Homepage
  280. if (api_get_setting('show_tabs', 'campus_homepage') == 'true') {
  281. $navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
  282. } else {
  283. $menu_navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
  284. }
  285. if (api_get_setting('course_catalog_published') == 'true' && api_is_anonymous()) {
  286. $navigation[SECTION_CATALOG] = $possible_tabs[SECTION_CATALOG];
  287. }
  288. if (api_get_user_id() && !api_is_anonymous()) {
  289. // My Courses
  290. if (api_get_setting('show_tabs', 'my_courses') == 'true') {
  291. $navigation['mycourses'] = $possible_tabs['mycourses'];
  292. } else {
  293. $menu_navigation['mycourses'] = $possible_tabs['mycourses'];
  294. }
  295. // My Profile
  296. if (api_get_setting('show_tabs', 'my_profile') == 'true' &&
  297. api_get_setting('allow_social_tool') != 'true'
  298. ) {
  299. $navigation['myprofile'] = $possible_tabs['myprofile'];
  300. } else {
  301. $menu_navigation['myprofile'] = $possible_tabs['myprofile'];
  302. }
  303. // My Agenda
  304. if (api_get_setting('show_tabs', 'my_agenda') == 'true') {
  305. $navigation['myagenda'] = $possible_tabs['myagenda'];
  306. } else {
  307. $menu_navigation['myagenda'] = $possible_tabs['myagenda'];
  308. }
  309. // Gradebook
  310. if (api_get_setting('gradebook_enable') == 'true') {
  311. if (api_get_setting('show_tabs', 'my_gradebook') == 'true') {
  312. $navigation['mygradebook'] = $possible_tabs['mygradebook'];
  313. } else {
  314. $menu_navigation['mygradebook'] = $possible_tabs['mygradebook'];
  315. }
  316. }
  317. // Reporting
  318. if (api_get_setting('show_tabs', 'reporting') == 'true') {
  319. if (api_is_teacher() || api_is_drh() || api_is_session_admin() || api_is_student_boss()) {
  320. $navigation['session_my_space'] = $possible_tabs['session_my_space'];
  321. } else {
  322. $navigation['session_my_space'] = $possible_tabs['session_my_progress'];
  323. }
  324. } else {
  325. if (api_is_teacher() || api_is_drh() || api_is_session_admin() || api_is_student_boss()) {
  326. $menu_navigation['session_my_space'] = $possible_tabs['session_my_space'];
  327. } else {
  328. $menu_navigation['session_my_space'] = $possible_tabs['session_my_progress'];
  329. }
  330. }
  331. // Social Networking
  332. if (api_get_setting('show_tabs', 'social') == 'true') {
  333. if (api_get_setting('allow_social_tool') == 'true') {
  334. $navigation['social'] = isset($possible_tabs['social']) ? $possible_tabs['social'] : null;
  335. }
  336. } else {
  337. $menu_navigation['social'] = isset($possible_tabs['social']) ? $possible_tabs['social'] : null;
  338. }
  339. // Dashboard
  340. if (api_get_setting('show_tabs', 'dashboard') == 'true') {
  341. if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
  342. $navigation['dashboard'] = isset($possible_tabs['dashboard']) ? $possible_tabs['dashboard'] : null;
  343. }
  344. } else {
  345. $menu_navigation['dashboard'] = isset($possible_tabs['dashboard']) ? $possible_tabs['dashboard'] : null;
  346. }
  347. ///if (api_is_student()) {
  348. if (true) {
  349. $params = ['variable = ? AND subkey = ?' => ['status', 'studentfollowup']];
  350. $result = api_get_settings_params_simple($params);
  351. $plugin = StudentFollowUpPlugin::create();
  352. if (!empty($result) && $result['selected_value'] === 'installed') {
  353. // Students
  354. $url = api_get_path(WEB_PLUGIN_PATH).'studentfollowup/posts.php';
  355. if (api_is_platform_admin() || api_is_drh() || api_is_teacher()) {
  356. $url = api_get_path(WEB_PLUGIN_PATH).'studentfollowup/my_students.php';
  357. }
  358. $navigation['follow_up']['url'] = $url;
  359. $navigation['follow_up']['title'] = $plugin->get_lang('CareDetailView');
  360. $navigation['follow_up']['key'] = 'homepage';
  361. $navigation['follow_up']['icon'] = 'homepage.png';
  362. }
  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. // $home_link.= '<span class="divider">/</span>';
  741. if (!empty($home_link)) {
  742. $lis .= Display::tag('li', $home_link);
  743. }
  744. foreach ($final_navigation as $bread) {
  745. $bread_check = trim(strip_tags($bread));
  746. if (!empty($bread_check)) {
  747. if ($final_navigation_count - 1 > $i) {
  748. $bread .= '';
  749. }
  750. $lis .= Display::tag('li', $bread, ['class' => 'active']);
  751. $i++;
  752. }
  753. }
  754. } else {
  755. if (!empty($home_link)) {
  756. $lis .= Display::tag('li', $home_link);
  757. }
  758. }
  759. // View as student/teacher link
  760. if (!empty($view_as_student_link)) {
  761. $html .= Display::tag('div', $view_as_student_link, ['id' => 'view_as_link', 'class' => 'pull-right']);
  762. }
  763. if (!empty($navigation_right)) {
  764. foreach ($navigation_right as $item) {
  765. $extra_class = isset($item['class']) ? $item['class'] : null;
  766. $lis .= Display::tag(
  767. 'li',
  768. $item['title'],
  769. ['class' => $extra_class.' pull-right']
  770. );
  771. }
  772. }
  773. if (!empty($lis)) {
  774. $html .= Display::tag('ul', $lis, ['class' => 'breadcrumb']);
  775. }
  776. }
  777. return $html.$additionalBlocks;
  778. }
  779. /**
  780. * Helper function to get the number of users online, using cache if available.
  781. *
  782. * @return int The number of users currently online
  783. */
  784. function getOnlineUsersCount()
  785. {
  786. $number = 0;
  787. $cacheAvailable = api_get_configuration_value('apc');
  788. if ($cacheAvailable === true) {
  789. $apcVar = api_get_configuration_value('apc_prefix').'my_campus_whoisonline_count_simple';
  790. if (apcu_exists($apcVar)) {
  791. $number = apcu_fetch($apcVar);
  792. } else {
  793. $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
  794. apcu_store($apcVar, $number, 15);
  795. }
  796. } else {
  797. $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
  798. }
  799. return $number;
  800. }
  801. /**
  802. * Helper function to get the number of users online in a course, using cache if available.
  803. *
  804. * @param int $userId The user ID
  805. * @param array $courseInfo The course details
  806. *
  807. * @return int The number of users currently online
  808. */
  809. function getOnlineUsersInCourseCount($userId, $courseInfo)
  810. {
  811. $cacheAvailable = api_get_configuration_value('apc');
  812. $numberOnlineInCourse = 0;
  813. if (!empty($courseInfo['id'])) {
  814. if ($cacheAvailable === true) {
  815. $apcVar = api_get_configuration_value('apc_prefix').'my_campus_whoisonline_count_simple_'.$courseInfo['id'];
  816. if (apcu_exists($apcVar)) {
  817. $numberOnlineInCourse = apcu_fetch($apcVar);
  818. } else {
  819. $numberOnlineInCourse = who_is_online_in_this_course_count(
  820. $userId,
  821. api_get_setting('time_limit_whosonline'),
  822. $courseInfo['id']
  823. );
  824. apcu_store(
  825. $apcVar,
  826. $numberOnlineInCourse,
  827. 15
  828. );
  829. }
  830. } else {
  831. $numberOnlineInCourse = who_is_online_in_this_course_count(
  832. $userId,
  833. api_get_setting('time_limit_whosonline'),
  834. $courseInfo['id']
  835. );
  836. }
  837. }
  838. return $numberOnlineInCourse;
  839. }
  840. /**
  841. * Helper function to get the number of users online in a session, using cache if available.
  842. *
  843. * @param int $sessionId The session ID
  844. *
  845. * @return int The number of users currently online
  846. */
  847. function getOnlineUsersInSessionCount($sessionId)
  848. {
  849. $cacheAvailable = api_get_configuration_value('apc');
  850. if (!$sessionId) {
  851. return 0;
  852. }
  853. if ($cacheAvailable === true) {
  854. $apcVar = api_get_configuration_value('apc_prefix').'my_campus_whoisonline_session_count_simple_'.$sessionId;
  855. if (apcu_exists($apcVar)) {
  856. return apcu_fetch($apcVar);
  857. }
  858. $numberOnlineInCourse = whoIsOnlineInThisSessionCount(
  859. api_get_setting('time_limit_whosonline'),
  860. $sessionId
  861. );
  862. apcu_store($apcVar, $numberOnlineInCourse, 15);
  863. return $numberOnlineInCourse;
  864. }
  865. return whoIsOnlineInThisSessionCount(
  866. api_get_setting('time_limit_whosonline'),
  867. $sessionId
  868. );
  869. }