banner.lib.php 35 KB

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