2 /* vim: set expandtab sw=4 ts=4 sts=4: */
8 use PMA\libraries\config\PageSettings
;
9 use PMA\libraries\Response
;
14 require_once 'libraries/common.inc.php';
15 require_once 'libraries/display_export.lib.php';
16 require_once 'libraries/config/user_preferences.forms.php';
17 require_once 'libraries/config/page_settings.forms.php';
19 PageSettings
::showGroup('Export');
21 $response = Response
::getInstance();
22 $header = $response->getHeader();
23 $scripts = $header->getScripts();
24 $scripts->addFile('export.js');
26 // Get the relation settings
27 $cfgRelation = PMA_getRelationsParam();
29 // handling export template actions
30 if (isset($_REQUEST['templateAction']) && $cfgRelation['exporttemplateswork']) {
31 PMA_handleExportTemplateActions($cfgRelation);
36 * Gets tables information and displays top links
38 require_once 'libraries/tbl_common.inc.php';
39 $url_query .= '&goto=tbl_export.php&back=tbl_export.php';
43 $export_page_title = __('View dump (schema) of table');
45 // When we have some query, we need to remove LIMIT from that and possibly
46 // generate WHERE clause (if we are asked to export specific rows)
48 if (! empty($sql_query)) {
49 $parser = new PhpMyAdmin\SqlParser\
Parser($sql_query);
51 if ((!empty($parser->statements
[0]))
52 && ($parser->statements
[0] instanceof PhpMyAdmin\SqlParser\Statements\SelectStatement
)
55 // Finding aliases and removing them, but we keep track of them to be
56 // able to replace them in select expression too.
58 foreach ($parser->statements
[0]->from
as $from) {
59 if ((!empty($from->table
)) && (!empty($from->alias
))) {
60 $aliases[$from->alias
] = $from->table
;
61 // We remove the alias of the table because they are going to
62 // be replaced anyway.
64 $from->expr
= null; // Force rebuild.
68 // Rebuilding the SELECT and FROM clauses.
69 if (count($parser->statements
[0]->from
) > 0
70 && count($parser->statements
[0]->union
) === 0
74 'FROM', 'FROM ' . PhpMyAdmin\SqlParser\Components\ExpressionArray
::build(
75 $parser->statements
[0]->from
81 // Checking if the WHERE clause has to be replaced.
82 if ((!empty($where_clause)) && (is_array($where_clause))) {
84 'WHERE', 'WHERE (' . implode(') OR (', $where_clause) . ')'
88 // Preparing to remove the LIMIT clause.
89 $replaces[] = array('LIMIT', '');
91 // Replacing the clauses.
92 $sql_query = PhpMyAdmin\SqlParser\Utils\Query
::replaceClauses(
93 $parser->statements
[0],
98 // Removing the aliases by finding the alias followed by a dot.
99 $tokens = PhpMyAdmin\SqlParser\Lexer
::getTokens($sql_query);
100 foreach ($aliases as $alias => $table) {
101 $tokens = PhpMyAdmin\SqlParser\Utils\Tokens
::replaceTokens(
105 'value_str' => $alias,
108 'type' => PhpMyAdmin\SqlParser\Token
::TYPE_OPERATOR
,
113 new PhpMyAdmin\SqlParser\
Token($table),
114 new PhpMyAdmin\SqlParser\
Token('.',PhpMyAdmin\SqlParser\Token
::TYPE_OPERATOR
)
118 $sql_query = PhpMyAdmin\SqlParser\TokensList
::build($tokens);
121 echo PMA\libraries\Util
::getMessage(PMA\libraries\Message
::success());
124 require_once 'libraries/display_export.lib.php';
126 if (! isset($sql_query)) {
129 if (! isset($num_tables)) {
132 if (! isset($unlim_num_rows)) {
135 if (! isset($multi_values)) {
138 $response = Response
::getInstance();
140 PMA_getExportDisplay(
141 'table', $db, $table, $sql_query, $num_tables,
142 $unlim_num_rows, $multi_values