banner.lib.php 37 KB

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