banner.lib.php 35 KB

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