Merge branch 'origin/master' into Weblate.
[phpmyadmin.git] / db_export.php
blob9b1d0e40a2a15e932f93459f23a43ab1d8aaf2d6
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * dumps a database
6 * @package PhpMyAdmin
7 */
8 declare(strict_types=1);
10 use PhpMyAdmin\Config\PageSettings;
11 use PhpMyAdmin\Display\Export as DisplayExport;
12 use PhpMyAdmin\Export;
13 use PhpMyAdmin\Message;
14 use PhpMyAdmin\Response;
15 use PhpMyAdmin\Util;
17 if (! defined('ROOT_PATH')) {
18 define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
21 /**
22 * Gets some core libraries
24 require_once ROOT_PATH . 'libraries/common.inc.php';
26 PageSettings::showGroup('Export');
28 $response = Response::getInstance();
29 $header = $response->getHeader();
30 $scripts = $header->getScripts();
31 $scripts->addFile('export.js');
33 $export = new Export();
35 // $sub_part is used in Util::getDbInfo() to see if we are coming from
36 // db_export.php, in which case we don't obey $cfg['MaxTableList']
37 $sub_part = '_export';
38 require_once ROOT_PATH . 'libraries/db_common.inc.php';
39 $url_query .= '&amp;goto=db_export.php';
41 list(
42 $tables,
43 $num_tables,
44 $total_num_tables,
45 $sub_part,
46 $is_show_stats,
47 $db_is_system_schema,
48 $tooltip_truename,
49 $tooltip_aliasname,
50 $pos
51 ) = Util::getDbInfo($db, is_null($sub_part) ? '' : $sub_part);
53 /**
54 * Displays the form
56 $export_page_title = __('View dump (schema) of database');
58 // exit if no tables in db found
59 if ($num_tables < 1) {
60 $response->addHTML(
61 Message::error(__('No tables found in database.'))->getDisplay()
63 exit;
64 } // end if
66 $multi_values = '<div class="export_table_list_container">';
67 if (isset($_POST['structure_or_data_forced'])) {
68 $force_val = htmlspecialchars($_POST['structure_or_data_forced']);
69 } else {
70 $force_val = 0;
72 $multi_values .= '<input type="hidden" name="structure_or_data_forced" value="'
73 . $force_val . '">';
74 $multi_values .= '<table class="export_table_select">'
75 . '<thead><tr><th></th>'
76 . '<th>' . __('Tables') . '</th>'
77 . '<th class="export_structure">' . __('Structure') . '</th>'
78 . '<th class="export_data">' . __('Data') . '</th>'
79 . '</tr><tr>'
80 . '<td></td>'
81 . '<td class="export_table_name all">' . __('Select all') . '</td>'
82 . '<td class="export_structure all">'
83 . '<input type="checkbox" id="table_structure_all"></td>'
84 . '<td class="export_data all"><input type="checkbox" id="table_data_all">'
85 . '</td>'
86 . '</tr></thead>'
87 . '<tbody>';
88 $multi_values .= "\n";
90 // when called by libraries/mult_submits.inc.php
91 if (! empty($_POST['selected_tbl']) && empty($table_select)) {
92 $table_select = $_POST['selected_tbl'];
95 foreach ($tables as $each_table) {
96 if (isset($_POST['table_select']) && is_array($_POST['table_select'])) {
97 $is_checked = $export->getCheckedClause(
98 $each_table['Name'],
99 $_POST['table_select']
101 } elseif (isset($table_select)) {
102 $is_checked = $export->getCheckedClause(
103 $each_table['Name'],
104 $table_select
106 } else {
107 $is_checked = ' checked="checked"';
109 if (isset($_POST['table_structure']) && is_array($_POST['table_structure'])) {
110 $structure_checked = $export->getCheckedClause(
111 $each_table['Name'],
112 $_POST['table_structure']
114 } else {
115 $structure_checked = $is_checked;
117 if (isset($_POST['table_data']) && is_array($_POST['table_data'])) {
118 $data_checked = $export->getCheckedClause(
119 $each_table['Name'],
120 $_POST['table_data']
122 } else {
123 $data_checked = $is_checked;
125 $table_html = htmlspecialchars($each_table['Name']);
126 $multi_values .= '<tr class="marked">';
127 $multi_values .= '<td><input type="checkbox" name="table_select[]"'
128 . ' value="' . $table_html . '"' . $is_checked . ' class="checkall"></td>';
129 $multi_values .= '<td class="export_table_name">'
130 . str_replace(' ', '&nbsp;', $table_html) . '</td>';
131 $multi_values .= '<td class="export_structure">'
132 . '<input type="checkbox" name="table_structure[]"'
133 . ' value="' . $table_html . '"' . $structure_checked . '></td>';
134 $multi_values .= '<td class="export_data">'
135 . '<input type="checkbox" name="table_data[]"'
136 . ' value="' . $table_html . '"' . $data_checked . '></td>';
137 $multi_values .= '</tr>';
138 } // end for
140 $multi_values .= "\n";
141 $multi_values .= '</tbody></table></div>';
143 if (! isset($sql_query)) {
144 $sql_query = '';
146 if (! isset($num_tables)) {
147 $num_tables = 0;
149 if (! isset($unlim_num_rows)) {
150 $unlim_num_rows = 0;
152 if (is_null($multi_values)) {
153 $multi_values = '';
155 $response = Response::getInstance();
156 $displayExport = new DisplayExport();
157 $response->addHTML(
158 $displayExport->getDisplay(
159 'database',
160 $db,
161 $table,
162 $sql_query,
163 $num_tables,
164 $unlim_num_rows,
165 $multi_values