template.lib.php 29 KB

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