banner.lib.php 36 KB

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