2 /* vim: set expandtab sw=4 ts=4 sts=4: */
8 use PhpMyAdmin\Config\PageSettings
;
9 use PhpMyAdmin\Display\Export
;
10 use PhpMyAdmin\Relation
;
11 use PhpMyAdmin\Response
;
16 require_once 'libraries/common.inc.php';
18 PageSettings
::showGroup('Export');
20 $response = Response
::getInstance();
21 $header = $response->getHeader();
22 $scripts = $header->getScripts();
23 $scripts->addFile('export.js');
25 // Get the relation settings
26 $relation = new Relation();
27 $cfgRelation = $relation->getRelationsParam();
29 $displayExport = new Export();
31 // handling export template actions
32 if (isset($_REQUEST['templateAction']) && $cfgRelation['exporttemplateswork']) {
33 $displayExport->handleTemplateActions($cfgRelation);
38 * Gets tables information and displays top links
40 require_once 'libraries/tbl_common.inc.php';
41 $url_query .= '&goto=tbl_export.php&back=tbl_export.php';
45 $export_page_title = __('View dump (schema) of table');
47 // When we have some query, we need to remove LIMIT from that and possibly
48 // generate WHERE clause (if we are asked to export specific rows)
50 if (! empty($sql_query)) {
51 $parser = new PhpMyAdmin\SqlParser\
Parser($sql_query);
53 if ((!empty($parser->statements
[0]))
54 && ($parser->statements
[0] instanceof PhpMyAdmin\SqlParser\Statements\SelectStatement
)
57 // Finding aliases and removing them, but we keep track of them to be
58 // able to replace them in select expression too.
60 foreach ($parser->statements
[0]->from
as $from) {
61 if ((!empty($from->table
)) && (!empty($from->alias
))) {
62 $aliases[$from->alias
] = $from->table
;
63 // We remove the alias of the table because they are going to
64 // be replaced anyway.
66 $from->expr
= null; // Force rebuild.
70 // Rebuilding the SELECT and FROM clauses.
71 if (count($parser->statements
[0]->from
) > 0
72 && count($parser->statements
[0]->union
) === 0
76 'FROM', 'FROM ' . PhpMyAdmin\SqlParser\Components\ExpressionArray
::build(
77 $parser->statements
[0]->from
83 // Checking if the WHERE clause has to be replaced.
84 if ((!empty($where_clause)) && (is_array($where_clause))) {
86 'WHERE', 'WHERE (' . implode(') OR (', $where_clause) . ')'
90 // Preparing to remove the LIMIT clause.
91 $replaces[] = array('LIMIT', '');
93 // Replacing the clauses.
94 $sql_query = PhpMyAdmin\SqlParser\Utils\Query
::replaceClauses(
95 $parser->statements
[0],
100 // Removing the aliases by finding the alias followed by a dot.
101 $tokens = PhpMyAdmin\SqlParser\Lexer
::getTokens($sql_query);
102 foreach ($aliases as $alias => $table) {
103 $tokens = PhpMyAdmin\SqlParser\Utils\Tokens
::replaceTokens(
107 'value_str' => $alias,
110 'type' => PhpMyAdmin\SqlParser\Token
::TYPE_OPERATOR
,
115 new PhpMyAdmin\SqlParser\
Token($table),
116 new PhpMyAdmin\SqlParser\
Token('.',PhpMyAdmin\SqlParser\Token
::TYPE_OPERATOR
)
120 $sql_query = PhpMyAdmin\SqlParser\TokensList
::build($tokens);
123 echo PhpMyAdmin\Util
::getMessage(PhpMyAdmin\Message
::success());
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 $displayExport->getDisplay(
141 'table', $db, $table, $sql_query, $num_tables,
142 $unlim_num_rows, $multi_values