2 /* vim: set expandtab sw=4 ts=4 sts=4: */
8 declare(strict_types
=1);
10 use PhpMyAdmin\Config\PageSettings
;
11 use PhpMyAdmin\Display\Export
;
12 use PhpMyAdmin\Relation
;
13 use PhpMyAdmin\Response
;
18 require_once 'libraries/common.inc.php';
20 PageSettings
::showGroup('Export');
22 $response = Response
::getInstance();
23 $header = $response->getHeader();
24 $scripts = $header->getScripts();
25 $scripts->addFile('export.js');
27 // Get the relation settings
28 $relation = new Relation($GLOBALS['dbi']);
29 $cfgRelation = $relation->getRelationsParam();
31 $displayExport = new Export();
33 // handling export template actions
34 if (isset($_REQUEST['templateAction']) && $cfgRelation['exporttemplateswork']) {
35 $displayExport->handleTemplateActions($cfgRelation);
40 * Gets tables information and displays top links
42 require_once 'libraries/tbl_common.inc.php';
43 $url_query .= '&goto=tbl_export.php&back=tbl_export.php';
47 $export_page_title = __('View dump (schema) of table');
49 // When we have some query, we need to remove LIMIT from that and possibly
50 // generate WHERE clause (if we are asked to export specific rows)
52 if (! empty($sql_query)) {
53 $parser = new PhpMyAdmin\SqlParser\
Parser($sql_query);
55 if ((!empty($parser->statements
[0]))
56 && ($parser->statements
[0] instanceof PhpMyAdmin\SqlParser\Statements\SelectStatement
)
58 // Finding aliases and removing them, but we keep track of them to be
59 // able to replace them in select expression too.
61 foreach ($parser->statements
[0]->from
as $from) {
62 if ((!empty($from->table
)) && (!empty($from->alias
))) {
63 $aliases[$from->alias
] = $from->table
;
64 // We remove the alias of the table because they are going to
65 // be replaced anyway.
67 $from->expr
= null; // Force rebuild.
71 // Rebuilding the SELECT and FROM clauses.
72 if (count($parser->statements
[0]->from
) > 0
73 && count($parser->statements
[0]->union
) === 0
77 'FROM', 'FROM ' . PhpMyAdmin\SqlParser\Components\ExpressionArray
::build(
78 $parser->statements
[0]->from
84 // Checking if the WHERE clause has to be replaced.
85 if ((!empty($where_clause)) && (is_array($where_clause))) {
87 'WHERE', 'WHERE (' . implode(') OR (', $where_clause) . ')'
91 // Preparing to remove the LIMIT clause.
92 $replaces[] = ['LIMIT', ''];
94 // Replacing the clauses.
95 $sql_query = PhpMyAdmin\SqlParser\Utils\Query
::replaceClauses(
96 $parser->statements
[0],
101 // Removing the aliases by finding the alias followed by a dot.
102 $tokens = PhpMyAdmin\SqlParser\Lexer
::getTokens($sql_query);
103 foreach ($aliases as $alias => $table) {
104 $tokens = PhpMyAdmin\SqlParser\Utils\Tokens
::replaceTokens(
108 'value_str' => $alias,
111 'type' => PhpMyAdmin\SqlParser\Token
::TYPE_OPERATOR
,
116 new PhpMyAdmin\SqlParser\
Token($table),
117 new PhpMyAdmin\SqlParser\
Token('.', PhpMyAdmin\SqlParser\Token
::TYPE_OPERATOR
)
121 $sql_query = PhpMyAdmin\SqlParser\TokensList
::build($tokens);
124 echo PhpMyAdmin\Util
::getMessage(PhpMyAdmin\Message
::success());
127 if (! isset($sql_query)) {
130 if (! isset($num_tables)) {
133 if (! isset($unlim_num_rows)) {
136 if (! isset($multi_values)) {
139 $response = Response
::getInstance();
141 $displayExport->getDisplay(