From 6e17c995fbf13d13ebdc49ea129ece76d0cbf909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Wed, 26 Apr 2006 16:33:59 +0000 Subject: [PATCH] Convert export to plugin architecture, so that plugins are independant piece of code (RFE #1325937). --- ChangeLog | 3 + libraries/config.default.php | 6 +- libraries/display_export.lib.php | 732 ++----------------------------- libraries/export/csv.php | 87 ++-- libraries/export/excel.php | 25 ++ libraries/export/htmlexcel.php | 19 +- libraries/export/htmlword.php | 19 +- libraries/export/latex.php | 64 ++- libraries/export/pdf.php | 12 + libraries/export/sql.php | 199 +++++++-- libraries/export/xls.php | 34 +- libraries/export/xml.php | 14 + 12 files changed, 419 insertions(+), 795 deletions(-) create mode 100644 libraries/export/excel.php diff --git a/ChangeLog b/ChangeLog index 9dfe9d1b7..8c7ee54cf 100755 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,9 @@ $Source$ * css/phpmyadmin.css.php, themes/darkblue_orange/css/theme_right.css.php, themes/original/css/theme_right.css.php: New style for non table forms used in plugins. + * libraries/config.default.php, libraries/display_export.lib.php, + libraries/export/*: Convert export to plugin architecture, so that + plugins are independant piece of code (RFE #1325937). 2006-04-26 Sebastian Mendel * themes/*: diff --git a/libraries/config.default.php b/libraries/config.default.php index 00783127d..00873ecaf 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -271,7 +271,7 @@ $cfg['Export']['xls_null'] = 'NULL'; $cfg['Export']['csv_columns'] = FALSE; $cfg['Export']['csv_null'] = 'NULL'; $cfg['Export']['csv_separator'] = ';'; -$cfg['Export']['csv_enclosed'] = '"'; +$cfg['Export']['csv_enclosed'] = '"'; $cfg['Export']['csv_escaped'] = '\\'; $cfg['Export']['csv_terminated'] = 'AUTO'; $cfg['Export']['excel_columns'] = FALSE; @@ -286,6 +286,10 @@ $cfg['Export']['latex_comments'] = TRUE; $cfg['Export']['latex_mime'] = TRUE; $cfg['Export']['latex_null'] = '\textit{NULL}'; $cfg['Export']['latex_caption'] = TRUE; +$cfg['Export']['latex_structure_caption'] = 'strLatexStructure'; +$cfg['Export']['latex_structure_continued_caption'] = 'strLatexStructure strLatexContinued'; +$cfg['Export']['latex_data_caption'] = 'strLatexContent'; +$cfg['Export']['latex_data_continued_caption'] = 'strLatexContent strLatexContinued'; $cfg['Export']['latex_data_label'] = 'tab:__TABLE__-data'; $cfg['Export']['latex_structure_label'] = 'tab:__TABLE__-structure'; diff --git a/libraries/display_export.lib.php b/libraries/display_export.lib.php index 3205d262a..0ae9c235b 100644 --- a/libraries/display_export.lib.php +++ b/libraries/display_export.lib.php @@ -8,17 +8,9 @@ require_once './libraries/Table.class.php'; require_once('./libraries/relation.lib.php'); $cfgRelation = PMA_getRelationsParam(); -// Check if we have native MS Excel export using PEAR class Spreadsheet_Excel_Writer -if (!empty($GLOBALS['cfg']['TempDir'])) { - @include_once('Spreadsheet/Excel/Writer.php'); - if (class_exists('Spreadsheet_Excel_Writer')) { - $xls = TRUE; - } else { - $xls = FALSE; - } -} else { - $xls = FALSE; -} + +require_once('./libraries/file_listing.php'); +require_once('./libraries/plugin_interface.lib.php'); function PMA_exportCheckboxCheck($str) { if (isset($GLOBALS['cfg']['Export'][$str]) && $GLOBALS['cfg']['Export'][$str]) { @@ -32,93 +24,41 @@ function PMA_exportIsActive($what, $val) { } } +/* Scan for plugins */ +$export_list = PMA_getPlugins('./libraries/export/', array('export_type' => $export_type, 'single_table' => isset($single_table))); + +/* Fail if we didn't find any plugin */ +if (empty($export_list)) { + $GLOBALS['show_error_header'] = TRUE; + PMA_showMessage($strCanNotLoadExportPlugins); + unset($GLOBALS['show_error_header']); + require('./libraries/footer.inc.php'); +} ?> +
' . "\n"; - } } + +// just to keep this value for possible next display of this form after saving on server +if (isset($single_table)) { + echo '' . "\n"; +} + echo '' . "\n"; if (isset($sql_query)) { echo '' . "\n"; } +echo PMA_pluginGetJavascript($export_list); ?> - - -
@@ -132,642 +72,20 @@ function show_checked_option() {
- - - -
- -
- - - -
- /> - -
- -
- /> - -
- -
- /> - -
- -
- /> - -
- -
- /> - -
- -
- /> - -
- -
- /> - -
- -
- /> - -
- -
- /> - -
- - +
- -
- - '; - echo ( $cfg['ReplaceHelpImg'] ? '' : '(' ) - . $goto_documentation - . ( $cfg['ReplaceHelpImg'] ? - ''
-             .$strDocu . '' - : $strDocu ) - . '' . ($cfg['ReplaceHelpImg'] ? '' : ')'); - ?> - -
- :
- -
- -
- /> - -
- -
- /> - -
- 0) { -?> - - - - -
- - /> - -
- -
- - - onclick=" - if (!this.checked && !document.getElementById('checkbox_sql_data').checked) - return false; - else return true;" /> - - - - /> -
- - /> -
- - /> -
- - /> -
- - :
- - /> -
- - /> -
- - /> -
- - /> -
- -
- -
- - - onclick=" - if (!this.checked && (!document.getElementById('checkbox_sql_structure') || !document.getElementById('checkbox_sql_structure').checked)) - return false; - else return true;" /> - - - /> -
- - /> -
- - -
- - /> -
- - /> -
- - /> -
- - - -
-
- - - -
- - -
- /> - -
- - -
- - - onclick=" - if (!this.checked && !document.getElementById('checkbox_latex_data').checked) - return false; - else return true;" /> - - - - - - - - - - - - - -
-
-
-
- - - /> -
- - /> -
- - /> -
- -
- -
- - - onclick=" - if (!this.checked && (!document.getElementById('checkbox_latex_structure') || !document.getElementById('checkbox_latex_structure').checked)) - return false; - else return true;" /> - - - /> -
- - - - - - - - - - - - - -
-
-
-
-
-
-
- - -
- - - - - - - - - - - - - - - - - - - -
-
-
-
" /> -
-
- /> - -
- - -
- - - - - - - - - - -
- -
- -
- - /> - -
- - -
- - - -
- - -
- -
- /> - -
-
- - -
- - -
- - onclick=" - if (!this.checked && (!document.getElementById('checkbox_htmlword_data') || !document.getElementById('checkbox_htmlword_data').checked)) - return false; - else return true;" /> - -
- -
- - - onclick=" - if (!this.checked && (!document.getElementById('checkbox_htmlword_structure') || !document.getElementById('checkbox_htmlword_structure').checked)) - return false; - else return true;" /> - - - -
- - -
- -
- /> - -
-
-
- - -
- - - -
- - -
- -
- /> - -
-
- - - -
- - - -
- - -
-
- -
- - - -
- + +
diff --git a/libraries/export/csv.php b/libraries/export/csv.php index 180f66a31..a24d36ff0 100644 --- a/libraries/export/csv.php +++ b/libraries/export/csv.php @@ -6,6 +6,23 @@ * Set of functions used to build CSV dumps of tables */ +if (isset($plugin_list)) { + $plugin_list['csv'] = array( + 'text' => 'strStrucCSV', + 'extension' => 'csv', + 'options' => array( + array('type' => 'text', 'name' => 'separator', 'text' => 'strFieldsTerminatedBy'), + array('type' => 'text', 'name' => 'enclosed', 'text' => 'strFieldsEnclosedBy'), + array('type' => 'text', 'name' => 'escaped', 'text' => 'strFieldsEscapedBy'), + array('type' => 'text', 'name' => 'terminated', 'text' => 'strLinesTerminatedBy'), + array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'), + array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'), + array('type' => 'hidden', 'name' => 'data'), + ), + 'options_text' => 'strCSVOptions', + ); +} else { + /** * Outputs comment * @@ -37,29 +54,29 @@ function PMA_exportFooter() { */ function PMA_exportHeader() { global $what; - global $add_character; - global $export_separator; - global $enclosed; - global $escaped; + global $csv_terminated; + global $csv_separator; + global $csv_enclosed; + global $csv_escaped; // Here we just prepare some values for export if ($what == 'excel') { - $add_character = "\015\012"; - $export_separator = isset($GLOBALS['excel_edition']) && $GLOBALS['excel_edition'] == 'mac' ? ';' : ','; - $enclosed = '"'; - $escaped = '"'; - if (isset($GLOBALS['showexcelnames']) && $GLOBALS['showexcelnames'] == 'yes') { - $GLOBALS['showcsvnames'] = 'yes'; + $csv_terminated = "\015\012"; + $csv_separator = isset($GLOBALS['excel_edition']) && $GLOBALS['excel_edition'] == 'mac' ? ';' : ','; + $csv_enclosed = '"'; + $csv_escaped = '"'; + if (isset($GLOBALS['excel_columns'])) { + $GLOBALS['cvs_columns'] = 'yes'; } } else { - if (empty($add_character)) { - $add_character = $GLOBALS['crlf']; + if (empty($csv_terminated)) { + $csv_terminated = $GLOBALS['crlf']; } else { - $add_character = str_replace('\\r', "\015", $add_character); - $add_character = str_replace('\\n', "\012", $add_character); - $add_character = str_replace('\\t', "\011", $add_character); + $csv_terminated = str_replace('\\r', "\015", $csv_terminated); + $csv_terminated = str_replace('\\n', "\012", $csv_terminated); + $csv_terminated = str_replace('\\t', "\011", $csv_terminated); } // end if - $export_separator = str_replace('\\t', "\011", $export_separator); + $csv_separator = str_replace('\\t', "\011", $csv_separator); } return TRUE; } @@ -118,30 +135,30 @@ function PMA_exportDBCreate($db) { */ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { global $what; - global $add_character; - global $export_separator; - global $enclosed; - global $escaped; + global $csv_terminated; + global $csv_separator; + global $csv_enclosed; + global $csv_escaped; // Gets the data from the database $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); $fields_cnt = PMA_DBI_num_fields($result); // If required, get fields name at the first line - if (isset($GLOBALS['showcsvnames']) && $GLOBALS['showcsvnames'] == 'yes') { + if (isset($GLOBALS['cvs_columns'])) { $schema_insert = ''; for ($i = 0; $i < $fields_cnt; $i++) { - if ($enclosed == '') { + if ($csv_enclosed == '') { $schema_insert .= stripslashes(PMA_DBI_field_name($result, $i)); } else { - $schema_insert .= $enclosed - . str_replace($enclosed, $escaped . $enclosed, stripslashes(PMA_DBI_field_name($result, $i))) - . $enclosed; + $schema_insert .= $csv_enclosed + . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, stripslashes(PMA_DBI_field_name($result, $i))) + . $csv_enclosed; } - $schema_insert .= $export_separator; + $schema_insert .= $csv_separator; } // end for $schema_insert =trim(substr($schema_insert, 0, -1)); - if (!PMA_exportOutputHandler($schema_insert . $add_character)) { + if (!PMA_exportOutputHandler($schema_insert . $csv_terminated)) { return FALSE; } } // end if @@ -151,28 +168,28 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { $schema_insert = ''; for ($j = 0; $j < $fields_cnt; $j++) { if (!isset($row[$j]) || is_null($row[$j])) { - $schema_insert .= $GLOBALS[$what . '_replace_null']; + $schema_insert .= $GLOBALS[$what . '_null']; } elseif ($row[$j] == '0' || $row[$j] != '') { // loic1 : always enclose fields if ($what == 'excel') { $row[$j] = ereg_replace("\015(\012)?", "\012", $row[$j]); } - if ($enclosed == '') { + if ($csv_enclosed == '') { $schema_insert .= $row[$j]; } else { - $schema_insert .= $enclosed - . str_replace($enclosed, $escaped . $enclosed, $row[$j]) - . $enclosed; + $schema_insert .= $csv_enclosed + . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) + . $csv_enclosed; } } else { $schema_insert .= ''; } if ($j < $fields_cnt-1) { - $schema_insert .= $export_separator; + $schema_insert .= $csv_separator; } } // end for - if (!PMA_exportOutputHandler($schema_insert . $add_character)) { + if (!PMA_exportOutputHandler($schema_insert . $csv_terminated)) { return FALSE; } } // end while @@ -180,4 +197,6 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { return TRUE; } // end of the 'PMA_getTableCsv()' function + +} ?> diff --git a/libraries/export/excel.php b/libraries/export/excel.php new file mode 100644 index 000000000..67c2e0ac8 --- /dev/null +++ b/libraries/export/excel.php @@ -0,0 +1,25 @@ + 'strStrucExcelCSV', + 'extension' => 'xls', + 'options' => array( + array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'), + array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'), + array('type' => 'select', 'name' => 'edition', 'values' => array('win' => 'Windows', 'mac' => 'Excel 2003 / Macintosh'), 'text' => 'strExcelEdition'), + array('type' => 'hidden', 'name' => 'data'), + ), + 'options_text' => 'strExcelOptions', + ); +} else { + /* Everything rest is coded in csv plugin */ + require('./libraries/export/csv.php'); +} +?> diff --git a/libraries/export/htmlexcel.php b/libraries/export/htmlexcel.php index a3d85d9e0..9dcb4e52a 100644 --- a/libraries/export/htmlexcel.php +++ b/libraries/export/htmlexcel.php @@ -6,6 +6,19 @@ * Set of functions used to build CSV dumps of tables */ +if (isset($plugin_list)) { + $plugin_list['htmlexcel'] = array( + 'text' => 'strHTMLExcel', + 'extension' => 'xsl', + 'options' => array( + array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'), + array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'), + array('type' => 'hidden', 'name' => 'data'), + ), + 'options_text' => 'strHTMLExcelOptions', + ); +} else { + /** * Outputs comment * @@ -130,7 +143,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { $fields_cnt = PMA_DBI_num_fields($result); // If required, get fields name at the first line - if (isset($GLOBALS[$what . '_shownames']) && $GLOBALS[$what . '_shownames'] == 'yes') { + if (isset($GLOBALS[$what . '_columns'])) { $schema_insert = ''; for ($i = 0; $i < $fields_cnt; $i++) { $schema_insert .= '' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . ''; @@ -146,7 +159,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { $schema_insert = ''; for ($j = 0; $j < $fields_cnt; $j++) { if (!isset($row[$j]) || is_null($row[$j])) { - $value = $GLOBALS[$what . '_replace_null']; + $value = $GLOBALS[$what . '_null']; } elseif ($row[$j] == '0' || $row[$j] != '') { $value = $row[$j]; } else { @@ -163,4 +176,6 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { return TRUE; } + +} ?> diff --git a/libraries/export/htmlword.php b/libraries/export/htmlword.php index c9219916f..89bc9da7e 100644 --- a/libraries/export/htmlword.php +++ b/libraries/export/htmlword.php @@ -6,6 +6,21 @@ * Set of functions used to build CSV dumps of tables */ +if (isset($plugin_list)) { + $plugin_list['htmlword'] = array( + 'text' => 'strHTMLWord', + 'extension' => 'doc', + 'options' => array( + array('type' => 'bool', 'name' => 'structure', 'text' => 'strStructure', 'force' => 'data'), + array('type' => 'bgroup', 'name' => 'data', 'text' => 'strData', 'force' => 'structure'), + array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'), + array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'), + array('type' => 'egroup'), + ), + 'options_text' => 'strHTMLWordOptions', + ); +} else { + /** * Outputs comment * @@ -133,7 +148,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) $schema_insert = ''; for ($j = 0; $j < $fields_cnt; $j++) { if (!isset($row[$j]) || is_null($row[$j])) { - $value = $GLOBALS[$what . '_replace_null']; + $value = $GLOBALS[$what . '_null']; } elseif ($row[$j] == '0' || $row[$j] != '') { $value = $row[$j]; } else { @@ -320,4 +335,6 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals return PMA_exportOutputHandler(''); } + +} ?> diff --git a/libraries/export/latex.php b/libraries/export/latex.php index 1a0bf2d65..08ee7c2c3 100644 --- a/libraries/export/latex.php +++ b/libraries/export/latex.php @@ -6,6 +6,62 @@ * Set of functions used to build dumps of tables */ +if (isset($plugin_list)) { + $hide_structure = false; + if ($plugin_param['export_type'] == 'table' && !$plugin_param['single_table']) { + $hide_structure = true; + } + $plugin_list['latex'] = array( + 'text' => 'strLaTeX', + 'extension' => 'tex', + 'options' => array( + array('type' => 'bool', 'name' => 'caption', 'text' => 'strLatexIncludeCaption'), + ), + 'options_text' => 'strLaTeXOptions', + ); + /* Structure options */ + if (!$hide_structure) { + $plugin_list['latex']['options'][] = + array('type' => 'bgroup', 'name' => 'structure', 'text' => 'strStructure', 'force' => 'data'); + $plugin_list['latex']['options'][] = + array('type' => 'text', 'name' => 'structure_caption', 'text' => 'strLatexCaption'); + $plugin_list['latex']['options'][] = + array('type' => 'text', 'name' => 'structure_continued_caption', 'text' => 'strLatexContinuedCaption'); + $plugin_list['latex']['options'][] = + array('type' => 'text', 'name' => 'structure_label', 'text' => 'strLatexLabel'); + if (!empty($GLOBALS['cfgRelation']['relation'])) { + $plugin_list['latex']['options'][] = + array('type' => 'bool', 'name' => 'relation', 'text' => 'strRelations'); + } + if (!empty($GLOBALS['cfgRelation']['commwork']) && PMA_MYSQL_INT_VERSION < 40100) { + $plugin_list['latex']['options'][] = + array('type' => 'bool', 'name' => 'comments', 'text' => 'strComments'); + } + if (!empty($GLOBALS['cfgRelation']['mimework'])) { + $plugin_list['latex']['options'][] = + array('type' => 'bool', 'name' => 'mime', 'text' => 'strMIME_MIMEtype'); + } + $plugin_list['latex']['options'][] = + array('type' => 'egroup'); + } + /* Data */ + $plugin_list['latex']['options'][] = + array('type' => 'bgroup', 'name' => 'data', 'text' => 'strData', 'force' => 'structure'); + $plugin_list['latex']['options'][] = + array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'); + $plugin_list['latex']['options'][] = + array('type' => 'text', 'name' => 'data_caption', 'text' => 'strLatexCaption'); + $plugin_list['latex']['options'][] = + array('type' => 'text', 'name' => 'data_continued_caption', 'text' => 'strLatexContinuedCaption'); + $plugin_list['latex']['options'][] = + array('type' => 'text', 'name' => 'data_label', 'text' => 'strLatexLabel'); + $plugin_list['latex']['options'][] = + array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'); + $plugin_list['latex']['options'][] = + array('type' => 'egroup'); +/* FIXME: force either data or structure */ +} else { + /** * Escapes some special characters for use in TeX/LaTeX * @@ -155,7 +211,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { } // show column names - if (isset($GLOBALS['latex_showcolumns'])) { + if (isset($GLOBALS['latex_columns'])) { $buffer = '\\hline '; for ($i = 0; $i < $columns_cnt; $i++) { $buffer .= '\\multicolumn{1}{|c|}{\\textbf{' . PMA_texEscape(stripslashes($columns[$i])) . '}} & '; @@ -186,7 +242,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { if ( isset($record[$columns[$i]]) && (!function_exists('is_null') || !is_null($record[$columns[$i]]))) { $column_value = PMA_texEscape(stripslashes($record[$columns[$i]])); } else { - $column_value = $GLOBALS['latex_replace_null']; + $column_value = $GLOBALS['latex_null']; } // last column ... no need for & character @@ -244,7 +300,7 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals } } PMA_DBI_free_result($keys_result); - + /** * Gets fields properties */ @@ -414,4 +470,6 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals $buffer = ' \\end{longtable}' . $crlf; return PMA_exportOutputHandler($buffer); } // end of the 'PMA_getTableStructureLaTeX()' function + +} ?> diff --git a/libraries/export/pdf.php b/libraries/export/pdf.php index 623700594..fec269482 100644 --- a/libraries/export/pdf.php +++ b/libraries/export/pdf.php @@ -6,6 +6,17 @@ * Produce a PDF report (export) from a query */ +if (isset($plugin_list)) { + $plugin_list['pdf'] = array( + 'text' => 'strPDF', + 'extension' => 'pdf', + 'options' => array( + array('type' => 'text', 'name' => 'report_title', 'text' => 'strPDFReportTitle'), + array('type' => 'hidden', 'name' => 'data'), + ), + 'options_text' => 'strPDFOptions', + ); +} else { define('FPDF_FONTPATH', './libraries/fpdf/font/'); //if ($charset == 'utf-8') { @@ -399,4 +410,5 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) return TRUE; } // end of the 'PMA_exportData()' function +} ?> diff --git a/libraries/export/sql.php b/libraries/export/sql.php index 263180a5c..15cd4829c 100644 --- a/libraries/export/sql.php +++ b/libraries/export/sql.php @@ -5,6 +5,116 @@ * Set of functions used to build SQL dumps of tables */ +if (isset($plugin_list)) { + $hide_sql = false; + $hide_structure = false; + if ($plugin_param['export_type'] == 'table' && !$plugin_param['single_table']) { + $hide_structure = true; + $hide_sql = true; + } + if (!$hide_sql) { + $plugin_list['sql'] = array( + 'text' => 'strSQL', + 'extension' => 'sql', + 'options' => array( + array('type' => 'text', 'name' => 'header_comment', 'text' => 'strAddHeaderComment'), + array('type' => 'bool', 'name' => 'use_transaction', 'text' => 'strEncloseInTransaction'), + array('type' => 'bool', 'name' => 'disable_fk', 'text' => 'strDisableForeignChecks'), + ), + 'options_text' => 'strSQLOptions', + ); + $compats = PMA_DBI_getCompatibilities(); + if (count($compats) > 0) { + $values = array(); + foreach($compats as $val) { + $values[$val] = $val; + } + $plugin_list['sql']['options'][] = + array('type' => 'select', 'name' => 'compatibility', 'text' => 'strSQLCompatibility', 'values' => $values, 'doc' => array('manual_MySQL_Database_Administration', 'Server_SQL_mode')); + unset($values); + } + + /* Server export options */ + if ($plugin_param['export_type'] == 'server') { + $plugin_list['sql']['options'][] = + array('type' => 'bgroup', 'text' => 'strDatabaseExportOptions'); + $plugin_list['sql']['options'][] = + array('type' => 'bool', 'name' => 'drop_database', 'text' => sprintf($GLOBALS['strAddClause'], 'DROP DATABASE')); + $plugin_list['sql']['options'][] = + array('type' => 'egroup'); + } + + /* Structure options */ + if (!$hide_structure) { + $plugin_list['sql']['options'][] = + array('type' => 'bgroup', 'name' => 'structure', 'text' => 'strStructure', 'force' => 'data'); + if ($plugin_param['export_type'] == 'table') { + if (PMA_Table::_isView($GLOBALS['db'], $GLOBALS['table'])) { + $drop_clause = 'DROP VIEW'; + } else { + $drop_clause = 'DROP TABLE'; + } + } elseif (PMA_MYSQL_INT_VERSION >= 50000) { + $drop_clause = 'DROP TABLE / DROP VIEW'; + } else { + $drop_clause = 'DROP TABLE'; + } + $plugin_list['sql']['options'][] = + array('type' => 'bool', 'name' => 'drop', 'text' => sprintf($GLOBALS['strAddClause'], $drop_clause)); + $plugin_list['sql']['options'][] = + array('type' => 'bool', 'name' => 'if_not_exists', 'text' => sprintf($GLOBALS['strAddClause'], 'IF NOT EXISTS')); + $plugin_list['sql']['options'][] = + array('type' => 'bool', 'name' => 'auto_increment', 'text' => 'strAddAutoIncrement'); + $plugin_list['sql']['options'][] = + array('type' => 'bool', 'name' => 'use_backquotes', 'text' => 'strUseBackquotes'); + + /* MIME stuff etc. */ + $plugin_list['sql']['options'][] = + array('type' => 'bgroup', 'text' => 'strAddIntoComments'); + $plugin_list['sql']['options'][] = + array('type' => 'bool', 'name' => 'dates', 'text' => 'strCreationDates'); + if (!empty($GLOBALS['cfgRelation']['relation'])) { + $plugin_list['sql']['options'][] = + array('type' => 'bool', 'name' => 'relation', 'text' => 'strRelations'); + } + if (!empty($GLOBALS['cfgRelation']['commwork']) && PMA_MYSQL_INT_VERSION < 40100) { + $plugin_list['sql']['options'][] = + array('type' => 'bool', 'name' => 'comments', 'text' => 'strComments'); + } + if (!empty($GLOBALS['cfgRelation']['mimework'])) { + $plugin_list['sql']['options'][] = + array('type' => 'bool', 'name' => 'mime', 'text' => 'strMIME_MIMEtype'); + } + $plugin_list['sql']['options'][] = + array('type' => 'egroup'); + + $plugin_list['sql']['options'][] = + array('type' => 'egroup'); + } + + /* Data */ + $plugin_list['sql']['options'][] = + array('type' => 'bgroup', 'name' => 'data', 'text' => 'strData', 'force' => 'structure'); + $plugin_list['sql']['options'][] = + array('type' => 'bool', 'name' => 'columns', 'text' => 'strCompleteInserts'); + $plugin_list['sql']['options'][] = + array('type' => 'bool', 'name' => 'extended', 'text' => 'strExtendedInserts'); + $plugin_list['sql']['options'][] = + array('type' => 'text', 'name' => 'max_query_size', 'text' => 'strMaximalQueryLength'); + $plugin_list['sql']['options'][] = + array('type' => 'bool', 'name' => 'delayed', 'text' => 'strDelayedInserts'); + $plugin_list['sql']['options'][] = + array('type' => 'bool', 'name' => 'ignore', 'text' => 'strIgnoreInserts'); + $plugin_list['sql']['options'][] = + array('type' => 'bool', 'name' => 'hex_for_binary', 'text' => 'strHexForBinary'); + $plugin_list['sql']['options'][] = + array('type' => 'select', 'name' => 'type', 'text' => 'strSQLExportType', 'values' => array('INSERT', 'UPDATE', 'REPLACE')); + $plugin_list['sql']['options'][] = + array('type' => 'egroup'); +/* FIXME: force either data or structure */ + } +} else { + /** * Marker for comments, -- is needed for ANSI SQL. */ @@ -13,8 +123,8 @@ $GLOBALS['comment_marker'] = '-- '; /** * Avoids undefined variables, use NULL so isset() returns false */ -if ( ! isset( $use_backquotes ) ) { - $use_backquotes = null; +if ( ! isset( $sql_use_backquotes ) ) { + $sql_use_backquotes = null; } /** @@ -42,11 +152,11 @@ function PMA_exportFooter() $foot = ''; - if (isset($GLOBALS['disable_fk'])) { + if (isset($GLOBALS['sql_disable_fk'])) { $foot .= $crlf . 'SET FOREIGN_KEY_CHECKS=1;' . $crlf; } - if (isset($GLOBALS['use_transaction'])) { + if (isset($GLOBALS['sql_use_transaction'])) { $foot .= $crlf . 'COMMIT;' . $crlf; } @@ -82,18 +192,18 @@ function PMA_exportHeader() . $GLOBALS['comment_marker'] . $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['comment_marker'] . $GLOBALS['strPHPVersion'] . ': ' . phpversion() . $crlf; - if (isset($GLOBALS['header_comment']) && !empty($GLOBALS['header_comment'])) { - $lines = explode('\n', $GLOBALS['header_comment']); + if (isset($GLOBALS['sql_header_comment']) && !empty($GLOBALS['sql_header_comment'])) { + $lines = explode('\n', $GLOBALS['sql_header_comment']); $head .= $GLOBALS['comment_marker'] . $crlf . $GLOBALS['comment_marker'] . implode($crlf . $GLOBALS['comment_marker'], $lines) . $crlf . $GLOBALS['comment_marker'] . $crlf; } - if (isset($GLOBALS['disable_fk'])) { + if (isset($GLOBALS['sql_disable_fk'])) { $head .= $crlf . 'SET FOREIGN_KEY_CHECKS=0;' . $crlf; } - if (isset($GLOBALS['use_transaction'])) { + if (isset($GLOBALS['sql_use_transaction'])) { $head .= $crlf .'SET AUTOCOMMIT=0;' . $crlf . 'START TRANSACTION;' . $crlf . $crlf; } @@ -113,12 +223,12 @@ function PMA_exportHeader() function PMA_exportDBCreate($db) { global $crlf; - if (isset($GLOBALS['drop_database'])) { - if (!PMA_exportOutputHandler('DROP DATABASE ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : $db) . ';' . $crlf)) { + if (isset($GLOBALS['sql_drop_database'])) { + if (!PMA_exportOutputHandler('DROP DATABASE ' . (isset($GLOBALS['sql_use_backquotes']) ? PMA_backquote($db) : $db) . ';' . $crlf)) { return FALSE; } } - $create_query = 'CREATE DATABASE ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : $db); + $create_query = 'CREATE DATABASE ' . (isset($GLOBALS['sql_use_backquotes']) ? PMA_backquote($db) : $db); if (PMA_MYSQL_INT_VERSION >= 40101) { $collation = PMA_getDbCollation($db); if (strpos($collation, '_')) { @@ -131,7 +241,7 @@ function PMA_exportDBCreate($db) if (!PMA_exportOutputHandler($create_query)) { return FALSE; } - if (isset($GLOBALS['use_backquotes']) && PMA_MYSQL_INT_VERSION >= 40100 && isset($GLOBALS['sql_compat']) && $GLOBALS['sql_compat'] == 'NONE') { + if (isset($GLOBALS['sql_use_backquotes']) && PMA_MYSQL_INT_VERSION >= 40100 && isset($GLOBALS['sql_compat']) && $GLOBALS['sql_compat'] == 'NONE') { return PMA_exportOutputHandler('USE ' . PMA_backquote($db) . ';' . $crlf); } return PMA_exportOutputHandler('USE ' . $db . ';' . $crlf); @@ -150,7 +260,7 @@ function PMA_exportDBHeader($db) { global $crlf; $head = $GLOBALS['comment_marker'] . $crlf - . $GLOBALS['comment_marker'] . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''). $crlf + . $GLOBALS['comment_marker'] . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['sql_use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''). $crlf . $GLOBALS['comment_marker'] . $crlf; return PMA_exportOutputHandler($head); } @@ -193,8 +303,8 @@ function PMA_exportDBFooter($db) */ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false) { - global $drop; - global $use_backquotes; + global $sql_drop; + global $sql_use_backquotes; global $cfgRelation; global $sql_constraints; @@ -231,19 +341,19 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false) $schema_create .= $new_crlf; - if (!empty($drop)) { + if (!empty($sql_drop)) { if (PMA_Table::_isView($db,$table)) { $drop_clause = 'DROP VIEW'; } else { $drop_clause = 'DROP TABLE'; } - $schema_create .= $drop_clause . ' IF EXISTS ' . PMA_backquote($table, $use_backquotes) . ';' . $crlf; + $schema_create .= $drop_clause . ' IF EXISTS ' . PMA_backquote($table, $sql_use_backquotes) . ';' . $crlf; unset($drop_clause); } // Steve Alberty's patch for complete table dump, // Whether to quote table and fields names or not - if ($use_backquotes) { + if ($sql_use_backquotes) { PMA_DBI_query('SET SQL_QUOTE_SHOW_CREATE = 1'); } else { PMA_DBI_query('SET SQL_QUOTE_SHOW_CREATE = 0'); @@ -264,7 +374,7 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false) } // Should we use IF NOT EXISTS? - if (isset($GLOBALS['if_not_exists'])) { + if (isset($GLOBALS['sql_if_not_exists'])) { $create_query = preg_replace('/^CREATE TABLE/', 'CREATE TABLE IF NOT EXISTS', $create_query); } @@ -357,7 +467,7 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false) function PMA_getTableComments($db, $table, $crlf, $do_relation = false, $do_comments = false, $do_mime = false) { global $cfgRelation; - global $use_backquotes; + global $sql_use_backquotes; global $sql_constraints; $schema_create = ''; @@ -392,32 +502,32 @@ function PMA_getTableComments($db, $table, $crlf, $do_relation = false, $do_comm if (isset($comments_map) && count($comments_map) > 0) { $schema_create .= $crlf . $GLOBALS['comment_marker'] . $crlf - . $GLOBALS['comment_marker'] . $GLOBALS['strCommentsForTable']. ' ' . PMA_backquote($table, $use_backquotes) . ':' . $crlf; + . $GLOBALS['comment_marker'] . $GLOBALS['strCommentsForTable']. ' ' . PMA_backquote($table, $sql_use_backquotes) . ':' . $crlf; foreach ($comments_map AS $comment_field => $comment) { - $schema_create .= $GLOBALS['comment_marker'] . ' ' . PMA_backquote($comment_field, $use_backquotes) . $crlf - . $GLOBALS['comment_marker'] . ' ' . PMA_backquote($comment, $use_backquotes) . $crlf; + $schema_create .= $GLOBALS['comment_marker'] . ' ' . PMA_backquote($comment_field, $sql_use_backquotes) . $crlf + . $GLOBALS['comment_marker'] . ' ' . PMA_backquote($comment, $sql_use_backquotes) . $crlf; } $schema_create .= $GLOBALS['comment_marker'] . $crlf; } if (isset($mime_map) && count($mime_map) > 0) { $schema_create .= $crlf . $GLOBALS['comment_marker'] . $crlf - . $GLOBALS['comment_marker'] . $GLOBALS['strMIMETypesForTable']. ' ' . PMA_backquote($table, $use_backquotes) . ':' . $crlf; + . $GLOBALS['comment_marker'] . $GLOBALS['strMIMETypesForTable']. ' ' . PMA_backquote($table, $sql_use_backquotes) . ':' . $crlf; @reset($mime_map); foreach ($mime_map AS $mime_field => $mime) { - $schema_create .= $GLOBALS['comment_marker'] . ' ' . PMA_backquote($mime_field, $use_backquotes) . $crlf - . $GLOBALS['comment_marker'] . ' ' . PMA_backquote($mime['mimetype'], $use_backquotes) . $crlf; + $schema_create .= $GLOBALS['comment_marker'] . ' ' . PMA_backquote($mime_field, $sql_use_backquotes) . $crlf + . $GLOBALS['comment_marker'] . ' ' . PMA_backquote($mime['mimetype'], $sql_use_backquotes) . $crlf; } $schema_create .= $GLOBALS['comment_marker'] . $crlf; } if ($have_rel) { $schema_create .= $crlf . $GLOBALS['comment_marker'] . $crlf - . $GLOBALS['comment_marker'] . $GLOBALS['strRelationsForTable']. ' ' . PMA_backquote($table, $use_backquotes) . ':' . $crlf; + . $GLOBALS['comment_marker'] . $GLOBALS['strRelationsForTable']. ' ' . PMA_backquote($table, $sql_use_backquotes) . ':' . $crlf; foreach ($res_rel AS $rel_field => $rel) { - $schema_create .= $GLOBALS['comment_marker'] . ' ' . PMA_backquote($rel_field, $use_backquotes) . $crlf - . $GLOBALS['comment_marker'] . ' ' . PMA_backquote($rel['foreign_table'], $use_backquotes) - . ' -> ' . PMA_backquote($rel['foreign_field'], $use_backquotes) . $crlf; + $schema_create .= $GLOBALS['comment_marker'] . ' ' . PMA_backquote($rel_field, $sql_use_backquotes) . $crlf + . $GLOBALS['comment_marker'] . ' ' . PMA_backquote($rel['foreign_table'], $sql_use_backquotes) + . ' -> ' . PMA_backquote($rel['foreign_field'], $sql_use_backquotes) . $crlf; } $schema_create .= $GLOBALS['comment_marker'] . $crlf; } @@ -443,7 +553,7 @@ function PMA_getTableComments($db, $table, $crlf, $do_relation = false, $do_comm */ function PMA_exportStructure($db, $table, $crlf, $error_url, $relation = FALSE, $comments = FALSE, $mime = FALSE, $dates = FALSE) { - $formatted_table_name = (isset($GLOBALS['use_backquotes'])) + $formatted_table_name = (isset($GLOBALS['sql_use_backquotes'])) ? PMA_backquote($table) : '\'' . $table . '\''; $dump = $crlf @@ -483,11 +593,11 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $relation = FALSE, */ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { - global $use_backquotes; + global $sql_use_backquotes; global $rows_cnt; global $current_row; - $formatted_table_name = (isset($GLOBALS['use_backquotes'])) + $formatted_table_name = (isset($GLOBALS['sql_use_backquotes'])) ? PMA_backquote($table) : '\'' . $table . '\''; $head = $crlf @@ -519,9 +629,9 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) for ($j = 0; $j < $fields_cnt; $j++) { if (isset($analyzed_sql[0]['select_expr'][$j]['column'])) { - $field_set[$j] = PMA_backquote($analyzed_sql[0]['select_expr'][$j]['column'], $use_backquotes); + $field_set[$j] = PMA_backquote($analyzed_sql[0]['select_expr'][$j]['column'], $sql_use_backquotes); } else { - $field_set[$j] = PMA_backquote($fields_meta[$j]->name, $use_backquotes); + $field_set[$j] = PMA_backquote($fields_meta[$j]->name, $sql_use_backquotes); } } @@ -531,7 +641,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) if (isset($GLOBALS['sql_ignore'])) { $schema_insert .= 'IGNORE '; } - $schema_insert .= PMA_backquote($table, $use_backquotes) . ' SET '; + $schema_insert .= PMA_backquote($table, $sql_use_backquotes) . ' SET '; } else { // insert or replace if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'replace') { @@ -541,7 +651,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) } // delayed inserts? - if (isset($GLOBALS['delayed'])) { + if (isset($GLOBALS['sql_delayed'])) { $insert_delayed = ' DELAYED'; } else { $insert_delayed = ''; @@ -553,12 +663,12 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) } // scheme for inserting fields - if (isset($GLOBALS['showcolumns'])) { + if (isset($GLOBALS['sql_columns'])) { $fields = implode(', ', $field_set); - $schema_insert = $sql_command . $insert_delayed .' INTO ' . PMA_backquote($table, $use_backquotes) + $schema_insert = $sql_command . $insert_delayed .' INTO ' . PMA_backquote($table, $sql_use_backquotes) . ' (' . $fields . ') VALUES '; } else { - $schema_insert = $sql_command . $insert_delayed .' INTO ' . PMA_backquote($table, $use_backquotes) + $schema_insert = $sql_command . $insert_delayed .' INTO ' . PMA_backquote($table, $sql_use_backquotes) . ' VALUES '; } } @@ -567,7 +677,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) $replace = array('\0', '\n', '\r', '\Z'); $current_row = 0; $query_size = 0; - if (isset($GLOBALS['extended_ins'])) { + if (isset($GLOBALS['sql_extended'])) { $separator = ','; $schema_insert .= $crlf; } else { @@ -589,7 +699,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) // Note: with mysqli, under MySQL 4.1.3, we get the flag // "binary" for those field types (I don't know why) } elseif (stristr($field_flags[$j], 'BINARY') - && isset($GLOBALS['hexforbinary']) + && isset($GLOBALS['sql_hex_for_binary']) && $fields_meta[$j]->type != 'datetime' && $fields_meta[$j]->type != 'date' && $fields_meta[$j]->type != 'time' @@ -623,12 +733,12 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) } else { // Extended inserts case - if (isset($GLOBALS['extended_ins'])) { + if (isset($GLOBALS['sql_extended'])) { if ($current_row == 1) { $insert_line = $schema_insert . '(' . implode(', ', $values) . ')'; } else { $insert_line = '(' . implode(', ', $values) . ')'; - if (isset($GLOBALS['max_query_size']) && $GLOBALS['max_query_size'] > 0 && $query_size + strlen($insert_line) > $GLOBALS['max_query_size']) { + if (isset($GLOBALS['sql_max_query_size']) && $GLOBALS['sql_max_query_size'] > 0 && $query_size + strlen($insert_line) > $GLOBALS['sql_max_query_size']) { if (!PMA_exportOutputHandler(';' . $crlf)) { return FALSE; } @@ -661,4 +771,5 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) return TRUE; } // end of the 'PMA_exportData()' function +} ?> diff --git a/libraries/export/xls.php b/libraries/export/xls.php index 43fef0a33..9dee121e3 100644 --- a/libraries/export/xls.php +++ b/libraries/export/xls.php @@ -2,7 +2,32 @@ /* $Id$ */ // vim: expandtab sw=4 ts=4 sts=4: -require_once('Spreadsheet/Excel/Writer.php'); +// Check if we have native MS Excel export using PEAR class Spreadsheet_Excel_Writer +if (!empty($GLOBALS['cfg']['TempDir'])) { + @include_once('Spreadsheet/Excel/Writer.php'); + if (class_exists('Spreadsheet_Excel_Writer')) { + $xls = TRUE; + } else { + $xls = FALSE; + } +} else { + $xls = FALSE; +} + +if ($xls) { + + if (isset($plugin_list)) { + $plugin_list['xls'] = array( + 'text' => 'strStrucNativeExcel', + 'extension' => 'xls', + 'options' => array( + array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'), + array('type' => 'text', 'name' => 'columns', 'text' => 'strPutColNames'), + array('type' => 'hidden', 'name' => 'data'), + ), + 'options_text' => 'strStrucNativeExcelOptions', + ); + } else { /** * Set of functions used to build MS Excel dumps of tables @@ -135,7 +160,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) $col = 0; // If required, get fields name at the first line - if (isset($GLOBALS['xls_shownames']) && $GLOBALS['xls_shownames'] == 'yes') { + if (isset($GLOBALS['xls_columns']) && $GLOBALS['xls_columns'] == 'yes') { $schema_insert = ''; for ($i = 0; $i < $fields_cnt; $i++) { $worksheet->write(0, $i, stripslashes(PMA_DBI_field_name($result, $i))); @@ -148,7 +173,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) $schema_insert = ''; for ($j = 0; $j < $fields_cnt; $j++) { if (!isset($row[$j]) || is_null($row[$j])) { - $worksheet->write($col, $j, $GLOBALS['xls_replace_null']); + $worksheet->write($col, $j, $GLOBALS['xls_null']); } elseif ($row[$j] == '0' || $row[$j] != '') { // FIXME: we should somehow handle character set here! $worksheet->write($col, $j, $row[$j]); @@ -162,4 +187,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) return TRUE; } + + } +} ?> diff --git a/libraries/export/xml.php b/libraries/export/xml.php index a66f84a27..3618677a4 100644 --- a/libraries/export/xml.php +++ b/libraries/export/xml.php @@ -6,6 +6,18 @@ * Set of functions used to build XML dumps of tables */ +if (isset($db) && strlen($db)) { /* Can't do server export */ + +if (isset($plugin_list)) { + $plugin_list['xml'] = array( + 'text' => 'strXML', + 'extension' => 'xml', + 'options' => array( + ), + 'options_text' => 'strXMLOptions', + ); +} else { + /** * Outputs comment * @@ -155,4 +167,6 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { return TRUE; } // end of the 'PMA_getTableXML()' function +} +} ?>