template.lib.php 31 KB

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