Translated using Weblate (French)
[phpmyadmin.git] / tbl_export.php
blobde533e8324c0757c0f2ea9b17461d03aa50c469a
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Table export
6 * @package PhpMyAdmin
7 */
8 use PhpMyAdmin\Config\PageSettings;
9 use PhpMyAdmin\Display\Export;
10 use PhpMyAdmin\Relation;
11 use PhpMyAdmin\Response;
13 /**
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($_POST['templateAction']) && $cfgRelation['exporttemplateswork']) {
33 $displayExport->handleTemplateActions($cfgRelation);
34 exit;
37 /**
38 * Gets tables information and displays top links
40 require_once 'libraries/tbl_common.inc.php';
41 $url_query .= '&amp;goto=tbl_export.php&amp;back=tbl_export.php';
43 // Dump of a table
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)
55 ) {
57 // Finding aliases and removing them, but we keep track of them to be
58 // able to replace them in select expression too.
59 $aliases = array();
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.
65 $from->alias = null;
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
73 ) {
74 $replaces = array(
75 array(
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))) {
85 $replaces[] = array(
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],
96 $parser->list,
97 $replaces
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(
104 $tokens,
105 array(
106 array(
107 'value_str' => $alias,
109 array(
110 'type' => PhpMyAdmin\SqlParser\Token::TYPE_OPERATOR,
111 'value_str' => '.',
114 array(
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)) {
127 $sql_query = '';
129 if (! isset($num_tables)) {
130 $num_tables = 0;
132 if (! isset($unlim_num_rows)) {
133 $unlim_num_rows = 0;
135 if (! isset($multi_values)) {
136 $multi_values = '';
138 $response = Response::getInstance();
139 $response->addHTML(
140 $displayExport->getDisplay(
141 'table', $db, $table, $sql_query, $num_tables,
142 $unlim_num_rows, $multi_values