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
;
15 if (! defined('ROOT_PATH')) {
16 define('ROOT_PATH', __DIR__
. DIRECTORY_SEPARATOR
);
22 require_once ROOT_PATH
. 'libraries/common.inc.php';
24 PageSettings
::showGroup('Export');
26 $response = Response
::getInstance();
27 $header = $response->getHeader();
28 $scripts = $header->getScripts();
29 $scripts->addFile('export.js');
31 // Get the relation settings
32 $relation = new Relation($GLOBALS['dbi']);
33 $cfgRelation = $relation->getRelationsParam();
35 $displayExport = new Export();
37 // handling export template actions
38 if (isset($_POST['templateAction']) && $cfgRelation['exporttemplateswork']) {
39 $displayExport->handleTemplateActions($cfgRelation);
44 * Gets tables information and displays top links
46 require_once ROOT_PATH
. 'libraries/tbl_common.inc.php';
47 $url_query .= '&goto=tbl_export.php&back=tbl_export.php';
51 $export_page_title = __('View dump (schema) of table');
53 // When we have some query, we need to remove LIMIT from that and possibly
54 // generate WHERE clause (if we are asked to export specific rows)
56 if (! empty($sql_query)) {
57 $parser = new PhpMyAdmin\SqlParser\
Parser($sql_query);
59 if (! empty($parser->statements
[0])
60 && ($parser->statements
[0] instanceof PhpMyAdmin\SqlParser\Statements\SelectStatement
)
62 // Finding aliases and removing them, but we keep track of them to be
63 // able to replace them in select expression too.
65 foreach ($parser->statements
[0]->from
as $from) {
66 if (! empty($from->table
) && ! empty($from->alias
)) {
67 $aliases[$from->alias
] = $from->table
;
68 // We remove the alias of the table because they are going to
69 // be replaced anyway.
71 $from->expr
= null; // Force rebuild.
75 // Rebuilding the SELECT and FROM clauses.
76 if (count($parser->statements
[0]->from
) > 0
77 && count($parser->statements
[0]->union
) === 0
82 'FROM ' . PhpMyAdmin\SqlParser\Components\ExpressionArray
::build(
83 $parser->statements
[0]->from
89 // Checking if the WHERE clause has to be replaced.
90 if (! empty($where_clause) && is_array($where_clause)) {
93 'WHERE (' . implode(') OR (', $where_clause) . ')',
97 // Preparing to remove the LIMIT clause.
103 // Replacing the clauses.
104 $sql_query = PhpMyAdmin\SqlParser\Utils\Query
::replaceClauses(
105 $parser->statements
[0],
110 // Removing the aliases by finding the alias followed by a dot.
111 $tokens = PhpMyAdmin\SqlParser\Lexer
::getTokens($sql_query);
112 foreach ($aliases as $alias => $table) {
113 $tokens = PhpMyAdmin\SqlParser\Utils\Tokens
::replaceTokens(
117 'value_str' => $alias,
120 'type' => PhpMyAdmin\SqlParser\Token
::TYPE_OPERATOR
,
125 new PhpMyAdmin\SqlParser\
Token($table),
126 new PhpMyAdmin\SqlParser\
Token('.', PhpMyAdmin\SqlParser\Token
::TYPE_OPERATOR
),
130 $sql_query = PhpMyAdmin\SqlParser\TokensList
::build($tokens);
133 echo PhpMyAdmin\Util
::getMessage(PhpMyAdmin\Message
::success());
136 if (! isset($sql_query)) {
139 if (! isset($num_tables)) {
142 if (! isset($unlim_num_rows)) {
145 if (! isset($multi_values)) {
148 $response = Response
::getInstance();
150 $displayExport->getDisplay(