Translated using Weblate (Ukrainian)
[phpmyadmin.git] / tbl_export.php
blobbd34210c162b3654b35fafb562898a38372af323
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 $cfgRelation = Relation::getRelationsParam();
28 // handling export template actions
29 if (isset($_REQUEST['templateAction']) && $cfgRelation['exporttemplateswork']) {
30 Export::handleExportTemplateActions($cfgRelation);
31 exit;
34 /**
35 * Gets tables information and displays top links
37 require_once 'libraries/tbl_common.inc.php';
38 $url_query .= '&amp;goto=tbl_export.php&amp;back=tbl_export.php';
40 // Dump of a table
42 $export_page_title = __('View dump (schema) of table');
44 // When we have some query, we need to remove LIMIT from that and possibly
45 // generate WHERE clause (if we are asked to export specific rows)
47 if (! empty($sql_query)) {
48 $parser = new PhpMyAdmin\SqlParser\Parser($sql_query);
50 if ((!empty($parser->statements[0]))
51 && ($parser->statements[0] instanceof PhpMyAdmin\SqlParser\Statements\SelectStatement)
52 ) {
54 // Finding aliases and removing them, but we keep track of them to be
55 // able to replace them in select expression too.
56 $aliases = array();
57 foreach ($parser->statements[0]->from as $from) {
58 if ((!empty($from->table)) && (!empty($from->alias))) {
59 $aliases[$from->alias] = $from->table;
60 // We remove the alias of the table because they are going to
61 // be replaced anyway.
62 $from->alias = null;
63 $from->expr = null; // Force rebuild.
67 // Rebuilding the SELECT and FROM clauses.
68 if (count($parser->statements[0]->from) > 0
69 && count($parser->statements[0]->union) === 0
70 ) {
71 $replaces = array(
72 array(
73 'FROM', 'FROM ' . PhpMyAdmin\SqlParser\Components\ExpressionArray::build(
74 $parser->statements[0]->from
80 // Checking if the WHERE clause has to be replaced.
81 if ((!empty($where_clause)) && (is_array($where_clause))) {
82 $replaces[] = array(
83 'WHERE', 'WHERE (' . implode(') OR (', $where_clause) . ')'
87 // Preparing to remove the LIMIT clause.
88 $replaces[] = array('LIMIT', '');
90 // Replacing the clauses.
91 $sql_query = PhpMyAdmin\SqlParser\Utils\Query::replaceClauses(
92 $parser->statements[0],
93 $parser->list,
94 $replaces
97 // Removing the aliases by finding the alias followed by a dot.
98 $tokens = PhpMyAdmin\SqlParser\Lexer::getTokens($sql_query);
99 foreach ($aliases as $alias => $table) {
100 $tokens = PhpMyAdmin\SqlParser\Utils\Tokens::replaceTokens(
101 $tokens,
102 array(
103 array(
104 'value_str' => $alias,
106 array(
107 'type' => PhpMyAdmin\SqlParser\Token::TYPE_OPERATOR,
108 'value_str' => '.',
111 array(
112 new PhpMyAdmin\SqlParser\Token($table),
113 new PhpMyAdmin\SqlParser\Token('.',PhpMyAdmin\SqlParser\Token::TYPE_OPERATOR)
117 $sql_query = PhpMyAdmin\SqlParser\TokensList::build($tokens);
120 echo PhpMyAdmin\Util::getMessage(PhpMyAdmin\Message::success());
123 if (! isset($sql_query)) {
124 $sql_query = '';
126 if (! isset($num_tables)) {
127 $num_tables = 0;
129 if (! isset($unlim_num_rows)) {
130 $unlim_num_rows = 0;
132 if (! isset($multi_values)) {
133 $multi_values = '';
135 $response = Response::getInstance();
136 $response->addHTML(
137 Export::getExportDisplay(
138 'table', $db, $table, $sql_query, $num_tables,
139 $unlim_num_rows, $multi_values