template.lib.php 35 KB

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