Translated using Weblate (Slovenian)
[phpmyadmin.git] / tbl_export.php
blobe8e7230cc06180d98469e5db90df32485a5656f9
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Table export
6 * @package PhpMyAdmin
7 */
8 use PMA\libraries\config\PageSettings;
9 use PMA\libraries\Response;
11 /**
14 require_once 'libraries/common.inc.php';
15 require_once 'libraries/display_export.lib.php';
16 require_once 'libraries/config/user_preferences.forms.php';
17 require_once 'libraries/config/page_settings.forms.php';
19 PageSettings::showGroup('Export');
21 $response = PMA\libraries\Response::getInstance();
22 $header = $response->getHeader();
23 $scripts = $header->getScripts();
24 $scripts->addFile('export.js');
26 // Get the relation settings
27 $cfgRelation = PMA_getRelationsParam();
29 // handling export template actions
30 if (isset($_REQUEST['templateAction']) && $cfgRelation['exporttemplateswork']) {
31 PMA_handleExportTemplateActions($cfgRelation);
32 exit;
35 /**
36 * Gets tables information and displays top links
38 require_once 'libraries/tbl_common.inc.php';
39 $url_query .= '&amp;goto=tbl_export.php&amp;back=tbl_export.php';
40 require_once 'libraries/tbl_info.inc.php';
42 // Dump of a table
44 $export_page_title = __('View dump (schema) of table');
46 // When we have some query, we need to remove LIMIT from that and possibly
47 // generate WHERE clause (if we are asked to export specific rows)
49 if (! empty($sql_query)) {
50 $parser = new SqlParser\Parser($sql_query);
52 if ((!empty($parser->statements[0]))
53 && ($parser->statements[0] instanceof SqlParser\Statements\SelectStatement)
54 ) {
56 // Finding aliases and removing them, but we keep track of them to be
57 // able to replace them in select expression too.
58 $aliases = array();
59 foreach ($parser->statements[0]->from as $from) {
60 if ((!empty($from->table)) && (!empty($from->alias))) {
61 $aliases[$from->alias] = $from->table;
62 // We remove the alias of the table because they are going to
63 // be replaced anyway.
64 $from->alias = null;
65 $from->expr = null; // Force rebuild.
69 // Rebuilding the SELECT and FROM clauses.
70 $replaces = array(
71 array(
72 'FROM', 'FROM ' . SqlParser\Components\ExpressionArray::build(
73 $parser->statements[0]->from
78 // Checking if the WHERE clause has to be replaced.
79 if ((!empty($where_clause)) && (is_array($where_clause))) {
80 $replaces[] = array(
81 'WHERE', 'WHERE (' . implode(') OR (', $where_clause) . ')'
85 // Preparing to remove the LIMIT clause.
86 $replaces[] = array('LIMIT', '');
88 // Replacing the clauses.
89 $sql_query = SqlParser\Utils\Query::replaceClauses(
90 $parser->statements[0],
91 $parser->list,
92 $replaces
95 // Removing the aliases by finding the alias followed by a dot.
96 $tokens = SqlParser\Lexer::getTokens($sql_query);
97 foreach ($aliases as $alias => $table) {
98 $tokens = SqlParser\Utils\Tokens::replaceTokens(
99 $tokens,
100 array(
101 array(
102 'value_str' => $alias,
104 array(
105 'type' => SqlParser\Token::TYPE_OPERATOR,
106 'value_str' => '.',
109 array(
110 new SqlParser\Token($table),
111 new SqlParser\Token('.', SqlParser\Token::TYPE_OPERATOR)
115 $sql_query = SqlParser\TokensList::build($tokens);
118 echo PMA\libraries\Util::getMessage(PMA\libraries\Message::success());
121 require_once 'libraries/display_export.lib.php';
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 PMA_getExportDisplay(
138 'table', $db, $table, $sql_query, $num_tables,
139 $unlim_num_rows, $multi_values