template.lib.php 53 KB

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