do not try to display a tab that was not built

This commit is contained in:
Marc Delisle
2009-08-22 11:22:50 +00:00
parent 869571ee16
commit 15441ded5d
233 changed files with 76811 additions and 2473 deletions

View File

@@ -3,6 +3,7 @@
/**
* Set of functions used to build XML dumps of tables
*
* @todo
* @version $Id$
* @package phpMyAdmin-Export-XML
*/
@@ -10,9 +11,6 @@ if (! defined('PHPMYADMIN')) {
exit;
}
/**
*
*/
if (strlen($GLOBALS['db'])) { /* Can't do server export */
if (isset($plugin_list)) {
@@ -23,8 +21,28 @@ if (isset($plugin_list)) {
'options' => array(
array('type' => 'hidden', 'name' => 'data'),
),
'options_text' => 'strOptions',
'options_text' => 'strOptions'
);
/* Export structure */
$plugin_list['xml']['options'][] =
array('type' => 'bgroup', 'name' => 'export_struc', 'text' => 'strXMLExportStructs');
$plugin_list['xml']['options'][] =
array('type' => 'bool', 'name' => 'export_functions', 'text' => 'strXMLExportFunctions');
$plugin_list['xml']['options'][] =
array('type' => 'bool', 'name' => 'export_procedures', 'text' => 'strXMLExportProcedures');
$plugin_list['xml']['options'][] =
array('type' => 'bool', 'name' => 'export_tables', 'text' => 'strXMLExportTables');
$plugin_list['xml']['options'][] =
array('type' => 'bool', 'name' => 'export_triggers', 'text' => 'strXMLExportTriggers');
$plugin_list['xml']['options'][] =
array('type' => 'bool', 'name' => 'export_views', 'text' => 'strXMLExportViews');
$plugin_list['xml']['options'][] =
array('type' => 'egroup');
/* Data */
$plugin_list['xml']['options'][] =
array('type' => 'bool', 'name' => 'export_contents', 'text' => 'strXMLExportContents');
} else {
/**
@@ -46,7 +64,9 @@ function PMA_exportComment($text) {
* @access public
*/
function PMA_exportFooter() {
return TRUE;
$foot = '</pma_xml_export>';
return PMA_exportOutputHandler($foot);
}
/**
@@ -59,6 +79,13 @@ function PMA_exportFooter() {
function PMA_exportHeader() {
global $crlf;
global $cfg;
global $what;
global $db;
global $table;
global $tables;
$export_struct = $GLOBALS[$what . '_export_struc'];
$export_data = $GLOBALS[$what . '_export_contents'];
if ($GLOBALS['output_charset_conversion']) {
$charset = $GLOBALS['charset_of_file'];
@@ -66,9 +93,8 @@ function PMA_exportHeader() {
$charset = $GLOBALS['charset'];
}
$head = '<?xml version="1.0" encoding="' . $charset . '" ?>' . $crlf
$head = '<?xml version="1.0" encoding="' . $charset . '"?>' . $crlf
. '<!--' . $crlf
. '-' . $crlf
. '- phpMyAdmin XML Dump' . $crlf
. '- version ' . PMA_VERSION . $crlf
. '- http://www.phpmyadmin.net' . $crlf
@@ -82,6 +108,132 @@ function PMA_exportHeader() {
. '- ' . $GLOBALS['strServerVersion'] . ': ' . substr(PMA_MYSQL_INT_VERSION, 0, 1) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 1, 2) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 3) . $crlf
. '- ' . $GLOBALS['strPHPVersion'] . ': ' . phpversion() . $crlf
. '-->' . $crlf . $crlf;
$head .= '<pma_xml_export version="1.0"' . (($export_struct) ? ' xmlns:pma="http://www.phpmyadmin.net/some_doc_url/"' : '') . '>' . $crlf;
if ($export_struct) {
$result = PMA_DBI_fetch_result('SELECT `DEFAULT_CHARACTER_SET_NAME`, `DEFAULT_COLLATION_NAME` FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME` = \''.$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="' . $db . '" collation="' . $db_collation . '" charset="' . $db_charset . '">' . $crlf;
if (count($tables) == 0) {
$tables[] = $table;
}
foreach ($tables as $table) {
// Export tables and views
$result = PMA_DBI_fetch_result('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), 0);
$tbl = $result[$table][1];
$is_view = PMA_isView($db, $table);
if ($is_view) {
$type = 'view';
} else {
$type = 'table';
}
if ($is_view && !$GLOBALS[$what . '_export_views']) {
continue;
}
if (!$is_view && !$GLOBALS[$what . '_export_tables']) {
continue;
}
$head .= ' <pma:' . $type . ' name="' . $table . '">' . $crlf;
$tbl = " " . $tbl;
$tbl = str_replace("\n", "\n ", $tbl);
$head .= $tbl . ';' . $crlf;
$head .= ' </pma:' . $type . '>' . $crlf;
if ($GLOBALS[$what . '_export_triggers']) {
// Export triggers
$triggers = PMA_DBI_get_triggers($db, $table);
if ($triggers) {
foreach ($triggers as $trigger) {
$code = $trigger['create'];
$head .= ' <pma:trigger name="' . $trigger['name'] . '">' . $crlf;
// Do some formatting
$code = substr(rtrim($code), 0, -3);
$code = " " . $code;
$code = str_replace("\n", "\n ", $code);
$head .= $code . $crlf;
$head .= ' </pma:trigger>' . $crlf;
}
unset($trigger);
unset($triggers);
}
}
}
if ($GLOBALS[$what . '_export_functions']) {
// Export functions
$functions = PMA_DBI_get_procedures_or_functions($db, 'FUNCTION');
if ($functions) {
foreach ($functions as $function) {
$head .= ' <pma:function name="' . $function . '">' . $crlf;
// Do some formatting
$sql = PMA_DBI_get_definition($db, 'FUNCTION', $function);
$sql = rtrim($sql);
$sql = " " . $sql;
$sql = str_replace("\n", "\n ", $sql);
$head .= $sql . $crlf;
$head .= ' </pma:function>' . $crlf;
}
unset($create_func);
unset($function);
unset($functions);
}
}
if ($GLOBALS[$what . '_export_procedures']) {
// Export procedures
$procedures = PMA_DBI_get_procedures_or_functions($db, 'PROCEDURE');
if ($procedures) {
foreach ($procedures as $procedure) {
$head .= ' <pma:procedure name="' . $procedure . '">' . $crlf;
// Do some formatting
$sql = PMA_DBI_get_definition($db, 'PROCEDURE', $procedure);
$sql = rtrim($sql);
$sql = " " . $sql;
$sql = str_replace("\n", "\n ", $sql);
$head .= $sql . $crlf;
$head .= ' </pma:procedure>' . $crlf;
}
unset($create_proc);
unset($procedure);
unset($procedures);
}
}
unset($result);
$head .= ' </pma:database>' . $crlf;
$head .= ' </pma:structure_schemas>' . $crlf;
if ($export_data) {
$head .= $crlf;
}
}
return PMA_exportOutputHandler($head);
}
@@ -96,12 +248,21 @@ function PMA_exportHeader() {
*/
function PMA_exportDBHeader($db) {
global $crlf;
$db = str_replace(' ', '_', $db);
$head = '<!--' . $crlf
. '- ' . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''). $crlf
. '-->' . $crlf
. '<' . $db . '>' . $crlf;
return PMA_exportOutputHandler($head);
global $what;
if ($GLOBALS[$what . '_export_contents'])
{
$head = ' <!--' . $crlf
. ' - ' . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''). $crlf
. ' -->' . $crlf
. ' <database name="' . $db . '">' . $crlf;
return PMA_exportOutputHandler($head);
}
else
{
return TRUE;
}
}
/**
@@ -115,8 +276,16 @@ function PMA_exportDBHeader($db) {
*/
function PMA_exportDBFooter($db) {
global $crlf;
$db = str_replace(' ', '_', $db);
return PMA_exportOutputHandler('</' . $db . '>' . $crlf);
global $what;
if ($GLOBALS[$what . '_export_contents'])
{
return PMA_exportOutputHandler(' </database>' . $crlf);
}
else
{
return TRUE;
}
}
/**
@@ -147,36 +316,41 @@ function PMA_exportDBCreate($db) {
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
$db = str_replace(' ', '_', $db);
$table = str_replace(' ', '_', $table);
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
$columns_cnt = PMA_DBI_num_fields($result);
for ($i = 0; $i < $columns_cnt; $i++) {
$columns[$i] = stripslashes(str_replace(' ', '_', PMA_DBI_field_name($result, $i)));
}
unset($i);
$buffer = ' <!-- ' . $GLOBALS['strTable'] . ' ' . $table . ' -->' . $crlf;
if (!PMA_exportOutputHandler($buffer)) {
return FALSE;
}
while ($record = PMA_DBI_fetch_row($result)) {
$buffer = ' <' . $table . '>' . $crlf;
global $what;
if ($GLOBALS[$what . '_export_contents'])
{
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
$columns_cnt = PMA_DBI_num_fields($result);
for ($i = 0; $i < $columns_cnt; $i++) {
if (isset($record[$i]) && !is_null($record[$i])) {
$buffer .= ' <' . $columns[$i] . '>' . htmlspecialchars($record[$i])
. '</' . $columns[$i] . '>' . $crlf;
}
$columns[$i] = stripslashes(str_replace(' ', '_', PMA_DBI_field_name($result, $i)));
}
$buffer .= ' </' . $table . '>' . $crlf;
unset($i);
$buffer = ' <!-- ' . $GLOBALS['strTable'] . ' ' . $table . ' -->' . $crlf;
if (!PMA_exportOutputHandler($buffer)) {
return FALSE;
}
while ($record = PMA_DBI_fetch_row($result)) {
$buffer = ' <table name="' . htmlspecialchars($table) . '">' . $crlf;
for ($i = 0; $i < $columns_cnt; $i++) {
// If a cell is NULL, still export it to preserve the XML structure
if (!isset($record[$i]) || is_null($record[$i])) {
$record[$i] = 'NULL';
}
$buffer .= ' <column name="' . $columns[$i] . '">' . htmlspecialchars(utf8_encode((string)$record[$i]))
. '</column>' . $crlf;
}
$buffer .= ' </table>' . $crlf;
if (!PMA_exportOutputHandler($buffer)) {
return FALSE;
}
}
PMA_DBI_free_result($result);
}
PMA_DBI_free_result($result);
return TRUE;
} // end of the 'PMA_getTableXML()' function