Merge remote-tracking branch 'origin/master'

This commit is contained in:
Michal Čihař 2012-05-02 10:15:46 +02:00
commit f568739e5c
16 changed files with 2332 additions and 1065 deletions

View File

@ -478,7 +478,11 @@ do {
if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
// for a view, export a stand-in definition of the table
// to resolve view dependencies
if (!PMA_exportStructure($current_db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, $is_view ? 'stand_in' : 'create_table', $export_type)) {
if (! PMA_exportStructure(
$current_db, $table, $crlf, $err_url,
$is_view ? 'stand_in' : 'create_table', $export_type,
$do_relation, $do_comments, $do_mime, $do_dates
)) {
break 3;
}
}
@ -492,7 +496,11 @@ do {
// now export the triggers (needs to be done after the data because
// triggers can modify already imported tables)
if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
if (!PMA_exportStructure($current_db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'triggers', $export_type)) {
if (! PMA_exportStructure(
$current_db, $table, $crlf, $err_url,
'triggers', $export_type,
$do_relation, $do_comments, $do_mime, $do_dates
)) {
break 2;
}
}
@ -500,7 +508,11 @@ do {
foreach ($views as $view) {
// no data export for a view
if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
if (!PMA_exportStructure($current_db, $view, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'create_view', $export_type)) {
if (! PMA_exportStructure(
$current_db, $view, $crlf, $err_url,
'create_view', $export_type,
$do_relation, $do_comments, $do_mime, $do_dates
)) {
break 3;
}
}
@ -532,7 +544,11 @@ do {
if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
// for a view, export a stand-in definition of the table
// to resolve view dependencies
if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, $is_view ? 'stand_in' : 'create_table', $export_type)) {
if (! PMA_exportStructure(
$db, $table, $crlf, $err_url,
$is_view ? 'stand_in' : 'create_table', $export_type,
$do_relation, $do_comments, $do_mime, $do_dates
)) {
break 2;
}
}
@ -546,7 +562,11 @@ do {
// now export the triggers (needs to be done after the data because
// triggers can modify already imported tables)
if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'triggers', $export_type)) {
if (! PMA_exportStructure(
$db, $table, $crlf, $err_url,
'triggers', $export_type,
$do_relation, $do_comments, $do_mime, $do_dates
)) {
break 2;
}
}
@ -554,7 +574,11 @@ do {
foreach ($views as $view) {
// no data export for a view
if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
if (!PMA_exportStructure($db, $view, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'create_view', $export_type)) {
if (! PMA_exportStructure(
$db, $view, $crlf, $err_url,
'create_view', $export_type,
$do_relation, $do_comments, $do_mime, $do_dates
)) {
break 2;
}
}
@ -579,7 +603,11 @@ do {
$is_view = PMA_Table::isView($db, $table);
if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, $is_view ? 'create_view' : 'create_table', $export_type)) {
if (! PMA_exportStructure(
$db, $table, $crlf, $err_url,
$is_view ? 'create_view' : 'create_table', $export_type,
$do_relation, $do_comments, $do_mime, $do_dates
)) {
break;
}
}
@ -605,7 +633,11 @@ do {
// now export the triggers (needs to be done after the data because
// triggers can modify already imported tables)
if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'triggers', $export_type)) {
if (! PMA_exportStructure(
$db, $table, $crlf, $err_url,
'triggers', $export_type,
$do_relation, $do_comments, $do_mime, $do_dates
)) {
break 2;
}
}

View File

@ -3,7 +3,7 @@
/**
* Set of functions used to build NHibernate dumps of tables
*
* @package PhpMyAdmin-Export
* @package PhpMyAdmin-Export
* @subpackage Codegen
*/
if (! defined('PHPMYADMIN')) {
@ -21,8 +21,14 @@ if (! defined('CG_FORMAT_NHIBERNATE_CS')) {
define("CG_HANDLER_NHIBERNATE_XML_BODY", "handleNHibernateXMLBody");
}
$CG_FORMATS = array(CG_FORMAT_NHIBERNATE_CS, CG_FORMAT_NHIBERNATE_XML);
$CG_HANDLERS = array(CG_HANDLER_NHIBERNATE_CS_BODY, CG_HANDLER_NHIBERNATE_XML_BODY);
$CG_FORMATS = array(
CG_FORMAT_NHIBERNATE_CS,
CG_FORMAT_NHIBERNATE_XML
);
$CG_HANDLERS = array(
CG_HANDLER_NHIBERNATE_CS_BODY,
CG_HANDLER_NHIBERNATE_XML_BODY
);
/**
*
@ -32,14 +38,28 @@ if (isset($plugin_list)) {
'text' => 'CodeGen',
'extension' => 'cs',
'mime_type' => 'text/cs',
'options' => array(
array('type' => 'begin_group', 'name' => 'general_opts'),
array('type' => 'hidden', 'name' => 'structure_or_data'),
array('type' => 'select', 'name' => 'format', 'text' => __('Format:'), 'values' => $CG_FORMATS),
array('type' => 'end_group')
),
'options_text' => __('Options'),
);
'options' => array(),
'options_text' => __('Options')
);
$plugin_list['codegen']['options'] = array(
array(
'type' => 'begin_group',
'name' => 'general_opts'
),
array(
'type' => 'hidden',
'name' => 'structure_or_data'
),
array('type' => 'select',
'name' => 'format',
'text' => __('Format:'),
'values' => $CG_FORMATS
),
array(
'type' => 'end_group'
)
);
} else {
/**
@ -49,9 +69,9 @@ if (isset($plugin_list)) {
/**
* Outputs export footer
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportFooter()
{
@ -61,9 +81,9 @@ if (isset($plugin_list)) {
/**
* Outputs export header
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportHeader()
{
@ -73,11 +93,11 @@ if (isset($plugin_list)) {
/**
* Outputs database header
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBHeader($db)
{
@ -87,11 +107,11 @@ if (isset($plugin_list)) {
/**
* Outputs database footer
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBFooter($db)
{
@ -101,11 +121,11 @@ if (isset($plugin_list)) {
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBCreate($db)
{
@ -115,29 +135,32 @@ if (isset($plugin_list)) {
/**
* Outputs the content of a table in NHibernate format
*
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
global $CG_FORMATS, $CG_HANDLERS, $what;
$format = $GLOBALS[$what . '_format'];
if (isset($CG_FORMATS[$format])) {
return PMA_exportOutputHandler($CG_HANDLERS[$format]($db, $table, $crlf));
return PMA_exportOutputHandler(
$CG_HANDLERS[$format]($db, $table, $crlf)
);
}
return PMA_exportOutputHandler(sprintf("%s is not supported.", $format));
}
/**
* TableProperty class
*
* @package PhpMyAdmin-Export
* @package PhpMyAdmin-Export
* @subpackage Codegen
*/
class TableProperty
@ -232,7 +255,9 @@ if (isset($plugin_list)) {
function getIndexName()
{
if (strlen($this->key) > 0) {
return "index=\"" . htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8') . "\"";
return "index=\""
. htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8')
. "\"";
}
return "";
}
@ -242,23 +267,59 @@ if (isset($plugin_list)) {
}
function formatCs($text)
{
$text=str_replace("#name#", cgMakeIdentifier($this->name, false), $text);
$text = str_replace(
"#name#",
cgMakeIdentifier($this->name, false),
$text
);
return $this->format($text);
}
function formatXml($text)
{
$text=str_replace("#name#", htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8'), $text);
$text=str_replace("#indexName#", $this->getIndexName(), $text);
$text = str_replace(
"#name#",
htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8'),
$text
);
$text = str_replace(
"#indexName#",
$this->getIndexName(),
$text
);
return $this->format($text);
}
function format($text)
{
$text=str_replace("#ucfirstName#", cgMakeIdentifier($this->name), $text);
$text=str_replace("#dotNetPrimitiveType#", $this->getDotNetPrimitiveType(), $text);
$text=str_replace("#dotNetObjectType#", $this->getDotNetObjectType(), $text);
$text=str_replace("#type#", $this->getPureType(), $text);
$text=str_replace("#notNull#", $this->isNotNull(), $text);
$text=str_replace("#unique#", $this->isUnique(), $text);
$text = str_replace(
"#ucfirstName#",
cgMakeIdentifier($this->name),
$text
);
$text = str_replace(
"#dotNetPrimitiveType#",
$this->getDotNetPrimitiveType(),
$text
);
$text = str_replace(
"#dotNetObjectType#",
$this->getDotNetObjectType(),
$text
);
$text = str_replace(
"#type#",
$this->getPureType(),
$text
);
$text = str_replace(
"#notNull#",
$this->isNotNull(),
$text
);
$text = str_replace(
"#unique#",
$this->isUnique(),
$text
);
return $text;
}
}
@ -268,7 +329,7 @@ if (isset($plugin_list)) {
// remove unsafe characters
$str = preg_replace('/[^\p{L}\p{Nl}_]/u', '', $str);
// make sure first character is a letter or _
if (!preg_match('/^\pL/u', $str)) {
if (! preg_match('/^\pL/u', $str)) {
$str = '_' . $str;
}
if ($ucfirst) {
@ -280,7 +341,9 @@ if (isset($plugin_list)) {
function handleNHibernateCSBody($db, $table, $crlf)
{
$lines = array();
$result = PMA_DBI_query(sprintf('DESC %s.%s', PMA_backquote($db), PMA_backquote($table)));
$result = PMA_DBI_query(
sprintf('DESC %s.%s', PMA_backquote($db), PMA_backquote($table))
);
if ($result) {
$tableProperties = array();
while ($row = PMA_DBI_fetch_row($result)) {
@ -298,7 +361,9 @@ if (isset($plugin_list)) {
$lines[] = ' {';
$lines[] = ' #region Member Variables';
foreach ($tableProperties as $tableProperty) {
$lines[] = $tableProperty->formatCs(' protected #dotNetPrimitiveType# _#name#;');
$lines[] = $tableProperty->formatCs(
' protected #dotNetPrimitiveType# _#name#;'
);
}
$lines[] = ' #endregion';
$lines[] = ' #region Constructors';
@ -306,14 +371,22 @@ if (isset($plugin_list)) {
$temp = array();
foreach ($tableProperties as $tableProperty) {
if (! $tableProperty->isPK()) {
$temp[] = $tableProperty->formatCs('#dotNetPrimitiveType# #name#');
$temp[] = $tableProperty->formatCs(
'#dotNetPrimitiveType# #name#'
);
}
}
$lines[] = ' public ' . cgMakeIdentifier($table) . '(' . implode(', ', $temp) . ')';
$lines[] = ' public '
. cgMakeIdentifier($table)
. '('
. implode(', ', $temp)
. ')';
$lines[] = ' {';
foreach ($tableProperties as $tableProperty) {
if (! $tableProperty->isPK()) {
$lines[] = $tableProperty->formatCs(' this._#name#=#name#;');
$lines[] = $tableProperty->formatCs(
' this._#name#=#name#;'
);
}
}
$lines[] = ' }';
@ -321,7 +394,8 @@ if (isset($plugin_list)) {
$lines[] = ' #region Public Properties';
foreach ($tableProperties as $tableProperty) {
$lines[] = $tableProperty->formatCs(
' public virtual #dotNetPrimitiveType# #ucfirstName#' . "\n"
' public virtual #dotNetPrimitiveType# #ucfirstName#'
. "\n"
. ' {' . "\n"
. ' get {return _#name#;}' . "\n"
. ' set {_#name#=value;}' . "\n"
@ -346,21 +420,28 @@ if (isset($plugin_list)) {
$lines[] = ' <class '
. 'name="' . cgMakeIdentifier($table) . '" '
. 'table="' . cgMakeIdentifier($table) . '">';
$result = PMA_DBI_query(sprintf("DESC %s.%s", PMA_backquote($db), PMA_backquote($table)));
$result = PMA_DBI_query(
sprintf("DESC %s.%s", PMA_backquote($db), PMA_backquote($table))
);
if ($result) {
while ($row = PMA_DBI_fetch_row($result)) {
$tableProperty = new TableProperty($row);
if ($tableProperty->isPK()) {
$lines[] = $tableProperty->formatXml(
' <id name="#ucfirstName#" type="#dotNetObjectType#" unsaved-value="0">' . "\n"
. ' <column name="#name#" sql-type="#type#" not-null="#notNull#" unique="#unique#" index="PRIMARY"/>' . "\n"
' <id name="#ucfirstName#" type="#dotNetObjectType#"'
. ' unsaved-value="0">' . "\n"
. ' <column name="#name#" sql-type="#type#"'
. ' not-null="#notNull#" unique="#unique#"'
. ' index="PRIMARY"/>' . "\n"
. ' <generator class="native" />' . "\n"
. ' </id>'
);
} else {
$lines[] = $tableProperty->formatXml(
' <property name="#ucfirstName#" type="#dotNetObjectType#">' . "\n"
. ' <column name="#name#" sql-type="#type#" not-null="#notNull#" #indexName#/>' . "\n"
' <property name="#ucfirstName#"'
. ' type="#dotNetObjectType#">' . "\n"
. ' <column name="#name#" sql-type="#type#"'
. ' not-null="#notNull#" #indexName#/>' . "\n"
. ' </property>'
);
}

View File

@ -3,7 +3,7 @@
/**
* CSV export code
*
* @package PhpMyAdmin-Export
* @package PhpMyAdmin-Export
* @subpackage CSV
*/
if (! defined('PHPMYADMIN')) {
@ -19,28 +19,68 @@ if (isset($plugin_list)) {
'text' => __('CSV'),
'extension' => 'csv',
'mime_type' => 'text/comma-separated-values',
'options' => array(
array('type' => 'begin_group', 'name' => 'general_opts'),
array('type' => 'text', 'name' => 'separator', 'text' => __('Columns separated with:')),
array('type' => 'text', 'name' => 'enclosed', 'text' => __('Columns enclosed with:')),
array('type' => 'text', 'name' => 'escaped', 'text' => __('Columns escaped with:')),
array('type' => 'text', 'name' => 'terminated', 'text' => __('Lines terminated with:')),
array('type' => 'text', 'name' => 'null', 'text' => __('Replace NULL with:')),
array('type' => 'bool', 'name' => 'removeCRLF', 'text' => __('Remove carriage return/line feed characters within columns')),
array('type' => 'bool', 'name' => 'columns', 'text' => __('Put columns names in the first row')),
array('type' => 'hidden', 'name' => 'structure_or_data'),
array('type' => 'end_group'),
'options' => array(),
'options_text' => __('Options')
);
$plugin_list['csv']['options'] = array(
array(
'type' => 'begin_group',
'name' => 'general_opts'
),
'options_text' => __('Options'),
);
array(
'type' => 'text',
'name' => 'separator',
'text' => __('Columns separated with:')
),
array(
'type' => 'text',
'name' => 'enclosed',
'text' => __('Columns enclosed with:')
),
array(
'type' => 'text',
'name' => 'escaped',
'text' => __('Columns escaped with:')
),
array(
'type' => 'text',
'name' => 'terminated',
'text' => __('Lines terminated with:')
),
array(
'type' => 'text',
'name' => 'null',
'text' => __('Replace NULL with:')
),
array(
'type' => 'bool',
'name' => 'removeCRLF',
'text' => __(
'Remove carriage return/line feed characters within columns'
)
),
array(
'type' => 'bool',
'name' => 'columns',
'text' => __('Put columns names in the first row')
),
array(
'type' => 'hidden',
'name' => 'structure_or_data'
),
array(
'type' => 'end_group'
)
);
} else {
/**
* Outputs export footer
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportFooter()
{
@ -50,9 +90,9 @@ if (isset($plugin_list)) {
/**
* Outputs export header
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportHeader()
{
@ -77,20 +117,20 @@ if (isset($plugin_list)) {
$csv_separator = ',';
break;
}
$csv_enclosed = '"';
$csv_escaped = '"';
$csv_enclosed = '"';
$csv_escaped = '"';
if (isset($GLOBALS['excel_columns'])) {
$GLOBALS['csv_columns'] = 'yes';
}
} else {
if (empty($csv_terminated) || strtolower($csv_terminated) == 'auto') {
$csv_terminated = $GLOBALS['crlf'];
$csv_terminated = $GLOBALS['crlf'];
} else {
$csv_terminated = str_replace('\\r', "\015", $csv_terminated);
$csv_terminated = str_replace('\\n', "\012", $csv_terminated);
$csv_terminated = str_replace('\\t', "\011", $csv_terminated);
$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
$csv_separator = str_replace('\\t', "\011", $csv_separator);
$csv_separator = str_replace('\\t', "\011", $csv_separator);
}
return true;
}
@ -98,11 +138,11 @@ if (isset($plugin_list)) {
/**
* Outputs database header
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBHeader($db)
{
@ -112,11 +152,11 @@ if (isset($plugin_list)) {
/**
* Outputs database footer
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBFooter($db)
{
@ -126,11 +166,11 @@ if (isset($plugin_list)) {
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBCreate($db)
{
@ -140,15 +180,15 @@ if (isset($plugin_list)) {
/**
* Outputs the content of a table in CSV format
*
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
@ -159,8 +199,8 @@ if (isset($plugin_list)) {
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);
$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['csv_columns'])) {
@ -170,13 +210,17 @@ if (isset($plugin_list)) {
$schema_insert .= stripslashes(PMA_DBI_field_name($result, $i));
} else {
$schema_insert .= $csv_enclosed
. str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, stripslashes(PMA_DBI_field_name($result, $i)))
. $csv_enclosed;
. str_replace(
$csv_enclosed,
$csv_escaped . $csv_enclosed,
stripslashes(PMA_DBI_field_name($result, $i))
)
. $csv_enclosed;
}
$schema_insert .= $csv_separator;
$schema_insert .= $csv_separator;
} // end for
$schema_insert =trim(substr($schema_insert, 0, -1));
if (!PMA_exportOutputHandler($schema_insert . $csv_terminated)) {
$schema_insert = trim(substr($schema_insert, 0, -1));
if (! PMA_exportOutputHandler($schema_insert . $csv_terminated)) {
return false;
}
} // end if
@ -185,16 +229,26 @@ if (isset($plugin_list)) {
while ($row = PMA_DBI_fetch_row($result)) {
$schema_insert = '';
for ($j = 0; $j < $fields_cnt; $j++) {
if (!isset($row[$j]) || is_null($row[$j])) {
if (! isset($row[$j]) || is_null($row[$j])) {
$schema_insert .= $GLOBALS[$what . '_null'];
} elseif ($row[$j] == '0' || $row[$j] != '') {
// always enclose fields
if ($what == 'excel') {
$row[$j] = preg_replace("/\015(\012)?/", "\012", $row[$j]);
$row[$j] = preg_replace("/\015(\012)?/", "\012", $row[$j]);
}
// remove CRLF characters within field
if (isset($GLOBALS[$what . '_removeCRLF']) && $GLOBALS[$what . '_removeCRLF']) {
$row[$j] = str_replace("\n", "", str_replace("\r", "", $row[$j]));
if (isset($GLOBALS[$what . '_removeCRLF'])
&& $GLOBALS[$what . '_removeCRLF']
) {
$row[$j] = str_replace(
"\n",
"",
str_replace(
"\r",
"",
$row[$j]
)
);
}
if ($csv_enclosed == '') {
$schema_insert .= $row[$j];
@ -202,13 +256,25 @@ if (isset($plugin_list)) {
// also double the escape string if found in the data
if ($csv_escaped != $csv_enclosed) {
$schema_insert .= $csv_enclosed
. str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, str_replace($csv_escaped, $csv_escaped . $csv_escaped, $row[$j]))
. $csv_enclosed;
. str_replace(
$csv_enclosed,
$csv_escaped . $csv_enclosed,
str_replace(
$csv_escaped,
$csv_escaped . $csv_escaped,
$row[$j]
)
)
. $csv_enclosed;
} else {
// avoid a problem when escape string equals enclose
$schema_insert .= $csv_enclosed
. str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j])
. $csv_enclosed;
. str_replace(
$csv_enclosed,
$csv_escaped . $csv_enclosed,
$row[$j]
)
. $csv_enclosed;
}
}
} else {
@ -219,7 +285,7 @@ if (isset($plugin_list)) {
}
} // end for
if (!PMA_exportOutputHandler($schema_insert . $csv_terminated)) {
if (! PMA_exportOutputHandler($schema_insert . $csv_terminated)) {
return false;
}
} // end while

View File

@ -3,7 +3,7 @@
/**
* Set of functions used to build CSV dumps of tables for excel
*
* @package PhpMyAdmin-Export
* @package PhpMyAdmin-Export
* @subpackage CSV-Excel
*/
if (! defined('PHPMYADMIN')) {
@ -18,24 +18,48 @@ if (isset($plugin_list)) {
'text' => __('CSV for MS Excel'),
'extension' => 'csv',
'mime_type' => 'text/comma-separated-values',
'options' => array(
array('type' => 'begin_group', 'name' => 'general_opts'),
array('type' => 'text', 'name' => 'null', 'text' => __('Replace NULL with:')),
array('type' => 'bool', 'name' => 'removeCRLF', 'text' => __('Remove carriage return/line feed characters within columns')),
array('type' => 'bool', 'name' => 'columns', 'text' => __('Put columns names in the first row')),
'options' => array(),
'options_text' => __('Options')
);
$plugin_list['excel']['options'] = array(
array(
'type' => 'begin_group',
'name' => 'general_opts'
),
array(
'type' => 'text',
'name' => 'null',
'text' => __('Replace NULL with:')
),
array(
'type' => 'bool',
'name' => 'removeCRLF',
'text' => __(
'Remove carriage return/line feed characters within columns'
)
),
array(
'type' => 'bool',
'name' => 'columns',
'text' => __('Put columns names in the first row')
),
array(
'type' => 'select',
'name' => 'edition',
'values' => array(
'win' => 'Windows',
'mac_excel2003' => 'Excel 2003 / Macintosh',
'mac_excel2008' => 'Excel 2008 / Macintosh'),
'text' => __('Excel edition:')),
array(
'type' => 'select',
'name' => 'edition',
'values' => array(
'win' => 'Windows',
'mac_excel2003' => 'Excel 2003 / Macintosh',
'mac_excel2008' => 'Excel 2008 / Macintosh'),
'text' => __('Excel edition:')),
array('type' => 'hidden', 'name' => 'structure_or_data'),
array('type' => 'end_group'),
'type' => 'hidden',
'name' => 'structure_or_data'
),
'options_text' => __('Options'),
);
array(
'type' => 'end_group'
)
);
} else {
/* Everything rest is coded in csv plugin */
include './libraries/export/csv.php';

View File

@ -3,7 +3,7 @@
/**
* Set of functions used to export a set of queries to a MS Word document
*
* @package PhpMyAdmin-Export
* @package PhpMyAdmin-Export
* @subpackage HTMLWord
*/
if (! defined('PHPMYADMIN')) {
@ -19,27 +19,59 @@ if (isset($plugin_list)) {
'extension' => 'doc',
'mime_type' => 'application/vnd.ms-word',
'force_file' => true,
'options' => array(
/* what to dump (structure/data/both) */
array('type' => 'begin_group', 'name' => 'dump_what', 'text' => __('Dump table')),
array('type' => 'radio', 'name' => 'structure_or_data', 'values' => array('structure' => __('structure'), 'data' => __('data'), 'structure_and_data' => __('structure and data'))),
array('type' => 'end_group'),
/* data options */
array('type' => 'begin_group', 'name' => 'data', 'text' => __('Data dump options'), 'force' => 'structure'),
array('type' => 'text', 'name' => 'null', 'text' => __('Replace NULL with:')),
array('type' => 'bool', 'name' => 'columns', 'text' => __('Put columns names in the first row')),
array('type' => 'end_group'),
),
'options_text' => __('Options'),
);
'options' => array(),
'options_text' => __('Options')
);
$plugin_list['htmlword']['options'] = array(
/* what to dump (structure/data/both) */
array(
'type' => 'begin_group',
'name' => 'dump_what',
'text' => __('Dump table')
),
array(
'type' => 'radio',
'name' => 'structure_or_data',
'values' => array(
'structure' => __('structure'),
'data' => __('data'),
'structure_and_data' => __('structure and data')
)
),
array(
'type' => 'end_group'
),
/* data options */
array(
'type' => 'begin_group',
'name' => 'data',
'text' => __('Data dump options'),
'force' => 'structure'
),
array(
'type' => 'text',
'name' => 'null',
'text' => __('Replace NULL with:')
),
array(
'type' => 'bool',
'name' => 'columns',
'text' => __('Put columns names in the first row')
),
array(
'type' => 'end_group'
)
);
} else {
/**
* Outputs export footer
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportFooter()
{
@ -49,9 +81,9 @@ if (isset($plugin_list)) {
/**
* Outputs export header
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportHeader()
{
@ -61,10 +93,12 @@ if (isset($plugin_list)) {
xmlns:x="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'
. ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=' . (isset($charset_of_file) ? $charset_of_file : 'utf-8') . '" />
<meta http-equiv="Content-type" content="text/html;charset='
. (isset($charset_of_file) ? $charset_of_file : 'utf-8') . '" />
</head>
<body>'
);
@ -73,25 +107,27 @@ if (isset($plugin_list)) {
/**
* Outputs database header
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBHeader($db)
{
return PMA_exportOutputHandler('<h1>' . __('Database') . ' ' . htmlspecialchars($db) . '</h1>');
return PMA_exportOutputHandler(
'<h1>' . __('Database') . ' ' . htmlspecialchars($db) . '</h1>'
);
}
/**
* Outputs database footer
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBFooter($db)
{
@ -101,11 +137,11 @@ if (isset($plugin_list)) {
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBCreate($db)
{
@ -115,36 +151,46 @@ if (isset($plugin_list)) {
/**
* Outputs the content of a table in HTML (Microsoft Word) format
*
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
global $what;
if (! PMA_exportOutputHandler('<h2>' . __('Dumping data for table') . ' ' . htmlspecialchars($table) . '</h2>')) {
if (! PMA_exportOutputHandler(
'<h2>'
. __('Dumping data for table') . ' ' . htmlspecialchars($table)
. '</h2>'
)) {
return false;
}
if (! PMA_exportOutputHandler('<table class="width100" cellspacing="1">')) {
if (! PMA_exportOutputHandler(
'<table class="width100" cellspacing="1">'
)) {
return false;
}
// Gets the data from the database
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
$fields_cnt = PMA_DBI_num_fields($result);
$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['htmlword_columns'])) {
$schema_insert = '<tr class="print-category">';
for ($i = 0; $i < $fields_cnt; $i++) {
$schema_insert .= '<td class="print"><strong>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</strong></td>';
$schema_insert .= '<td class="print"><strong>'
. htmlspecialchars(
stripslashes(PMA_DBI_field_name($result, $i))
)
. '</strong></td>';
} // end for
$schema_insert .= '</tr>';
if (! PMA_exportOutputHandler($schema_insert)) {
@ -163,7 +209,9 @@ if (isset($plugin_list)) {
} else {
$value = '';
}
$schema_insert .= '<td class="print">' . htmlspecialchars($value) . '</td>';
$schema_insert .= '<td class="print">'
. htmlspecialchars($value)
. '</td>';
} // end for
$schema_insert .= '</tr>';
if (! PMA_exportOutputHandler($schema_insert)) {
@ -195,10 +243,18 @@ if (isset($plugin_list)) {
$columns_cnt = 4;
$schema_insert .= '<tr class="print-category">';
$schema_insert .= '<th class="print">' . __('Column') . '</th>';
$schema_insert .= '<td class="print"><strong>' . __('Type') . '</strong></td>';
$schema_insert .= '<td class="print"><strong>' . __('Null') . '</strong></td>';
$schema_insert .= '<td class="print"><strong>' . __('Default') . '</strong></td>';
$schema_insert .= '<th class="print">'
. __('Column')
. '</th>';
$schema_insert .= '<td class="print"><strong>'
. __('Type')
. '</strong></td>';
$schema_insert .= '<td class="print"><strong>'
. __('Null')
. '</strong></td>';
$schema_insert .= '<td class="print"><strong>'
. __('Default')
. '</strong></td>';
$schema_insert .= '</tr>';
/**
@ -230,22 +286,34 @@ if (isset($plugin_list)) {
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column comments
* as comments in the structure; this is deprecated
* but the parameter is left here because export.php
* calls PMA_exportStructure() also for other export
* types which use this parameter
* @param bool $do_comments whether to include the pmadb-style column
* comments as comments in the structure;
* this is deprecated but the parameter is
* left here because export.php calls
* PMA_exportStructure() also for other
* export types which use this parameter
* @param bool $do_mime whether to include mime comments
* @param bool $show_dates whether to include creation/update/check dates
* @param bool $add_semicolon whether to add semicolon and end-of-line at the end
* @param bool $add_semicolon whether to add semicolon and end-of-line
* at the end
* @param bool $view whether we're handling a view
*
* @return string resulting schema
*
* @access public
*/
function PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $show_dates = false, $add_semicolon = true, $view = false)
{
function PMA_getTableDef(
$db,
$table,
$crlf,
$error_url,
$do_relation,
$do_comments,
$do_mime,
$show_dates = false,
$add_semicolon = true,
$view = false
) {
global $cfgRelation;
$schema_insert = '';
@ -287,19 +355,33 @@ if (isset($plugin_list)) {
}
$schema_insert .= '<tr class="print-category">';
$schema_insert .= '<th class="print">' . __('Column') . '</th>';
$schema_insert .= '<td class="print"><strong>' . __('Type') . '</strong></td>';
$schema_insert .= '<td class="print"><strong>' . __('Null') . '</strong></td>';
$schema_insert .= '<td class="print"><strong>' . __('Default') . '</strong></td>';
$schema_insert .= '<th class="print">'
. __('Column')
. '</th>';
$schema_insert .= '<td class="print"><strong>'
. __('Type')
. '</strong></td>';
$schema_insert .= '<td class="print"><strong>'
. __('Null')
. '</strong></td>';
$schema_insert .= '<td class="print"><strong>'
. __('Default')
. '</strong></td>';
if ($do_relation && $have_rel) {
$schema_insert .= '<td class="print"><strong>' . __('Links to') . '</strong></td>';
$schema_insert .= '<td class="print"><strong>'
. __('Links to')
. '</strong></td>';
}
if ($do_comments) {
$schema_insert .= '<td class="print"><strong>' . __('Comments') . '</strong></td>';
$schema_insert .= '<td class="print"><strong>'
. __('Comments')
. '</strong></td>';
$comments = PMA_getComments($db, $table);
}
if ($do_mime && $cfgRelation['mimework']) {
$schema_insert .= '<td class="print"><strong>' . htmlspecialchars('MIME') . '</strong></td>';
$schema_insert .= '<td class="print"><strong>'
. htmlspecialchars('MIME')
. '</strong></td>';
$mime_map = PMA_getMIME($db, $table, true);
}
$schema_insert .= '</tr>';
@ -320,13 +402,28 @@ if (isset($plugin_list)) {
$field_name = $column['Field'];
if ($do_relation && $have_rel) {
$schema_insert .= '<td class="print">' . (isset($res_rel[$field_name]) ? htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') : '') . '</td>';
$schema_insert .= '<td class="print">'
. (isset($res_rel[$field_name])
? htmlspecialchars(
$res_rel[$field_name]['foreign_table']
. ' (' . $res_rel[$field_name]['foreign_field']
. ')'
)
: '') . '</td>';
}
if ($do_comments && $cfgRelation['commwork']) {
$schema_insert .= '<td class="print">' . (isset($comments[$field_name]) ? htmlspecialchars($comments[$field_name]) : '') . '</td>';
$schema_insert .= '<td class="print">'
. (isset($comments[$field_name])
? htmlspecialchars($comments[$field_name])
: '') . '</td>';
}
if ($do_mime && $cfgRelation['mimework']) {
$schema_insert .= '<td class="print">' . (isset($mime_map[$field_name]) ? htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) : '') . '</td>';
$schema_insert .= '<td class="print">'
. (isset($mime_map[$field_name]) ?
htmlspecialchars(
str_replace('_', '/', $mime_map[$field_name]['mimetype'])
)
: '') . '</td>';
}
$schema_insert .= '</tr>';
@ -339,10 +436,10 @@ if (isset($plugin_list)) {
/**
* Outputs triggers
*
* @param string $db database name
* @param string $table table name
* @param string $db database name
* @param string $table table name
*
* @return string Formatted triggers list
* @return string Formatted triggers list
*
* @access public
*/
@ -360,11 +457,19 @@ if (isset($plugin_list)) {
foreach ($triggers as $trigger) {
$dump .= '<tr class="print-category">';
$dump .= '<td class="print">' . htmlspecialchars($trigger['name']) . '</td>';
$dump .= '<td class="print">' . htmlspecialchars($trigger['action_timing']) . '</td>';
$dump .= '<td class="print">' . htmlspecialchars($trigger['event_manipulation']) . '</td>';
$dump .= '<td class="print">' . htmlspecialchars($trigger['definition']) . '</td>';
$dump .= '</tr>';
$dump .= '<td class="print">'
. htmlspecialchars($trigger['name'])
. '</td>'
. '<td class="print">'
. htmlspecialchars($trigger['action_timing'])
. '</td>'
. '<td class="print">'
. htmlspecialchars($trigger['event_manipulation'])
. '</td>'
. '<td class="print">'
. htmlspecialchars($trigger['definition'])
. '</td>'
. '</tr>';
}
$dump .= '</table>';
@ -374,48 +479,74 @@ if (isset($plugin_list)) {
/**
* Outputs table's structure
*
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column comments
* as comments in the structure; this is deprecated
* but the parameter is left here because export.php
* calls PMA_exportStructure() also for other export
* types which use this parameter
* @param bool $do_mime whether to include mime comments
* @param bool $dates whether to include creation/update/check dates
* @param string $export_mode 'create_table', 'triggers', 'create_view', 'stand_in'
* @param string $export_type 'server', 'database', 'table'
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $export_mode 'create_table', 'triggers', 'create_view',
* 'stand_in'
* @param string $export_type 'server', 'database', 'table'
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column
* comments as comments in the structure;
* this is deprecated but the parameter is
* left here because export.php calls
* PMA_exportStructure() also for other
* export types which use this parameter
* @param bool $do_mime whether to include mime comments
* @param bool $dates whether to include creation/update/check dates
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $export_mode, $export_type)
{
function PMA_exportStructure(
$db,
$table,
$crlf,
$error_url,
$export_mode,
$export_type,
$do_relation = false,
$do_comments = false,
$do_mime = false,
$dates = false
) {
$dump = '';
switch($export_mode) {
case 'create_table':
$dump .= '<h2>' . __('Table structure for table') . ' ' . htmlspecialchars($table) . '</h2>';
$dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates);
$dump .= '<h2>'
. __('Table structure for table') . ' ' . htmlspecialchars($table)
. '</h2>';
$dump .= PMA_getTableDef(
$db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime,
$dates
);
break;
case 'triggers':
$dump = '';
$triggers = PMA_DBI_get_triggers($db, $table);
if ($triggers) {
$dump .= '<h2>' . __('Triggers') . ' ' . htmlspecialchars($table) . '</h2>';
$dump .= '<h2>'
. __('Triggers') . ' ' . htmlspecialchars($table)
. '</h2>';
$dump .= PMA_getTriggers($db, $table);
}
break;
case 'create_view':
$dump .= '<h2>' . __('Structure for view') . ' ' . htmlspecialchars($table) . '</h2>';
$dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates, true, true);
$dump .= '<h2>'
. __('Structure for view') . ' ' . htmlspecialchars($table)
. '</h2>';
$dump .= PMA_getTableDef(
$db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime,
$dates, true, true
);
break;
case 'stand_in':
$dump .= '<h2>' . __('Stand-in structure for view') . ' ' . htmlspecialchars($table) . '</h2>';
$dump .= '<h2>'
. __('Stand-in structure for view') . ' ' . htmlspecialchars($table)
. '</h2>';
// export a stand-in definition to resolve view dependencies
$dump .= PMA_getTableDefStandIn($db, $table, $crlf);
} // end switch
@ -426,10 +557,10 @@ if (isset($plugin_list)) {
/**
* Formats the definition for one column
*
* @param array $column info about this column
* @param array $unique_keys unique keys of the table
* @param array $column info about this column
* @param array $unique_keys unique keys of the table
*
* @return string Formatted column definition
* @return string Formatted column definition
*
* @access public
*/
@ -469,9 +600,11 @@ if (isset($plugin_list)) {
: __('Yes'))
. '</td>';
$definition .= '<td class="print">'
. htmlspecialchars(isset($column['Default'])
? $column['Default']
: '')
. htmlspecialchars(
isset($column['Default'])
? $column['Default']
: ''
)
. '</td>';
return $definition;

View File

@ -3,7 +3,7 @@
/**
* Set of functions used to build dumps of tables as JSON
*
* @package PhpMyAdmin-Export
* @package PhpMyAdmin-Export
* @subpackage JSON
*/
if (! defined('PHPMYADMIN')) {
@ -15,18 +15,25 @@ if (! defined('PHPMYADMIN')) {
*/
if (isset($plugin_list)) {
$plugin_list['json'] = array(
'text' => 'JSON',
'extension' => 'json',
'mime_type' => 'text/plain',
'options' => array(
array('type' => 'begin_group', 'name' => 'general_opts'),
array(
'type' => 'hidden',
'name' => 'structure_or_data',
),
array('type' => 'end_group')
'text' => 'JSON',
'extension' => 'json',
'mime_type' => 'text/plain',
'options' => array(),
'options_text' => __('Options')
);
$plugin_list['json']['options'] = array(
array(
'type' => 'begin_group',
'name' => 'general_opts'
),
'options_text' => __('Options'),
array(
'type' => 'hidden',
'name' => 'structure_or_data',
),
array(
'type' => 'end_group'
)
);
} else {
@ -37,9 +44,9 @@ if (isset($plugin_list)) {
/**
* Outputs export footer
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportFooter()
{
@ -49,9 +56,9 @@ if (isset($plugin_list)) {
/**
* Outputs export header
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportHeader()
{
@ -67,11 +74,11 @@ if (isset($plugin_list)) {
/**
* Outputs database header
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBHeader($db)
{
@ -82,11 +89,11 @@ if (isset($plugin_list)) {
/**
* Outputs database footer
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBFooter($db)
{
@ -96,11 +103,11 @@ if (isset($plugin_list)) {
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBCreate($db)
{
@ -110,15 +117,15 @@ if (isset($plugin_list)) {
/**
* Outputs the content of a table in JSON format
*
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
@ -155,11 +162,20 @@ if (isset($plugin_list)) {
$column = $columns[$i];
if (is_null($record[$i])) {
$buffer .= '"' . addslashes($column) . '": null' . (! $isLastLine ? ',' : '');
$buffer .= '"' . addslashes($column)
. '": null'
. (! $isLastLine ? ',' : '');
} elseif ($fields_meta[$i]->numeric) {
$buffer .= '"' . addslashes($column) . '": ' . $record[$i] . (! $isLastLine ? ',' : '');
$buffer .= '"' . addslashes($column)
. '": '
. $record[$i]
. (! $isLastLine ? ',' : '');
} else {
$buffer .= '"' . addslashes($column) . '": "' . addslashes($record[$i]) . '"' . (! $isLastLine ? ',' : '');
$buffer .= '"' . addslashes($column)
. '": "'
. addslashes($record[$i])
. '"'
. (! $isLastLine ? ',' : '');
}
}

View File

@ -3,7 +3,7 @@
/**
* Set of functions used to build LaTeX dumps of tables
*
* @package PhpMyAdmin-Export
* @package PhpMyAdmin-Export
* @subpackage Latex
*/
if (! defined('PHPMYADMIN')) {
@ -27,59 +27,131 @@ if (isset($plugin_list)) {
'text' => __('LaTeX'),
'extension' => 'tex',
'mime_type' => 'application/x-tex',
'options' => array(
array('type' => 'begin_group', 'name' => 'general_opts'),
array('type' => 'bool', 'name' => 'caption', 'text' => __('Include table caption')),
array('type' => 'end_group')
),
'options_text' => __('Options'),
);
'options' => array(),
'options_text' => __('Options')
);
$plugin_list['latex']['options'] = array(
array(
'type' => 'begin_group',
'name' => 'general_opts'
),
array(
'type' => 'bool',
'name' => 'caption',
'text' => __('Include table caption')
),
array(
'type' => 'end_group'
)
);
/* what to dump (structure/data/both) */
$plugin_list['latex']['options'][]
= array('type' => 'begin_group', 'name' => 'dump_what', 'text' => __('Dump table'));
$plugin_list['latex']['options'][]
= array('type' => 'radio', 'name' => 'structure_or_data', 'values' => array('structure' => __('structure'), 'data' => __('data'), 'structure_and_data' => __('structure and data')));
$plugin_list['latex']['options'][] = array('type' => 'end_group');
$plugin_list['latex']['options'][] = array(
'type' => 'begin_group',
'name' => 'dump_what',
'text' => __('Dump table')
);
$plugin_list['latex']['options'][] = array(
'type' => 'radio',
'name' => 'structure_or_data',
'values' => array(
'structure' => __('structure'),
'data' => __('data'),
'structure_and_data' => __('structure and data')
)
);
$plugin_list['latex']['options'][] = array(
'type' => 'end_group'
);
/* Structure options */
if (! $hide_structure) {
$plugin_list['latex']['options'][]
= array('type' => 'begin_group', 'name' => 'structure', 'text' => __('Object creation options'), 'force' => 'data');
$plugin_list['latex']['options'][]
= array('type' => 'text', 'name' => 'structure_caption', 'text' => __('Table caption'), 'doc' => 'faq6_27');
$plugin_list['latex']['options'][]
= array('type' => 'text', 'name' => 'structure_continued_caption', 'text' => __('Table caption (continued)'), 'doc' => 'faq6_27');
$plugin_list['latex']['options'][]
= array('type' => 'text', 'name' => 'structure_label', 'text' => __('Label key'), 'doc' => 'faq6_27');
$plugin_list['latex']['options'][] = array(
'type' => 'begin_group',
'name' => 'structure',
'text' => __('Object creation options'),
'force' => 'data'
);
$plugin_list['latex']['options'][] = array(
'type' => 'text',
'name' => 'structure_caption',
'text' => __('Table caption'),
'doc' => 'faq6_27'
);
$plugin_list['latex']['options'][] = array(
'type' => 'text',
'name' => 'structure_continued_caption',
'text' => __('Table caption (continued)'),
'doc' => 'faq6_27'
);
$plugin_list['latex']['options'][] = array(
'type' => 'text',
'name' => 'structure_label',
'text' => __('Label key'),
'doc' => 'faq6_27'
);
if (! empty($GLOBALS['cfgRelation']['relation'])) {
$plugin_list['latex']['options'][]
= array('type' => 'bool', 'name' => 'relation', 'text' => __('Display foreign key relationships'));
$plugin_list['latex']['options'][] = array(
'type' => 'bool',
'name' => 'relation',
'text' => __('Display foreign key relationships')
);
}
$plugin_list['latex']['options'][]
= array('type' => 'bool', 'name' => 'comments', 'text' => __('Display comments'));
$plugin_list['latex']['options'][] = array(
'type' => 'bool',
'name' => 'comments',
'text' => __('Display comments')
);
if (! empty($GLOBALS['cfgRelation']['mimework'])) {
$plugin_list['latex']['options'][]
= array('type' => 'bool', 'name' => 'mime', 'text' => __('Display MIME types'));
$plugin_list['latex']['options'][] = array(
'type' => 'bool',
'name' => 'mime',
'text' => __('Display MIME types')
);
}
$plugin_list['latex']['options'][]
= array('type' => 'end_group');
$plugin_list['latex']['options'][] = array(
'type' => 'end_group'
);
}
/* Data */
$plugin_list['latex']['options'][]
= array('type' => 'begin_group', 'name' => 'data', 'text' => __('Data dump options'), 'force' => 'structure');
$plugin_list['latex']['options'][]
= array('type' => 'bool', 'name' => 'columns', 'text' => __('Put columns names in the first row'));
$plugin_list['latex']['options'][]
= array('type' => 'text', 'name' => 'data_caption', 'text' => __('Table caption'), 'doc' => 'faq6_27');
$plugin_list['latex']['options'][]
= array('type' => 'text', 'name' => 'data_continued_caption', 'text' => __('Table caption (continued)'), 'doc' => 'faq6_27');
$plugin_list['latex']['options'][]
= array('type' => 'text', 'name' => 'data_label', 'text' => __('Label key'), 'doc' => 'faq6_27');
$plugin_list['latex']['options'][]
= array('type' => 'text', 'name' => 'null', 'text' => __('Replace NULL with:'));
$plugin_list['latex']['options'][]
= array('type' => 'end_group');
$plugin_list['latex']['options'][] = array(
'type' => 'begin_group',
'name' => 'data',
'text' => __('Data dump options'),
'force' => 'structure'
);
$plugin_list['latex']['options'][] = array(
'type' => 'bool',
'name' => 'columns',
'text' => __('Put columns names in the first row')
);
$plugin_list['latex']['options'][] = array(
'type' => 'text',
'name' => 'data_caption',
'text' => __('Table caption'),
'doc' => 'faq6_27'
);
$plugin_list['latex']['options'][] = array(
'type' => 'text',
'name' => 'data_continued_caption',
'text' => __('Table caption (continued)'),
'doc' => 'faq6_27'
);
$plugin_list['latex']['options'][] = array(
'type' => 'text',
'name' => 'data_label',
'text' => __('Label key'),
'doc' => 'faq6_27'
);
$plugin_list['latex']['options'][] = array(
'type' => 'text',
'name' => 'null',
'text' => __('Replace NULL with:')
);
$plugin_list['latex']['options'][] = array(
'type' => 'end_group'
);
} else {
/**
@ -87,15 +159,15 @@ if (isset($plugin_list)) {
*
* @param string $string the string to convert
*
* @return string the converted string with escape codes
* @return string the converted string with escape codes
*
* @access private
* @access private
*/
function PMA_texEscape($string)
{
$escape = array('$', '%', '{', '}', '&', '#', '_', '^');
$cnt_escape = count($escape);
for ($k=0; $k < $cnt_escape; $k++) {
for ($k = 0; $k < $cnt_escape; $k++) {
$string = str_replace($escape[$k], '\\' . $escape[$k], $string);
}
return $string;
@ -104,9 +176,9 @@ if (isset($plugin_list)) {
/**
* Outputs export footer
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportFooter()
{
@ -277,10 +349,13 @@ if (isset($plugin_list)) {
$buffer = '';
// print each row
for ($i = 0; $i < $columns_cnt; $i++) {
if (isset($record[$columns[$i]])
&& (! function_exists('is_null') || ! is_null($record[$columns[$i]]))
if ((! function_exists('is_null')
|| ! is_null($record[$columns[$i]]))
&& isset($record[$columns[$i]])
) {
$column_value = PMA_texEscape(stripslashes($record[$columns[$i]]));
$column_value = PMA_texEscape(
stripslashes($record[$columns[$i]])
);
} else {
$column_value = $GLOBALS['latex_null'];
}
@ -315,23 +390,35 @@ if (isset($plugin_list)) {
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $export_mode 'create_table', 'triggers', 'create_view',
* 'stand_in'
* @param string $export_type 'server', 'database', 'table'
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column comments
* as comments in the structure; this is deprecated
* but the parameter is left here because export.php
* calls PMA_exportStructure() also for other export
* types which use this parameter
* @param bool $do_comments whether to include the pmadb-style column
* comments as comments in the structure;
* this is deprecated but the parameter is
* left here because export.php calls
* PMA_exportStructure() also for other
* export types which use this parameter
* @param bool $do_mime whether to include mime comments
* @param bool $dates whether to include creation/update/check dates
* @param string $export_mode 'create_table', 'triggers', 'create_view', 'stand_in'
* @param string $export_type 'server', 'database', 'table'
*
* @return bool Whether it succeeded
*
* @access public
*/
function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $export_mode, $export_type)
{
function PMA_exportStructure(
$db,
$table,
$crlf,
$error_url,
$export_mode,
$export_type,
$do_relation = false,
$do_comments = false,
$do_mime = false,
$dates = false
) {
global $cfgRelation;
/**
@ -423,7 +510,8 @@ if (isset($plugin_list)) {
)
. '} \\\\' . $crlf;
}
$buffer .= $header . ' \\\\ \\hline \\hline' . $crlf . '\\endfirsthead' . $crlf;
$buffer .= $header . ' \\\\ \\hline \\hline' . $crlf
. '\\endfirsthead' . $crlf;
// Table caption on next pages
if (isset($GLOBALS['latex_caption'])) {
$buffer .= ' \\caption{'
@ -445,7 +533,7 @@ if (isset($plugin_list)) {
$extracted_columnspec = PMA_extractColumnSpec($row['Type']);
$type = $extracted_columnspec['print_type'];
if (empty($type)) {
$type = ' ';
$type = ' ';
}
if (! isset($row['Default'])) {
@ -457,7 +545,8 @@ if (isset($plugin_list)) {
$field_name = $row['Field'];
$local_buffer = $field_name . "\000" . $type . "\000"
. (($row['Null'] == '' || $row['Null'] == 'NO') ? __('No') : __('Yes'))
. (($row['Null'] == '' || $row['Null'] == 'NO')
? __('No') : __('Yes'))
. "\000" . (isset($row['Default']) ? $row['Default'] : '');
if ($do_relation && $have_rel) {
@ -476,17 +565,25 @@ if (isset($plugin_list)) {
if ($do_mime && $cfgRelation['mimework']) {
$local_buffer .= "\000";
if (isset($mime_map[$field_name])) {
$local_buffer .= str_replace('_', '/', $mime_map[$field_name]['mimetype']);
$local_buffer .= str_replace(
'_',
'/',
$mime_map[$field_name]['mimetype']
);
}
}
$local_buffer = PMA_texEscape($local_buffer);
if ($row['Key']=='PRI') {
$pos=strpos($local_buffer, "\000");
$local_buffer = '\\textit{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos);
$local_buffer = '\\textit{'
. substr($local_buffer, 0, $pos)
. '}' . substr($local_buffer, $pos);
}
if (in_array($field_name, $unique_keys)) {
$pos=strpos($local_buffer, "\000");
$local_buffer = '\\textbf{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos);
$local_buffer = '\\textbf{'
. substr($local_buffer, 0, $pos)
. '}' . substr($local_buffer, $pos);
}
$buffer = str_replace("\000", ' & ', $local_buffer);
$buffer .= ' \\\\ \\hline ' . $crlf;

View File

@ -3,7 +3,7 @@
/**
* Set of functions used to build MediaWiki dumps of tables
*
* @package PhpMyAdmin-Export
* @package PhpMyAdmin-Export
* @subpackage MediaWiki
*/
if (! defined('PHPMYADMIN')) {
@ -15,53 +15,55 @@ if (isset($plugin_list)) {
'text' => __('MediaWiki Table'),
'extension' => 'mediawiki',
'mime_type' => 'text/plain',
'options' => array(
),
'options_text' => __('Options'),
);
'options' => array(),
'options_text' => __('Options')
);
// general options
$plugin_list['mediawiki']['options'][] = array(
'type' => 'begin_group',
'name' => 'general_opts');
// general options
$plugin_list['mediawiki']['options'][] = array(
'type' => 'begin_group',
'name' => 'general_opts'
);
// what to dump (structure/data/both)
$plugin_list['mediawiki']['options'][] = array(
'type' => 'begin_subgroup',
'subgroup_header' => array(
'type' => 'message_only',
'text' => __('Dump table')
));
$plugin_list['mediawiki']['options'][] = array(
'type' => 'radio',
'name' => 'structure_or_data',
'values' => array(
'structure' => __('structure'),
'data' => __('data'),
'structure_and_data' => __('structure and data')
));
$plugin_list['mediawiki']['options'][] = array(
'type' => 'end_subgroup'
);
// what to dump (structure/data/both)
$plugin_list['mediawiki']['options'][] = array(
'type' => 'begin_subgroup',
'subgroup_header' => array(
'type' => 'message_only',
'text' => __('Dump table')
)
);
$plugin_list['mediawiki']['options'][] = array(
'type' => 'radio',
'name' => 'structure_or_data',
'values' => array(
'structure' => __('structure'),
'data' => __('data'),
'structure_and_data' => __('structure and data')
)
);
$plugin_list['mediawiki']['options'][] = array(
'type' => 'end_subgroup'
);
// export table name
$plugin_list['mediawiki']['options'][] = array(
'type' => 'bool',
'name' => 'caption',
'text' => __('Export table names')
);
// export table name
$plugin_list['mediawiki']['options'][] = array(
'type' => 'bool',
'name' => 'caption',
'text' => __('Export table names')
);
// export table headers
$plugin_list['mediawiki']['options'][] = array(
'type' => 'bool',
'name' => 'headers',
'text' => __('Export table headers')
);
// export table headers
$plugin_list['mediawiki']['options'][] = array(
'type' => 'bool',
'name' => 'headers',
'text' => __('Export table headers')
);
// end general options
$plugin_list['mediawiki']['options'][] = array(
'type' => 'end_group'
);
// end general options
$plugin_list['mediawiki']['options'][] = array(
'type' => 'end_group'
);
} else {
/**
@ -100,9 +102,9 @@ if (isset($plugin_list)) {
/**
* Outputs export footer
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportFooter()
{
@ -112,9 +114,9 @@ if (isset($plugin_list)) {
/**
* Outputs export header
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportHeader()
{
@ -128,7 +130,7 @@ if (isset($plugin_list)) {
*
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBHeader($db)
{
@ -142,7 +144,7 @@ if (isset($plugin_list)) {
*
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBFooter($db)
{
@ -156,7 +158,7 @@ if (isset($plugin_list)) {
*
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBCreate($db)
{
@ -170,17 +172,17 @@ if (isset($plugin_list)) {
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
*
* @param bool $relation whether to include relation comments
* @param bool $comments whether to include the pmadb-style column comments
* @param string $export_mode 'create_table','triggers','create_view',
* 'stand_in'
* @param string $export_type 'server', 'database', 'table'
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column comments
* as comments in the structure; this is deprecated
* but the parameter is left here because export.php
* calls PMA_exportStructure() also for other export
* types which use this parameter
* @param bool $mime whether to include mime comments
* @param bool $do_mime whether to include mime comments
* @param bool $dates whether to include creation/update/check dates
* @param string $export_mode 'create_table','triggers','create_view','stand_in'
* @param string $export_type 'server', 'database', 'table'
*
* @return bool Whether it succeeded
*
@ -191,12 +193,12 @@ if (isset($plugin_list)) {
$table,
$crlf,
$error_url,
$relation = false,
$comments = false,
$mime = false,
$dates = false,
$export_mode,
$export_type
$export_type,
$do_relation = false,
$do_comments = false,
$do_mime = false,
$dates = false
) {
switch($export_mode) {
case 'create_table':
@ -271,7 +273,7 @@ if (isset($plugin_list)) {
*
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportData(
$db,

View File

@ -3,7 +3,7 @@
/**
* Set of functions used to build OpenDocument Spreadsheet dumps of tables
*
* @package PhpMyAdmin-Export
* @package PhpMyAdmin-Export
* @subpackage ODS
*/
if (! defined('PHPMYADMIN')) {
@ -19,15 +19,33 @@ if (isset($plugin_list)) {
'extension' => 'ods',
'mime_type' => 'application/vnd.oasis.opendocument.spreadsheet',
'force_file' => true,
'options' => array(
array('type' => 'begin_group', 'name' => 'general_opts'),
array('type' => 'text', 'name' => 'null', 'text' => __('Replace NULL with:')),
array('type' => 'bool', 'name' => 'columns', 'text' => __('Put columns names in the first row')),
array('type' => 'hidden', 'name' => 'structure_or_data'),
array('type' => 'end_group'),
),
'options_text' => __('Options'),
);
'options' => array(),
'options_text' => __('Options')
);
$plugin_list['ods']['options'] = array(
array(
'type' => 'begin_group',
'name' => 'general_opts'
),
array(
'type' => 'text',
'name' => 'null',
'text' => __('Replace NULL with:')
),
array(
'type' => 'bool',
'name' => 'columns',
'text' => __('Put columns names in the first row')
),
array(
'type' => 'hidden',
'name' => 'structure_or_data'
),
array(
'type' => 'end_group'
)
);
} else {
$GLOBALS['ods_buffer'] = '';
@ -36,16 +54,21 @@ if (isset($plugin_list)) {
/**
* Outputs export footer
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportFooter()
{
$GLOBALS['ods_buffer'] .= '</office:spreadsheet>'
. '</office:body>'
. '</office:document-content>';
if (!PMA_exportOutputHandler(PMA_createOpenDocument('application/vnd.oasis.opendocument.spreadsheet', $GLOBALS['ods_buffer']))) {
if (! PMA_exportOutputHandler(
PMA_createOpenDocument(
'application/vnd.oasis.opendocument.spreadsheet',
$GLOBALS['ods_buffer']
)
)) {
return false;
}
return true;
@ -54,16 +77,18 @@ if (isset($plugin_list)) {
/**
* Outputs export header
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportHeader()
{
$GLOBALS['ods_buffer'] .= '<?xml version="1.0" encoding="utf-8"?' . '>'
. '<office:document-content '. $GLOBALS['OpenDocumentNS'] . 'office:version="1.0">'
. '<office:document-content '
. $GLOBALS['OpenDocumentNS'] . 'office:version="1.0">'
. '<office:automatic-styles>'
. '<number:date-style style:name="N37" number:automatic-order="true">'
. '<number:date-style style:name="N37"'
.' number:automatic-order="true">'
. '<number:month number:style="long"/>'
. '<number:text>/</number:text>'
. '<number:day number:style="long"/>'
@ -79,7 +104,9 @@ if (isset($plugin_list)) {
. '<number:text> </number:text>'
. '<number:am-pm/>'
. '</number:time-style>'
. '<number:date-style style:name="N50" number:automatic-order="true" number:format-source="language">'
. '<number:date-style style:name="N50"'
. ' number:automatic-order="true"'
. ' number:format-source="language">'
. '<number:month/>'
. '<number:text>/</number:text>'
. '<number:day/>'
@ -92,9 +119,12 @@ if (isset($plugin_list)) {
. '<number:text> </number:text>'
. '<number:am-pm/>'
. '</number:date-style>'
. '<style:style style:name="DateCell" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N37"/>'
. '<style:style style:name="TimeCell" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N43"/>'
. '<style:style style:name="DateTimeCell" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N50"/>'
. '<style:style style:name="DateCell" style:family="table-cell"'
. ' style:parent-style-name="Default" style:data-style-name="N37"/>'
. '<style:style style:name="TimeCell" style:family="table-cell"'
. ' style:parent-style-name="Default" style:data-style-name="N43"/>'
. '<style:style style:name="DateTimeCell" style:family="table-cell"'
. ' style:parent-style-name="Default" style:data-style-name="N50"/>'
. '</office:automatic-styles>'
. '<office:body>'
. '<office:spreadsheet>';
@ -104,11 +134,11 @@ if (isset($plugin_list)) {
/**
* Outputs database header
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBHeader($db)
{
@ -118,11 +148,11 @@ if (isset($plugin_list)) {
/**
* Outputs database footer
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBFooter($db)
{
@ -132,11 +162,11 @@ if (isset($plugin_list)) {
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBCreate($db)
{
@ -146,15 +176,15 @@ if (isset($plugin_list)) {
/**
* Outputs the content of a table in ODS format
*
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
@ -169,14 +199,20 @@ if (isset($plugin_list)) {
$field_flags[$j] = PMA_DBI_field_flags($result, $j);
}
$GLOBALS['ods_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '">';
$GLOBALS['ods_buffer'] .=
'<table:table table:name="' . htmlspecialchars($table) . '">';
// If required, get fields name at the first line
if (isset($GLOBALS[$what . '_columns'])) {
$GLOBALS['ods_buffer'] .= '<table:table-row>';
for ($i = 0; $i < $fields_cnt; $i++) {
$GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</text:p>'
$GLOBALS['ods_buffer'] .=
'<table:table-cell office:value-type="string">'
. '<text:p>'
. htmlspecialchars(
stripslashes(PMA_DBI_field_name($result, $i))
)
. '</text:p>'
. '</table:table-cell>';
} // end for
$GLOBALS['ods_buffer'] .= '</table:table-row>';
@ -186,35 +222,68 @@ if (isset($plugin_list)) {
while ($row = PMA_DBI_fetch_row($result)) {
$GLOBALS['ods_buffer'] .= '<table:table-row>';
for ($j = 0; $j < $fields_cnt; $j++) {
if (!isset($row[$j]) || is_null($row[$j])) {
$GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars($GLOBALS[$what . '_null']) . '</text:p>'
if (! isset($row[$j]) || is_null($row[$j])) {
$GLOBALS['ods_buffer'] .=
'<table:table-cell office:value-type="string">'
. '<text:p>'
. htmlspecialchars($GLOBALS[$what . '_null'])
. '</text:p>'
. '</table:table-cell>';
// ignore BLOB
} elseif (stristr($field_flags[$j], 'BINARY')
&& $fields_meta[$j]->blob) {
$GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
&& $fields_meta[$j]->blob
) {
// ignore BLOB
$GLOBALS['ods_buffer'] .=
'<table:table-cell office:value-type="string">'
. '<text:p></text:p>'
. '</table:table-cell>';
} elseif ($fields_meta[$j]->type == "date") {
$GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="date" office:date-value="' . date("Y-m-d", strtotime($row[$j])) . '" table:style-name="DateCell">'
. '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>'
$GLOBALS['ods_buffer'] .=
'<table:table-cell office:value-type="date"'
. ' office:date-value="'
. date("Y-m-d", strtotime($row[$j]))
. '" table:style-name="DateCell">'
. '<text:p>'
. htmlspecialchars($row[$j])
. '</text:p>'
. '</table:table-cell>';
} elseif ($fields_meta[$j]->type == "time") {
$GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="time" office:time-value="' . date("\P\TH\Hi\Ms\S", strtotime($row[$j])) . '" table:style-name="TimeCell">'
. '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>'
$GLOBALS['ods_buffer'] .=
'<table:table-cell office:value-type="time"'
. ' office:time-value="'
. date("\P\TH\Hi\Ms\S", strtotime($row[$j]))
. '" table:style-name="TimeCell">'
. '<text:p>'
. htmlspecialchars($row[$j])
. '</text:p>'
. '</table:table-cell>';
} elseif ($fields_meta[$j]->type == "datetime") {
$GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="date" office:date-value="' . date("Y-m-d\TH:i:s", strtotime($row[$j])) . '" table:style-name="DateTimeCell">'
. '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>'
$GLOBALS['ods_buffer'] .=
'<table:table-cell office:value-type="date"'
. ' office:date-value="'
. date("Y-m-d\TH:i:s", strtotime($row[$j]))
. '" table:style-name="DateTimeCell">'
. '<text:p>'
. htmlspecialchars($row[$j])
. '</text:p>'
. '</table:table-cell>';
} elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp' && ! $fields_meta[$j]->blob) {
$GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="float" office:value="' . $row[$j] . '" >'
. '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>'
} elseif ($fields_meta[$j]->numeric
&& $fields_meta[$j]->type != 'timestamp'
&& ! $fields_meta[$j]->blob
) {
$GLOBALS['ods_buffer'] .=
'<table:table-cell office:value-type="float"'
. ' office:value="' . $row[$j] . '" >'
. '<text:p>'
. htmlspecialchars($row[$j])
. '</text:p>'
. '</table:table-cell>';
} else {
$GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>'
$GLOBALS['ods_buffer'] .=
'<table:table-cell office:value-type="string">'
. '<text:p>'
. htmlspecialchars($row[$j])
. '</text:p>'
. '</table:table-cell>';
}
} // end for

View File

@ -3,7 +3,7 @@
/**
* Set of functions used to build OpenDocument Text dumps of tables
*
* @package PhpMyAdmin-Export
* @package PhpMyAdmin-Export
* @subpackage ODT
*/
if (! defined('PHPMYADMIN')) {
@ -15,7 +15,9 @@ if (! defined('PHPMYADMIN')) {
*/
if (isset($plugin_list)) {
$hide_structure = false;
if ($plugin_param['export_type'] == 'table' && !$plugin_param['single_table']) {
if ($plugin_param['export_type'] == 'table'
&& ! $plugin_param['single_table']
) {
$hide_structure = true;
}
$plugin_list['odt'] = array(
@ -23,43 +25,81 @@ if (isset($plugin_list)) {
'extension' => 'odt',
'mime_type' => 'application/vnd.oasis.opendocument.text',
'force_file' => true,
'options' => array(), /* Filled later */
'options_text' => __('Options'),
);
'options' => array(),
'options_text' => __('Options')
);
/* what to dump (structure/data/both) */
$plugin_list['odt']['options'][]
= array('type' => 'begin_group', 'text' => __('Dump table') , 'name' => 'general_opts');
$plugin_list['odt']['options'][]
= array('type' => 'radio', 'name' => 'structure_or_data', 'values' => array('structure' => __('structure'), 'data' => __('data'), 'structure_and_data' => __('structure and data')));
$plugin_list['odt']['options'][] = array('type' => 'end_group');
$plugin_list['odt']['options'][] = array(
'type' => 'begin_group',
'text' => __('Dump table'),
'name' => 'general_opts'
);
$plugin_list['odt']['options'][] = array(
'type' => 'radio',
'name' => 'structure_or_data',
'values' => array(
'structure' => __('structure'),
'data' => __('data'),
'structure_and_data' => __('structure and data')
)
);
$plugin_list['odt']['options'][] = array(
'type' => 'end_group'
);
/* Structure options */
if (!$hide_structure) {
$plugin_list['odt']['options'][]
= array('type' => 'begin_group', 'name' => 'structure', 'text' => __('Object creation options'), 'force' => 'data');
if (!empty($GLOBALS['cfgRelation']['relation'])) {
$plugin_list['odt']['options'][]
= array('type' => 'bool', 'name' => 'relation', 'text' => __('Display foreign key relationships'));
if (! $hide_structure) {
$plugin_list['odt']['options'][] = array(
'type' => 'begin_group',
'name' => 'structure',
'text' => __('Object creation options'),
'force' => 'data'
);
if (! empty($GLOBALS['cfgRelation']['relation'])) {
$plugin_list['odt']['options'][] = array(
'type' => 'bool',
'name' => 'relation',
'text' => __('Display foreign key relationships')
);
}
$plugin_list['odt']['options'][]
= array('type' => 'bool', 'name' => 'comments', 'text' => __('Display comments'));
if (!empty($GLOBALS['cfgRelation']['mimework'])) {
$plugin_list['odt']['options'][]
= array('type' => 'bool', 'name' => 'mime', 'text' => __('Display MIME types'));
$plugin_list['odt']['options'][] = array(
'type' => 'bool',
'name' => 'comments',
'text' => __('Display comments')
);
if (! empty($GLOBALS['cfgRelation']['mimework'])) {
$plugin_list['odt']['options'][] = array(
'type' => 'bool',
'name' => 'mime',
'text' => __('Display MIME types')
);
}
$plugin_list['odt']['options'][]
= array('type' => 'end_group');
$plugin_list['odt']['options'][] = array(
'type' => 'end_group'
);
}
/* Data */
$plugin_list['odt']['options'][]
= array('type' => 'begin_group', 'name' => 'data', 'text' => __('Data dump options'), 'force' => 'structure');
$plugin_list['odt']['options'][]
= array('type' => 'bool', 'name' => 'columns', 'text' => __('Put columns names in the first row'));
$plugin_list['odt']['options'][]
= array('type' => 'text', 'name' => 'null', 'text' => __('Replace NULL with:'));
$plugin_list['odt']['options'][]
= array('type' => 'end_group');
$plugin_list['odt']['options'][] = array(
'type' => 'begin_group',
'name' => 'data',
'text' => __('Data dump options'),
'force' => 'structure'
);
$plugin_list['odt']['options'][] = array(
'type' => 'bool',
'name' => 'columns',
'text' => __('Put columns names in the first row')
);
$plugin_list['odt']['options'][] = array(
'type' => 'text',
'name' => 'null',
'text' => __('Replace NULL with:')
);
$plugin_list['odt']['options'][] = array(
'type' => 'end_group'
);
} else {
$GLOBALS['odt_buffer'] = '';
@ -77,7 +117,12 @@ if (isset($plugin_list)) {
$GLOBALS['odt_buffer'] .= '</office:text>'
. '</office:body>'
. '</office:document-content>';
if (! PMA_exportOutputHandler(PMA_createOpenDocument('application/vnd.oasis.opendocument.text', $GLOBALS['odt_buffer']))) {
if (! PMA_exportOutputHandler(
PMA_createOpenDocument(
'application/vnd.oasis.opendocument.text',
$GLOBALS['odt_buffer']
)
)) {
return false;
}
return true;
@ -93,7 +138,8 @@ if (isset($plugin_list)) {
function PMA_exportHeader()
{
$GLOBALS['odt_buffer'] .= '<?xml version="1.0" encoding="utf-8"?' . '>'
. '<office:document-content '. $GLOBALS['OpenDocumentNS'] . 'office:version="1.0">'
. '<office:document-content '
. $GLOBALS['OpenDocumentNS'] . 'office:version="1.0">'
. '<office:body>'
. '<office:text>';
return true;
@ -110,8 +156,11 @@ if (isset($plugin_list)) {
*/
function PMA_exportDBHeader($db)
{
$GLOBALS['odt_buffer'] .= '<text:h text:outline-level="1" text:style-name="Heading_1" text:is-list-header="true">'
. __('Database') . ' ' . htmlspecialchars($db) . '</text:h>';
$GLOBALS['odt_buffer'] .=
'<text:h text:outline-level="1" text:style-name="Heading_1"'
. ' text:is-list-header="true">'
. __('Database') . ' ' . htmlspecialchars($db)
. '</text:h>';
return true;
}
@ -169,17 +218,29 @@ if (isset($plugin_list)) {
$field_flags[$j] = PMA_DBI_field_flags($result, $j);
}
$GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">'
. __('Dumping data for table') . ' ' . htmlspecialchars($table) . '</text:h>';
$GLOBALS['odt_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '_structure">';
$GLOBALS['odt_buffer'] .= '<table:table-column table:number-columns-repeated="' . $fields_cnt . '"/>';
$GLOBALS['odt_buffer'] .=
'<text:h text:outline-level="2" text:style-name="Heading_2"'
. ' text:is-list-header="true">'
. __('Dumping data for table') . ' ' . htmlspecialchars($table)
. '</text:h>';
$GLOBALS['odt_buffer'] .=
'<table:table'
. ' table:name="' . htmlspecialchars($table) . '_structure">';
$GLOBALS['odt_buffer'] .=
'<table:table-column'
. ' table:number-columns-repeated="' . $fields_cnt . '"/>';
// If required, get fields name at the first line
if (isset($GLOBALS[$what . '_columns'])) {
$GLOBALS['odt_buffer'] .= '<table:table-row>';
for ($i = 0; $i < $fields_cnt; $i++) {
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</text:p>'
$GLOBALS['odt_buffer'] .=
'<table:table-cell office:value-type="string">'
. '<text:p>'
. htmlspecialchars(
stripslashes(PMA_DBI_field_name($result, $i))
)
. '</text:p>'
. '</table:table-cell>';
} // end for
$GLOBALS['odt_buffer'] .= '</table:table-row>';
@ -189,23 +250,38 @@ if (isset($plugin_list)) {
while ($row = PMA_DBI_fetch_row($result)) {
$GLOBALS['odt_buffer'] .= '<table:table-row>';
for ($j = 0; $j < $fields_cnt; $j++) {
if (!isset($row[$j]) || is_null($row[$j])) {
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars($GLOBALS[$what . '_null']) . '</text:p>'
if (! isset($row[$j]) || is_null($row[$j])) {
$GLOBALS['odt_buffer'] .=
'<table:table-cell office:value-type="string">'
. '<text:p>'
. htmlspecialchars($GLOBALS[$what . '_null'])
. '</text:p>'
. '</table:table-cell>';
// ignore BLOB
} elseif (stristr($field_flags[$j], 'BINARY')
&& $fields_meta[$j]->blob) {
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
&& $fields_meta[$j]->blob
) {
// ignore BLOB
$GLOBALS['odt_buffer'] .=
'<table:table-cell office:value-type="string">'
. '<text:p></text:p>'
. '</table:table-cell>';
} elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp' && ! $fields_meta[$j]->blob) {
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="float" office:value="' . $row[$j] . '" >'
. '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>'
} elseif ($fields_meta[$j]->numeric
&& $fields_meta[$j]->type != 'timestamp'
&& ! $fields_meta[$j]->blob
) {
$GLOBALS['odt_buffer'] .=
'<table:table-cell office:value-type="float"'
. ' office:value="' . $row[$j] . '" >'
. '<text:p>'
. htmlspecialchars($row[$j])
. '</text:p>'
. '</table:table-cell>';
} else {
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>'
$GLOBALS['odt_buffer'] .=
'<table:table-cell office:value-type="string">'
. '<text:p>'
. htmlspecialchars($row[$j])
. '</text:p>'
. '</table:table-cell>';
}
} // end for
@ -239,9 +315,13 @@ if (isset($plugin_list)) {
/**
* Displays the table structure
*/
$GLOBALS['odt_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '_data">';
$GLOBALS['odt_buffer'] .=
'<table:table table:name="'
. htmlspecialchars($table) . '_data">';
$columns_cnt = 4;
$GLOBALS['odt_buffer'] .= '<table:table-column table:number-columns-repeated="' . $columns_cnt . '"/>';
$GLOBALS['odt_buffer'] .=
'<table:table-column'
. ' table:number-columns-repeated="' . $columns_cnt . '"/>';
/* Header */
$GLOBALS['odt_buffer'] .= '<table:table-row>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
@ -276,22 +356,33 @@ if (isset($plugin_list)) {
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column comments
* as comments in the structure; this is deprecated
* but the parameter is left here because export.php
* calls PMA_exportStructure() also for other export
* types which use this parameter
* @param bool $do_comments whether to include the pmadb-style column
* comments as comments in the structure;
* this is deprecated but the parameter is
* left here because export.php calls
* PMA_exportStructure() also for other
* @param bool $do_mime whether to include mime comments
* @param bool $show_dates whether to include creation/update/check dates
* @param bool $add_semicolon whether to add semicolon and end-of-line at the end
* @param bool $add_semicolon whether to add semicolon and end-of-line at
* the end
* @param bool $view whether we're handling a view
*
* @return bool true
*
* @access public
*/
function PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $show_dates = false, $add_semicolon = true, $view = false)
{
function PMA_getTableDef(
$db,
$table,
$crlf,
$error_url,
$do_relation,
$do_comments,
$do_mime,
$show_dates = false,
$add_semicolon = true,
$view = false
) {
global $cfgRelation;
/**
@ -300,7 +391,7 @@ if (isset($plugin_list)) {
PMA_DBI_select_db($db);
// Check if we can use Relations
if ($do_relation && !empty($cfgRelation['relation'])) {
if ($do_relation && ! empty($cfgRelation['relation'])) {
// Find which tables are related with the current one and write it in
// an array
$res_rel = PMA_getForeigners($db, $table);
@ -317,7 +408,8 @@ if (isset($plugin_list)) {
/**
* Displays the table structure
*/
$GLOBALS['odt_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '_structure">';
$GLOBALS['odt_buffer'] .= '<table:table table:name="'
. htmlspecialchars($table) . '_structure">';
$columns_cnt = 4;
if ($do_relation && $have_rel) {
$columns_cnt++;
@ -328,7 +420,8 @@ if (isset($plugin_list)) {
if ($do_mime && $cfgRelation['mimework']) {
$columns_cnt++;
}
$GLOBALS['odt_buffer'] .= '<table:table-column table:number-columns-repeated="' . $columns_cnt . '"/>';
$GLOBALS['odt_buffer'] .= '<table:table-column'
. ' table:number-columns-repeated="' . $columns_cnt . '"/>';
/* Header */
$GLOBALS['odt_buffer'] .= '<table:table-row>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
@ -368,29 +461,45 @@ if (isset($plugin_list)) {
if ($do_relation && $have_rel) {
if (isset($res_rel[$field_name])) {
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') . '</text:p>'
$GLOBALS['odt_buffer'] .=
'<table:table-cell office:value-type="string">'
. '<text:p>'
. htmlspecialchars(
$res_rel[$field_name]['foreign_table']
. ' (' . $res_rel[$field_name]['foreign_field'] . ')'
)
. '</text:p>'
. '</table:table-cell>';
}
}
if ($do_comments) {
if (isset($comments[$field_name])) {
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars($comments[$field_name]) . '</text:p>'
$GLOBALS['odt_buffer'] .=
'<table:table-cell office:value-type="string">'
. '<text:p>'
. htmlspecialchars($comments[$field_name])
. '</text:p>'
. '</table:table-cell>';
} else {
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
$GLOBALS['odt_buffer'] .=
'<table:table-cell office:value-type="string">'
. '<text:p></text:p>'
. '</table:table-cell>';
}
}
if ($do_mime && $cfgRelation['mimework']) {
if (isset($mime_map[$field_name])) {
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) . '</text:p>'
$GLOBALS['odt_buffer'] .=
'<table:table-cell office:value-type="string">'
. '<text:p>'
. htmlspecialchars(
str_replace('_', '/', $mime_map[$field_name]['mimetype'])
)
. '</text:p>'
. '</table:table-cell>';
} else {
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
$GLOBALS['odt_buffer'] .=
'<table:table-cell office:value-type="string">'
. '<text:p></text:p>'
. '</table:table-cell>';
}
@ -405,16 +514,19 @@ if (isset($plugin_list)) {
/**
* Outputs triggers
*
* @param string $db database name
* @param string $table table name
* @param string $db database name
* @param string $table table name
*
* @return bool true
*
* @access public
*/
function PMA_getTriggers($db, $table)
{
$GLOBALS['odt_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '_triggers">';
$GLOBALS['odt_buffer'] .= '<table:table-column table:number-columns-repeated="4"/>';
$GLOBALS['odt_buffer'] .= '<table:table'
. ' table:name="' . htmlspecialchars($table) . '_triggers">';
$GLOBALS['odt_buffer'] .= '<table:table-column'
. ' table:number-columns-repeated="4"/>';
$GLOBALS['odt_buffer'] .= '<table:table-row>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . __('Name') . '</text:p>'
@ -435,16 +547,24 @@ if (isset($plugin_list)) {
foreach ($triggers as $trigger) {
$GLOBALS['odt_buffer'] .= '<table:table-row>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars($trigger['name']) . '</text:p>'
. '<text:p>'
. htmlspecialchars($trigger['name'])
. '</text:p>'
. '</table:table-cell>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars($trigger['action_timing']) . '</text:p>'
. '<text:p>'
. htmlspecialchars($trigger['action_timing'])
. '</text:p>'
. '</table:table-cell>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars($trigger['event_manipulation']) . '</text:p>'
. '<text:p>'
. htmlspecialchars($trigger['event_manipulation'])
. '</text:p>'
. '</table:table-cell>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars($trigger['definition']) . '</text:p>'
. '<text:p>'
. htmlspecialchars($trigger['definition'])
. '</text:p>'
. '</table:table-cell>';
$GLOBALS['odt_buffer'] .= '</table:table-row>';
}
@ -460,45 +580,78 @@ if (isset($plugin_list)) {
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $export_mode 'create_table', 'triggers', 'create_view',
* 'stand_in'
* @param string $export_type 'server', 'database', 'table'
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column comments
* as comments in the structure; this is deprecated
* but the parameter is left here because export.php
* calls PMA_exportStructure() also for other export
* types which use this parameter
* @param bool $do_comments whether to include the pmadb-style column
* comments as comments in the structure;
* this is deprecated but the parameter is
* left here because export.php calls
* PMA_exportStructure() also for other
* @param bool $do_mime whether to include mime comments
* @param bool $dates whether to include creation/update/check dates
* @param string $export_mode 'create_table', 'triggers', 'create_view', 'stand_in'
* @param string $export_type 'server', 'database', 'table'
*
* @return bool Whether it succeeded
*
* @access public
*/
function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $export_mode, $export_type)
{
function PMA_exportStructure(
$db,
$table,
$crlf,
$error_url,
$export_mode,
$export_type,
$do_relation = false,
$do_comments = false,
$do_mime = false,
$dates = false
) {
switch($export_mode) {
case 'create_table':
$GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">'
. __('Table structure for table') . ' ' . htmlspecialchars($table) . '</text:h>';
PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates);
$GLOBALS['odt_buffer'] .=
'<text:h text:outline-level="2" text:style-name="Heading_2"'
. ' text:is-list-header="true">'
. __('Table structure for table') . ' ' .
htmlspecialchars($table)
. '</text:h>';
PMA_getTableDef(
$db, $table, $crlf, $error_url, $do_relation, $do_comments,
$do_mime, $dates
);
break;
case 'triggers':
$triggers = PMA_DBI_get_triggers($db, $table);
if ($triggers) {
$GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">'
. __('Triggers') . ' ' . htmlspecialchars($table) . '</text:h>';
$GLOBALS['odt_buffer'] .=
'<text:h text:outline-level="2" text:style-name="Heading_2"'
. ' text:is-list-header="true">'
. __('Triggers') . ' '
. htmlspecialchars($table)
. '</text:h>';
PMA_getTriggers($db, $table);
}
break;
case 'create_view':
$GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">'
. __('Structure for view') . ' ' . htmlspecialchars($table) . '</text:h>';
PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates, true, true);
$GLOBALS['odt_buffer'] .=
'<text:h text:outline-level="2" text:style-name="Heading_2"'
. ' text:is-list-header="true">'
. __('Structure for view') . ' '
. htmlspecialchars($table)
. '</text:h>';
PMA_getTableDef(
$db, $table, $crlf, $error_url, $do_relation, $do_comments,
$do_mime, $dates, true, true
);
break;
case 'stand_in':
$GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">'
. __('Stand-in structure for view') . ' ' . htmlspecialchars($table) . '</text:h>';
$GLOBALS['odt_buffer'] .=
'<text:h text:outline-level="2" text:style-name="Heading_2"'
. ' text:is-list-header="true">'
. __('Stand-in structure for view') . ' '
. htmlspecialchars($table)
. '</text:h>';
// export a stand-in definition to resolve view dependencies
PMA_getTableDefStandIn($db, $table, $crlf);
} // end switch
@ -509,15 +662,14 @@ if (isset($plugin_list)) {
/**
* Formats the definition for one column
*
* @param array $column info about this column
* @param array $column info about this column
*
* @return string Formatted column definition
* @return string Formatted column definition
*
* @access public
*/
function PMA_formatOneColumnDefinition(
$column
) {
function PMA_formatOneColumnDefinition($column)
{
$field_name = $column['Field'];
$definition = '<table:table-row>';
$definition .= '<table:table-cell office:value-type="string">'
@ -527,7 +679,7 @@ if (isset($plugin_list)) {
$extracted_columnspec = PMA_extractColumnSpec($column['Type']);
$type = htmlspecialchars($extracted_columnspec['print_type']);
if (empty($type)) {
$type = '&nbsp;';
$type = '&nbsp;';
}
$definition .= '<table:table-cell office:value-type="string">'

View File

@ -3,7 +3,7 @@
/**
* Produce a PDF report (export) from a query
*
* @package PhpMyAdmin-Export
* @package PhpMyAdmin-Export
* @subpackage PDF
*/
if (! defined('PHPMYADMIN')) {
@ -19,22 +19,43 @@ if (isset($plugin_list)) {
'extension' => 'pdf',
'mime_type' => 'application/pdf',
'force_file' => true,
'options' => array(
array('type' => 'begin_group', 'name' => 'general_opts'),
array('type' => 'message_only', 'name' => 'explanation', 'text' => __('(Generates a report containing the data of a single table)')),
array('type' => 'text', 'name' => 'report_title', 'text' => __('Report title:')),
array('type' => 'hidden', 'name' => 'structure_or_data'),
array('type' => 'end_group')
),
'options_text' => __('Options'),
);
'options' => array(),
'options_text' => __('Options')
);
$plugin_list['pdf']['options'] = array(
array(
'type' => 'begin_group',
'name' => 'general_opts'
),
array(
'type' => 'message_only',
'name' => 'explanation',
'text' => __(
'(Generates a report containing the data of a single table)'
)
),
array(
'type' => 'text',
'name' => 'report_title',
'text' => __('Report title:')
),
array(
'type' => 'hidden',
'name' => 'structure_or_data'
),
array(
'type' => 'end_group'
)
);
} else {
include_once './libraries/PDF.class.php';
/**
* Adapted from a LGPL script by Philip Clarke
* @package PhpMyAdmin-Export
*
* @package PhpMyAdmin-Export
* @subpackage PDF
*/
class PMA_Export_PDF extends PMA_PDF
@ -48,22 +69,30 @@ if (isset($plugin_list)) {
$y = $this->y;
}
$current_page = $this->page;
if ((($y + $h) > $this->PageBreakTrigger) AND (! $this->InFooter) AND ($this->AcceptPageBreak())) {
if ((($y + $h) > $this->PageBreakTrigger)
AND (! $this->InFooter)
AND ($this->AcceptPageBreak())
) {
if ($addpage) {
//Automatic page break
$x = $this->x;
$this->AddPage($this->CurOrientation);
$this->y = $this->dataY;
$oldpage = $this->page - 1;
$this_page_orm = $this->pagedim[$this->page]['orm'];
$old_page_orm = $this->pagedim[$oldpage]['orm'];
$this_page_olm = $this->pagedim[$this->page]['olm'];
$old_page_olm = $this->pagedim[$oldpage]['olm'];
if ($this->rtl) {
if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm']) {
$this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']);
if ($this_page_orm!= $old_page_orm) {
$this->x = $x - ($this_page_orm - $old_page_orm);
} else {
$this->x = $x;
}
} else {
if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
$this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']);
if ($this_page_olm != $old_page_olm) {
$this->x = $x + ($this_page_olm - $old_page_olm);
} else {
$this->x = $x;
}
@ -89,19 +118,31 @@ if (isset($plugin_list)) {
}
$this->SetY(($this->tMargin) - ($this->FontSizePt / $this->k) * 5);
$this->cellFontSize = $this->FontSizePt ;
$this->SetFont(PMA_PDF_FONT, '', ($this->titleFontSize ? $this->titleFontSize : $this->FontSizePt));
$this->SetFont(
PMA_PDF_FONT,
'',
($this->titleFontSize
? $this->titleFontSize
: $this->FontSizePt)
);
$this->Cell(0, $this->FontSizePt, $this->titleText, 0, 1, 'C');
$this->SetFont(PMA_PDF_FONT, '', $this->cellFontSize);
$this->SetY(($this->tMargin) - ($this->FontSizePt / $this->k) * 2.5);
$this->Cell(
0, $this->FontSizePt,
__('Database') . ': ' . $this->currentDb . ', ' . __('Table') . ': ' . $this->currentTable,
0,
$this->FontSizePt,
__('Database') . ': ' . $this->currentDb . ', '
. __('Table') . ': ' . $this->currentTable,
0, 1, 'L'
);
$l = ($this->lMargin);
foreach ($this->colTitles as $col => $txt) {
$this->SetXY($l, ($this->tMargin));
$this->MultiCell($this->tablewidths[$col], $this->FontSizePt, $txt);
$this->MultiCell(
$this->tablewidths[$col],
$this->FontSizePt,
$txt
);
$l += $this->tablewidths[$col] ;
$maxY = ($maxY < $this->getY()) ? $this->getY() : $maxY ;
}
@ -110,9 +151,23 @@ if (isset($plugin_list)) {
$l = ($this->lMargin);
foreach ($this->colTitles as $col => $txt) {
$this->SetXY($l, $this->tMargin);
$this->cell($this->tablewidths[$col], $maxY-($this->tMargin), '', 1, 0, 'L', 1);
$this->cell(
$this->tablewidths[$col],
$maxY-($this->tMargin),
'',
1,
0,
'L',
1
);
$this->SetXY($l, $this->tMargin);
$this->MultiCell($this->tablewidths[$col], $this->FontSizePt, $txt, 0, 'C');
$this->MultiCell(
$this->tablewidths[$col],
$this->FontSizePt,
$txt,
0,
'C'
);
$l += $this->tablewidths[$col];
}
$this->setFillColor(255, 255, 255);
@ -150,11 +205,17 @@ if (isset($plugin_list)) {
$this->page = $currpage;
$this->SetXY($l, $h);
if ($this->tablewidths[$col] > 0) {
$this->MultiCell($this->tablewidths[$col], $lineheight, $txt, 0, $this->colAlign[$col]);
$this->MultiCell(
$this->tablewidths[$col],
$lineheight,
$txt,
0,
$this->colAlign[$col]
);
$l += $this->tablewidths[$col];
}
if (!isset($tmpheight[$row.'-'.$this->page])) {
if (! isset($tmpheight[$row.'-'.$this->page])) {
$tmpheight[$row.'-'.$this->page] = 0;
}
if ($tmpheight[$row.'-'.$this->page] < $this->GetY()) {
@ -207,7 +268,7 @@ if (isset($plugin_list)) {
$this->tMargin = $topMargin;
}
function mysql_report($query)
function mysqlReport($query)
{
unset($this->tablewidths);
unset($this->colTitles);
@ -228,8 +289,10 @@ if (isset($plugin_list)) {
$this->sColWidth = $availableWidth / $this->numFields;
$totalTitleWidth = 0;
// loop through results header and set initial col widths/ titles/ alignment
// if a col title is less than the starting col width, reduce that column size
// loop through results header and set initial
// col widths/ titles/ alignment
// if a col title is less than the starting col width,
// reduce that column size
$colFits = array();
for ($i = 0; $i < $this->numFields; $i++) {
$stringWidth = $this->getstringwidth($this->fields[$i]->name) + 6 ;
@ -237,7 +300,8 @@ if (isset($plugin_list)) {
$titleWidth[$i] = $stringWidth;
$totalTitleWidth += $stringWidth;
// set any column titles less than the start width to the column title width
// set any column titles less than the start width to
// the column title width
if ($stringWidth < $this->sColWidth) {
$colFits[$i] = $stringWidth ;
}
@ -295,7 +359,9 @@ if (isset($plugin_list)) {
// if data's width is bigger than the current column width,
// enlarge the column (but avoid enlarging it if the
// data's width is very big)
if ($stringWidth > $val && $stringWidth < ($this->sColWidth * 3)) {
if ($stringWidth > $val
&& $stringWidth < ($this->sColWidth * 3)
) {
$colFits[$key] = $stringWidth ;
}
}
@ -317,8 +383,8 @@ if (isset($plugin_list)) {
$surplusToAdd = 0;
}
for ($i=0; $i < $this->numFields; $i++) {
if (!in_array($i, array_keys($colFits))) {
for ($i = 0; $i < $this->numFields; $i++) {
if (! in_array($i, array_keys($colFits))) {
$this->tablewidths[$i] = $this->sColWidth + $surplusToAdd;
}
if ($this->display_column[$i] == false) {
@ -339,7 +405,7 @@ if (isset($plugin_list)) {
$this->morepagestable($this->FontSizePt);
PMA_DBI_free_result($this->results);
} // end of mysql_report function
} // end of mysqlReport function
} // end of PMA_Export_PDF class
@ -348,16 +414,16 @@ if (isset($plugin_list)) {
/**
* Finalize the pdf.
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportFooter()
{
global $pdf;
// instead of $pdf->Output():
if (!PMA_exportOutputHandler($pdf->getPDFData())) {
if (! PMA_exportOutputHandler($pdf->getPDFData())) {
return false;
}
@ -367,9 +433,9 @@ if (isset($plugin_list)) {
/**
* Initialize the pdf to export data.
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportHeader()
{
@ -444,9 +510,9 @@ if (isset($plugin_list)) {
{
global $pdf;
$attr=array('currentDb' => $db, 'currentTable' => $table);
$attr = array('currentDb' => $db, 'currentTable' => $table);
$pdf->setAttributes($attr);
$pdf->mysql_report($sql_query);
$pdf->mysqlReport($sql_query);
return true;
} // end of the 'PMA_exportData()' function

View File

@ -3,7 +3,7 @@
/**
* Set of functions used to build dumps of tables as PHP Arrays
*
* @package PhpMyAdmin-Export
* @package PhpMyAdmin-Export
* @subpackage PHP
*/
if (! defined('PHPMYADMIN')) {
@ -15,18 +15,25 @@ if (! defined('PHPMYADMIN')) {
*/
if (isset($plugin_list)) {
$plugin_list['php_array'] = array(
'text' => __('PHP array'),
'extension' => 'php',
'mime_type' => 'text/plain',
'options' => array(
array('type' => 'begin_group', 'name' => 'general_opts'),
array(
'type' => 'hidden',
'name' => 'structure_or_data',
),
array('type' => 'end_group')
'text' => __('PHP array'),
'extension' => 'php',
'mime_type' => 'text/plain',
'options' => array(),
'options_text' => __('Options')
);
$plugin_list['php_array']['options'] = array(
array(
'type' => 'begin_group',
'name' => 'general_opts'
),
'options_text' => __('Options'),
array(
'type' => 'hidden',
'name' => 'structure_or_data',
),
array(
'type' => 'end_group'
)
);
} else {
@ -37,9 +44,9 @@ if (isset($plugin_list)) {
/**
* Outputs export footer
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportFooter()
{
@ -49,9 +56,9 @@ if (isset($plugin_list)) {
/**
* Outputs export header
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportHeader()
{
@ -68,26 +75,30 @@ if (isset($plugin_list)) {
/**
* Outputs database header
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBHeader($db)
{
PMA_exportOutputHandler('//' . $GLOBALS['crlf'] . '// Database ' . PMA_backquote($db) . $GLOBALS['crlf'] . '//' . $GLOBALS['crlf']);
PMA_exportOutputHandler(
'//' . $GLOBALS['crlf']
. '// Database ' . PMA_backquote($db) . $GLOBALS['crlf']
. '//' . $GLOBALS['crlf']
);
return true;
}
/**
* Outputs database footer
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBFooter($db)
{
@ -97,11 +108,11 @@ if (isset($plugin_list)) {
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBCreate($db)
{
@ -111,15 +122,15 @@ if (isset($plugin_list)) {
/**
* Outputs the content of a table as a fragment of PHP code
*
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
@ -131,8 +142,13 @@ if (isset($plugin_list)) {
}
unset($i);
// fix variable names (based on http://www.php.net/manual/language.variables.basics.php)
if (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $table) == false) {
// fix variable names (based on
// http://www.php.net/manual/language.variables.basics.php)
if (preg_match(
'/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/',
$table
) == false
) {
// fix invalid chars in variable names by replacing them with underscores
$tablefixed = preg_replace('/[^a-zA-Z0-9_\x7f-\xff]/', '_', $table);
@ -152,7 +168,8 @@ if (isset($plugin_list)) {
// Output table name as comment if this is the first record of the table
if ($record_cnt == 1) {
$buffer .= $crlf . '// ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $crlf;
$buffer .= $crlf . '// '. PMA_backquote($db) . '.'
. PMA_backquote($table) . $crlf;
$buffer .= '$' . $tablefixed . ' = array(' . $crlf;
$buffer .= ' array(';
} else {
@ -160,7 +177,9 @@ if (isset($plugin_list)) {
}
for ($i = 0; $i < $columns_cnt; $i++) {
$buffer .= var_export($columns[$i], true) . " => " . var_export($record[$i], true) . (($i + 1 >= $columns_cnt) ? '' : ',');
$buffer .= var_export($columns[$i], true)
. " => " . var_export($record[$i], true)
. (($i + 1 >= $columns_cnt) ? '' : ',');
}
$buffer .= ')';

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
/**
* Export to Texy! text.
*
* @package PhpMyAdmin-Export
* @package PhpMyAdmin-Export
* @subpackage Texy
*/
if (! defined('PHPMYADMIN')) {
@ -18,26 +18,57 @@ if (isset($plugin_list)) {
'text' => __('Texy! text'),
'extension' => 'txt',
'mime_type' => 'text/plain',
'options' => array(
'options' => array(),
'options_text' => __('Options')
);
$plugin_list['texytext']['options'] = array(
/* what to dump (structure/data/both) */
array('type' => 'begin_group', 'text' => __('Dump table'), 'name' => 'general_opts'),
array('type' => 'radio', 'name' => 'structure_or_data', 'values' => array('structure' => __('structure'), 'data' => __('data'), 'structure_and_data' => __('structure and data'))),
array('type' => 'end_group'),
array('type' => 'begin_group', 'name' => 'data', 'text' => __('Data dump options'), 'force' => 'structure'),
array('type' => 'text', 'name' => 'null', 'text' => __('Replace NULL by')),
array('type' => 'bool', 'name' => 'columns', 'text' => __('Put columns names in the first row')),
array('type' => 'end_group'),
array(
'type' => 'begin_group',
'text' => __('Dump table'),
'name' => 'general_opts'
),
'options_text' => __('Options'),
);
array(
'type' => 'radio',
'name' => 'structure_or_data',
'values' => array(
'structure' => __('structure'),
'data' => __('data'),
'structure_and_data' => __('structure and data')
)
),
array(
'type' => 'end_group'
),
array(
'type' => 'begin_group',
'name' => 'data',
'text' => __('Data dump options'),
'force' => 'structure'
),
array(
'type' => 'text',
'name' => 'null',
'text' => __('Replace NULL by')
),
array(
'type' => 'bool',
'name' => 'columns',
'text' => __('Put columns names in the first row')
),
array(
'type' => 'end_group'
)
);
} else {
/**
* Outputs export footer
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportFooter()
{
@ -47,9 +78,9 @@ if (isset($plugin_list)) {
/**
* Outputs export header
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportHeader()
{
@ -59,25 +90,27 @@ if (isset($plugin_list)) {
/**
* Outputs database header
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBHeader($db)
{
return PMA_exportOutputHandler('===' . __('Database') . ' ' . $db . "\n\n");
return PMA_exportOutputHandler(
'===' . __('Database') . ' ' . $db . "\n\n"
);
}
/**
* Outputs database footer
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBFooter($db)
{
@ -87,11 +120,11 @@ if (isset($plugin_list)) {
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBCreate($db)
{
@ -101,21 +134,23 @@ if (isset($plugin_list)) {
/**
* Outputs the content of a table in Texy format
*
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
global $what;
if (! PMA_exportOutputHandler('== ' . __('Dumping data for table') . ' ' . $table . "\n\n")) {
if (! PMA_exportOutputHandler(
'== ' . __('Dumping data for table') . ' ' . $table . "\n\n"
)) {
return false;
}
@ -127,7 +162,10 @@ if (isset($plugin_list)) {
if (isset($GLOBALS[$what . '_columns'])) {
$text_output = "|------\n";
for ($i = 0; $i < $fields_cnt; $i++) {
$text_output .= '|' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i)));
$text_output .= '|'
. htmlspecialchars(
stripslashes(PMA_DBI_field_name($result, $i))
);
} // end for
$text_output .= "\n|------\n";
if (! PMA_exportOutputHandler($text_output)) {
@ -146,7 +184,10 @@ if (isset($plugin_list)) {
} else {
$value = ' ';
}
$text_output .= '|' . str_replace('|', '&#124;', htmlspecialchars($value));
$text_output .= '|'
. str_replace(
'|', '&#124;', htmlspecialchars($value)
);
} // end for
$text_output .= "\n";
if (! PMA_exportOutputHandler($text_output)) {
@ -219,22 +260,34 @@ if (isset($plugin_list)) {
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column comments
* as comments in the structure; this is deprecated
* but the parameter is left here because export.php
* calls PMA_exportStructure() also for other export
* types which use this parameter
* @param bool $do_comments whether to include the pmadb-style column
* comments as comments in the structure;
* this is deprecated but the parameter is
* left here because export.php calls
* PMA_exportStructure() also for other
* export types which use this parameter
* @param bool $do_mime whether to include mime comments
* @param bool $show_dates whether to include creation/update/check dates
* @param bool $add_semicolon whether to add semicolon and end-of-line at the end
* @param bool $add_semicolon whether to add semicolon and end-of-line
* at the end
* @param bool $view whether we're handling a view
*
* @return string resulting schema
*
* @access public
*/
function PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $show_dates = false, $add_semicolon = true, $view = false)
{
function PMA_getTableDef(
$db,
$table,
$crlf,
$error_url,
$do_relation,
$do_comments,
$do_mime,
$show_dates = false,
$add_semicolon = true,
$view = false
) {
global $cfgRelation;
$text_output = '';
@ -309,13 +362,27 @@ if (isset($plugin_list)) {
$field_name = $column['Field'];
if ($do_relation && $have_rel) {
$text_output .= '|' . (isset($res_rel[$field_name]) ? htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') : '');
$text_output .= '|'
. (isset($res_rel[$field_name])
? htmlspecialchars(
$res_rel[$field_name]['foreign_table']
. ' (' . $res_rel[$field_name]['foreign_field'] . ')'
)
: '');
}
if ($do_comments && $cfgRelation['commwork']) {
$text_output .= '|' . (isset($comments[$field_name]) ? htmlspecialchars($comments[$field_name]) : '');
$text_output .= '|'
. (isset($comments[$field_name])
? htmlspecialchars($comments[$field_name])
: '');
}
if ($do_mime && $cfgRelation['mimework']) {
$text_output .= '|' . (isset($mime_map[$field_name]) ? htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) : '');
$text_output .= '|'
. (isset($mime_map[$field_name])
? htmlspecialchars(
str_replace('_', '/', $mime_map[$field_name]['mimetype'])
)
: '');
}
$text_output .= "\n";
@ -327,10 +394,10 @@ if (isset($plugin_list)) {
/**
* Outputs triggers
*
* @param string $db database name
* @param string $table table name
* @param string $db database name
* @param string $table table name
*
* @return string Formatted triggers list
* @return string Formatted triggers list
*
* @access public
*/
@ -351,7 +418,12 @@ if (isset($plugin_list)) {
$dump .= '|' . $trigger['name'];
$dump .= '|' . $trigger['action_timing'];
$dump .= '|' . $trigger['event_manipulation'];
$dump .= '|' . str_replace('|', '&#124;', htmlspecialchars($trigger['definition']));
$dump .= '|' .
str_replace(
'|',
'&#124;',
htmlspecialchars($trigger['definition'])
);
$dump .= "\n";
}
@ -361,33 +433,48 @@ if (isset($plugin_list)) {
/**
* Outputs table's structure
*
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column comments
* as comments in the structure; this is deprecated
* but the parameter is left here because export.php
* calls PMA_exportStructure() also for other export
* types which use this parameter
* @param bool $do_mime whether to include mime comments
* @param bool $dates whether to include creation/update/check dates
* @param string $export_mode 'create_table', 'triggers', 'create_view', 'stand_in'
* @param string $export_type 'server', 'database', 'table'
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $export_mode 'create_table', 'triggers', 'create_view',
* 'stand_in'
* @param string $export_type 'server', 'database', 'table'
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column
* comments as comments in the structure;
* this is deprecated but the parameter is
* left here because export.php calls
* PMA_exportStructure() also for other
* export types which use this parameter
* @param bool $do_mime whether to include mime comments
* @param bool $dates whether to include creation/update/check dates
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $export_mode, $export_type)
{
function PMA_exportStructure(
$db,
$table,
$crlf,
$error_url,
$export_mode,
$export_type,
$do_relation = false,
$do_comments = false,
$do_mime = false,
$dates = false
) {
$dump = '';
switch($export_mode) {
case 'create_table':
$dump .= '== ' . __('Table structure for table') . ' ' .$table . "\n\n";
$dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates);
$dump .= PMA_getTableDef(
$db, $table, $crlf, $error_url, $do_relation, $do_comments,
$do_mime, $dates
);
break;
case 'triggers':
$dump = '';
@ -399,10 +486,14 @@ if (isset($plugin_list)) {
break;
case 'create_view':
$dump .= '== ' . __('Structure for view') . ' ' .$table . "\n\n";
$dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates, true, true);
$dump .= PMA_getTableDef(
$db, $table, $crlf, $error_url, $do_relation, $do_comments,
$do_mime, $dates, true, true
);
break;
case 'stand_in':
$dump .= '== ' . __('Stand-in structure for view') . ' ' .$table . "\n\n";
$dump .= '== ' . __('Stand-in structure for view')
. ' ' .$table . "\n\n";
// export a stand-in definition to resolve view dependencies
$dump .= PMA_getTableDefStandIn($db, $table, $crlf);
} // end switch
@ -413,10 +504,10 @@ if (isset($plugin_list)) {
/**
* Formats the definition for one column
*
* @param array $column info about this column
* @param array $unique_keys unique keys for this table
* @param array $column info about this column
* @param array $unique_keys unique keys for this table
*
* @return string Formatted column definition
* @return string Formatted column definition
*
* @access public
*/
@ -445,10 +536,16 @@ if (isset($plugin_list)) {
$fmt_pre = '//' . $fmt_pre;
$fmt_post = $fmt_post . '//';
}
$definition = '|' . $fmt_pre . htmlspecialchars($column['Field']) . $fmt_post;
$definition = '|'
. $fmt_pre . htmlspecialchars($column['Field']) . $fmt_post;
$definition .= '|' . htmlspecialchars($type);
$definition .= '|' . (($column['Null'] == '' || $column['Null'] == 'NO') ? __('No') : __('Yes'));
$definition .= '|' . htmlspecialchars(isset($column['Default']) ? $column['Default'] : '');
$definition .= '|'
. (($column['Null'] == '' || $column['Null'] == 'NO')
? __('No') : __('Yes'));
$definition .= '|'
. htmlspecialchars(
isset($column['Default']) ? $column['Default'] : ''
);
return $definition;
}
}

View File

@ -3,14 +3,14 @@
/**
* Set of functions used to build XML dumps of tables
*
* @package PhpMyAdmin-Export
* @package PhpMyAdmin-Export
* @subpackage XML
*/
if (! defined('PHPMYADMIN')) {
exit;
}
if (!strlen($GLOBALS['db'])) { /* Can't do server export */
if (! strlen($GLOBALS['db'])) { /* Can't do server export */
return;
}
@ -19,75 +19,85 @@ if (isset($plugin_list)) {
'text' => __('XML'),
'extension' => 'xml',
'mime_type' => 'text/xml',
'options' => array(
array('type' => 'begin_group', 'name' => 'general_opts'),
array('type' => 'hidden', 'name' => 'structure_or_data'),
array('type' => 'end_group')
),
'options' => array(),
'options_text' => __('Options')
);
);
$plugin_list['xml']['options'] = array(
array(
'type' => 'begin_group',
'name' => 'general_opts'
),
array(
'type' => 'hidden',
'name' => 'structure_or_data'
),
array(
'type' => 'end_group'
)
);
/* Export structure */
$plugin_list['xml']['options'][] = array(
'type' => 'begin_group',
'name' => 'structure',
'text' => __('Object creation options (all are recommended)')
);
if (!PMA_DRIZZLE) {
);
if (! PMA_DRIZZLE) {
$plugin_list['xml']['options'][] = array(
'type' => 'bool',
'name' => 'export_functions',
'text' => __('Functions')
);
);
$plugin_list['xml']['options'][] = array(
'type' => 'bool',
'name' => 'export_procedures',
'text' => __('Procedures')
);
);
}
$plugin_list['xml']['options'][] = array(
'type' => 'bool',
'name' => 'export_tables',
'text' => __('Tables')
);
if (!PMA_DRIZZLE) {
);
if (! PMA_DRIZZLE) {
$plugin_list['xml']['options'][] = array(
'type' => 'bool',
'name' => 'export_triggers',
'text' => __('Triggers')
);
);
$plugin_list['xml']['options'][] = array(
'type' => 'bool',
'name' => 'export_views',
'text' => __('Views')
);
);
}
$plugin_list['xml']['options'][] = array(
'type' => 'end_group'
);
);
/* Data */
$plugin_list['xml']['options'][] = array(
'type' => 'begin_group',
'name' => 'data',
'text' => __('Data dump options')
);
);
$plugin_list['xml']['options'][] = array(
'type' => 'bool',
'name' => 'export_contents',
'text' => __('Export contents')
);
);
$plugin_list['xml']['options'][] = array(
'type' => 'end_group'
);
);
} else {
/**
* Outputs export footer
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportFooter()
{
@ -99,9 +109,9 @@ if (isset($plugin_list)) {
/**
* Outputs export header
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportHeader()
{
@ -111,8 +121,10 @@ if (isset($plugin_list)) {
global $table;
global $tables;
$export_struct = isset($GLOBALS['xml_export_functions']) || isset($GLOBALS['xml_export_procedures'])
|| isset($GLOBALS['xml_export_tables']) || isset($GLOBALS['xml_export_triggers'])
$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;
@ -129,7 +141,7 @@ if (isset($plugin_list)) {
. '- http://www.phpmyadmin.net' . $crlf
. '-' . $crlf
. '- ' . __('Host') . ': ' . $cfg['Server']['host'];
if (!empty($cfg['Server']['port'])) {
if (! empty($cfg['Server']['port'])) {
$head .= ':' . $cfg['Server']['port'];
}
$head .= $crlf
@ -138,7 +150,11 @@ if (isset($plugin_list)) {
. '- ' . __('PHP Version') . ': ' . phpversion() . $crlf
. '-->' . $crlf . $crlf;
$head .= '<pma_xml_export version="1.0"' . (($export_struct) ? ' xmlns:pma="http://www.phpmyadmin.net/some_doc_url/"' : '') . '>' . $crlf;
$head .= '<pma_xml_export version="1.0"'
. (($export_struct)
? ' xmlns:pma="http://www.phpmyadmin.net/some_doc_url/"'
: '')
. '>' . $crlf;
if ($export_struct) {
if (PMA_DRIZZLE) {
@ -150,7 +166,11 @@ if (isset($plugin_list)) {
WHERE SCHEMA_NAME = '" . PMA_sqlAddSlashes($db) . "'"
);
} else {
$result = PMA_DBI_fetch_result('SELECT `DEFAULT_CHARACTER_SET_NAME`, `DEFAULT_COLLATION_NAME` FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME` = \''.PMA_sqlAddSlashes($db).'\' LIMIT 1');
$result = PMA_DBI_fetch_result(
'SELECT `DEFAULT_CHARACTER_SET_NAME`, `DEFAULT_COLLATION_NAME`'
. ' FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME`'
. ' = \''.PMA_sqlAddSlashes($db).'\' LIMIT 1'
);
}
$db_collation = $result[0]['DEFAULT_COLLATION_NAME'];
$db_charset = $result[0]['DEFAULT_CHARACTER_SET_NAME'];
@ -159,7 +179,9 @@ if (isset($plugin_list)) {
$head .= ' - Structure schemas' . $crlf;
$head .= ' -->' . $crlf;
$head .= ' <pma:structure_schemas>' . $crlf;
$head .= ' <pma:database name="' . htmlspecialchars($db) . '" collation="' . $db_collation . '" charset="' . $db_charset . '">' . $crlf;
$head .= ' <pma:database name="' . htmlspecialchars($db)
. '" collation="' . $db_collation . '" charset="' . $db_charset
. '">' . $crlf;
if (count($tables) == 0) {
$tables[] = $table;
@ -167,7 +189,11 @@ if (isset($plugin_list)) {
foreach ($tables as $table) {
// Export tables and views
$result = PMA_DBI_fetch_result('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), 0);
$result = PMA_DBI_fetch_result(
'SHOW CREATE TABLE ' . PMA_backquote($db) . '.'
. PMA_backquote($table),
0
);
$tbl = $result[$table][1];
$is_view = PMA_Table::isView($db, $table);
@ -186,7 +212,8 @@ if (isset($plugin_list)) {
continue;
}
$head .= ' <pma:' . $type . ' name="' . $table . '">' . $crlf;
$head .= ' <pma:' . $type . ' name="' . $table . '">'
. $crlf;
$tbl = " " . htmlspecialchars($tbl);
$tbl = str_replace("\n", "\n ", $tbl);
@ -194,13 +221,16 @@ if (isset($plugin_list)) {
$head .= $tbl . ';' . $crlf;
$head .= ' </pma:' . $type . '>' . $crlf;
if (isset($GLOBALS['xml_export_triggers']) && $GLOBALS['xml_export_triggers']) {
if (isset($GLOBALS['xml_export_triggers'])
&& $GLOBALS['xml_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;
$head .= ' <pma:trigger name="'
. $trigger['name'] . '">' . $crlf;
// Do some formatting
$code = substr(rtrim($code), 0, -3);
@ -217,12 +247,15 @@ if (isset($plugin_list)) {
}
}
if (isset($GLOBALS['xml_export_functions']) && $GLOBALS['xml_export_functions']) {
if (isset($GLOBALS['xml_export_functions'])
&& $GLOBALS['xml_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;
$head .= ' <pma:function name="'
. $function . '">' . $crlf;
// Do some formatting
$sql = PMA_DBI_get_definition($db, 'FUNCTION', $function);
@ -240,12 +273,15 @@ if (isset($plugin_list)) {
}
}
if (isset($GLOBALS['xml_export_procedures']) && $GLOBALS['xml_export_procedures']) {
if (isset($GLOBALS['xml_export_procedures'])
&& $GLOBALS['xml_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;
$head .= ' <pma:procedure name="'
. $procedure . '">' . $crlf;
// Do some formatting
$sql = PMA_DBI_get_definition($db, 'PROCEDURE', $procedure);
@ -279,17 +315,19 @@ if (isset($plugin_list)) {
/**
* Outputs database header
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBHeader($db)
{
global $crlf;
if (isset($GLOBALS['xml_export_contents']) && $GLOBALS['xml_export_contents']) {
if (isset($GLOBALS['xml_export_contents'])
&& $GLOBALS['xml_export_contents']
) {
$head = ' <!--' . $crlf
. ' - ' . __('Database') . ': ' . '\'' . $db . '\'' . $crlf
. ' -->' . $crlf
@ -304,17 +342,19 @@ if (isset($plugin_list)) {
/**
* Outputs database footer
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBFooter($db)
{
global $crlf;
if (isset($GLOBALS['xml_export_contents']) && $GLOBALS['xml_export_contents']) {
if (isset($GLOBALS['xml_export_contents'])
&& $GLOBALS['xml_export_contents']
) {
return PMA_exportOutputHandler(' </database>' . $crlf);
} else {
return true;
@ -324,11 +364,11 @@ if (isset($plugin_list)) {
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBCreate($db)
{
@ -338,21 +378,22 @@ if (isset($plugin_list)) {
/**
* Outputs the content of a table in XML format
*
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
if (isset($GLOBALS['xml_export_contents']) && $GLOBALS['xml_export_contents']) {
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
if (isset($GLOBALS['xml_export_contents'])
&& $GLOBALS['xml_export_contents']
) {
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
$columns_cnt = PMA_DBI_num_fields($result);
$columns = array();
@ -361,24 +402,28 @@ if (isset($plugin_list)) {
}
unset($i);
$buffer = ' <!-- ' . __('Table') . ' ' . $table . ' -->' . $crlf;
if (!PMA_exportOutputHandler($buffer)) {
$buffer = ' <!-- ' . __('Table') . ' ' . $table . ' -->' . $crlf;
if (! PMA_exportOutputHandler($buffer)) {
return false;
}
while ($record = PMA_DBI_fetch_row($result)) {
$buffer = ' <table name="' . htmlspecialchars($table) . '">' . $crlf;
$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])) {
// 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="' . htmlspecialchars($columns[$i]) . '">' . htmlspecialchars((string)$record[$i])
. '</column>' . $crlf;
$buffer .= ' <column name="'
. htmlspecialchars($columns[$i]) . '">'
. htmlspecialchars((string)$record[$i])
. '</column>' . $crlf;
}
$buffer .= ' </table>' . $crlf;
$buffer .= ' </table>' . $crlf;
if (!PMA_exportOutputHandler($buffer)) {
if (! PMA_exportOutputHandler($buffer)) {
return false;
}
}

View File

@ -3,7 +3,7 @@
/**
* Set of functions used to build YAML dumps of tables
*
* @package PhpMyAdmin-Export
* @package PhpMyAdmin-Export
* @subpackage YAML
*/
if (! defined('PHPMYADMIN')) {
@ -15,19 +15,26 @@ if (! defined('PHPMYADMIN')) {
*/
if (isset($plugin_list)) {
$plugin_list['yaml'] = array(
'text' => 'YAML',
'extension' => 'yml',
'mime_type' => 'text/yaml',
'force_file' => true,
'options' => array(
array('type' => 'begin_group', 'name' => 'general_opts'),
array(
'type' => 'hidden',
'name' => 'structure_or_data',
),
array('type' => 'end_group')
'text' => 'YAML',
'extension' => 'yml',
'mime_type' => 'text/yaml',
'force_file' => true,
'options' => array(),
'options_text' => __('Options')
);
$plugin_list['yaml']['options'] = array(
array(
'type' => 'begin_group',
'name' => 'general_opts'
),
'options_text' => __('Options'),
array(
'type' => 'hidden',
'name' => 'structure_or_data',
),
array(
'type' => 'end_group'
)
);
} else {
@ -38,9 +45,9 @@ if (isset($plugin_list)) {
/**
* Outputs export footer
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportFooter()
{
@ -51,24 +58,26 @@ if (isset($plugin_list)) {
/**
* Outputs export header
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportHeader()
{
PMA_exportOutputHandler('%YAML 1.1' . $GLOBALS['crlf'] . '---' . $GLOBALS['crlf']);
PMA_exportOutputHandler(
'%YAML 1.1' . $GLOBALS['crlf'] . '---' . $GLOBALS['crlf']
);
return true;
}
/**
* Outputs database header
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBHeader($db)
{
@ -78,11 +87,11 @@ if (isset($plugin_list)) {
/**
* Outputs database footer
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBFooter($db)
{
@ -92,11 +101,11 @@ if (isset($plugin_list)) {
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $db Database name
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportDBCreate($db)
{
@ -106,15 +115,15 @@ if (isset($plugin_list)) {
/**
* Outputs the content of a table in YAML format
*
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param string $sql_query SQL query for obtaining data
*
* @return bool Whether it succeeded
* @return bool Whether it succeeded
*
* @access public
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
@ -156,7 +165,11 @@ if (isset($plugin_list)) {
continue;
}
$record[$i] = str_replace(array('\\', '"', "\n", "\r"), array('\\\\', '\"', '\n', '\r'), $record[$i]);
$record[$i] = str_replace(
array('\\', '"', "\n", "\r"),
array('\\\\', '\"', '\n', '\r'),
$record[$i]
);
$buffer .= ' ' . $column . ': "' . $record[$i] . '"' . $crlf;
}