public function exportHeader()
{
$this->initSpecificVariables();
global $crlf, $cfg, $db;
$table = $this->_getTable();
$tables = $this->_getTables();
$export_struct = isset($GLOBALS['xml_export_functions']) || isset($GLOBALS['xml_export_procedures']) || isset($GLOBALS['xml_export_tables']) || isset($GLOBALS['xml_export_triggers']) || isset($GLOBALS['xml_export_views']);
$export_data = isset($GLOBALS['xml_export_contents']) ? true : false;
if ($GLOBALS['output_charset_conversion']) {
$charset = $GLOBALS['charset'];
} else {
$charset = 'utf-8';
}
$head = '<?xml version="1.0" encoding="' . $charset . '"?>' . $crlf . '<!--' . $crlf . '- phpMyAdmin XML Dump' . $crlf . '- version ' . PMA_VERSION . $crlf . '- https://www.phpmyadmin.net' . $crlf . '-' . $crlf . '- ' . __('Host:') . ' ' . htmlspecialchars($cfg['Server']['host']);
if (!empty($cfg['Server']['port'])) {
$head .= ':' . $cfg['Server']['port'];
}
$head .= $crlf . '- ' . __('Generation Time:') . ' ' . Util::localisedDate() . $crlf . '- ' . __('Server version:') . ' ' . PMA_MYSQL_STR_VERSION . $crlf . '- ' . __('PHP Version:') . ' ' . phpversion() . $crlf . '-->' . $crlf . $crlf;
$head .= '<pma_xml_export version="1.0"' . ($export_struct ? ' xmlns:pma="https://www.phpmyadmin.net/some_doc_url/"' : '') . '>' . $crlf;
if ($export_struct) {
$result = $GLOBALS['dbi']->fetchResult('SELECT `DEFAULT_CHARACTER_SET_NAME`, `DEFAULT_COLLATION_NAME`' . ' FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME`' . ' = \'' . $GLOBALS['dbi']->escapeString($db) . '\' LIMIT 1');
$db_collation = $result[0]['DEFAULT_COLLATION_NAME'];
$db_charset = $result[0]['DEFAULT_CHARACTER_SET_NAME'];
$head .= ' <!--' . $crlf;
$head .= ' - Structure schemas' . $crlf;
$head .= ' -->' . $crlf;
$head .= ' <pma:structure_schemas>' . $crlf;
$head .= ' <pma:database name="' . htmlspecialchars($db) . '" collation="' . htmlspecialchars($db_collation) . '" charset="' . htmlspecialchars($db_charset) . '">' . $crlf;
if (count($tables) == 0) {
$tables[] = $table;
}
foreach ($tables as $table) {
// Export tables and views
$result = $GLOBALS['dbi']->fetchResult('SHOW CREATE TABLE ' . Util::backquote($db) . '.' . Util::backquote($table), 0);
$tbl = $result[$table][1];
$is_view = $GLOBALS['dbi']->getTable($db, $table)->isView();
if ($is_view) {
$type = 'view';
} else {
$type = 'table';
}
if ($is_view && !isset($GLOBALS['xml_export_views'])) {
continue;
}
if (!$is_view && !isset($GLOBALS['xml_export_tables'])) {
continue;
}
$head .= ' <pma:' . $type . ' name="' . htmlspecialchars($table) . '">' . $crlf;
$tbl = " " . htmlspecialchars($tbl);
$tbl = str_replace("\n", "\n ", $tbl);
$head .= $tbl . ';' . $crlf;
$head .= ' </pma:' . $type . '>' . $crlf;
if (isset($GLOBALS['xml_export_triggers']) && $GLOBALS['xml_export_triggers']) {
// Export triggers
$triggers = $GLOBALS['dbi']->getTriggers($db, $table);
if ($triggers) {
foreach ($triggers as $trigger) {
$code = $trigger['create'];
$head .= ' <pma:trigger name="' . htmlspecialchars($trigger['name']) . '">' . $crlf;
// Do some formatting
$code = mb_substr(rtrim($code), 0, -3);
$code = " " . htmlspecialchars($code);
$code = str_replace("\n", "\n ", $code);
$head .= $code . $crlf;
$head .= ' </pma:trigger>' . $crlf;
}
unset($trigger);
unset($triggers);
}
}
}
if (isset($GLOBALS['xml_export_functions']) && $GLOBALS['xml_export_functions']) {
$head .= $this->_exportRoutines($db, 'function', 'FUNCTION');
}
if (isset($GLOBALS['xml_export_procedures']) && $GLOBALS['xml_export_procedures']) {
$head .= $this->_exportRoutines($db, 'procedure', 'PROCEDURE');
}
if (isset($GLOBALS['xml_export_events']) && $GLOBALS['xml_export_events']) {
// Export events
$events = $GLOBALS['dbi']->fetchResult("SELECT EVENT_NAME FROM information_schema.EVENTS " . "WHERE EVENT_SCHEMA='" . $GLOBALS['dbi']->escapeString($db) . "'");
$head .= $this->_exportDefinitions($db, 'event', 'EVENT', $events);
}
unset($result);
$head .= ' </pma:database>' . $crlf;
$head .= ' </pma:structure_schemas>' . $crlf;
if ($export_data) {
$head .= $crlf;
}
}
return PMA_exportOutputHandler($head);
}