';
}
}
$this->assign('help_content', $content);
}
/**
* Use template system to parse the actions menu
* @todo finish it!
**/
public function set_actions($actions)
{
$action_string = '';
if (!empty($actions)) {
foreach ($actions as $action) {
$action_string .= $action;
}
}
$this->assign('actions', $actions);
}
/**
* Shortcut to display a 1 col layout (index.php)
* */
public function display_one_col_template()
{
$tpl = $this->get_template('layout/layout_1_col.tpl');
$this->display($tpl);
}
/**
* Shortcut to display a 2 col layout (userportal.php)
**/
public function display_two_col_template()
{
$tpl = $this->get_template('layout/layout_2_col.tpl');
$this->display($tpl);
}
/**
* Displays an empty template
*/
public function display_blank_template()
{
$tpl = $this->get_template('layout/blank.tpl');
$this->display($tpl);
}
/**
* Displays an empty template
*/
public function displayBlankTemplateNoHeader()
{
$tpl = $this->get_template('layout/blank_no_header.tpl');
$this->display($tpl);
}
/**
* Displays an empty template
*/
public function display_no_layout_template()
{
$tpl = $this->get_template('layout/no_layout.tpl');
$this->display($tpl);
}
/**
* Sets the footer visibility
* @param bool true if we show the footer
*/
public function set_footer($status)
{
$this->show_footer = $status;
$this->assign('show_footer', $status);
}
/**
* return true if toolbar has to be displayed for user
* @return bool
*/
public static function isToolBarDisplayedForUser()
{
//Toolbar
$show_admin_toolbar = api_get_setting('show_admin_toolbar');
$show_toolbar = false;
switch ($show_admin_toolbar) {
case 'do_not_show':
break;
case 'show_to_admin':
if (api_is_platform_admin()) {
$show_toolbar = true;
}
break;
case 'show_to_admin_and_teachers':
if (api_is_platform_admin() || api_is_allowed_to_edit()) {
$show_toolbar = true;
}
break;
case 'show_to_all':
$show_toolbar = true;
break;
}
return $show_toolbar;
}
/**
* Sets the header visibility
* @param bool true if we show the header
*/
public function set_header($status)
{
$this->show_header = $status;
$this->assign('show_header', $status);
$show_toolbar = 0;
if (self::isToolBarDisplayedForUser()) {
$show_toolbar = 1;
}
$this->assign('show_toolbar', $show_toolbar);
//Only if course is available
$show_course_shortcut = null;
$show_course_navigation_menu = null;
if (!empty($this->course_id) && $this->user_is_logged_in) {
if (api_get_setting('show_toolshortcuts') != 'false') {
//Course toolbar
$show_course_shortcut = CourseHome::show_navigation_tool_shortcuts();
}
if (api_get_setting('show_navigation_menu') != 'false') {
//Course toolbar
$show_course_navigation_menu = CourseHome::show_navigation_menu();
}
}
$this->assign('show_course_shortcut', $show_course_shortcut);
$this->assign('show_course_navigation_menu', $show_course_navigation_menu);
}
/**
* Returns the sub-folder and filename for the given tpl file.
* If template not found in overrides/ or custom template folder, the
* default template will be used.
* @param string $name
*
* @return string
*/
public function get_template($name)
{
// Check if the tpl file is present in the main/template/overrides/ dir
// Overrides is a special directory meant for temporary template
// customization. It must be taken into account before anything else
$file = api_get_path(SYS_CODE_PATH).'template/overrides/'.$name;
if (is_readable($file)) {
return 'overrides/'.$name;
}
// If a template folder has been manually defined, search for the right
// file, and if not found, go for the same file in the default template
if ($this->templateFolder != 'default') {
// Avoid missing template error, use the default file.
$file = api_get_path(SYS_CODE_PATH).'template/'.$this->templateFolder.'/'.$name;
if (!file_exists($file)) {
return 'default/'.$name;
}
}
return $this->templateFolder.'/'.$name;
}
/**
* Prepare the _c array for template files. The _c array contains
* information about the current course
* @return void
*/
private function set_course_parameters()
{
//Setting course id
$course = api_get_course_info();
if (empty($course)) {
$this->assign('course_is_set', false);
return;
}
$this->assign('course_is_set', true);
$this->course_id = $course['id'];
$_c = [
'id' => $course['real_id'],
'code' => $course['code'],
'title' => $course['name'],
'visibility' => $course['visibility'],
'language' => $course['language'],
'directory' => $course['directory'],
'session_id' => api_get_session_id(),
'user_is_teacher' => api_is_course_admin(),
'student_view' => (!empty($_GET['isStudentView']) && $_GET['isStudentView'] == 'true'),
];
$this->assign('course_code', $course['code']);
$this->assign('_c', $_c);
}
/**
* Prepare the _u array for template files. The _u array contains
* information about the current user, as returned by
* api_get_user_info()
* @return void
*/
private function set_user_parameters()
{
$user_info = [];
$user_info['logged'] = 0;
$this->user_is_logged_in = false;
if (api_user_is_login()) {
$user_info = api_get_user_info(api_get_user_id(), true);
$user_info['logged'] = 1;
$user_info['is_admin'] = 0;
if (api_is_platform_admin()) {
$user_info['is_admin'] = 1;
}
$user_info['messages_count'] = MessageManager::getCountNewMessages();
$this->user_is_logged_in = true;
}
// Setting the $_u array that could be use in any template
$this->assign('_u', $user_info);
}
/**
* Get CSS themes sub-directory
* @param string $theme
* @return string with a trailing slash, e.g. 'themes/chamilo_red/'
*/
public static function getThemeDir($theme)
{
$themeDir = 'themes/'.$theme.'/';
$virtualTheme = api_get_configuration_value('virtual_css_theme_folder');
if (!empty($virtualTheme)) {
$virtualThemeList = api_get_themes(true);
$isVirtualTheme = in_array($theme, array_keys($virtualThemeList));
if ($isVirtualTheme) {
$themeDir = 'themes/'.$virtualTheme.'/'.$theme.'/';
}
}
return $themeDir;
}
/**
* Get an array of all the web paths available (e.g. 'web' => 'https://my.chamilo.site/')
* @return array
*/
private function getWebPaths()
{
return [
'web' => api_get_path(WEB_PATH),
'web_url' => api_get_web_url(),
'web_relative' => api_get_path(REL_PATH),
'web_course' => api_get_path(WEB_COURSE_PATH),
'web_main' => api_get_path(WEB_CODE_PATH),
'web_css' => api_get_path(WEB_CSS_PATH),
'web_css_theme' => api_get_path(WEB_CSS_PATH).$this->themeDir,
'web_ajax' => api_get_path(WEB_AJAX_PATH),
'web_img' => api_get_path(WEB_IMG_PATH),
'web_plugin' => api_get_path(WEB_PLUGIN_PATH),
'web_lib' => api_get_path(WEB_LIBRARY_PATH),
'web_upload' => api_get_path(WEB_UPLOAD_PATH),
'web_self' => api_get_self(),
'web_query_vars' => api_htmlentities($_SERVER['QUERY_STRING']),
'web_self_query_vars' => api_htmlentities($_SERVER['REQUEST_URI']),
'web_cid_query' => api_get_cidreq(),
];
}
/**
* Set system parameters from api_get_configuration into _s array for use in TPLs
* Also fills the _p array from getWebPaths()
* @uses self::getWebPaths()
*/
public function set_system_parameters()
{
$this->theme = api_get_visual_theme();
if (!empty($this->preview_theme)) {
$this->theme = $this->preview_theme;
}
$this->themeDir = self::getThemeDir($this->theme);
// Setting app paths/URLs
$this->assign('_p', $this->getWebPaths());
// Here we can add system parameters that can be use in any template
$_s = [
'software_name' => api_get_configuration_value('software_name'),
'system_version' => api_get_configuration_value('system_version'),
'site_name' => api_get_setting('siteName'),
'institution' => api_get_setting('Institution'),
'date' => api_format_date('now', DATE_FORMAT_LONG),
'timezone' => api_get_timezone(),
'gamification_mode' => api_get_setting('gamification_mode')
];
$this->assign('_s', $_s);
}
/**
* Set theme, include mainstream CSS files
* @return void
* @see setCssCustomFiles() for additional CSS sheets
*/
public function setCssFiles()
{
global $disable_js_and_css_files;
$css = [];
// Default CSS Bootstrap
$bowerCSSFiles = [
'fontawesome/css/font-awesome.min.css',
'jquery-ui/themes/smoothness/theme.css',
'jquery-ui/themes/smoothness/jquery-ui.min.css',
'mediaelement/build/mediaelementplayer.min.css',
'jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.min.css',
'bootstrap/dist/css/bootstrap.min.css',
'jquery.scrollbar/jquery.scrollbar.css',
'bootstrap-daterangepicker/daterangepicker.css',
'bootstrap-select/dist/css/bootstrap-select.min.css',
'select2/dist/css/select2.min.css',
'flag-icon-css/css/flag-icon.min.css'
];
foreach ($bowerCSSFiles as $file) {
$css[] = api_get_path(WEB_PUBLIC_PATH).'assets/'.$file;
}
$css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/chosen/chosen.css';
if (api_is_global_chat_enabled()) {
$css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/chat/css/chat.css';
}
$css_file_to_string = '';
foreach ($css as $file) {
$css_file_to_string .= api_get_css($file);
}
if (!$disable_js_and_css_files) {
$this->assign('css_static_file_to_string', $css_file_to_string);
}
}
/**
*
*/
public function setCSSEditor()
{
$cssEditor = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'editor.css');
if (is_file(api_get_path(SYS_CSS_PATH).$this->themeDir.'editor.css')) {
$cssEditor = api_get_path(WEB_CSS_PATH).$this->themeDir.'editor.css';
}
$this->assign('cssEditor', $cssEditor);
}
/**
* Prepare custom CSS to be added at the very end of the section
* @return void
* @see setCssFiles() for the mainstream CSS files
*/
public function setCssCustomFiles()
{
global $disable_js_and_css_files;
// Base CSS
$css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'base.css');
if ($this->show_learnpath) {
$css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'scorm.css');
if (is_file(api_get_path(SYS_CSS_PATH).$this->themeDir.'learnpath.css')) {
$css[] = api_get_path(WEB_CSS_PATH).$this->themeDir.'learnpath.css';
}
}
$css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).$this->themeDir.'default.css');
$css_file_to_string = null;
foreach ($css as $file) {
$css_file_to_string .= api_get_css($file);
}
// @todo move this somewhere else. Special fix when using tablets in order to see the text near icons
if (SHOW_TEXT_NEAR_ICONS == true) {
//hack in order to fix the actions buttons
$css_file_to_string .= '';
}
$navigator_info = api_get_navigator();
if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
$css_file_to_string .= 'img, div { behavior: url('.api_get_path(WEB_LIBRARY_PATH).'javascript/iepngfix/iepngfix.htc) } '."\n";
}
if (!$disable_js_and_css_files) {
$this->assign('css_custom_file_to_string', $css_file_to_string);
$style_print = '';
if (is_readable(api_get_path(SYS_CSS_PATH).$this->theme.'/print.css')) {
$style_print = api_get_css(
api_get_cdn_path(api_get_path(WEB_CSS_PATH).$this->theme.'/print.css'),
'print'
);
}
$this->assign('css_style_print', $style_print);
}
// Logo
$logo = return_logo($this->theme);
$this->assign('logo', $logo);
$this->assign('show_media_element', 1);
}
/**
* Declare and define the template variable that will be used to load
* javascript libraries in the header.
*/
public function set_js_files()
{
global $disable_js_and_css_files, $htmlHeadXtra;
$isoCode = api_get_language_isocode();
$selectLink = 'bootstrap-select/dist/js/i18n/defaults-'.$isoCode.'_'.strtoupper($isoCode).'.min.js';
if ($isoCode == 'en') {
$selectLink = 'bootstrap-select/dist/js/i18n/defaults-'.$isoCode.'_US.min.js';
}
// JS files
$js_files = [
'chosen/chosen.jquery.min.js'
];
$viewBySession = api_get_setting('my_courses_view_by_session') === 'true';
if (api_is_global_chat_enabled() || $viewBySession) {
// Do not include the global chat in LP
if ($this->show_learnpath == false &&
$this->show_footer == true &&
$this->hide_global_chat == false
) {
$js_files[] = 'chat/js/chat.js';
}
}
if (api_get_setting('accessibility_font_resize') == 'true') {
$js_files[] = 'fontresize.js';
}
$js_file_to_string = '';
$bowerJsFiles = [
'modernizr/modernizr.js',
'jquery/dist/jquery.min.js',
'bootstrap/dist/js/bootstrap.min.js',
'jquery-ui/jquery-ui.min.js',
'moment/min/moment-with-locales.js',
'bootstrap-daterangepicker/daterangepicker.js',
'jquery-timeago/jquery.timeago.js',
'mediaelement/build/mediaelement-and-player.min.js',
'jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.min.js',
'image-map-resizer/js/imageMapResizer.min.js',
'jquery.scrollbar/jquery.scrollbar.min.js',
'readmore-js/readmore.min.js',
'bootstrap-select/dist/js/bootstrap-select.min.js',
$selectLink,
'select2/dist/js/select2.min.js',
"select2/dist/js/i18n/$isoCode.js"
];
if (CHAMILO_LOAD_WYSIWYG == true) {
$bowerJsFiles[] = 'ckeditor/ckeditor.js';
}
if (api_get_setting('include_asciimathml_script') == 'true') {
$bowerJsFiles[] = 'MathJax/MathJax.js?config=TeX-MML-AM_HTMLorMML';
}
if ($isoCode != 'en') {
$bowerJsFiles[] = 'jqueryui-timepicker-addon/dist/i18n/jquery-ui-timepicker-'.$isoCode.'.js';
$bowerJsFiles[] = 'jquery-ui/ui/minified/i18n/datepicker-'.$isoCode.'.min.js';
}
foreach ($bowerJsFiles as $file) {
$js_file_to_string .= ''."\n";
}
foreach ($js_files as $file) {
$js_file_to_string .= api_get_js($file);
}
// Loading email_editor js
if (!api_is_anonymous() && api_get_setting('allow_email_editor') == 'true') {
$template = $this->get_template('mail_editor/email_link.js.tpl');
$js_file_to_string .= $this->fetch($template);
}
if (!$disable_js_and_css_files) {
$this->assign('js_file_to_string', $js_file_to_string);
$extra_headers = '';
//Adding jquery ui by default
$extra_headers .= api_get_jquery_ui_js();
//$extra_headers = '';
if (isset($htmlHeadXtra) && $htmlHeadXtra) {
foreach ($htmlHeadXtra as & $this_html_head) {
$extra_headers .= $this_html_head."\n";
}
}
$this->assign('extra_headers', $extra_headers);
}
}
/**
* Special function to declare last-minute JS libraries which depend on
* other things to be declared first. In particular, it might be useful
* under IE9 with compatibility mode, which for some reason is getting
* upset when a variable is used in a function (even if not used yet)
* when this variable hasn't been defined yet.
*/
public function set_js_files_post()
{
global $disable_js_and_css_files;
$js_files = [];
if (api_is_global_chat_enabled()) {
//Do not include the global chat in LP
if ($this->show_learnpath == false && $this->show_footer == true && $this->hide_global_chat == false) {
$js_files[] = 'chat/js/chat.js';
}
}
$js_file_to_string = null;
foreach ($js_files as $js_file) {
$js_file_to_string .= api_get_js($js_file);
}
if (!$disable_js_and_css_files) {
$this->assign('js_file_to_string_post', $js_file_to_string);
}
}
/**
* Set header parameters
* @param bool $sendHeaders send headers
*/
private function set_header_parameters($sendHeaders)
{
global $httpHeadXtra, $interbreadcrumb, $language_file, $_configuration, $this_section;
$_course = api_get_course_info();
$nameTools = $this->title;
$navigation = return_navigation_array();
$this->menu_navigation = $navigation['menu_navigation'];
$this->assign('system_charset', api_get_system_encoding());
if (isset($httpHeadXtra) && $httpHeadXtra) {
foreach ($httpHeadXtra as & $thisHttpHead) {
header($thisHttpHead);
}
}
$this->assign(
'online_button',
Display::return_icon('statusonline.png', null, [], ICON_SIZE_ATOM)
);
$this->assign(
'offline_button',
Display::return_icon('statusoffline.png', null, [], ICON_SIZE_ATOM)
);
// Get language iso-code for this page - ignore errors
$this->assign('document_language', api_get_language_isocode());
$course_title = isset($_course['name']) ? $_course['name'] : null;
$title_list = [];
$title_list[] = api_get_setting('Institution');
$title_list[] = api_get_setting('siteName');
if (!empty($course_title)) {
$title_list[] = $course_title;
}
if ($nameTools != '') {
$title_list[] = $nameTools;
}
$title_string = '';
for ($i = 0; $i < count($title_list); $i++) {
$title_string .= $title_list[$i];
if (isset($title_list[$i + 1])) {
$item = trim($title_list[$i + 1]);
if (!empty($item)) {
$title_string .= ' - ';
}
}
}
$this->assign('title_string', $title_string);
// Setting the theme and CSS files
$this->setCssFiles();
$this->set_js_files();
$this->setCssCustomFiles();
$browser = api_browser_support('check_browser');
if ($browser[0] == 'Internet Explorer' && $browser[1] >= '11') {
$browser_head = '';
$this->assign('browser_specific_head', $browser_head);
}
// Implementation of prefetch.
// See http://cdn.chamilo.org/main/img/online.png for details
$prefetch = '';
if (!empty($_configuration['cdn_enable'])) {
$prefetch .= '';
foreach ($_configuration['cdn'] as $host => $exts) {
$prefetch .= '';
}
}
$this->assign('prefetch', $prefetch);
$this->assign('text_direction', api_get_text_direction());
$this->assign('section_name', 'section-'.$this_section);
// Default root chamilo favicon
$favico = '';
//Added to verify if in the current Chamilo Theme exist a favicon
$favicoThemeUrl = api_get_path(SYS_CSS_PATH).$this->themeDir.'images/';
//If exist pick the current chamilo theme favicon
if (is_file($favicoThemeUrl.'favicon.ico')) {
$favico = '';
}
if (api_is_multiple_url_enabled()) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$url_info = api_get_access_url($access_url_id);
$url = api_remove_trailing_slash(
preg_replace('/https?:\/\//i', '', $url_info['url'])
);
$clean_url = api_replace_dangerous_char($url);
$clean_url = str_replace('/', '-', $clean_url);
$clean_url .= '/';
$homep = api_get_path(REL_PATH).'home/'.$clean_url; //homep for Home Path
$icon_real_homep = api_get_path(SYS_APP_PATH).'home/'.$clean_url;
//we create the new dir for the new sites
if (is_file($icon_real_homep.'favicon.ico')) {
$favico = '';
}
}
}
$this->assign('favico', $favico);
$this->setHelp();
//@todo move this in the template
$rightFloatMenu = '';
$iconBug = Display::return_icon(
'bug.png',
get_lang('ReportABug'),
[],
ICON_SIZE_LARGE
);
if (api_get_setting('show_link_bug_notification') == 'true' && $this->user_is_logged_in) {
$rightFloatMenu = '