assign('user_in_anon_survey', $userInAnonSurvey); // Fixing tools with any help it takes xxx part of main/xxx/index.php if (empty($help)) { $currentURL = api_get_self(); preg_match('/main\/([^*\/]+)/', $currentURL, $matches); $toolList = self::toolList(); if (!empty($matches)) { foreach ($matches as $match) { if (in_array($match, $toolList)) { $help = explode('_', $match); $help = array_map('ucfirst', $help); $help = implode('', $help); break; } } } } self::$global_template->setHelp($help); if (!empty(self::$preview_style)) { self::$global_template->preview_theme = self::$preview_style; self::$global_template->set_system_parameters(); self::$global_template->setCssFiles(); self::$global_template->set_js_files(); self::$global_template->setCssCustomFiles(); } if (!empty($page_header)) { self::$global_template->assign('header', $page_header); } echo self::$global_template->show_header_template(); } /** * Displays the reduced page header (without banner). */ public static function display_reduced_header() { global $show_learnpath, $tool_name; self::$global_template = new Template( $tool_name, false, false, $show_learnpath ); echo self::$global_template->show_header_template(); } /** * Display no header. */ public static function display_no_header() { global $tool_name, $show_learnpath; $disable_js_and_css_files = true; self::$global_template = new Template( $tool_name, false, false, $show_learnpath ); } /** * Display the page footer. */ public static function display_footer() { $contents = ob_get_contents(); if (ob_get_length()) { ob_end_clean(); } $tpl = '@ChamiloTheme/Layout/layout_one_col.html.twig'; $response = new Response(); $params['content'] = $contents; global $interbreadcrumb, $htmlHeadXtra; $params['legacy_javascript'] = $htmlHeadXtra; $params['legacy_breadcrumb'] = $interbreadcrumb; $flash = Display::getFlashToString(); Display::cleanFlashMessages(); $params['flash_messages'] = $flash; $content = Container::getTemplating()->render($tpl, $params); $response->setContent($content); $response->send(); exit; } /** * Display the page footer. */ public static function display_reduced_footer() { echo self::$global_template->show_footer_js_template(); echo ''; } /** * Displays the tool introduction of a tool. * * @author Patrick Cool , Ghent University * * @param string $tool these are the constants that are used for indicating the tools * @param array $editor_config Optional configuration settings for the online editor. * return: $tool return a string array list with the "define" in main_api.lib * * @return string html code for adding an introduction */ public static function display_introduction_section( $tool, $editor_config = null ) { echo self::return_introduction_section($tool, $editor_config); } /** * @param string $tool * @param array $editor_config */ public static function return_introduction_section( $tool, $editor_config = null ) { $moduleId = $tool; if (api_get_setting('enable_tool_introduction') == 'true' || $tool == TOOL_COURSE_HOMEPAGE) { $introduction_section = null; require api_get_path(SYS_INC_PATH).'introductionSection.inc.php'; return $introduction_section; } } /** * Displays a table. * * @param array $header Titles for the table header * each item in this array can contain 3 values * - 1st element: the column title * - 2nd element: true or false (column sortable?) * - 3th element: additional attributes for * th-tag (eg for column-width) * - 4the element: additional attributes for the td-tags * @param array $content 2D-array with the tables content * @param array $sorting_options Keys are: * 'column' = The column to use as sort-key * 'direction' = SORT_ASC or SORT_DESC * @param array $paging_options Keys are: * 'per_page_default' = items per page when switching from * full- list to per-page-view * 'per_page' = number of items to show per page * 'page_nr' = The page to display * @param array $query_vars Additional variables to add in the query-string * @param array $form_actions * @param string $style The style that the table will show. You can set 'table' or 'grid' * @param string $tableName * @param string $tableId * * @author bart.mollet@hogent.be */ public static function display_sortable_table( $header, $content, $sorting_options = [], $paging_options = [], $query_vars = null, $form_actions = [], $style = 'table', $tableName = 'tablename', $tableId = '' ) { $column = isset($sorting_options['column']) ? $sorting_options['column'] : 0; $default_items_per_page = isset($paging_options['per_page']) ? $paging_options['per_page'] : 20; $table = new SortableTableFromArray($content, $column, $default_items_per_page, $tableName, null, $tableId); if (is_array($query_vars)) { $table->set_additional_parameters($query_vars); } if ($style == 'table') { if (is_array($header) && count($header) > 0) { foreach ($header as $index => $header_item) { $table->set_header( $index, isset($header_item[0]) ? $header_item[0] : null, isset($header_item[1]) ? $header_item[1] : null, isset($header_item[2]) ? $header_item[2] : null, isset($header_item[3]) ? $header_item[3] : null ); } } $table->set_form_actions($form_actions); $table->display(); } else { $table->display_grid(); } } /** * Returns an HTML table with sortable column (through complete page refresh). * * @param array $header * @param array $content Array of row arrays * @param array $sorting_options * @param array $paging_options * @param array $query_vars * @param array $form_actions * @param string $style * * @return string HTML string for array */ public static function return_sortable_table( $header, $content, $sorting_options = [], $paging_options = [], $query_vars = null, $form_actions = [], $style = 'table' ) { ob_start(); self::display_sortable_table( $header, $content, $sorting_options, $paging_options, $query_vars, $form_actions, $style ); $content = ob_get_contents(); ob_end_clean(); return $content; } /** * Shows a nice grid. * * @param string grid name (important to create css) * @param array header content * @param array array with the information to show * @param array $paging_options Keys are: * 'per_page_default' = items per page when switching from * full- list to per-page-view * 'per_page' = number of items to show per page * 'page_nr' = The page to display * 'hide_navigation' = true to hide the navigation * @param array $query_vars Additional variables to add in the query-string * @param array $form actions Additional variables to add in the query-string * @param mixed An array with bool values to know which columns show. * i.e: $visibility_options= array(true, false) we will only show the first column * Can be also only a bool value. TRUE: show all columns, FALSE: show nothing */ public static function display_sortable_grid( $name, $header, $content, $paging_options = [], $query_vars = null, $form_actions = [], $visibility_options = true, $sort_data = true, $grid_class = [] ) { echo self::return_sortable_grid( $name, $header, $content, $paging_options, $query_vars, $form_actions, $visibility_options, $sort_data, $grid_class ); } /** * Gets a nice grid in html string. * * @param string grid name (important to create css) * @param array header content * @param array array with the information to show * @param array $paging_options Keys are: * 'per_page_default' = items per page when switching from * full- list to per-page-view * 'per_page' = number of items to show per page * 'page_nr' = The page to display * 'hide_navigation' = true to hide the navigation * @param array $query_vars Additional variables to add in the query-string * @param array $form actions Additional variables to add in the query-string * @param mixed An array with bool values to know which columns show. i.e: * $visibility_options= array(true, false) we will only show the first column * Can be also only a bool value. TRUE: show all columns, FALSE: show nothing * @param bool true for sorting data or false otherwise * @param array grid classes * * @return string html grid */ public static function return_sortable_grid( $name, $header, $content, $paging_options = [], $query_vars = null, $form_actions = [], $visibility_options = true, $sort_data = true, $grid_class = [], $elementCount = 0 ) { $column = 0; $default_items_per_page = isset($paging_options['per_page']) ? $paging_options['per_page'] : 20; $table = new SortableTableFromArray($content, $column, $default_items_per_page, $name); $table->total_number_of_items = intval($elementCount); if (is_array($query_vars)) { $table->set_additional_parameters($query_vars); } return $table->display_simple_grid( $visibility_options, $paging_options['hide_navigation'], $default_items_per_page, $sort_data, $grid_class ); } /** * Displays a table with a special configuration. * * @param array $header Titles for the table header * each item in this array can contain 3 values * - 1st element: the column title * - 2nd element: true or false (column sortable?) * - 3th element: additional attributes for th-tag (eg for column-width) * - 4the element: additional attributes for the td-tags * @param array $content 2D-array with the tables content * @param array $sorting_options Keys are: * 'column' = The column to use as sort-key * 'direction' = SORT_ASC or SORT_DESC * @param array $paging_options Keys are: * 'per_page_default' = items per page when switching from full list to per-page-view * 'per_page' = number of items to show per page * 'page_nr' = The page to display * @param array $query_vars Additional variables to add in the query-string * @param array $column_show Array of binaries 1= show columns 0. hide a column * @param array $column_order An array of integers that let us decide how the columns are going to be sort. * i.e: $column_order=array('1''4','3','4'); The 2nd column will be order like the 4th column * @param array $form_actions Set optional forms actions * * @author Julio Montoya */ public static function display_sortable_config_table( $table_name, $header, $content, $sorting_options = [], $paging_options = [], $query_vars = null, $column_show = [], $column_order = [], $form_actions = [] ) { $column = isset($sorting_options['column']) ? $sorting_options['column'] : 0; $default_items_per_page = isset($paging_options['per_page']) ? $paging_options['per_page'] : 20; $table = new SortableTableFromArrayConfig( $content, $column, $default_items_per_page, $table_name, $column_show, $column_order ); if (is_array($query_vars)) { $table->set_additional_parameters($query_vars); } // Show or hide the columns header if (is_array($column_show)) { for ($i = 0; $i < count($column_show); $i++) { if (!empty($column_show[$i])) { $val0 = isset($header[$i][0]) ? $header[$i][0] : null; $val1 = isset($header[$i][1]) ? $header[$i][1] : null; $val2 = isset($header[$i][2]) ? $header[$i][2] : null; $val3 = isset($header[$i][3]) ? $header[$i][3] : null; $table->set_header($i, $val0, $val1, $val2, $val3); } } } $table->set_form_actions($form_actions); $table->display(); } /** * Returns a div html string with. * * @param string $message * @param string $type Example: confirm, normal, warning, error * @param bool $filter Whether to XSS-filter or not * * @return string Message wrapped into an HTML div */ public static function return_message( $message, $type = 'normal', $filter = true ) { if (empty($message)) { return ''; } if ($filter) { $message = api_htmlentities( $message, ENT_QUOTES, api_is_xml_http_request() ? 'UTF-8' : api_get_system_encoding() ); } $class = ''; switch ($type) { case 'warning': $class .= 'alert alert-warning'; break; case 'error': $class .= 'alert alert-danger'; break; case 'confirmation': case 'confirm': case 'success': $class .= 'alert alert-success'; break; case 'normal': default: $class .= 'alert alert-info'; } return self::div($message, ['class' => $class]); } /** * Returns an encrypted mailto hyperlink. * * @param string e-mail * @param string clickable text * @param string optional, class from stylesheet * @param bool $addExtraContent * * @return string encrypted mailto hyperlink */ public static function encrypted_mailto_link( $email, $clickable_text = null, $style_class = '', $addExtraContent = false ) { if (is_null($clickable_text)) { $clickable_text = $email; } // "mailto:" already present? if (substr($email, 0, 7) !== 'mailto:') { $email = 'mailto:'.$email; } // Class (stylesheet) defined? if ($style_class !== '') { $style_class = ' class="'.$style_class.'"'; } // Encrypt email $hmail = ''; for ($i = 0; $i < strlen($email); $i++) { $hmail .= '&#'.ord($email[$i]).';'; } $value = api_get_configuration_value('add_user_course_information_in_mailto'); if ($value) { if (api_get_setting('allow_email_editor') === 'false') { $hmail .= '?'; } if (!api_is_anonymous()) { $hmail .= '&subject='.Security::remove_XSS(api_get_setting('siteName')); } if ($addExtraContent) { $content = ''; if (!api_is_anonymous()) { $userInfo = api_get_user_info(); $content .= get_lang('User').': '.$userInfo['complete_name']."\n"; $courseInfo = api_get_course_info(); if (!empty($courseInfo)) { $content .= get_lang('Course').': '; $content .= $courseInfo['name']; $sessionInfo = api_get_session_info(api_get_session_id()); if (!empty($sessionInfo)) { $content .= ' '.$sessionInfo['name'].'
'; } } } $hmail .= '&body='.rawurlencode($content); } } $hclickable_text = ''; // Encrypt clickable text if @ is present if (strpos($clickable_text, '@')) { for ($i = 0; $i < strlen($clickable_text); $i++) { $hclickable_text .= '&#'.ord($clickable_text[$i]).';'; } } else { $hclickable_text = @htmlspecialchars( $clickable_text, ENT_QUOTES, api_get_system_encoding() ); } // Return encrypted mailto hyperlink return ''.$hclickable_text.''; } /** * Returns an mailto icon hyperlink. * * @param string e-mail * @param string icon source file from the icon lib * @param int icon size from icon lib * @param string optional, class from stylesheet * * @return string encrypted mailto hyperlink */ public static function icon_mailto_link( $email, $icon_file = "mail.png", $icon_size = 22, $style_class = '' ) { // "mailto:" already present? if (substr($email, 0, 7) != 'mailto:') { $email = 'mailto:'.$email; } // Class (stylesheet) defined? if ($style_class != '') { $style_class = ' class="'.$style_class.'"'; } // Encrypt email $hmail = ''; for ($i = 0; $i < strlen($email); $i++) { $hmail .= '&#'.ord($email[ $i]).';'; } // icon html code $icon_html_source = self::return_icon( $icon_file, $hmail, '', $icon_size ); // Return encrypted mailto hyperlink return ''.$icon_html_source.''; } /** * Prints an