template.lib.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  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. require_once api_get_path(LIBRARY_PATH) . 'banner.lib.php';
  9. require_once api_get_path(LIBRARY_PATH) . 'symfony/Twig/Autoloader.php';
  10. class Template {
  11. var $style = 'default'; //see the template folder
  12. var $preview_theme = null;
  13. var $theme; // the chamilo theme public_admin, chamilo, chamilo_red, etc
  14. var $title = null;
  15. var $show_header;
  16. var $show_footer;
  17. var $help;
  18. var $menu_navigation = array(); //Used in the userportal.lib.php function: return_navigation_course_links()
  19. var $show_learnpath = false; // This is a learnpath section or not?
  20. var $plugin = null;
  21. var $course_id = null;
  22. var $user_is_logged_in = false;
  23. var $twig = null;
  24. /* Loads chamilo plugins */
  25. var $load_plugins = false;
  26. var $params = array();
  27. function __construct($title = '', $show_header = true, $show_footer = true, $show_learnpath = false, $hide_global_chat = false, $load_plugins = true) {
  28. //Page title
  29. $this->title = $title;
  30. $this->show_learnpath = $show_learnpath;
  31. $this->hide_global_chat = $hide_global_chat;
  32. $this->load_plugins = $load_plugins;
  33. //Twig settings
  34. Twig_Autoloader::register();
  35. $template_paths = array(
  36. api_get_path(SYS_CODE_PATH) . 'template', //template folder
  37. api_get_path(SYS_PLUGIN_PATH) //plugin folder
  38. );
  39. $cache_folder = api_get_path(SYS_ARCHIVE_PATH) . 'twig';
  40. if (!is_dir($cache_folder)) {
  41. mkdir($cache_folder, api_get_permissions_for_new_directories());
  42. }
  43. $loader = new Twig_Loader_Filesystem($template_paths);
  44. //Setting Twig options depending on the server see http://twig.sensiolabs.org/doc/api.html#environment-options
  45. if (api_get_setting('server_type') == 'test') {
  46. $options = array(
  47. //'cache' => api_get_path(SYS_ARCHIVE_PATH), //path to the cache folder
  48. 'autoescape' => false,
  49. 'debug' => true,
  50. 'auto_reload' => true,
  51. 'optimizations' => 0, // turn on optimizations with -1
  52. 'strict_variables' => false, //If set to false, Twig will silently ignore invalid variables
  53. );
  54. } else {
  55. $options = array(
  56. 'cache' => $cache_folder, //path to the cache folder
  57. 'autoescape' => false,
  58. 'debug' => false,
  59. 'auto_reload' => false,
  60. 'optimizations' => -1, // turn on optimizations with -1
  61. 'strict_variables' => false //If set to false, Twig will silently ignore invalid variables
  62. );
  63. }
  64. $this->twig = new Twig_Environment($loader, $options);
  65. $this->twig->addFilter('get_lang', new Twig_Filter_Function('get_lang'));
  66. $this->twig->addFilter('get_path', new Twig_Filter_Function('api_get_path'));
  67. $this->twig->addFilter('get_setting', new Twig_Filter_Function('api_get_setting'));
  68. $this->twig->addFilter('var_dump', new Twig_Filter_Function('var_dump'));
  69. $this->twig->addFilter('return_message', new Twig_Filter_Function('Display::return_message_and_translate'));
  70. $this->twig->addFilter('display_page_header', new Twig_Filter_Function('Display::page_header_and_translate'));
  71. $this->twig->addFilter('display_page_subheader', new Twig_Filter_Function('Display::page_subheader_and_translate'));
  72. $this->twig->addFilter('icon', new Twig_Filter_Function('Template::get_icon_path'));
  73. $this->twig->addFilter('format_date', new Twig_Filter_Function('Template::format_date'));
  74. /*
  75. $lexer = new Twig_Lexer($this->twig, array(
  76. //'tag_comment' => array('{*', '*}'),
  77. //'tag_comment' => array('{#', '#}'),
  78. //'tag_block' => array('{', '}'),
  79. //'tag_variable' => array('{$', '}'),
  80. ));
  81. $this->twig->setLexer($lexer); */
  82. //Setting system variables
  83. $this->set_system_parameters();
  84. //Setting user variables
  85. $this->set_user_parameters();
  86. //Setting course variables
  87. $this->set_course_parameters();
  88. //header and footer are showed by default
  89. $this->set_footer($show_footer);
  90. $this->set_header($show_header);
  91. $this->set_header_parameters();
  92. $this->set_footer_parameters();
  93. $this->assign('style', $this->style);
  94. //Chamilo plugins
  95. if ($this->show_header) {
  96. if ($this->load_plugins) {
  97. $this->plugin = new AppPlugin();
  98. //1. Showing installed plugins in regions
  99. $plugin_regions = $this->plugin->get_plugin_regions();
  100. foreach ($plugin_regions as $region) {
  101. $this->set_plugin_region($region);
  102. }
  103. //2. Loading the course plugin info
  104. global $course_plugin;
  105. if (isset($course_plugin) && !empty($course_plugin) && !empty($this->course_id)) {
  106. //Load plugin get_langs
  107. $this->plugin->load_plugin_lang_variables($course_plugin);
  108. }
  109. }
  110. }
  111. }
  112. public static function get_icon_path($image, $size = ICON_SIZE_SMALL) {
  113. return Display:: return_icon($image, '', array(), $size, false, true);
  114. }
  115. public static function format_date($timestamp, $format = null) {
  116. return api_format_date($timestamp, $format);
  117. }
  118. /**
  119. * Return the item's url key:
  120. *
  121. * c_id=xx&id=xx
  122. *
  123. * @param object $item
  124. * @return string
  125. */
  126. public static function key($item){
  127. $id = isset($item->id) ? $item->id : null;
  128. $c_id = isset($item->c_id) ? $item->c_id : null;
  129. $result = '';
  130. if($c_id){
  131. $result = "c_id=$c_id";
  132. }
  133. if($id){
  134. if($result){
  135. $result .= "&amp;id=$id";
  136. }else{
  137. $result .= "&amp;id=$id";
  138. }
  139. }
  140. return $result;
  141. }
  142. function set_help($help_input = null) {
  143. if (!empty($help_input)) {
  144. $help = $help_input;
  145. } else {
  146. $help = $this->help;
  147. }
  148. $help_content = '';
  149. if (api_get_setting('enable_help_link') == 'true') {
  150. if (!empty($help)) {
  151. $help = Security::remove_XSS($help);
  152. $help_content = '<li class="help">';
  153. $help_content .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'help/help.php?open=' . $help . '&height=400&width=600" class="ajax" title="' . get_lang('Help') . '">';
  154. $help_content .= '<img src="' . api_get_path(WEB_IMG_PATH) . 'help.large.png" alt="' . get_lang('Help') . '" title="' . get_lang('Help') . '" />';
  155. $help_content .= '</a></li>';
  156. }
  157. }
  158. $this->assign('help_content', $help_content);
  159. }
  160. /*
  161. * Use template system to parse the actions menu
  162. * @todo finish it!
  163. * */
  164. function set_actions($actions) {
  165. $action_string = '';
  166. if (!empty($actions)) {
  167. foreach ($actions as $action) {
  168. $action_string .= $action;
  169. }
  170. }
  171. $this->assign('actions', $actions);
  172. }
  173. /**
  174. * Shortcut to display a 1 col layout (index.php)
  175. * */
  176. function display_one_col_template() {
  177. $tpl = $this->get_template('layout/layout_1_col.tpl');
  178. $this->display($tpl);
  179. }
  180. /**
  181. * Shortcut to display a 2 col layout (userportal.php)
  182. * */
  183. function display_two_col_template() {
  184. $tpl = $this->get_template('layout/layout_2_col.tpl');
  185. $this->display($tpl);
  186. }
  187. /**
  188. * Displays an empty template
  189. */
  190. function display_blank_template() {
  191. $tpl = $this->get_template('layout/blank.tpl');
  192. $this->display($tpl);
  193. }
  194. /**
  195. * Displays an empty template
  196. */
  197. function display_no_layout_template() {
  198. $tpl = $this->get_template('layout/no_layout.tpl');
  199. $this->display($tpl);
  200. }
  201. /**
  202. * Sets the footer visibility
  203. * @param bool true if we show the footer
  204. */
  205. function set_footer($status) {
  206. $this->show_footer = $status;
  207. $this->assign('show_footer', $status);
  208. }
  209. /**
  210. * Sets the header visibility
  211. * @param bool true if we show the header
  212. */
  213. function set_header($status) {
  214. $this->show_header = $status;
  215. $this->assign('show_header', $status);
  216. //Toolbar
  217. $show_admin_toolbar = api_get_setting('show_admin_toolbar');
  218. $show_toolbar = 0;
  219. switch ($show_admin_toolbar) {
  220. case 'do_not_show':
  221. break;
  222. case 'show_to_admin':
  223. if (api_is_platform_admin()) {
  224. $show_toolbar = 1;
  225. }
  226. break;
  227. case 'show_to_admin_and_teachers':
  228. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  229. $show_toolbar = 1;
  230. }
  231. break;
  232. case 'show_to_all':
  233. $show_toolbar = 1;
  234. break;
  235. }
  236. $this->assign('show_toolbar', $show_toolbar);
  237. //Only if course is available
  238. $show_course_shortcut = null;
  239. $show_course_navigation_menu = null;
  240. if (!empty($this->course_id) && $this->user_is_logged_in) {
  241. if (api_get_setting('show_toolshortcuts') != 'false') {
  242. //Course toolbar
  243. $show_course_shortcut = CourseHome::show_navigation_tool_shortcuts();
  244. }
  245. if (api_get_setting('show_navigation_menu') != 'false') {
  246. //Course toolbar
  247. $show_course_navigation_menu = CourseHome::show_navigation_menu();
  248. }
  249. }
  250. $this->assign('show_course_shortcut', $show_course_shortcut);
  251. $this->assign('show_course_navigation_menu', $show_course_navigation_menu);
  252. }
  253. function get_template($name) {
  254. return $this->style . '/' . $name;
  255. }
  256. /** Set course parameters */
  257. private function set_course_parameters() {
  258. //Setting course id
  259. $course_id = api_get_course_int_id();
  260. $this->course_id = $course_id;
  261. }
  262. /** Set user parameters */
  263. private function set_user_parameters() {
  264. $user_info = array();
  265. $user_info['logged'] = 0;
  266. $this->user_is_logged_in = false;
  267. if (api_user_is_login()) {
  268. $user_info = api_get_user_info();
  269. $user_info['logged'] = 1;
  270. $user_info['is_admin'] = 0;
  271. if (api_is_platform_admin()) {
  272. $user_info['is_admin'] = 1;
  273. }
  274. $user_info['messages_count'] = MessageManager::get_new_messages();
  275. $this->user_is_logged_in = true;
  276. }
  277. //Setting the $_u array that could be use in any template
  278. $this->assign('_u', $user_info);
  279. }
  280. /** Set system parameters */
  281. private function set_system_parameters() {
  282. global $_configuration;
  283. //Setting app paths
  284. $_p = array('web' => api_get_path(WEB_PATH),
  285. 'web_course' => api_get_path(WEB_COURSE_PATH),
  286. 'web_main' => api_get_path(WEB_CODE_PATH),
  287. 'web_css' => api_get_path(WEB_CSS_PATH),
  288. 'web_ajax' => api_get_path(WEB_AJAX_PATH),
  289. 'web_img' => api_get_path(WEB_IMG_PATH),
  290. 'web_plugin' => api_get_path(WEB_PLUGIN_PATH),
  291. 'web_lib' => api_get_path(WEB_LIBRARY_PATH),
  292. );
  293. $this->assign('_p', $_p);
  294. //Here we can add system parameters that can be use in any template
  295. $_s = array(
  296. 'software_name' => $_configuration['software_name'],
  297. 'system_version' => $_configuration['system_version'],
  298. 'site_name' => api_get_setting('siteName'),
  299. 'institution' => api_get_setting('Institution')
  300. );
  301. $this->assign('_s', $_s);
  302. }
  303. /**
  304. * Set theme, include CSS files */
  305. function set_theme() {
  306. //$platform_theme = api_get_setting('stylesheets');
  307. $this->theme = api_get_visual_theme();
  308. if (!empty($this->preview_theme)) {
  309. $this->theme = $this->preview_theme;
  310. }
  311. //Base CSS
  312. $style_html = '@import "' . api_get_cdn_path(api_get_path(WEB_CSS_PATH) . 'base.css') . '";' . "\n";
  313. //Default theme CSS
  314. $style_html .= '@import "' . api_get_cdn_path(api_get_path(WEB_CSS_PATH) . $this->theme . '/default.css') . '";' . "\n";
  315. $navigator_info = api_get_navigator();
  316. if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
  317. $style_html .= 'img, div { behavior: url(' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/iepngfix/iepngfix.htc) } ' . "\n";
  318. }
  319. $style_html .= '@import "' . api_get_cdn_path(api_get_path(WEB_CSS_PATH) . 'bootstrap-responsive.css') . '";' . "\n";
  320. $style_html .= '@import "' . api_get_cdn_path(api_get_path(WEB_CSS_PATH) . 'responsive.css') . '";' . "\n";
  321. $this->assign('css_style', $style_html);
  322. $style_print = '@import "' . api_get_cdn_path(api_get_path(WEB_CSS_PATH) . $this->theme . '/print.css') . '";' . "\n";
  323. $this->assign('css_style_print', $style_print);
  324. // Logo
  325. $logo = return_logo($this->theme);
  326. $this->assign('logo', $logo);
  327. }
  328. /**
  329. * Set header parameters
  330. */
  331. private function set_header_parameters() {
  332. $help = $this->help;
  333. $nameTools = $this->title;
  334. global $lp_theme_css, $mycoursetheme, $user_theme;
  335. global $httpHeadXtra, $htmlHeadXtra, $_course, $text_dir,
  336. $interbreadcrumb, $charset, $language_file, $noPHP_SELF;
  337. $navigation = return_navigation_array();
  338. $this->menu_navigation = $navigation['menu_navigation'];
  339. global $_configuration;
  340. $this->assign('system_charset', api_get_system_encoding());
  341. if (isset($httpHeadXtra) && $httpHeadXtra) {
  342. foreach ($httpHeadXtra as & $thisHttpHead) {
  343. header($thisHttpHead);
  344. }
  345. }
  346. $this->assign('online_button', Security::remove_XSS(Display::return_icon('online.png')));
  347. $this->assign('offline_button', Security::remove_XSS(Display::return_icon('offline.png')));
  348. // Get language iso-code for this page - ignore errors
  349. $this->assign('document_language', api_get_language_isocode());
  350. $course_title = $_course['name'];
  351. $title_list = array();
  352. $title_list[] = api_get_setting('Institution');
  353. $title_list[] = api_get_setting('siteName');
  354. if (!empty($course_title)) {
  355. $title_list[] = $course_title;
  356. }
  357. if ($nameTools != '') {
  358. $title_list[] = $nameTools;
  359. }
  360. $title_string = '';
  361. for ($i = 0; $i < count($title_list); $i++) {
  362. $title_string .=$title_list[$i];
  363. if (isset($title_list[$i + 1])) {
  364. $item = trim($title_list[$i + 1]);
  365. if (!empty($item))
  366. $title_string .=' - ';
  367. }
  368. }
  369. $this->assign('title_string', $title_string);
  370. //Setting the theme and CSS files
  371. $this->set_theme();
  372. //Extra JS files
  373. $js_files = array(
  374. 'modernizr.js',
  375. 'jquery.min.js',
  376. 'chosen/chosen.jquery.min.js',
  377. 'thickbox.js',
  378. //'dtree/dtree.js',
  379. 'email_links.lib.js.php',
  380. 'bootstrap/bootstrap.js',
  381. );
  382. if (api_is_global_chat_enabled()) {
  383. //Do not include the global chat in LP
  384. if ($this->show_learnpath == false && $this->show_footer == true && $this->hide_global_chat == false) {
  385. $js_files[] = 'chat/js/chat.js';
  386. }
  387. }
  388. if (api_get_setting('accessibility_font_resize') == 'true') {
  389. $js_files[] = 'fontresize.js';
  390. }
  391. if (api_get_setting('include_asciimathml_script') == 'true') {
  392. $js_files[] = 'asciimath/ASCIIMathML.js';
  393. }
  394. $js_file_to_string = '';
  395. foreach ($js_files as $js_file) {
  396. $js_file_to_string .= api_get_js($js_file);
  397. }
  398. //Extra CSS files
  399. $css_files = array(
  400. api_get_path(WEB_LIBRARY_PATH) . 'javascript/thickbox.css',
  401. api_get_path(WEB_LIBRARY_PATH) . 'javascript/chosen/chosen.css'
  402. );
  403. if ($this->show_learnpath) {
  404. $css_files[] = api_get_path(WEB_CSS_PATH) . $this->theme . '/learnpath.css';
  405. $css_files[] = api_get_path(WEB_CSS_PATH) . $this->theme . '/scorm.css';
  406. }
  407. if (api_is_global_chat_enabled()) {
  408. $css_files[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/chat/css/chat.css';
  409. }
  410. $css_file_to_string = '';
  411. foreach ($css_files as $css_file) {
  412. $css_file_to_string .= api_get_css($css_file);
  413. }
  414. // @todo move this somewhere else. Special fix when using tablets in order to see the text near icons
  415. if (SHOW_TEXT_NEAR_ICONS == true) {
  416. //hack in order to fix the actions buttons
  417. $css_file_to_string .= '<style>
  418. .td_actions a {
  419. float:left;
  420. width:100%;
  421. }
  422. .forum_message_left a {
  423. float:left;
  424. width:100%;
  425. }
  426. </style>';
  427. }
  428. // Implementation of prefetch.
  429. // See http://cdn.chamilo.org/main/img/online.png for details
  430. $prefetch = '';
  431. if (!empty($_configuration['cdn_enable'])) {
  432. $prefetch .= '<meta http-equiv="x-dns-prefetch-control" content="on">';
  433. foreach ($_configuration['cdn'] as $host => $exts) {
  434. $prefetch .= '<link rel="dns-prefetch" href="' . $host . '">';
  435. }
  436. }
  437. global $this_section;
  438. //@todo minify CSS and JS
  439. $this->assign('prefetch', $prefetch);
  440. $this->assign('css_file_to_string', $css_file_to_string);
  441. $this->assign('js_file_to_string', $js_file_to_string);
  442. $this->assign('text_direction', api_get_text_direction());
  443. $this->assign('section_name', 'section-' . $this_section);
  444. //Adding jquery ui by default
  445. $extra_headers = api_get_jquery_ui_js();
  446. //$extra_headers = '';
  447. if (isset($htmlHeadXtra) && $htmlHeadXtra) {
  448. foreach ($htmlHeadXtra as & $this_html_head) {
  449. $extra_headers .= $this_html_head . "\n";
  450. }
  451. }
  452. $this->assign('extra_headers', $extra_headers);
  453. $favico = '<link rel="shortcut icon" href="' . api_get_path(WEB_PATH) . 'favicon.ico" type="image/x-icon" />';
  454. if (isset($_configuration['multiple_access_urls']) && $_configuration['multiple_access_urls']) {
  455. $access_url_id = api_get_current_access_url_id();
  456. if ($access_url_id != -1) {
  457. $url_info = api_get_access_url($access_url_id);
  458. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  459. $clean_url = replace_dangerous_char($url);
  460. $clean_url = str_replace('/', '-', $clean_url);
  461. $clean_url .= '/';
  462. $homep = api_get_path(REL_PATH) . 'home/' . $clean_url; //homep for Home Path
  463. $icon_real_homep = api_get_path(SYS_PATH) . 'home/' . $clean_url;
  464. //we create the new dir for the new sites
  465. if (is_file($icon_real_homep . 'favicon.ico')) {
  466. $favico = '<link rel="shortcut icon" href="' . $homep . 'favicon.ico" type="image/x-icon" />';
  467. }
  468. }
  469. }
  470. $this->assign('favico', $favico);
  471. $this->set_help();
  472. //@todo move this in the template
  473. $bug_notification_link = '';
  474. if (api_get_setting('show_link_bug_notification') == 'true' && $this->user_is_logged_in) {
  475. $bug_notification_link = '<li class="report">
  476. <a href="http://support.chamilo.org/projects/chamilo-18/wiki/How_to_report_bugs" target="_blank">
  477. <img src="' . api_get_path(WEB_IMG_PATH) . 'bug.large.png" style="vertical-align: middle;" alt="' . get_lang('ReportABug') . '" title="' . get_lang('ReportABug') . '"/></a>
  478. </li>';
  479. }
  480. $this->assign('bug_notification_link', $bug_notification_link);
  481. $notification = return_notification_menu();
  482. $this->assign('notification_menu', $notification);
  483. //Preparing values for the menu
  484. //Logout link
  485. $this->assign('logout_link', api_get_path(WEB_PATH).'index.php?logout=logout&&uid='.api_get_user_id());
  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 = return_menu();
  504. $this->assign('menu', $menu);
  505. //Breadcrumb
  506. $breadcrumb = return_breadcrumb($interbreadcrumb, $language_file, $nameTools);
  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. if ($this->show_header == 1) {
  515. header('Content-Type: text/html; charset=' . api_get_system_encoding());
  516. header('X-Powered-By: ' . $_configuration['software_name'] . ' ' . substr($_configuration['system_version'], 0, 1));
  517. }
  518. }
  519. /**
  520. * Set footer parameteres
  521. */
  522. private function set_footer_parameters() {
  523. global $_configuration;
  524. //Show admin data
  525. //$this->assign('show_administrator_data', api_get_setting('show_administrator_data'));
  526. if (api_get_setting('show_administrator_data') == 'true') {
  527. //Administrator name
  528. $administrator_data = get_lang('Manager') . ' : ' . Display::encrypted_mailto_link(api_get_setting('emailAdministrator'), api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname')));
  529. $this->assign('administrator_name', $administrator_data);
  530. }
  531. //Loading footer extra content
  532. if (!api_is_platform_admin()) {
  533. $extra_footer = trim(api_get_setting('footer_extra_content'));
  534. if (!empty($extra_footer)) {
  535. $this->assign('footer_extra_content', $extra_footer);
  536. }
  537. }
  538. //Tutor name
  539. if (api_get_setting('show_tutor_data') == 'true') {
  540. // Course manager
  541. $id_course = api_get_course_id();
  542. $id_session = api_get_session_id();
  543. if (isset($id_course) && $id_course != -1) {
  544. $tutor_data = '';
  545. if ($id_session != 0) {
  546. $coachs_email = CourseManager::get_email_of_tutor_to_session($id_session, $id_course);
  547. $email_link = array();
  548. foreach ($coachs_email as $coach) {
  549. $email_link[] = Display::encrypted_mailto_link($coach['email'], $coach['complete_name']);
  550. }
  551. if (count($coachs_email) > 1) {
  552. $tutor_data .= get_lang('Coachs') . ' : ';
  553. $tutor_data .= array_to_string($email_link, CourseManager::USER_SEPARATOR);
  554. } elseif (count($coachs_email) == 1) {
  555. $tutor_data .= get_lang('Coach') . ' : ';
  556. $tutor_data .= array_to_string($email_link, CourseManager::USER_SEPARATOR);
  557. } elseif (count($coachs_email) == 0) {
  558. $tutor_data .= '';
  559. }
  560. }
  561. $this->assign('session_teachers', $tutor_data);
  562. }
  563. }
  564. if (api_get_setting('show_teacher_data') == 'true') {
  565. // course manager
  566. $id_course = api_get_course_id();
  567. if (isset($id_course) && $id_course != -1) {
  568. $teacher_data = '';
  569. $mail = CourseManager::get_emails_of_tutors_to_course($id_course);
  570. if (!empty($mail)) {
  571. $teachers_parsed = array();
  572. foreach ($mail as $value) {
  573. foreach ($value as $email => $name) {
  574. $teachers_parsed[] = Display::encrypted_mailto_link($email, $name);
  575. }
  576. }
  577. $label = get_lang('Teacher');
  578. if (count($mail) > 1) {
  579. $label = get_lang('Teachers');
  580. }
  581. $teacher_data .= $label . ' : ' . array_to_string($teachers_parsed, CourseManager::USER_SEPARATOR);
  582. }
  583. $this->assign('teachers', $teacher_data);
  584. }
  585. }
  586. /* $stats = '';
  587. $this->assign('execution_stats', $stats); */
  588. }
  589. function show_header_template() {
  590. $tpl = $this->get_template('layout/show_header.tpl');
  591. $this->display($tpl);
  592. }
  593. function show_footer_template() {
  594. $tpl = $this->get_template('layout/show_footer.tpl');
  595. $this->display($tpl);
  596. }
  597. /* Sets the plugin content in a template variable */
  598. function set_plugin_region($plugin_region) {
  599. if (!empty($plugin_region)) {
  600. $region_content = $this->plugin->load_region($plugin_region, $this, $this->force_plugin_load);
  601. if (!empty($region_content)) {
  602. $this->assign('plugin_' . $plugin_region, $region_content);
  603. } else {
  604. $this->assign('plugin_' . $plugin_region, null);
  605. }
  606. }
  607. return null;
  608. }
  609. public function fetch($template = null) {
  610. $template = $this->twig->loadTemplate($template);
  611. return $template->render($this->params);
  612. }
  613. public function assign($tpl_var, $value = null) {
  614. $this->params[$tpl_var] = $value;
  615. }
  616. public function display($template) {
  617. echo $this->twig->render($template, $this->params);
  618. }
  619. }