template.lib.php 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Julio Montoya <gugli100@gmail.com>
  5. * @todo better organization of the class, methods and variables
  6. *
  7. * */
  8. use \ChamiloSession as Session;
  9. class Template
  10. {
  11. private $app;
  12. public $style = 'default'; //see the template folder
  13. public $preview_theme = null;
  14. public $theme; // the chamilo theme public_admin, chamilo, chamilo_red, etc
  15. public $title = null;
  16. public $show_header;
  17. public $show_footer;
  18. public $help;
  19. public $menu_navigation = array(); //Used in the userportal.lib.php function: return_navigation_course_links()
  20. public $show_learnpath = false; // This is a learnpath section or not?
  21. public $plugin = null;
  22. public $course_id = null;
  23. public $user_is_logged_in = false;
  24. public $twig = null;
  25. public $jquery_ui_theme;
  26. public $load_plugins = false; /* Loads chamilo plugins */
  27. public $force_plugin_load = true;
  28. public $navigation_array;
  29. /**
  30. * @param string $title
  31. * @param Application $app
  32. */
  33. public function __construct($title = null, $app = null)
  34. {
  35. if (empty($app)) {
  36. global $app;
  37. $this->app = &$app;
  38. } else {
  39. //ugly fix just for now
  40. $this->app = &$app;
  41. }
  42. $this->app['classic_layout'] = true;
  43. $this->navigation_array = $this->returnNavigationArray();
  44. $show_header = $app['template.show_header'];
  45. $show_footer = $app['template.show_footer'];
  46. $show_learnpath = $app['template.show_learnpath'];
  47. $load_plugins = $app['template.load_plugins'];
  48. //Page title
  49. $this->title = $title;
  50. $this->show_learnpath = $show_learnpath;
  51. $this->load_plugins = $load_plugins;
  52. // Current themes: cupertino, smoothness, ui-lightness. Find the themes folder in main/inc/lib/javascript/jquery-ui
  53. $this->jquery_ui_theme = 'smoothness';
  54. //Setting system variables
  55. $this->set_system_parameters();
  56. //Setting user variables
  57. $this->setUserParameters();
  58. //Setting course variables
  59. $this->setCourseParameters();
  60. //header and footer are showed by default
  61. $this->setFooter($show_footer);
  62. $this->setHeader($show_header);
  63. $this->setHeaderParameters();
  64. $this->setFooterParameters();
  65. $this->assign('style', $this->style);
  66. //Chamilo plugins
  67. if ($this->show_header) {
  68. if ($this->load_plugins) {
  69. $this->plugin = new AppPlugin();
  70. //1. Showing installed plugins in regions
  71. $plugin_regions = $this->plugin->get_plugin_regions();
  72. foreach ($plugin_regions as $region) {
  73. $this->set_plugin_region($region);
  74. }
  75. //2. Loading the course plugin info
  76. global $course_plugin;
  77. if (isset($course_plugin) && !empty($course_plugin) && !empty($this->course_id)) {
  78. //Load plugin get_langs
  79. $this->plugin->load_plugin_lang_variables($course_plugin);
  80. }
  81. }
  82. }
  83. }
  84. /**
  85. * Get icon path
  86. * @param string $image
  87. * @param int $size
  88. * @return string
  89. */
  90. public static function get_icon_path($image, $size = ICON_SIZE_SMALL)
  91. {
  92. return Display:: return_icon($image, '', array(), $size, false, true);
  93. }
  94. /**
  95. * Format date
  96. * @param string $timestamp
  97. * @param string $format
  98. * @return string
  99. */
  100. public static function format_date($timestamp, $format = null)
  101. {
  102. return api_format_date($timestamp, $format);
  103. }
  104. /**
  105. * @param string $help_input
  106. */
  107. public function set_help($help_input = null)
  108. {
  109. if (!empty($help_input)) {
  110. $help = $help_input;
  111. } else {
  112. $help = $this->help;
  113. }
  114. $this->assign('help_content', $help);
  115. }
  116. /**
  117. * Use template system to parse the actions menu
  118. * @todo finish it!
  119. * @param array $actions
  120. *
  121. **/
  122. public function setActions($actions)
  123. {
  124. $action_string = '';
  125. if (!empty($actions)) {
  126. foreach ($actions as $action) {
  127. $action_string .= $action;
  128. }
  129. }
  130. $this->assign('actions', $actions);
  131. }
  132. /**
  133. * Shortcut to display a 1 col layout (index.php)
  134. * */
  135. public function display_one_col_template()
  136. {
  137. $tpl = $this->get_template('layout/layout_1_col.tpl');
  138. $this->display($tpl);
  139. }
  140. /**
  141. * Shortcut to display a 2 col layout (userportal.php)
  142. * */
  143. public function display_two_col_template()
  144. {
  145. $tpl = $this->get_template('layout/layout_2_col.tpl');
  146. $this->display($tpl);
  147. }
  148. /**
  149. * Displays an empty template
  150. */
  151. public function display_blank_template()
  152. {
  153. $tpl = $this->get_template('layout/blank.tpl');
  154. $this->display($tpl);
  155. }
  156. /**
  157. * Displays an empty template
  158. */
  159. public function display_no_layout_template()
  160. {
  161. $tpl = $this->get_template('layout/no_layout.tpl');
  162. $this->display($tpl);
  163. }
  164. /**
  165. * Sets the footer visibility
  166. * @param bool true if we show the footer
  167. */
  168. public function setFooter($status)
  169. {
  170. $this->show_footer = $status;
  171. $this->assign('show_footer', $status);
  172. }
  173. /**
  174. * Sets the header visibility
  175. * @param bool true if we show the header
  176. */
  177. public function setHeader($status)
  178. {
  179. $this->show_header = $status;
  180. $this->assign('show_header', $status);
  181. //Toolbar
  182. $show_admin_toolbar = api_get_setting('show_admin_toolbar');
  183. $show_toolbar = 0;
  184. switch ($show_admin_toolbar) {
  185. case 'do_not_show':
  186. break;
  187. case 'show_to_admin':
  188. if (api_is_platform_admin()) {
  189. $show_toolbar = 1;
  190. }
  191. break;
  192. case 'show_to_admin_and_teachers':
  193. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  194. $show_toolbar = 1;
  195. }
  196. break;
  197. case 'show_to_all':
  198. $show_toolbar = 1;
  199. break;
  200. }
  201. $this->assign('show_toolbar', $show_toolbar);
  202. //Only if course is available
  203. $show_course_shortcut = null;
  204. $show_course_navigation_menu = null;
  205. if (!empty($this->course_id) && $this->user_is_logged_in) {
  206. if (api_get_setting('show_toolshortcuts') != 'false') {
  207. //Course toolbar
  208. $show_course_shortcut = CourseHome::show_navigation_tool_shortcuts();
  209. }
  210. if (api_get_setting('show_navigation_menu') != 'false') {
  211. //Course toolbar
  212. $show_course_navigation_menu = CourseHome::show_navigation_menu();
  213. }
  214. }
  215. $this->assign('show_course_shortcut', $show_course_shortcut);
  216. $this->assign('show_course_navigation_menu', $show_course_navigation_menu);
  217. }
  218. public function get_template($name)
  219. {
  220. return $this->app['template_style'].'/'.$name;
  221. }
  222. /** Set course parameters */
  223. private function setCourseParameters()
  224. {
  225. //Setting course id
  226. $this->course_id = api_get_course_int_id();
  227. }
  228. /** Set user parameters */
  229. private function setUserParameters()
  230. {
  231. $user_info = array();
  232. $user_info['logged'] = 0;
  233. $this->user_is_logged_in = false;
  234. if (api_user_is_login()) {
  235. $user_info = $this->app['current_user'];
  236. $user_info['logged'] = 1;
  237. $user_info['is_admin'] = 0;
  238. if (api_is_platform_admin()) {
  239. $user_info['is_admin'] = 1;
  240. }
  241. $new_messages = MessageManager::get_new_messages();
  242. $user_info['messages_count'] = $new_messages != 0 ? Display::label($new_messages, 'warning') : null;
  243. $usergroup = new UserGroup();
  244. $messages_invitations_count = $usergroup->get_groups_by_user_count(
  245. $user_info['user_id'],
  246. GROUP_USER_PERMISSION_PENDING_INVITATION,
  247. false
  248. );
  249. $user_info['messages_invitations_count'] = $messages_invitations_count != 0 ? Display::label(
  250. $messages_invitations_count,
  251. 'warning'
  252. ) : null;
  253. $this->user_is_logged_in = true;
  254. }
  255. //Setting the $_u array that could be use in any template
  256. $this->assign('_u', $user_info);
  257. }
  258. /** Set system parameters */
  259. private function set_system_parameters()
  260. {
  261. global $_configuration;
  262. //Setting app paths/URLs
  263. $_p = array(
  264. 'web' => api_get_path(WEB_PATH),
  265. 'web_course' => api_get_path(WEB_COURSE_PATH),
  266. 'web_main' => api_get_path(WEB_CODE_PATH),
  267. 'web_css' => api_get_path(WEB_CSS_PATH),
  268. 'web_ajax' => api_get_path(WEB_AJAX_PATH),
  269. 'web_img' => api_get_path(WEB_IMG_PATH),
  270. 'web_plugin' => api_get_path(WEB_PLUGIN_PATH),
  271. 'web_lib' => api_get_path(WEB_LIBRARY_PATH),
  272. );
  273. $this->assign('_p', $_p);
  274. //Here we can add system parameters that can be use in any template
  275. $_s = array(
  276. 'software_name' => $_configuration['software_name'],
  277. 'system_version' => $_configuration['system_version'],
  278. 'site_name' => api_get_setting('siteName'),
  279. 'institution' => api_get_setting('Institution')
  280. );
  281. $this->assign('_s', $_s);
  282. }
  283. /**
  284. * Set theme, include CSS files */
  285. private function set_css_files()
  286. {
  287. global $disable_js_and_css_files;
  288. $css = array();
  289. $this->theme = api_get_visual_theme();
  290. if (!empty($this->preview_theme)) {
  291. $this->theme = $this->preview_theme;
  292. }
  293. $cssPath = api_get_path(WEB_CSS_PATH);
  294. //Base CSS
  295. $css[] = api_get_cdn_path($cssPath.'base.css');
  296. //Compressed version of default + all CSS files
  297. //$css[] = api_get_cdn_path(api_get_path(WEB_PATH).'web/css/'.$this->theme.'/style.css');
  298. //Default theme CSS
  299. $css[] = api_get_cdn_path($cssPath.$this->theme.'/default.css');
  300. $css[] = api_get_cdn_path($cssPath.'bootstrap-responsive.css');
  301. $css[] = api_get_cdn_path($cssPath.'responsive.css');
  302. $css[] = api_get_cdn_path($cssPath.'font_awesome/font-awesome.css');
  303. //Extra CSS files
  304. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/thickbox.css';
  305. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/chosen/chosen.css';
  306. if ($this->show_learnpath) {
  307. $css[] = $cssPath.$this->theme.'/learnpath.css';
  308. $css[] = $cssPath.$this->theme.'/scorm.css';
  309. }
  310. if (api_is_global_chat_enabled()) {
  311. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/chat/css/chat.css';
  312. }
  313. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-ui/'.$this->jquery_ui_theme.'/jquery-ui-custom.css';
  314. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-ui/default.css';
  315. $css_file_to_string = null;
  316. foreach ($css as $file) {
  317. $css_file_to_string .= api_get_css($file);
  318. }
  319. // @todo move this somewhere else. Special fix when using tablets in order to see the text near icons
  320. if (SHOW_TEXT_NEAR_ICONS == true) {
  321. //hack in order to fix the actions buttons
  322. $css_file_to_string .= '<style>
  323. .td_actions a {
  324. float:left;
  325. width:100%;
  326. }
  327. .forum_message_left a {
  328. float:left;
  329. width:100%;
  330. }
  331. </style>';
  332. }
  333. $navigator_info = api_get_navigator();
  334. if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
  335. $css_file_to_string .= 'img, div { behavior: url('.api_get_path(
  336. WEB_LIBRARY_PATH
  337. ).'javascript/iepngfix/iepngfix.htc) } '."\n";
  338. }
  339. if (!$disable_js_and_css_files) {
  340. $this->assign('css_file_to_string', $css_file_to_string);
  341. $style_print = api_get_css(api_get_cdn_path($cssPath.$this->theme.'/print.css'), 'print');
  342. $this->assign('css_style_print', $style_print);
  343. }
  344. // Logo
  345. $logo = $this->return_logo($this->theme);
  346. $this->assign('logo', $logo);
  347. }
  348. private function set_js_files()
  349. {
  350. global $disable_js_and_css_files, $htmlHeadXtra;
  351. //JS files
  352. $js_files = array(
  353. 'modernizr.js',
  354. 'jquery.min.js',
  355. 'chosen/chosen.jquery.min.js',
  356. 'jquery-ui/'.$this->jquery_ui_theme.'/jquery-ui-custom.min.js',
  357. //'jquery-ui/jquery.ui.touch-punch.js',
  358. 'thickbox.js',
  359. 'bootstrap/bootstrap.js',
  360. );
  361. if (api_is_global_chat_enabled()) {
  362. //Do not include the global chat in LP
  363. if ($this->show_learnpath == false && $this->show_footer == true && $this->app['template.hide_global_chat'] == false) {
  364. $js_files[] = 'chat/js/chat.js';
  365. }
  366. }
  367. if (api_get_setting('accessibility_font_resize') == 'true') {
  368. $js_files[] = 'fontresize.js';
  369. }
  370. if (api_get_setting('include_asciimathml_script') == 'true') {
  371. $js_files[] = 'asciimath/ASCIIMathML.js';
  372. }
  373. $js_file_to_string = null;
  374. foreach ($js_files as $js_file) {
  375. $js_file_to_string .= api_get_js($js_file);
  376. }
  377. //Loading email_editor js
  378. if (!api_is_anonymous() && api_get_setting('allow_email_editor') == 'true') {
  379. $js_file_to_string .= $this->fetch('default/mail_editor/email_link.js.tpl');
  380. }
  381. //$js_file_to_string = api_get_js_simple(api_get_path(WEB_PATH).'web/js/script.js').$js_file_to_string;
  382. if (!$disable_js_and_css_files) {
  383. $this->assign('js_file_to_string', $js_file_to_string);
  384. $extra_headers = null;
  385. if (isset($htmlHeadXtra) && $htmlHeadXtra) {
  386. foreach ($htmlHeadXtra as $this_html_head) {
  387. $extra_headers .= $this_html_head."\n";
  388. }
  389. }
  390. if (isset($this->app['extraJS'])) {
  391. foreach ($this->app['extraJS'] as $this_html_head) {
  392. $extra_headers .= $this_html_head."\n";
  393. }
  394. }
  395. $this->assign('extra_headers', $extra_headers);
  396. }
  397. }
  398. /**
  399. * Set header parameters
  400. */
  401. private function setHeaderParameters() {
  402. global $interbreadcrumb;
  403. if (isset($this->app['breadcrumb']) && !empty($this->app['breadcrumb'])) {
  404. if (empty($interbreadcrumb)) {
  405. $interbreadcrumb = $this->app['breadcrumb'];
  406. } else {
  407. $interbreadcrumb = array_merge($interbreadcrumb, $this->app['breadcrumb']);
  408. }
  409. }
  410. $_course = api_get_course_info();
  411. $_configuration = $this->app['configuration'];
  412. $this_section = $this->app['this_section'];
  413. $nameTools = $this->title;
  414. $navigation = $this->navigation_array;
  415. $this->menu_navigation = $navigation['menu_navigation'];
  416. $this->assign('system_charset', api_get_system_encoding());
  417. $this->assign('online_button', Display::return_icon('online.png'));
  418. $this->assign('offline_button', Display::return_icon('offline.png'));
  419. // Get language iso-code for this page - ignore errors
  420. $this->assign('document_language', api_get_language_isocode());
  421. $course_title = isset($_course['name']) ? $_course['name'] : null;
  422. $title_list = array();
  423. $title_list[] = api_get_setting('Institution');
  424. $title_list[] = api_get_setting('siteName');
  425. if (!empty($course_title)) {
  426. $title_list[] = $course_title;
  427. }
  428. if ($nameTools != '') {
  429. $title_list[] = $nameTools;
  430. }
  431. $title_string = '';
  432. for ($i = 0; $i < count($title_list); $i++) {
  433. $title_string .= $title_list[$i];
  434. if (isset($title_list[$i + 1])) {
  435. $item = trim($title_list[$i + 1]);
  436. if (!empty($item)) {
  437. $title_string .= ' - ';
  438. }
  439. }
  440. }
  441. $this->assign('title_string', $title_string);
  442. //Setting the theme and CSS files
  443. $this->set_css_files();
  444. $this->set_js_files();
  445. // Implementation of prefetch.
  446. // See http://cdn.chamilo.org/main/img/online.png for details
  447. $prefetch = '';
  448. if (!empty($_configuration['cdn_enable'])) {
  449. $prefetch .= '<meta http-equiv="x-dns-prefetch-control" content="on">';
  450. foreach ($_configuration['cdn'] as $host => $exts) {
  451. $prefetch .= '<link rel="dns-prefetch" href="'.$host.'">';
  452. }
  453. }
  454. $this->assign('prefetch', $prefetch);
  455. $this->assign('text_direction', api_get_text_direction());
  456. $this->assign('section_name', 'section-'.$this_section);
  457. $favico = '<link rel="shortcut icon" href="'.api_get_path(WEB_PATH).'favicon.ico" type="image/x-icon" />';
  458. if (isset($_configuration['multiple_access_urls']) && $_configuration['multiple_access_urls']) {
  459. $access_url_id = api_get_current_access_url_id();
  460. if ($access_url_id != -1) {
  461. $url_info = api_get_access_url($access_url_id);
  462. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  463. $clean_url = replace_dangerous_char($url);
  464. $clean_url = str_replace('/', '-', $clean_url);
  465. $clean_url .= '/';
  466. $homep = api_get_path(REL_PATH).'home/'.$clean_url; //homep for Home Path
  467. $icon_real_homep = api_get_path(SYS_PATH).'home/'.$clean_url;
  468. //we create the new dir for the new sites
  469. if (is_file($icon_real_homep.'favicon.ico')) {
  470. $favico = '<link rel="shortcut icon" href="'.$homep.'favicon.ico" type="image/x-icon" />';
  471. }
  472. }
  473. }
  474. $this->assign('favico', $favico);
  475. $this->set_help();
  476. $notification = $this->return_notification_menu();
  477. $this->assign('notification_menu', $notification);
  478. //Preparing values for the menu
  479. //Logout link
  480. $this->assign('logout_link', api_get_path(WEB_PUBLIC_PATH).'logout');
  481. //Profile link
  482. if (api_get_setting('allow_social_tool') == 'true') {
  483. $profile_link = '<a href="'.api_get_path(WEB_CODE_PATH).'social/home.php">'.get_lang('Profile').'</a>';
  484. } else {
  485. $profile_link = '<a href="'.api_get_path(WEB_CODE_PATH).'auth/profile.php">'.get_lang('Profile').'</a>';
  486. }
  487. $this->assign('profile_link', $profile_link);
  488. //Message link
  489. $message_link = null;
  490. if (api_get_setting('allow_message_tool') == 'true') {
  491. $message_link = '<a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php">'.get_lang('Inbox').'</a>';
  492. }
  493. $this->assign('message_link', $message_link);
  494. $institution = api_get_setting('Institution');
  495. $portal_name = empty($institution) ? api_get_setting('siteName') : $institution;
  496. $this->assign('portal_name', $portal_name);
  497. //Menu
  498. $menu = $this->return_menu();
  499. $this->assign('menu', $menu);
  500. //Breadcrumb
  501. $breadcrumb = $this->returnBreadcrumb($interbreadcrumb, $nameTools);
  502. $this->assign('breadcrumb', $breadcrumb);
  503. //Extra content
  504. $extra_header = null;
  505. if (!api_is_platform_admin()) {
  506. $extra_header = trim(api_get_setting('header_extra_content'));
  507. }
  508. $this->assign('header_extra_content', $extra_header);
  509. }
  510. /**
  511. * Set footer parameters
  512. */
  513. private function setFooterParameters()
  514. {
  515. //Show admin data
  516. //$this->assign('show_administrator_data', api_get_setting('show_administrator_data'));
  517. if (api_get_setting('show_administrator_data') == 'true') {
  518. //Administrator name
  519. $administrator_data = get_lang('Manager').' : '.Display::encrypted_mailto_link(
  520. api_get_setting('emailAdministrator'),
  521. api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))
  522. );
  523. $this->assign('administrator_name', $administrator_data);
  524. }
  525. //Loading footer extra content
  526. if (!api_is_platform_admin()) {
  527. $extra_footer = trim(api_get_setting('footer_extra_content'));
  528. if (!empty($extra_footer)) {
  529. $this->assign('footer_extra_content', $extra_footer);
  530. }
  531. }
  532. //Tutor name
  533. if (api_get_setting('show_tutor_data') == 'true') {
  534. // Course manager
  535. $id_course = api_get_course_id();
  536. $id_session = api_get_session_id();
  537. if (isset($id_course) && $id_course != -1) {
  538. $tutor_data = '';
  539. if ($id_session != 0) {
  540. $coachs_email = CourseManager::get_email_of_tutor_to_session($id_session, $id_course);
  541. $email_link = array();
  542. foreach ($coachs_email as $coach) {
  543. $email_link[] = Display::encrypted_mailto_link($coach['email'], $coach['complete_name']);
  544. }
  545. if (count($coachs_email) > 1) {
  546. $tutor_data .= get_lang('Coachs').' : ';
  547. $tutor_data .= ArrayClass::array_to_string($email_link, CourseManager::USER_SEPARATOR);
  548. } elseif (count($coachs_email) == 1) {
  549. $tutor_data .= get_lang('Coach').' : ';
  550. $tutor_data .= ArrayClass::array_to_string($email_link, CourseManager::USER_SEPARATOR);
  551. } elseif (count($coachs_email) == 0) {
  552. $tutor_data .= '';
  553. }
  554. }
  555. $this->assign('session_teachers', $tutor_data);
  556. }
  557. }
  558. if (api_get_setting('show_teacher_data') == 'true') {
  559. // course manager
  560. $id_course = api_get_course_id();
  561. if (isset($id_course) && $id_course != -1) {
  562. $teacher_data = '';
  563. $mail = CourseManager::get_emails_of_tutors_to_course($id_course);
  564. if (!empty($mail)) {
  565. $teachers_parsed = array();
  566. foreach ($mail as $value) {
  567. foreach ($value as $email => $name) {
  568. $teachers_parsed[] = Display::encrypted_mailto_link($email, $name);
  569. }
  570. }
  571. $label = get_lang('Teacher');
  572. if (count($mail) > 1) {
  573. $label = get_lang('Teachers');
  574. }
  575. $teacher_data .= $label.' : '.ArrayClass::array_to_string($teachers_parsed, CourseManager::USER_SEPARATOR);
  576. }
  577. $this->assign('teachers', $teacher_data);
  578. }
  579. }
  580. }
  581. function show_header_template()
  582. {
  583. $tpl = $this->get_template('layout/show_header.tpl');
  584. $this->display($tpl);
  585. }
  586. public function show_footer_template()
  587. {
  588. $tpl = $this->get_template('layout/show_footer.tpl');
  589. $this->display($tpl);
  590. }
  591. public function manage_display($content)
  592. {
  593. //$this->assign('content', $content);
  594. }
  595. /* Sets the plugin content in a template variable */
  596. private function set_plugin_region($plugin_region)
  597. {
  598. if (!empty($plugin_region)) {
  599. $region_content = $this->plugin->load_region($plugin_region, $this, $this->force_plugin_load);
  600. if (!empty($region_content)) {
  601. $this->assign('plugin_'.$plugin_region, $region_content);
  602. } else {
  603. $this->assign('plugin_'.$plugin_region, null);
  604. }
  605. }
  606. return null;
  607. }
  608. public function fetch($template = null)
  609. {
  610. $template = $this->app['twig']->loadTemplate($template);
  611. return $template->render(array());
  612. }
  613. public function assign($key, $value = null)
  614. {
  615. $this->app['twig']->addGlobal($key, $value);
  616. }
  617. public function display($template = null)
  618. {
  619. if (!empty($template)) {
  620. $this->app['default_layout'] = $template;
  621. }
  622. $this->app->run();
  623. }
  624. function show_page_loaded_info()
  625. {
  626. //@todo will be removed before a stable release
  627. $mtime = microtime();
  628. $mtime = explode(" ", $mtime);
  629. $mtime = $mtime[1] + $mtime[0];
  630. error_log('--------------------------------------------------------');
  631. error_log("Page loaded in:".($mtime - START));
  632. error_log("memory_get_usage: ".Text::format_file_size(memory_get_usage(true)));
  633. error_log("memory_get_peak_usage: ".Text::format_file_size(memory_get_peak_usage(true)));
  634. }
  635. function return_menu()
  636. {
  637. $navigation = $this->navigation_array;
  638. $navigation = $navigation['navigation'];
  639. // Displaying the tabs
  640. $lang = null; //el for "Edit Language"
  641. $user_language_choice = isset($_SESSION['user_language_choice']) ? $_SESSION['user_language_choice'] : null;
  642. $user_info = $this->app['current_user'];
  643. if (!empty($user_language_choice)) {
  644. $lang = $user_language_choice;
  645. } elseif (!empty($user_info['language'])) {
  646. $lang = $user_info['language'];
  647. } else {
  648. $lang = api_get_setting('platformLanguage');
  649. }
  650. //Preparing home folder for multiple urls
  651. if (api_get_multiple_access_url()) {
  652. $access_url_id = api_get_current_access_url_id();
  653. if ($access_url_id != -1) {
  654. $url_info = api_get_access_url($access_url_id);
  655. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  656. $clean_url = replace_dangerous_char($url);
  657. $clean_url = str_replace('/', '-', $clean_url);
  658. $clean_url .= '/';
  659. $homep = api_get_path(SYS_PATH).'home/'.$clean_url; //homep for Home Path
  660. //we create the new dir for the new sites
  661. if (!is_dir($homep)) {
  662. mkdir($homep, api_get_permissions_for_new_directories());
  663. }
  664. }
  665. } else {
  666. $homep = api_get_path(SYS_PATH).'home/';
  667. }
  668. $ext = '.html';
  669. $menutabs = 'home_tabs';
  670. $home_top = '';
  671. if (is_file($homep.$menutabs.'_'.$lang.$ext) && is_readable($homep.$menutabs.'_'.$lang.$ext)) {
  672. $home_top = @(string)file_get_contents($homep.$menutabs.'_'.$lang.$ext);
  673. } elseif (is_file($homep.$menutabs.$lang.$ext) && is_readable($homep.$menutabs.$lang.$ext)) {
  674. $home_top = @(string)file_get_contents($homep.$menutabs.$lang.$ext);
  675. } else {
  676. //$errorMsg = get_lang('HomePageFilesNotReadable');
  677. }
  678. $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
  679. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top);
  680. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  681. $lis = '';
  682. if (!empty($open)) {
  683. if (strpos($open, 'show_menu') === false) {
  684. if (api_is_anonymous()) {
  685. $navigation[SECTION_CAMPUS] = null;
  686. }
  687. } else {
  688. //$lis .= Display::tag('li', $open);
  689. $lis .= $open;
  690. }
  691. }
  692. if (count($navigation) > 0 || !empty($lis)) {
  693. $pre_lis = '';
  694. foreach ($navigation as $section => $navigation_info) {
  695. if (isset($GLOBALS['this_section'])) {
  696. $current = $section == $GLOBALS['this_section'] ? ' id="current" class="active" ' : '';
  697. } else {
  698. $current = '';
  699. }
  700. if (!empty($navigation_info['title'])) {
  701. $pre_lis .= '<li'.$current.' ><a href="'.$navigation_info['url'].'" target="_top">'.$navigation_info['title'].'</a></li>';
  702. }
  703. }
  704. $lis = $pre_lis.$lis;
  705. }
  706. $menu = null;
  707. if (!empty($lis)) {
  708. $menu .= $lis;
  709. }
  710. return $menu;
  711. }
  712. function returnNavigationLinks()
  713. {
  714. $html = '';
  715. // Deleting the myprofile link.
  716. if (api_get_setting('allow_social_tool') == 'true') {
  717. unset($this->menu_navigation['myprofile']);
  718. }
  719. // Main navigation section.
  720. // Tabs that are deactivated are added here.
  721. if (!empty($this->menu_navigation)) {
  722. $content = '<ul class="nav nav-list">';
  723. foreach ($this->menu_navigation as $section => $navigation_info) {
  724. $current = isset($GLOBALS['this_section']) && $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  725. $content .= '<li'.$current.'>';
  726. $content .= '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  727. $content .= '</li>';
  728. }
  729. $content .= '</ul>';
  730. $html = $this->app['page_controller']->show_right_block(get_lang('MainNavigation'), $content, 'navigation_link_block');
  731. }
  732. return $html;
  733. }
  734. function render_layout($layout = null)
  735. {
  736. if (empty($layout)) {
  737. $layout = $this->app['default_layout'];
  738. }
  739. return $this->app['twig']->render($this->app['template_style'].'/layout/'.$layout);
  740. }
  741. function render_template($template, $elements = array())
  742. {
  743. return $this->app['twig']->render($this->app['template_style'].'/'.$template, $elements);
  744. }
  745. /**
  746. * Determines the possible tabs (=sections) that are available.
  747. * This function is used when creating the tabs in the third header line and
  748. * all the sections that do not appear there (as determined by the
  749. * platform admin on the Dokeos configuration settings page)
  750. * will appear in the right hand menu that appears on several other pages
  751. * @return array containing all the possible tabs
  752. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  753. */
  754. function get_tabs()
  755. {
  756. global $_course;
  757. $navigation = array();
  758. // Campus Homepage
  759. $navigation[SECTION_CAMPUS]['url'] = api_get_path(WEB_PATH).'index.php';
  760. $navigation[SECTION_CAMPUS]['title'] = get_lang('CampusHomepage');
  761. // My Courses
  762. if (api_is_allowed_to_create_course()) {
  763. // Link to my courses for teachers
  764. $navigation['mycourses']['url'] = api_get_path(WEB_PATH).'user_portal.php?nosession=true';
  765. $navigation['mycourses']['title'] = get_lang('MyCourses');
  766. } else {
  767. // Link to my courses for students
  768. $navigation['mycourses']['url'] = api_get_path(WEB_PATH).'user_portal.php';
  769. $navigation['mycourses']['title'] = get_lang('MyCourses');
  770. }
  771. // My Profile
  772. $navigation['myprofile']['url'] = api_get_path(WEB_CODE_PATH).'auth/profile.php'.(!empty($_course['path']) ? '?coursePath='.$_course['path'].'&amp;courseCode='.$_course['official_code'] : '');
  773. $navigation['myprofile']['title'] = get_lang('ModifyProfile');
  774. // Link to my agenda
  775. $navigation['myagenda']['url'] = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type=personal';
  776. $navigation['myagenda']['title'] = get_lang('MyAgenda');
  777. // Gradebook
  778. if (api_get_setting('gradebook_enable') == 'true') {
  779. $navigation['mygradebook']['url'] = api_get_path(
  780. WEB_CODE_PATH
  781. ).'gradebook/gradebook.php'.(!empty($_course['path']) ? '?coursePath='.$_course['path'].'&amp;courseCode='.$_course['official_code'] : '');
  782. $navigation['mygradebook']['title'] = get_lang('MyGradebook');
  783. }
  784. // Reporting
  785. if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin()) {
  786. // Link to my space
  787. $navigation['session_my_space']['url'] = api_get_path(WEB_CODE_PATH).'mySpace/';
  788. $navigation['session_my_space']['title'] = get_lang('MySpace');
  789. } else {
  790. // Link to my progress
  791. $navigation['session_my_progress']['url'] = api_get_path(WEB_CODE_PATH).'auth/my_progress.php';
  792. $navigation['session_my_progress']['title'] = get_lang('MyProgress');
  793. }
  794. // Social
  795. if (api_get_setting('allow_social_tool') == 'true') {
  796. $navigation['social']['url'] = api_get_path(WEB_CODE_PATH).'social/home.php';
  797. $navigation['social']['title'] = get_lang('SocialNetwork');
  798. }
  799. // Dashboard
  800. if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
  801. $navigation['dashboard']['url'] = api_get_path(WEB_CODE_PATH).'dashboard/index.php';
  802. $navigation['dashboard']['title'] = get_lang('Dashboard');
  803. }
  804. // Reports
  805. /*
  806. if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
  807. $navigation['reports']['url'] = api_get_path(WEB_CODE_PATH).'reports/index.php';
  808. $navigation['reports']['title'] = get_lang('Reports');
  809. }*/
  810. // Custom tabs
  811. for ($i = 1; $i <= 3; $i++) {
  812. if (api_get_setting('custom_tab_'.$i.'_name') && api_get_setting('custom_tab_'.$i.'_url')) {
  813. $navigation['custom_tab_'.$i]['url'] = api_get_setting('custom_tab_'.$i.'_url');
  814. $navigation['custom_tab_'.$i]['title'] = api_get_setting('custom_tab_'.$i.'_name');
  815. }
  816. }
  817. // Platform administration
  818. if (api_is_platform_admin(true)) {
  819. $navigation['platform_admin']['url'] = api_get_path(WEB_CODE_PATH).'admin/';
  820. $navigation['platform_admin']['title'] = get_lang('PlatformAdmin');
  821. }
  822. return $navigation;
  823. }
  824. function return_logo($theme)
  825. {
  826. $_course = api_get_course_info();
  827. $html = '';
  828. $logo = api_get_path(SYS_CODE_PATH).'css/'.$theme.'/images/header-logo.png';
  829. $site_name = api_get_setting('siteName');
  830. if (file_exists($logo)) {
  831. $site_name = api_get_setting('Institution').' - '.$site_name;
  832. $html .= '<div id="logo">';
  833. $image_url = api_get_path(WEB_CSS_PATH).$theme.'/images/header-logo.png';
  834. $logo = Display::img($image_url, $site_name, array('title' => $site_name));
  835. $html .= Display::url($logo, api_get_path(WEB_PATH).'index.php');
  836. $html .= '</div>';
  837. } else {
  838. $html .= '<a href="'.api_get_path(WEB_PATH).'index.php" target="_top">'.$site_name.'</a>';
  839. $iurl = api_get_setting('InstitutionUrl');
  840. $iname = api_get_setting('Institution');
  841. if (!empty($iname)) {
  842. $html .= '-&nbsp;<a href="'.$iurl.'" target="_top">'.$iname.'</a>';
  843. }
  844. // External link section a.k.a Department - Department URL
  845. if (isset($_course['extLink']) && $_course['extLink']['name'] != '') {
  846. $html .= '<span class="extLinkSeparator"> - </span>';
  847. if ($_course['extLink']['url'] != '') {
  848. $html .= '<a class="extLink" href="'.$_course['extLink']['url'].'" target="_top">';
  849. $html .= $_course['extLink']['name'];
  850. $html .= '</a>';
  851. } else {
  852. $html .= $_course['extLink']['name'];
  853. }
  854. }
  855. }
  856. /* // Course title section
  857. if (!empty($_cid) and $_cid != -1 and isset($_course)) {
  858. //Put the name of the course in the header
  859. $html .= '<div id="my_courses">';
  860. $html .= '</div>';
  861. } elseif (isset($nameTools) && $language_file != 'course_home') {
  862. //Put the name of the user-tools in the header
  863. if (!isset($user_id)) {
  864. //echo '<div id="my_courses"></div>';
  865. } elseif (!$noPHP_SELF) {
  866. $html .= '<div id="my_courses"><a href="'.api_get_self().'?'.api_get_cidreq(). '" target="_top">'.$nameTools.'</a></div>';
  867. } else {
  868. $html .= '<div id="my_courses">'.$nameTools.'</div>';
  869. }
  870. }*/
  871. return $html;
  872. }
  873. function return_notification_menu()
  874. {
  875. $_course = api_get_course_info();
  876. $course_id = api_get_course_id();
  877. $user_id = api_get_user_id();
  878. $html = '';
  879. if ((api_get_setting('showonline', 'world') == 'true' AND !$user_id) OR (api_get_setting(
  880. 'showonline',
  881. 'users'
  882. ) == 'true' AND $user_id) OR (api_get_setting('showonline', 'course') == 'true' AND $user_id AND $course_id)
  883. ) {
  884. $number = Online::who_is_online_count(api_get_setting('time_limit_whosonline'));
  885. $number_online_in_course = 0;
  886. if (!empty($_course['id'])) {
  887. $number_online_in_course = Online::who_is_online_in_this_course_count(
  888. $user_id,
  889. api_get_setting('time_limit_whosonline'),
  890. $_course['id']
  891. );
  892. }
  893. // Display the who's online of the platform
  894. if ($number) {
  895. if ((api_get_setting('showonline', 'world') == 'true' AND !$user_id) OR (api_get_setting(
  896. 'showonline',
  897. 'users'
  898. ) == 'true' AND $user_id)
  899. ) {
  900. $html .= '<li><a href="'.api_get_path(WEB_PATH).'whoisonline.php" target="_top" title="'.get_lang(
  901. 'UsersOnline'
  902. ).'" >'.
  903. Display::return_icon(
  904. 'user.png',
  905. get_lang('UsersOnline'),
  906. array(),
  907. ICON_SIZE_TINY
  908. ).' '.$number.'</a></li>';
  909. }
  910. }
  911. // Display the who's online for the course
  912. if ($number_online_in_course) {
  913. if (is_array($_course) AND api_get_setting(
  914. 'showonline',
  915. 'course'
  916. ) == 'true' AND isset($_course['sysCode'])
  917. ) {
  918. $html .= '<li><a href="'.api_get_path(
  919. WEB_PATH
  920. ).'whoisonline.php?cidReq='.$_course['sysCode'].'" target="_top">'.
  921. Display::return_icon(
  922. 'course.png',
  923. get_lang('UsersOnline').' '.get_lang('InThisCourse'),
  924. array(),
  925. ICON_SIZE_TINY
  926. ).' '.$number_online_in_course.' </a></li>';
  927. }
  928. }
  929. // Display the who's online for the session
  930. if (isset($user_id) && api_get_session_id() != 0) {
  931. if (api_is_allowed_to_edit()) {
  932. $html .= '<li><a href="'.api_get_path(
  933. WEB_PATH
  934. ).'whoisonlinesession.php?session_id='.api_get_session_id().'&id_coach='.$user_id.'" >'.
  935. Display::return_icon(
  936. 'session.png',
  937. get_lang('UsersConnectedToMySessions'),
  938. array(),
  939. ICON_SIZE_TINY
  940. ).' </a></li>';
  941. }
  942. }
  943. }
  944. if (api_get_setting('accessibility_font_resize') == 'true') {
  945. $html .= '<li class="resize_font">';
  946. $html .= '<span class="decrease_font" title="'.get_lang(
  947. 'DecreaseFontSize'
  948. ).'">A</span> <span class="reset_font" title="'.get_lang(
  949. 'ResetFontSize'
  950. ).'">A</span> <span class="increase_font" title="'.get_lang('IncreaseFontSize').'">A</span>';
  951. $html .= '</li>';
  952. }
  953. return $html;
  954. }
  955. public function returnNavigationArray()
  956. {
  957. $navigation = array();
  958. $menu_navigation = array();
  959. $possible_tabs = $this->get_tabs();
  960. // Campus Homepage
  961. if (api_get_setting('show_tabs', 'campus_homepage') == 'true') {
  962. $navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
  963. } else {
  964. $menu_navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
  965. }
  966. if (api_get_user_id() && !api_is_anonymous()) {
  967. // My Courses
  968. if (api_get_setting('show_tabs', 'my_courses') == 'true') {
  969. $navigation['mycourses'] = $possible_tabs['mycourses'];
  970. } else {
  971. $menu_navigation['mycourses'] = $possible_tabs['mycourses'];
  972. }
  973. // My Profile
  974. if (api_get_setting('show_tabs', 'my_profile') == 'true' && api_get_setting(
  975. 'allow_social_tool'
  976. ) != 'true'
  977. ) {
  978. $navigation['myprofile'] = $possible_tabs['myprofile'];
  979. } else {
  980. $menu_navigation['myprofile'] = $possible_tabs['myprofile'];
  981. }
  982. // My Agenda
  983. if (api_get_setting('show_tabs', 'my_agenda') == 'true') {
  984. $navigation['myagenda'] = $possible_tabs['myagenda'];
  985. } else {
  986. $menu_navigation['myagenda'] = $possible_tabs['myagenda'];
  987. }
  988. // Gradebook
  989. if (api_get_setting('gradebook_enable') == 'true') {
  990. if (api_get_setting('show_tabs', 'my_gradebook') == 'true') {
  991. $navigation['mygradebook'] = $possible_tabs['mygradebook'];
  992. } else {
  993. $menu_navigation['mygradebook'] = $possible_tabs['mygradebook'];
  994. }
  995. }
  996. // Reporting
  997. if (api_get_setting('show_tabs', 'reporting') == 'true') {
  998. if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin()) {
  999. $navigation['session_my_space'] = $possible_tabs['session_my_space'];
  1000. } else {
  1001. $navigation['session_my_space'] = $possible_tabs['session_my_progress'];
  1002. }
  1003. } else {
  1004. if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin()) {
  1005. $menu_navigation['session_my_space'] = $possible_tabs['session_my_space'];
  1006. } else {
  1007. $menu_navigation['session_my_space'] = $possible_tabs['session_my_progress'];
  1008. }
  1009. }
  1010. // Social Networking
  1011. if (api_get_setting('show_tabs', 'social') == 'true') {
  1012. if (api_get_setting('allow_social_tool') == 'true') {
  1013. $navigation['social'] = $possible_tabs['social'];
  1014. }
  1015. } else {
  1016. $menu_navigation['social'] = isset($possible_tabs['social']) ? $possible_tabs['social'] : null;
  1017. }
  1018. // Dashboard
  1019. if (api_get_setting('show_tabs', 'dashboard') == 'true') {
  1020. if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
  1021. $navigation['dashboard'] = $possible_tabs['dashboard'];
  1022. }
  1023. } else {
  1024. $menu_navigation['dashboard'] = isset($possible_tabs['dashboard']) ? $possible_tabs['dashboard'] : null;
  1025. }
  1026. // Administration
  1027. if (api_is_platform_admin(true)) {
  1028. if (api_get_setting('show_tabs', 'platform_administration') == 'true') {
  1029. $navigation['platform_admin'] = $possible_tabs['platform_admin'];
  1030. } else {
  1031. $menu_navigation['platform_admin'] = $possible_tabs['platform_admin'];
  1032. }
  1033. }
  1034. // Reports
  1035. if (!empty($possible_tabs['reports'])) {
  1036. if (api_get_setting('show_tabs', 'reports') == 'true') {
  1037. if ((api_is_platform_admin() || api_is_drh() || api_is_session_admin()) && Rights::hasRight(
  1038. 'show_tabs:reports'
  1039. )
  1040. ) {
  1041. $navigation['reports'] = $possible_tabs['reports'];
  1042. }
  1043. } else {
  1044. $menu_navigation['reports'] = $possible_tabs['reports'];
  1045. }
  1046. }
  1047. // Custom tabs
  1048. for ($i = 1; $i <= 3; $i++) {
  1049. if (api_get_setting('show_tabs', 'custom_tab_'.$i) == 'true') {
  1050. if (isset($possible_tabs['custom_tab_'.$i])) {
  1051. $navigation['custom_tab_'.$i] = $possible_tabs['custom_tab_'.$i];
  1052. }
  1053. } else {
  1054. if (isset($possible_tabs['custom_tab_'.$i])) {
  1055. $menu_navigation['custom_tab_'.$i] = $possible_tabs['custom_tab_'.$i];
  1056. }
  1057. }
  1058. }
  1059. }
  1060. $return = array(
  1061. 'menu_navigation' => $menu_navigation,
  1062. 'navigation' => $navigation,
  1063. 'possible_tabs' => $possible_tabs
  1064. );
  1065. return $return;
  1066. }
  1067. /**
  1068. * Return breadcrumb
  1069. * @param array $interbreadcrumb
  1070. * @return string
  1071. */
  1072. public function returnBreadcrumb($interbreadcrumb)
  1073. {
  1074. $session_id = api_get_session_id();
  1075. $session_name = api_get_session_name($session_id);
  1076. $_course = api_get_course_info();
  1077. $user_id = api_get_user_id();
  1078. $course_id = api_get_course_id();
  1079. /* Plugins for banner section */
  1080. $web_course_path = api_get_path(WEB_COURSE_PATH);
  1081. /* If the user is a coach he can see the users who are logged in its session */
  1082. $navigation = array();
  1083. // part 1: Course Homepage. If we are in a course then the first breadcrumb is a link to the course homepage
  1084. // hide_course_breadcrumb the parameter has been added to hide the name of the course, that appeared in the default $interbreadcrumb
  1085. $session_name = Text::cut($session_name, MAX_LENGTH_BREADCRUMB);
  1086. $my_session_name = is_null($session_name) ? '' : '&nbsp;('.$session_name.')';
  1087. if (!empty($_course) && !isset($_GET['hide_course_breadcrumb'])) {
  1088. $navigation_item['url'] = $web_course_path.$_course['path'].'/index.php'.(!empty($session_id) ? '?id_session='.$session_id : '');
  1089. $course_title = Text::cut($_course['name'], MAX_LENGTH_BREADCRUMB);
  1090. switch (api_get_setting('breadcrumbs_course_homepage')) {
  1091. case 'get_lang':
  1092. $navigation_item['title'] = Display::img(
  1093. api_get_path(WEB_CSS_PATH).'home.png',
  1094. get_lang('CourseHomepageLink')
  1095. ).' '.get_lang('CourseHomepageLink');
  1096. break;
  1097. case 'course_code':
  1098. $navigation_item['title'] = Display::img(
  1099. api_get_path(WEB_CSS_PATH).'home.png',
  1100. $_course['official_code']
  1101. ).' '.$_course['official_code'];
  1102. break;
  1103. case 'session_name_and_course_title':
  1104. $navigation_item['title'] = Display::img(
  1105. api_get_path(WEB_CSS_PATH).'home.png',
  1106. $_course['name'].$my_session_name
  1107. ).' '.$course_title.$my_session_name;
  1108. break;
  1109. default:
  1110. if (api_get_session_id() != -1) {
  1111. $navigation_item['title'] = Display::img(
  1112. api_get_path(WEB_CSS_PATH).'home.png',
  1113. $_course['name'].$my_session_name
  1114. ).' '.$course_title.$my_session_name;
  1115. } else {
  1116. $navigation_item['title'] = Display::img(
  1117. api_get_path(WEB_CSS_PATH).'home.png',
  1118. $_course['name']
  1119. ).' '.$course_title;
  1120. }
  1121. break;
  1122. }
  1123. $navigation[] = $navigation_item;
  1124. }
  1125. // part 2: Interbreadcrumbs.
  1126. //If there is an array $interbreadcrumb defined then these have to appear before the last breadcrumb (which is the tool itself)
  1127. if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
  1128. foreach ($interbreadcrumb as $breadcrumb_step) {
  1129. if ($breadcrumb_step['url'] != '#') {
  1130. $sep = (strrchr($breadcrumb_step['url'], '?') ? '&amp;' : '?');
  1131. $navigation_item['url'] = $breadcrumb_step['url'].$sep.api_get_cidreq();
  1132. } else {
  1133. $navigation_item['url'] = '#';
  1134. }
  1135. $navigation_item['title'] = $breadcrumb_step['name'];
  1136. // titles for shared folders
  1137. if ($breadcrumb_step['name'] == 'shared_folder') {
  1138. $navigation_item['title'] = get_lang('UserFolders');
  1139. } elseif (strstr($breadcrumb_step['name'], 'shared_folder_session_')) {
  1140. $navigation_item['title'] = get_lang('UserFolders');
  1141. } elseif (strstr($breadcrumb_step['name'], 'sf_user_')) {
  1142. $userinfo = api_get_user_info(substr($breadcrumb_step['name'], 8));
  1143. $navigation_item['title'] = $userinfo['complete_name'];
  1144. } elseif ($breadcrumb_step['name'] == 'chat_files') {
  1145. $navigation_item['title'] = get_lang('ChatFiles');
  1146. } elseif ($breadcrumb_step['name'] == 'images') {
  1147. $navigation_item['title'] = get_lang('Images');
  1148. } elseif ($breadcrumb_step['name'] == 'video') {
  1149. $navigation_item['title'] = get_lang('Video');
  1150. } elseif ($breadcrumb_step['name'] == 'audio') {
  1151. $navigation_item['title'] = get_lang('Audio');
  1152. } elseif ($breadcrumb_step['name'] == 'flash') {
  1153. $navigation_item['title'] = get_lang('Flash');
  1154. } elseif ($breadcrumb_step['name'] == 'gallery') {
  1155. $navigation_item['title'] = get_lang('Gallery');
  1156. }
  1157. //Fixes breadcrumb title now we applied the Security::remove_XSS and we cut the string depending of the MAX_LENGTH_BREADCRUMB value
  1158. $navigation_item['title'] = Text::cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
  1159. $navigation_item['title'] = Security::remove_XSS($navigation_item['title']);
  1160. $navigation[] = $navigation_item;
  1161. }
  1162. }
  1163. // part 3: The tool itself. If we are on the course homepage we do not want to display the title of the course because this
  1164. // is the same as the first part of the breadcrumbs (see part 1)
  1165. $final_navigation = array();
  1166. $counter = 0;
  1167. foreach ($navigation as $index => $navigation_info) {
  1168. if (!empty($navigation_info['title'])) {
  1169. if ($navigation_info['url'] == '#') {
  1170. $final_navigation[$index] = $navigation_info['title'];
  1171. } else {
  1172. $final_navigation[$index] = '<a href="'.$navigation_info['url'].'" class="" target="_top">'.$navigation_info['title'].'</a>';
  1173. }
  1174. $counter++;
  1175. }
  1176. }
  1177. $html = '';
  1178. /* Part 4 . Show the teacher view/student view button at the right of the breadcrumb */
  1179. $view_as_student_link = null;
  1180. if ($user_id && isset($course_id)) {
  1181. if ((api_is_course_admin() || api_is_platform_admin()) && api_get_setting(
  1182. 'student_view_enabled'
  1183. ) == 'true'
  1184. ) {
  1185. $view_as_student_link = api_display_tool_view_option();
  1186. }
  1187. }
  1188. if (!empty($final_navigation)) {
  1189. $lis = '';
  1190. $i = 0;
  1191. $final_navigation_count = count($final_navigation);
  1192. if (!empty($final_navigation)) {
  1193. // $home_link.= '<span class="divider">/</span>';
  1194. if (!empty($home_link)) {
  1195. $lis .= Display::tag('li', $home_link);
  1196. }
  1197. foreach ($final_navigation as $bread) {
  1198. $bread_check = trim(strip_tags($bread));
  1199. if (!empty($bread_check)) {
  1200. if ($final_navigation_count - 1 > $i) {
  1201. $bread .= '<span class="divider">/</span>';
  1202. }
  1203. $lis .= Display::tag('li', $bread);
  1204. $i++;
  1205. }
  1206. }
  1207. } else {
  1208. if (!empty($home_link)) {
  1209. $lis .= Display::tag('li', $home_link);
  1210. }
  1211. }
  1212. // View as student/teacher link
  1213. if (!empty($view_as_student_link)) {
  1214. $lis .= Display::tag(
  1215. 'li',
  1216. $view_as_student_link,
  1217. array('id' => 'view_as_link', 'class' => 'pull-right')
  1218. );
  1219. }
  1220. if (!empty($lis)) {
  1221. $html .= Display::tag('ul', $lis, array('class' => 'breadcrumb'));
  1222. }
  1223. }
  1224. return $html;
  1225. }
  1226. }