Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 834 lines (777 sloc) 30.151 kb
c430dc8 @nijel export rework
nijel authored
1 <?php
5d3c12c bug #1682044 Export file even if file not selected
Sebastian Mendel authored
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5904800 Don't rely on grab_globals for export.php
Jo Michael authored
4 * Main export handling code
73d6930 @madhuracj Fix warning "There must be exactly one blank line before the tags in fil...
madhuracj authored
5 *
e56949f @nijel Use package name PhpMyAdmin
nijel authored
6 * @package PhpMyAdmin
5d3c12c bug #1682044 Export file even if file not selected
Sebastian Mendel authored
7 */
c430dc8 @nijel export rework
nijel authored
8
9 /**
10 * Get the variables sent or posted to this script and a core script
11 */
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
12 require_once 'libraries/common.inc.php';
13 require_once 'libraries/zip.lib.php';
14 require_once 'libraries/plugin_interface.lib.php';
c430dc8 @nijel export rework
nijel authored
15
7664661 @Chanaka Implement class behavior of common.lib.php file
Chanaka authored
16 $common_functions = PMA_CommonFunctions::getInstance();
17
5904800 Don't rely on grab_globals for export.php
Jo Michael authored
18 /**
19 * Sets globals from all $_POST (in export.php only)
20 * Would it not be tiresome to list all export-plugin options here?
21 */
50e6f3b @madhuracj Coding style improvements (ControlSignature)
madhuracj authored
22 foreach ($_POST as $one_post_param => $one_post_value) {
5904800 Don't rely on grab_globals for export.php
Jo Michael authored
23 $GLOBALS[$one_post_param] = $one_post_value;
24 }
25
7664661 @Chanaka Implement class behavior of common.lib.php file
Chanaka authored
26 $common_functions->checkParameters(array('what', 'export_type'));
e3161cf @lem9 path disclosure
lem9 authored
27
a87f283 @alexukf plugins and OOP: create general class structure and ExportXML
alexukf authored
28 // export class instance, not array of properties, as before
29 $export_plugin = PMA_getPlugin(
30 "export",
06d6645 @alexukf oop: ExportPhparray
alexukf authored
31 $what,
a87f283 @alexukf plugins and OOP: create general class structure and ExportXML
alexukf authored
32 'libraries/plugins/export/',
297bd67 @nijel Wrap long line
nijel authored
33 array(
34 'export_type' => $export_type,
ef68eaa @madhuracj Fix Checkstyle Warnings - Type: CloseBracketLine
madhuracj authored
35 'single_table' => isset($single_table)
36 )
37 );
9199199 @nijel Use plugins for extension and MIME type.
nijel authored
38
39 // Backward compatbility
40 $type = $what;
41
42 // Check export type
a87f283 @alexukf plugins and OOP: create general class structure and ExportXML
alexukf authored
43 if (! isset($export_plugin)) {
54dc10a @nijel Use PMA_fatalError instead of die
nijel authored
44 PMA_fatalError(__('Bad type!'));
c430dc8 @nijel export rework
nijel authored
45 }
46
5d3c12c bug #1682044 Export file even if file not selected
Sebastian Mendel authored
47 /**
48 * valid compression methods
49 */
50 $compression_methods = array(
51 'zip',
52 'gzip',
ec99ab3 @lem9 bug #3426031 [export] Export to bzip2 is not working
lem9 authored
53 'bzip2',
5d3c12c bug #1682044 Export file even if file not selected
Sebastian Mendel authored
54 );
55
56 /**
57 * init and variable checking
58 */
59 $compression = false;
60 $onserver = false;
a53ccda fixed NOTICES introduced by commit(bug #1682044 Export file even if file...
Sebastian Mendel authored
61 $save_on_server = false;
62 $buffer_needed = false;
e3f4e4a @teekirol Quick export
teekirol authored
63
64 // Is it a quick or custom export?
12a3129 @nijel Spacing around if
nijel authored
65 if ($_REQUEST['quick_or_custom'] == 'quick') {
e3f4e4a @teekirol Quick export
teekirol authored
66 $quick_export = true;
67 } else {
68 $quick_export = false;
69 }
70
b1c8124 @teekirol Updated variable checks for structure and data to reflect new form field...
teekirol authored
71 if ($_REQUEST['output_format'] == 'astext') {
5d3c12c bug #1682044 Export file even if file not selected
Sebastian Mendel authored
72 $asfile = false;
73 } else {
74 $asfile = true;
75 if (in_array($_REQUEST['compression'], $compression_methods)) {
76 $compression = $_REQUEST['compression'];
77 $buffer_needed = true;
78 }
5d71c1c @madhuracj Add spaces after exclamation marks to improve readability
madhuracj authored
79 if (($quick_export && ! empty($_REQUEST['quick_export_onserver']))
80 || (! $quick_export && ! empty($_REQUEST['onserver']))
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
81 ) {
12a3129 @nijel Spacing around if
nijel authored
82 if ($quick_export) {
e3f4e4a @teekirol Quick export
teekirol authored
83 $onserver = $_REQUEST['quick_export_onserver'];
84 } else {
85 $onserver = $_REQUEST['onserver'];
86 }
5d3c12c bug #1682044 Export file even if file not selected
Sebastian Mendel authored
87 // Will we save dump on server?
88 $save_on_server = ! empty($cfg['SaveDir']) && $onserver;
89 }
90 }
91
0afc370 @nijel Allow forcing of export to file, it makes no sense to display PDF in tex...
nijel authored
92 // Does export require to be into file?
9458f9d @alexukf oop: integrate the properties system for ExportXml
alexukf authored
93 if ($export_plugin->getProperties()->getForceFile() != null && ! $asfile) {
94 $message = PMA_Message::error(
95 __('Selected export type has to be saved in file!')
96 );
ab4ed43 @nijel better error message for user
nijel authored
97 if ($export_type == 'server') {
98 $active_page = 'server_export.php';
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
99 include 'server_export.php';
ab4ed43 @nijel better error message for user
nijel authored
100 } elseif ($export_type == 'database') {
cac4247 @nijel Rename db_* files to drop useless _details part.
nijel authored
101 $active_page = 'db_export.php';
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
102 include 'db_export.php';
ab4ed43 @nijel better error message for user
nijel authored
103 } else {
ad06b4a @nijel Rename tbl_* files to drop useless _properties part.
nijel authored
104 $active_page = 'tbl_export.php';
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
105 include 'tbl_export.php';
ab4ed43 @nijel better error message for user
nijel authored
106 }
107 exit();
0afc370 @nijel Allow forcing of export to file, it makes no sense to display PDF in tex...
nijel authored
108 }
c430dc8 @nijel export rework
nijel authored
109
0afc370 @nijel Allow forcing of export to file, it makes no sense to display PDF in tex...
nijel authored
110 // Generate error url and check for needed variables
c430dc8 @nijel export rework
nijel authored
111 if ($export_type == 'server') {
6884f97 @nijel no more support for php3
nijel authored
112 $err_url = 'server_export.php?' . PMA_generate_common_url();
5d3c12c bug #1682044 Export file even if file not selected
Sebastian Mendel authored
113 } elseif ($export_type == 'database' && strlen($db)) {
cac4247 @nijel Rename db_* files to drop useless _details part.
nijel authored
114 $err_url = 'db_export.php?' . PMA_generate_common_url($db);
fb9a3a5 @nijel Check before commit!
nijel authored
115 // Check if we have something to export
116 if (isset($table_select)) {
5d3c12c bug #1682044 Export file even if file not selected
Sebastian Mendel authored
117 $tables = $table_select;
fb9a3a5 @nijel Check before commit!
nijel authored
118 } else {
119 $tables = array();
120 }
5d3c12c bug #1682044 Export file even if file not selected
Sebastian Mendel authored
121 } elseif ($export_type == 'table' && strlen($db) && strlen($table)) {
ad06b4a @nijel Rename tbl_* files to drop useless _properties part.
nijel authored
122 $err_url = 'tbl_export.php?' . PMA_generate_common_url($db, $table);
5b8329b @nijel Check for correct parameters.
nijel authored
123 } else {
54dc10a @nijel Use PMA_fatalError instead of die
nijel authored
124 PMA_fatalError(__('Bad parameters!'));
c430dc8 @nijel export rework
nijel authored
125 }
126
127 /**
128 * Increase time limit for script execution and initializes some variables
129 */
130 @set_time_limit($cfg['ExecTimeLimit']);
5d71c1c @madhuracj Add spaces after exclamation marks to improve readability
madhuracj authored
131 if (! empty($cfg['MemoryLimit'])) {
8c6b399 @nijel Configurable memory limit (RFE #1373904).
nijel authored
132 @ini_set('memory_limit', $cfg['MemoryLimit']);
133 }
c430dc8 @nijel export rework
nijel authored
134
135 // Start with empty buffer
136 $dump_buffer = '';
a199e51 @lem9 clarification
lem9 authored
137 $dump_buffer_len = 0;
c430dc8 @nijel export rework
nijel authored
138
139 // We send fake headers to avoid browser timeout when buffering
140 $time_start = time();
141
142
143 /**
144 * Output handler for all exports, if needed buffering, it stores data into
145 * $dump_buffer, otherwise it prints thems out.
146 *
2b6f9bf @madhuracj Coding style improvements
madhuracj authored
147 * @param string $line the insert statement
148 *
149 * @return bool Whether output succeeded
c430dc8 @nijel export rework
nijel authored
150 */
151 function PMA_exportOutputHandler($line)
152 {
2526d8a @lem9 bug 899610
lem9 authored
153 global $time_start, $dump_buffer, $dump_buffer_len, $save_filename;
c430dc8 @nijel export rework
nijel authored
154
155 // Kanji encoding convert feature
08db25e @nijel EXPERIMENTAL native MS Excel export support, using PEAR module Spreadshe...
nijel authored
156 if ($GLOBALS['output_kanji_conversion']) {
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
157 $line = PMA_kanji_str_conv(
158 $line,
159 $GLOBALS['knjenc'],
160 isset($GLOBALS['xkana']) ? $GLOBALS['xkana'] : ''
161 );
c430dc8 @nijel export rework
nijel authored
162 }
163 // If we have to buffer data, we will perform everything at once at the end
164 if ($GLOBALS['buffer_needed']) {
165
a199e51 @lem9 clarification
lem9 authored
166 $dump_buffer .= $line;
167 if ($GLOBALS['onfly_compression']) {
168
382283d @nijel minor export fixes
nijel authored
169 $dump_buffer_len += strlen($line);
37d50c1 @derrabus Huge set of optimizations, please test!
derrabus authored
170
a199e51 @lem9 clarification
lem9 authored
171 if ($dump_buffer_len > $GLOBALS['memory_limit']) {
172 if ($GLOBALS['output_charset_conversion']) {
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
173 $dump_buffer = PMA_convert_string(
174 'utf-8',
175 $GLOBALS['charset_of_file'],
176 $dump_buffer
177 );
a199e51 @lem9 clarification
lem9 authored
178 }
08db25e @nijel EXPERIMENTAL native MS Excel export support, using PEAR module Spreadshe...
nijel authored
179 // as bzipped
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
180 if ($GLOBALS['compression'] == 'bzip2'
181 && @function_exists('bzcompress')
182 ) {
a199e51 @lem9 clarification
lem9 authored
183 $dump_buffer = bzcompress($dump_buffer);
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
184 } elseif ($GLOBALS['compression'] == 'gzip'
185 && @function_exists('gzencode')
186 ) {
94c6836 @ruleant fix coding style : control structures
ruleant authored
187 // as a gzipped file
a199e51 @lem9 clarification
lem9 authored
188 // without the optional parameter level because it bug
189 $dump_buffer = gzencode($dump_buffer);
190 }
191 if ($GLOBALS['save_on_server']) {
192 $write_result = @fwrite($GLOBALS['file_handle'], $dump_buffer);
5d71c1c @madhuracj Add spaces after exclamation marks to improve readability
madhuracj authored
193 if (! $write_result || ($write_result != strlen($dump_buffer))) {
ab646aa @madhuracj Wrap some more long lines
madhuracj authored
194 $GLOBALS['message'] = PMA_Message::error(
195 __('Insufficient space to save the file %s.')
196 );
6ee1069 make use of PMA_Message
Sebastian Mendel authored
197 $GLOBALS['message']->addParam($save_filename);
5d3c12c bug #1682044 Export file even if file not selected
Sebastian Mendel authored
198 return false;
a199e51 @lem9 clarification
lem9 authored
199 }
200 } else {
201 echo $dump_buffer;
202 }
203 $dump_buffer = '';
204 $dump_buffer_len = 0;
205 }
206 } else {
207 $time_now = time();
208 if ($time_start >= $time_now + 30) {
209 $time_start = $time_now;
210 header('X-pmaPing: Pong');
211 } // end if
212 }
c430dc8 @nijel export rework
nijel authored
213 } else {
214 if ($GLOBALS['asfile']) {
aa0a464 @lem9 bug #1804081 [export] export on server does not obey AllowAnyWhereRecodi...
lem9 authored
215 if ($GLOBALS['output_charset_conversion']) {
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
216 $line = PMA_convert_string(
217 'utf-8',
218 $GLOBALS['charset_of_file'],
219 $line
220 );
aa0a464 @lem9 bug #1804081 [export] export on server does not obey AllowAnyWhereRecodi...
lem9 authored
221 }
89ecfb8 @lem9 bug 1038804 - insufficient space to save
lem9 authored
222 if ($GLOBALS['save_on_server'] && strlen($line) > 0) {
c430dc8 @nijel export rework
nijel authored
223 $write_result = @fwrite($GLOBALS['file_handle'], $line);
5d71c1c @madhuracj Add spaces after exclamation marks to improve readability
madhuracj authored
224 if (! $write_result || ($write_result != strlen($line))) {
ab646aa @madhuracj Wrap some more long lines
madhuracj authored
225 $GLOBALS['message'] = PMA_Message::error(
226 __('Insufficient space to save the file %s.')
227 );
6ee1069 make use of PMA_Message
Sebastian Mendel authored
228 $GLOBALS['message']->addParam($save_filename);
5d3c12c bug #1682044 Export file even if file not selected
Sebastian Mendel authored
229 return false;
c430dc8 @nijel export rework
nijel authored
230 }
231 $time_now = time();
232 if ($time_start >= $time_now + 30) {
233 $time_start = $time_now;
234 header('X-pmaPing: Pong');
235 } // end if
236 } else {
237 // We export as file - output normally
238 echo $line;
239 }
240 } else {
241 // We export as html - replace special chars
242 echo htmlspecialchars($line);
243 }
244 }
5d3c12c bug #1682044 Export file even if file not selected
Sebastian Mendel authored
245 return true;
c430dc8 @nijel export rework
nijel authored
246 } // end of the 'PMA_exportOutputHandler()' function
247
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
248 // Defines the default <CR><LF> format.
249 // For SQL always use \n as MySQL wants this on all platforms.
fcdfa25 @nijel Use just \n for SQL exports (bug #1042521).
nijel authored
250 if ($what == 'sql') {
251 $crlf = "\n";
252 } else {
7664661 @Chanaka Implement class behavior of common.lib.php file
Chanaka authored
253 $crlf = $common_functions->whichCrlf();
fcdfa25 @nijel Use just \n for SQL exports (bug #1042521).
nijel authored
254 }
c430dc8 @nijel export rework
nijel authored
255
08db25e @nijel EXPERIMENTAL native MS Excel export support, using PEAR module Spreadshe...
nijel authored
256 $output_kanji_conversion = function_exists('PMA_kanji_str_conv') && $type != 'xls';
257
c430dc8 @nijel export rework
nijel authored
258 // Do we need to convert charset?
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
259 $output_charset_conversion = $asfile
260 && $GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE
8f54092 @nijel Remove forgotten references to $charset
nijel authored
261 && isset($charset_of_file) && $charset_of_file != 'utf-8'
08db25e @nijel EXPERIMENTAL native MS Excel export support, using PEAR module Spreadshe...
nijel authored
262 && $type != 'xls';
c430dc8 @nijel export rework
nijel authored
263
91ae7b6 @lem9 various code improvements, thanks to Piotr Przybylski
lem9 authored
264 // Use on the fly compression?
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
265 $onfly_compression = $GLOBALS['cfg']['CompressOnFly']
266 && ($compression == 'gzip' || $compression == 'bzip2');
a199e51 @lem9 clarification
lem9 authored
267 if ($onfly_compression) {
268 $memory_limit = trim(@ini_get('memory_limit'));
269 // 2 MB as default
0ae8842 (not complete) PEAR coding standard
Sebastian Mendel authored
270 if (empty($memory_limit)) {
271 $memory_limit = 2 * 1024 * 1024;
272 }
a199e51 @lem9 clarification
lem9 authored
273
0ae8842 (not complete) PEAR coding standard
Sebastian Mendel authored
274 if (strtolower(substr($memory_limit, -1)) == 'm') {
275 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024;
276 } elseif (strtolower(substr($memory_limit, -1)) == 'k') {
277 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024;
278 } elseif (strtolower(substr($memory_limit, -1)) == 'g') {
279 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024 * 1024;
280 } else {
281 $memory_limit = (int)$memory_limit;
282 }
a199e51 @lem9 clarification
lem9 authored
283
284 // Some of memory is needed for other thins and as treshold.
285 // Nijel: During export I had allocated (see memory_get_usage function)
286 // approx 1.2MB so this comes from that.
0ae8842 (not complete) PEAR coding standard
Sebastian Mendel authored
287 if ($memory_limit > 1500000) {
288 $memory_limit -= 1500000;
289 }
a199e51 @lem9 clarification
lem9 authored
290
291 // Some memory is needed for compression, assume 1/3
1159c2c @nijel Increase magic contstant to avoid problems with compression of some spec...
nijel authored
292 $memory_limit /= 8;
a199e51 @lem9 clarification
lem9 authored
293 }
294
c430dc8 @nijel export rework
nijel authored
295 // Generate filename and mime type if needed
296 if ($asfile) {
297 $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']);
298 if ($export_type == 'server') {
299 if (isset($remember_template)) {
2b6f9bf @madhuracj Coding style improvements
madhuracj authored
300 $GLOBALS['PMA_Config']->setUserValue(
301 'pma_server_filename_template',
302 'Export/file_template_server',
303 $filename_template
304 );
c430dc8 @nijel export rework
nijel authored
305 }
306 } elseif ($export_type == 'database') {
307 if (isset($remember_template)) {
2b6f9bf @madhuracj Coding style improvements
madhuracj authored
308 $GLOBALS['PMA_Config']->setUserValue(
309 'pma_db_filename_template',
310 'Export/file_template_database',
311 $filename_template
312 );
c430dc8 @nijel export rework
nijel authored
313 }
314 } else {
315 if (isset($remember_template)) {
2b6f9bf @madhuracj Coding style improvements
madhuracj authored
316 $GLOBALS['PMA_Config']->setUserValue(
317 'pma_table_filename_template',
318 'Export/file_template_table',
319 $filename_template
320 );
c430dc8 @nijel export rework
nijel authored
321 }
322 }
7664661 @Chanaka Implement class behavior of common.lib.php file
Chanaka authored
323 $filename = $common_functions->expandUserString($filename_template);
b55019e Fix function call not camelCased yet
J.M authored
324 $filename = PMA_sanitizeFilename($filename);
c430dc8 @nijel export rework
nijel authored
325
9199199 @nijel Use plugins for extension and MIME type.
nijel authored
326 // Grab basic dump extension and mime type
5b8c603 @teekirol If the user already appended the file extension, don't add it again
teekirol authored
327 // Check if the user already added extension; get the substring where the extension would be if it was included
9458f9d @alexukf oop: integrate the properties system for ExportXml
alexukf authored
328 $extension_start_pos = strlen($filename) - strlen(
329 $export_plugin->getProperties()->getExtension()
330 ) - 1;
5b8c603 @teekirol If the user already appended the file extension, don't add it again
teekirol authored
331 $user_extension = substr($filename, $extension_start_pos, strlen($filename));
9458f9d @alexukf oop: integrate the properties system for ExportXml
alexukf authored
332 $required_extension = "." . $export_plugin->getProperties()->getExtension();
12a3129 @nijel Spacing around if
nijel authored
333 if (strtolower($user_extension) != $required_extension) {
5b8c603 @teekirol If the user already appended the file extension, don't add it again
teekirol authored
334 $filename .= $required_extension;
335 }
9458f9d @alexukf oop: integrate the properties system for ExportXml
alexukf authored
336 $mime_type = $export_plugin->getProperties()->getMimeType();
c430dc8 @nijel export rework
nijel authored
337
0214a6f @lem9 patch #2773818 [export] Invalid "Content-Encoding" header
lem9 authored
338 // If dump is going to be compressed, set correct mime_type and add
c430dc8 @nijel export rework
nijel authored
339 // compression to extension
ec99ab3 @lem9 bug #3426031 [export] Export to bzip2 is not working
lem9 authored
340 if ($compression == 'bzip2') {
c430dc8 @nijel export rework
nijel authored
341 $filename .= '.bz2';
db02f14 @nijel Back to Content-Type application/x-bzip2 on bzip2 export (bug #1106652).
nijel authored
342 $mime_type = 'application/x-bzip2';
5d3c12c bug #1682044 Export file even if file not selected
Sebastian Mendel authored
343 } elseif ($compression == 'gzip') {
c430dc8 @nijel export rework
nijel authored
344 $filename .= '.gz';
0214a6f @lem9 patch #2773818 [export] Invalid "Content-Encoding" header
lem9 authored
345 $mime_type = 'application/x-gzip';
5d3c12c bug #1682044 Export file even if file not selected
Sebastian Mendel authored
346 } elseif ($compression == 'zip') {
c430dc8 @nijel export rework
nijel authored
347 $filename .= '.zip';
5ad4d83 @nijel Use standardised mime types and use content encoding for gzip/bzip2. I h...
nijel authored
348 $mime_type = 'application/zip';
c430dc8 @nijel export rework
nijel authored
349 }
350 }
351
352 // Open file on server if needed
353 if ($save_on_server) {
7664661 @Chanaka Implement class behavior of common.lib.php file
Chanaka authored
354 $save_filename = $common_functions->userDir($cfg['SaveDir'])
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
355 . preg_replace('@[/\\\\]@', '_', $filename);
c430dc8 @nijel export rework
nijel authored
356 unset($message);
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
357 if (file_exists($save_filename)
5d71c1c @madhuracj Add spaces after exclamation marks to improve readability
madhuracj authored
358 && ((! $quick_export && empty($onserverover))
5623356 @alexukf oop: fix bugs and phpcs errors for all export plugins
alexukf authored
359 || ($quick_export
360 && $_REQUEST['quick_export_onserverover'] != 'saveitover'))
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
361 ) {
5623356 @alexukf oop: fix bugs and phpcs errors for all export plugins
alexukf authored
362 $message = PMA_Message::error(__(
363 'File %s already exists on server, change filename or check'
364 . ' overwrite option.'
365 ));
107fc46 make use of PMA_Message
Sebastian Mendel authored
366 $message->addParam($save_filename);
c430dc8 @nijel export rework
nijel authored
367 } else {
5d71c1c @madhuracj Add spaces after exclamation marks to improve readability
madhuracj authored
368 if (is_file($save_filename) && ! is_writable($save_filename)) {
5623356 @alexukf oop: fix bugs and phpcs errors for all export plugins
alexukf authored
369 $message = PMA_Message::error(__(
370 'The web server does not have permission to save the file %s.'
371 ));
107fc46 make use of PMA_Message
Sebastian Mendel authored
372 $message->addParam($save_filename);
c430dc8 @nijel export rework
nijel authored
373 } else {
5d71c1c @madhuracj Add spaces after exclamation marks to improve readability
madhuracj authored
374 if (! $file_handle = @fopen($save_filename, 'w')) {
5623356 @alexukf oop: fix bugs and phpcs errors for all export plugins
alexukf authored
375 $message = PMA_Message::error(__(
376 'The web server does not have permission to save the file %s.'
377 ));
107fc46 make use of PMA_Message
Sebastian Mendel authored
378 $message->addParam($save_filename);
c430dc8 @nijel export rework
nijel authored
379 }
380 }
381 }
382 if (isset($message)) {
383 if ($export_type == 'server') {
6884f97 @nijel no more support for php3
nijel authored
384 $active_page = 'server_export.php';
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
385 include 'server_export.php';
c430dc8 @nijel export rework
nijel authored
386 } elseif ($export_type == 'database') {
cac4247 @nijel Rename db_* files to drop useless _details part.
nijel authored
387 $active_page = 'db_export.php';
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
388 include 'db_export.php';
c430dc8 @nijel export rework
nijel authored
389 } else {
ad06b4a @nijel Rename tbl_* files to drop useless _properties part.
nijel authored
390 $active_page = 'tbl_export.php';
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
391 include 'tbl_export.php';
c430dc8 @nijel export rework
nijel authored
392 }
393 exit();
394 }
395 }
396
397 /**
398 * Send headers depending on whether the user chose to download a dump file
399 * or not
400 */
5d71c1c @madhuracj Add spaces after exclamation marks to improve readability
madhuracj authored
401 if (! $save_on_server) {
cfeb306 coding standard: no spaces inside braces
Sebastian Mendel authored
402 if ($asfile) {
c430dc8 @nijel export rework
nijel authored
403 // Download
6554e98 @lem9 bug #1981043 [export] HTML in exports getting corrupted
lem9 authored
404 // (avoid rewriting data containing HTML with anchors and forms;
405 // this was reported to happen under Plesk)
e67a0a2 @madhuracj Spaces between parameters in function calls
madhuracj authored
406 @ini_set('url_rewriter.tags', '');
f5ed603 @madhuracj Use camel case for function names - another instance
madhuracj authored
407 $filename = PMA_sanitizeFilename($filename);
6554e98 @lem9 bug #1981043 [export] HTML in exports getting corrupted
lem9 authored
408
10510e1 @madhuracj Fix function name: PMA_download_header -> PMA_downloadHeader
madhuracj authored
409 PMA_downloadHeader($filename, $mime_type);
c430dc8 @nijel export rework
nijel authored
410 } else {
411 // HTML
3cd881c @lem9 export nothing if no tables are selected
lem9 authored
412 if ($export_type == 'database') {
413 $num_tables = count($tables);
414 if ($num_tables == 0) {
7925c03 @lem9 gettext conversion
lem9 authored
415 $message = PMA_Message::error(__('No tables found in database.'));
cac4247 @nijel Rename db_* files to drop useless _details part.
nijel authored
416 $active_page = 'db_export.php';
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
417 include 'db_export.php';
3cd881c @lem9 export nothing if no tables are selected
lem9 authored
418 exit();
419 }
420 }
c430dc8 @nijel export rework
nijel authored
421 $backup_cfgServer = $cfg['Server'];
422 $cfg['Server'] = $backup_cfgServer;
423 unset($backup_cfgServer);
b9c474c Replaced *[align] with *[class] for HTML5 validity
Jo Michael authored
424 echo "\n" . '<div style="text-align: ' . $cell_align_left . '">' . "\n";
d9a2161 @lem9 redesign part 3
lem9 authored
425 //echo ' <pre>' . "\n";
948abf1 @teekirol Added back button on the top of the page as well
teekirol authored
426
427 /**
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
428 * Displays a back button with all the $_REQUEST data in the URL
429 * (store in a variable to also display after the textarea)
948abf1 @teekirol Added back button on the top of the page as well
teekirol authored
430 */
2b6f9bf @madhuracj Coding style improvements
madhuracj authored
431 $back_button = '<p>[ <a href="';
948abf1 @teekirol Added back button on the top of the page as well
teekirol authored
432 if ($export_type == 'server') {
2b6f9bf @madhuracj Coding style improvements
madhuracj authored
433 $back_button .= 'server_export.php?' . PMA_generate_common_url();
434 } elseif ($export_type == 'database') {
948abf1 @teekirol Added back button on the top of the page as well
teekirol authored
435 $back_button .= 'db_export.php?' . PMA_generate_common_url($db);
436 } else {
437 $back_button .= 'tbl_export.php?' . PMA_generate_common_url($db, $table);
438 }
439
440 // Convert the multiple select elements from an array to a string
12a3129 @nijel Spacing around if
nijel authored
441 if ($export_type == 'server' && isset($_REQUEST['db_select'])) {
948abf1 @teekirol Added back button on the top of the page as well
teekirol authored
442 $_REQUEST['db_select'] = implode(",", $_REQUEST['db_select']);
12a3129 @nijel Spacing around if
nijel authored
443 } elseif ($export_type == 'database' && isset($_REQUEST['table_select'])) {
948abf1 @teekirol Added back button on the top of the page as well
teekirol authored
444 $_REQUEST['table_select'] = implode(",", $_REQUEST['table_select']);
445 }
446
48e9af4 @nijel Add missing space after foreach calls
nijel authored
447 foreach ($_REQUEST as $name => $value) {
3449d9f Fix html entities for astext export backlink, use jQuery for textSQLDUMP...
J.M authored
448 $back_button .= '&amp;' . urlencode($name) . '=' . urlencode($value);
948abf1 @teekirol Added back button on the top of the page as well
teekirol authored
449 }
3449d9f Fix html entities for astext export backlink, use jQuery for textSQLDUMP...
J.M authored
450 $back_button .= '&amp;repopulate=1">Back</a> ]</p>';
948abf1 @teekirol Added back button on the top of the page as well
teekirol authored
451
452 echo $back_button;
d9a2161 @lem9 redesign part 3
lem9 authored
453 echo ' <form name="nofunction">' . "\n"
0321262 @lem9 remove auto-select of exported textarea
lem9 authored
454 // remove auto-select for now: there is no way to select
455 // only a part of the text; anyway, it should obey
456 // $cfg['TextareaAutoSelect']
457 //. ' <textarea name="sqldump" cols="50" rows="30" onclick="this.select();" id="textSQLDUMP" wrap="OFF">' . "\n";
458 . ' <textarea name="sqldump" cols="50" rows="30" id="textSQLDUMP" wrap="OFF">' . "\n";
c430dc8 @nijel export rework
nijel authored
459 } // end download
460 }
461
f28ddb7 @nijel Correctly report error when export fails.
nijel authored
462 // Fake loop just to allow skip of remain of this code by break, I'd really
463 // need exceptions here :-)
464 do {
465
84c6bd7 @nijel Fix indentation
nijel authored
466 // Add possibly some comments to export
a87f283 @alexukf plugins and OOP: create general class structure and ExportXML
alexukf authored
467 if (! $export_plugin->exportHeader($db)) {
84c6bd7 @nijel Fix indentation
nijel authored
468 break;
469 }
c848070 @nijel - Allow to supress dates in SQL dump separately.
nijel authored
470
84c6bd7 @nijel Fix indentation
nijel authored
471 // Will we need relation & co. setup?
472 $do_relation = isset($GLOBALS[$what . '_relation']);
473 $do_comments = isset($GLOBALS[$what . '_include_comments']);
474 $do_mime = isset($GLOBALS[$what . '_mime']);
475 if ($do_relation || $do_comments || $do_mime) {
476 $cfgRelation = PMA_getRelationsParam();
477 }
478 if ($do_mime) {
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
479 include_once 'libraries/transformations.lib.php';
c430dc8 @nijel export rework
nijel authored
480 }
1484ca6 @lem9 Procedures and functions should be exported also when entering Export on...
lem9 authored
481
84c6bd7 @nijel Fix indentation
nijel authored
482 // Include dates in export?
5623356 @alexukf oop: fix bugs and phpcs errors for all export plugins
alexukf authored
483 $do_dates = isset($GLOBALS[$what . '_dates']);
84c6bd7 @nijel Fix indentation
nijel authored
484
485 /**
486 * Builds the dump
487 */
488 // Gets the number of tables if a dump of a database has been required
489 if ($export_type == 'server') {
490 if (isset($db_select)) {
491 $tmp_select = implode($db_select, '|');
492 $tmp_select = '|' . $tmp_select . '|';
493 }
494 // Walk over databases
495 foreach ($GLOBALS['pma']->databases as $current_db) {
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
496 if ((isset($tmp_select)
497 && strpos(' ' . $tmp_select, '|' . $current_db . '|'))
2b6f9bf @madhuracj Coding style improvements
madhuracj authored
498 || ! isset($tmp_select)
499 ) {
a87f283 @alexukf plugins and OOP: create general class structure and ExportXML
alexukf authored
500 if (! $export_plugin->exportDBHeader($current_db)) {
84c6bd7 @nijel Fix indentation
nijel authored
501 break 2;
5aa902d @lem9 bug #1443004, VIEW and export
lem9 authored
502 }
a87f283 @alexukf plugins and OOP: create general class structure and ExportXML
alexukf authored
503 if (! $export_plugin->exportDBCreate($current_db)) {
84c6bd7 @nijel Fix indentation
nijel authored
504 break 2;
505 }
4b0dbf6 @alexukf oop: ExportLatex
alexukf authored
506 if (method_exists($export_plugin, 'exportRoutines')
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
507 && strpos($GLOBALS['sql_structure_or_data'], 'structure') !== false
508 && isset($GLOBALS['sql_procedure_function'])
509 ) {
683d767 @alexukf oop: export codegen; camel caps export naming convention
alexukf authored
510 $export_plugin->exportRoutines($current_db);
2915b5c @derrabus Added MySQLi library; Removed calls to old mysql_wrappers library.
derrabus authored
511 }
84c6bd7 @nijel Fix indentation
nijel authored
512
513 $tables = PMA_DBI_get_tables($current_db);
514 $views = array();
515 foreach ($tables as $table) {
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
516 // if this is a view, collect it for later;
517 // views must be exported after the tables
84c6bd7 @nijel Fix indentation
nijel authored
518 $is_view = PMA_Table::isView($current_db, $table);
519 if ($is_view) {
520 $views[] = $table;
521 }
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
522 if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
523 || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
524 ) {
84c6bd7 @nijel Fix indentation
nijel authored
525 // for a view, export a stand-in definition of the table
526 // to resolve view dependencies
683d767 @alexukf oop: export codegen; camel caps export naming convention
alexukf authored
527 if (! $export_plugin->exportStructure(
4806c07 @alexukf Export plugins coding style: move arguments with default values at the e...
alexukf authored
528 $current_db, $table, $crlf, $err_url,
529 $is_view ? 'stand_in' : 'create_table', $export_type,
530 $do_relation, $do_comments, $do_mime, $do_dates
531 )) {
84c6bd7 @nijel Fix indentation
nijel authored
532 break 3;
533 }
534 }
535 // if this is a view or a merge table, don't export data
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
536 if (($GLOBALS[$what . '_structure_or_data'] == 'data'
537 || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data')
5d71c1c @madhuracj Add spaces after exclamation marks to improve readability
madhuracj authored
538 && ! ($is_view || PMA_Table::isMerge($current_db, $table))
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
539 ) {
7664661 @Chanaka Implement class behavior of common.lib.php file
Chanaka authored
540 $local_query = 'SELECT * FROM ' . $common_functions->backquote($current_db)
541 . '.' . $common_functions->backquote($table);
a87f283 @alexukf plugins and OOP: create general class structure and ExportXML
alexukf authored
542 if (! $export_plugin->exportData($current_db, $table, $crlf, $err_url, $local_query)) {
84c6bd7 @nijel Fix indentation
nijel authored
543 break 3;
544 }
545 }
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
546 // now export the triggers (needs to be done after the data
547 // because triggers can modify already imported tables)
548 if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
549 || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
550 ) {
683d767 @alexukf oop: export codegen; camel caps export naming convention
alexukf authored
551 if (! $export_plugin->exportStructure(
4806c07 @alexukf Export plugins coding style: move arguments with default values at the e...
alexukf authored
552 $current_db, $table, $crlf, $err_url,
553 'triggers', $export_type,
554 $do_relation, $do_comments, $do_mime, $do_dates
555 )) {
84c6bd7 @nijel Fix indentation
nijel authored
556 break 2;
557 }
0ae8842 (not complete) PEAR coding standard
Sebastian Mendel authored
558 }
2915b5c @derrabus Added MySQLi library; Removed calls to old mysql_wrappers library.
derrabus authored
559 }
84c6bd7 @nijel Fix indentation
nijel authored
560 foreach ($views as $view) {
561 // no data export for a view
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
562 if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
563 || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
564 ) {
683d767 @alexukf oop: export codegen; camel caps export naming convention
alexukf authored
565 if (! $export_plugin->exportStructure(
4806c07 @alexukf Export plugins coding style: move arguments with default values at the e...
alexukf authored
566 $current_db, $view, $crlf, $err_url,
567 'create_view', $export_type,
568 $do_relation, $do_comments, $do_mime, $do_dates
569 )) {
84c6bd7 @nijel Fix indentation
nijel authored
570 break 3;
571 }
f038959 @lem9 bug #2839548 [export] Triggers order on export
lem9 authored
572 }
573 }
683d767 @alexukf oop: export codegen; camel caps export naming convention
alexukf authored
574 if (! $export_plugin->exportDBFooter($current_db)) {
84c6bd7 @nijel Fix indentation
nijel authored
575 break 2;
576 }
c430dc8 @nijel export rework
nijel authored
577 }
84c6bd7 @nijel Fix indentation
nijel authored
578 }
579 } elseif ($export_type == 'database') {
683d767 @alexukf oop: export codegen; camel caps export naming convention
alexukf authored
580 if (! $export_plugin->exportDBHeader($db)) {
84c6bd7 @nijel Fix indentation
nijel authored
581 break;
582 }
583
4b0dbf6 @alexukf oop: ExportLatex
alexukf authored
584 if (method_exists($export_plugin, 'exportRoutines')
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
585 && strpos($GLOBALS['sql_structure_or_data'], 'structure') !== false
586 && isset($GLOBALS['sql_procedure_function'])
587 ) {
683d767 @alexukf oop: export codegen; camel caps export naming convention
alexukf authored
588 $export_plugin->exportRoutines($db);
84c6bd7 @nijel Fix indentation
nijel authored
589 }
590
591 $i = 0;
592 $views = array();
593 // $tables contains the choices from the user (via $table_select)
594 foreach ($tables as $table) {
595 // if this is a view, collect it for later; views must be exported after
596 // the tables
597 $is_view = PMA_Table::isView($db, $table);
598 if ($is_view) {
599 $views[] = $table;
600 }
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
601 if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
602 || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
603 ) {
84c6bd7 @nijel Fix indentation
nijel authored
604 // for a view, export a stand-in definition of the table
605 // to resolve view dependencies
683d767 @alexukf oop: export codegen; camel caps export naming convention
alexukf authored
606 if (! $export_plugin->exportStructure(
4806c07 @alexukf Export plugins coding style: move arguments with default values at the e...
alexukf authored
607 $db, $table, $crlf, $err_url,
608 $is_view ? 'stand_in' : 'create_table', $export_type,
609 $do_relation, $do_comments, $do_mime, $do_dates
610 )) {
84c6bd7 @nijel Fix indentation
nijel authored
611 break 2;
5aa902d @lem9 bug #1443004, VIEW and export
lem9 authored
612 }
613 }
84c6bd7 @nijel Fix indentation
nijel authored
614 // if this is a view or a merge table, don't export data
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
615 if (($GLOBALS[$what . '_structure_or_data'] == 'data'
616 || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data')
5d71c1c @madhuracj Add spaces after exclamation marks to improve readability
madhuracj authored
617 && ! ($is_view || PMA_Table::isMerge($db, $table))
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
618 ) {
7664661 @Chanaka Implement class behavior of common.lib.php file
Chanaka authored
619 $local_query = 'SELECT * FROM ' . $common_functions->backquote($db)
620 . '.' . $common_functions->backquote($table);
a87f283 @alexukf plugins and OOP: create general class structure and ExportXML
alexukf authored
621 if (! $export_plugin->exportData($db, $table, $crlf, $err_url, $local_query)) {
84c6bd7 @nijel Fix indentation
nijel authored
622 break 2;
623 }
624 }
625 // now export the triggers (needs to be done after the data because
626 // triggers can modify already imported tables)
627 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
683d767 @alexukf oop: export codegen; camel caps export naming convention
alexukf authored
628 if (! $export_plugin->exportStructure(
4806c07 @alexukf Export plugins coding style: move arguments with default values at the e...
alexukf authored
629 $db, $table, $crlf, $err_url,
630 'triggers', $export_type,
631 $do_relation, $do_comments, $do_mime, $do_dates
632 )) {
84c6bd7 @nijel Fix indentation
nijel authored
633 break 2;
634 }
635 }
636 }
637 foreach ($views as $view) {
638 // no data export for a view
639 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
683d767 @alexukf oop: export codegen; camel caps export naming convention
alexukf authored
640 if (! $export_plugin->exportStructure(
4806c07 @alexukf Export plugins coding style: move arguments with default values at the e...
alexukf authored
641 $db, $view, $crlf, $err_url,
642 'create_view', $export_type,
643 $do_relation, $do_comments, $do_mime, $do_dates
644 )) {
84c6bd7 @nijel Fix indentation
nijel authored
645 break 2;
646 }
0ae8842 (not complete) PEAR coding standard
Sebastian Mendel authored
647 }
c430dc8 @nijel export rework
nijel authored
648 }
1484ca6 @lem9 Procedures and functions should be exported also when entering Export on...
lem9 authored
649
683d767 @alexukf oop: export codegen; camel caps export naming convention
alexukf authored
650 if (! $export_plugin->exportDBFooter($db)) {
84c6bd7 @nijel Fix indentation
nijel authored
651 break;
652 }
653 } else {
683d767 @alexukf oop: export codegen; camel caps export naming convention
alexukf authored
654 if (! $export_plugin->exportDBHeader($db)) {
84c6bd7 @nijel Fix indentation
nijel authored
655 break;
656 }
657 // We export just one table
658 // $allrows comes from the form when "Dump all rows" has been selected
659 if ($allrows == '0' && $limit_to > 0 && $limit_from >= 0) {
660 $add_query = ' LIMIT '
661 . (($limit_from > 0) ? $limit_from . ', ' : '')
662 . $limit_to;
663 } else {
664 $add_query = '';
665 }
1484ca6 @lem9 Procedures and functions should be exported also when entering Export on...
lem9 authored
666
b0588d3 @lem9 bug #1621280, support VIEW dependencies during export
lem9 authored
667 $is_view = PMA_Table::isView($db, $table);
b1c8124 @teekirol Updated variable checks for structure and data to reflect new form field...
teekirol authored
668 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
683d767 @alexukf oop: export codegen; camel caps export naming convention
alexukf authored
669 if (! $export_plugin->exportStructure(
4806c07 @alexukf Export plugins coding style: move arguments with default values at the e...
alexukf authored
670 $db, $table, $crlf, $err_url,
671 $is_view ? 'create_view' : 'create_table', $export_type,
672 $do_relation, $do_comments, $do_mime, $do_dates
673 )) {
84c6bd7 @nijel Fix indentation
nijel authored
674 break;
2915b5c @derrabus Added MySQLi library; Removed calls to old mysql_wrappers library.
derrabus authored
675 }
ac5be02 @lem9 set local_query only if we are exporting data
lem9 authored
676 }
84c6bd7 @nijel Fix indentation
nijel authored
677 // If this is an export of a single view, we have to export data;
678 // for example, a PDF report
679 // if it is a merge table, no data is exported
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
680 if (($GLOBALS[$what . '_structure_or_data'] == 'data'
681 || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data')
682 && ! PMA_Table::isMerge($db, $table)
683 ) {
5d71c1c @madhuracj Add spaces after exclamation marks to improve readability
madhuracj authored
684 if (! empty($sql_query)) {
84c6bd7 @nijel Fix indentation
nijel authored
685 // only preg_replace if needed
5d71c1c @madhuracj Add spaces after exclamation marks to improve readability
madhuracj authored
686 if (! empty($add_query)) {
84c6bd7 @nijel Fix indentation
nijel authored
687 // remove trailing semicolon before adding a LIMIT
688 $sql_query = preg_replace('%;\s*$%', '', $sql_query);
689 }
690 $local_query = $sql_query . $add_query;
691 PMA_DBI_select_db($db);
692 } else {
7664661 @Chanaka Implement class behavior of common.lib.php file
Chanaka authored
693 $local_query = 'SELECT * FROM ' . $common_functions->backquote($db)
694 . '.' . $common_functions->backquote($table) . $add_query;
84c6bd7 @nijel Fix indentation
nijel authored
695 }
06d6645 @alexukf oop: ExportPhparray
alexukf authored
696 if (! $export_plugin->exportData($db, $table, $crlf, $err_url,
697 $local_query
698 )) {
84c6bd7 @nijel Fix indentation
nijel authored
699 break;
2915b5c @derrabus Added MySQLi library; Removed calls to old mysql_wrappers library.
derrabus authored
700 }
ac5be02 @lem9 set local_query only if we are exporting data
lem9 authored
701 }
f038959 @lem9 bug #2839548 [export] Triggers order on export
lem9 authored
702 // now export the triggers (needs to be done after the data because
703 // triggers can modify already imported tables)
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
704 if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
705 || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
706 ) {
683d767 @alexukf oop: export codegen; camel caps export naming convention
alexukf authored
707 if (! $export_plugin->exportStructure(
4806c07 @alexukf Export plugins coding style: move arguments with default values at the e...
alexukf authored
708 $db, $table, $crlf, $err_url,
709 'triggers', $export_type,
710 $do_relation, $do_comments, $do_mime, $do_dates
711 )) {
f038959 @lem9 bug #2839548 [export] Triggers order on export
lem9 authored
712 break 2;
713 }
714 }
a87f283 @alexukf plugins and OOP: create general class structure and ExportXML
alexukf authored
715 if (! $export_plugin->exportDBFooter($db)) {
f28ddb7 @nijel Correctly report error when export fails.
nijel authored
716 break;
0ae8842 (not complete) PEAR coding standard
Sebastian Mendel authored
717 }
f28ddb7 @nijel Correctly report error when export fails.
nijel authored
718 }
a87f283 @alexukf plugins and OOP: create general class structure and ExportXML
alexukf authored
719 if (! $export_plugin->exportFooter()) {
f28ddb7 @nijel Correctly report error when export fails.
nijel authored
720 break;
0ae8842 (not complete) PEAR coding standard
Sebastian Mendel authored
721 }
f28ddb7 @nijel Correctly report error when export fails.
nijel authored
722
5d3c12c bug #1682044 Export file even if file not selected
Sebastian Mendel authored
723 } while (false);
f28ddb7 @nijel Correctly report error when export fails.
nijel authored
724 // End of fake loop
725
726 if ($save_on_server && isset($message)) {
727 if ($export_type == 'server') {
728 $active_page = 'server_export.php';
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
729 include 'server_export.php';
f28ddb7 @nijel Correctly report error when export fails.
nijel authored
730 } elseif ($export_type == 'database') {
cac4247 @nijel Rename db_* files to drop useless _details part.
nijel authored
731 $active_page = 'db_export.php';
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
732 include 'db_export.php';
f28ddb7 @nijel Correctly report error when export fails.
nijel authored
733 } else {
ad06b4a @nijel Rename tbl_* files to drop useless _properties part.
nijel authored
734 $active_page = 'tbl_export.php';
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
735 include 'tbl_export.php';
f28ddb7 @nijel Correctly report error when export fails.
nijel authored
736 }
737 exit();
c430dc8 @nijel export rework
nijel authored
738 }
739
740 /**
741 * Send the dump as a file...
742 */
5d71c1c @madhuracj Add spaces after exclamation marks to improve readability
madhuracj authored
743 if (! empty($asfile)) {
c430dc8 @nijel export rework
nijel authored
744 // Convert the charset if required.
745 if ($output_charset_conversion) {
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
746 $dump_buffer = PMA_convert_string(
747 'utf-8',
748 $GLOBALS['charset_of_file'],
749 $dump_buffer
750 );
c430dc8 @nijel export rework
nijel authored
751 }
752
753 // Do the compression
667300c @lem9 typo
lem9 authored
754 // 1. as a zipped file
5d3c12c bug #1682044 Export file even if file not selected
Sebastian Mendel authored
755 if ($compression == 'zip') {
c2b46ac Final batch of PHP3-Compatibility fixes. Please test. :-)
Garvin Hicking authored
756 if (@function_exists('gzcompress')) {
6fdf3a9 @madhuracj Class names should start with capital letters
madhuracj authored
757 $zipfile = new ZipFile();
3449d9f Fix html entities for astext export backlink, use jQuery for textSQLDUMP...
J.M authored
758 $zipfile->addFile($dump_buffer, substr($filename, 0, -4));
759 $dump_buffer = $zipfile->file();
c430dc8 @nijel export rework
nijel authored
760 }
9db5e44 @lem9 Fix merge conflicts
lem9 authored
761 } elseif ($compression == 'bzip2') {
94c6836 @ruleant fix coding style : control structures
ruleant authored
762 // 2. as a bzipped file
c2b46ac Final batch of PHP3-Compatibility fixes. Please test. :-)
Garvin Hicking authored
763 if (@function_exists('bzcompress')) {
1fdc8c0 @nijel Fixed saving compressed dumps on server.
nijel authored
764 $dump_buffer = bzcompress($dump_buffer);
c430dc8 @nijel export rework
nijel authored
765 }
94c6836 @ruleant fix coding style : control structures
ruleant authored
766 } elseif ($compression == 'gzip') {
767 // 3. as a gzipped file
5d71c1c @madhuracj Add spaces after exclamation marks to improve readability
madhuracj authored
768 if (@function_exists('gzencode') && ! @ini_get('zlib.output_compression')) {
c430dc8 @nijel export rework
nijel authored
769 // without the optional parameter level because it bug
1fdc8c0 @nijel Fixed saving compressed dumps on server.
nijel authored
770 $dump_buffer = gzencode($dump_buffer);
c430dc8 @nijel export rework
nijel authored
771 }
772 }
773
eb98110 @roccivic Dropped footer.inc.php
authored
774 /* If we saved on server, we have to close file now */
c430dc8 @nijel export rework
nijel authored
775 if ($save_on_server) {
1fdc8c0 @nijel Fixed saving compressed dumps on server.
nijel authored
776 $write_result = @fwrite($file_handle, $dump_buffer);
c430dc8 @nijel export rework
nijel authored
777 fclose($file_handle);
3449d9f Fix html entities for astext export backlink, use jQuery for textSQLDUMP...
J.M authored
778 if (strlen($dump_buffer) > 0
5d71c1c @madhuracj Add spaces after exclamation marks to improve readability
madhuracj authored
779 && (! $write_result || ($write_result != strlen($dump_buffer)))
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
780 ) {
781 $message = new PMA_Message(
782 __('Insufficient space to save the file %s.'),
783 PMA_Message::ERROR,
784 $save_filename
785 );
1fdc8c0 @nijel Fixed saving compressed dumps on server.
nijel authored
786 } else {
dae2a92 @madhuracj Wrap some long lines
madhuracj authored
787 $message = new PMA_Message(
788 __('Dump has been saved to file %s.'),
789 PMA_Message::SUCCESS,
790 $save_filename
791 );
1fdc8c0 @nijel Fixed saving compressed dumps on server.
nijel authored
792 }
c430dc8 @nijel export rework
nijel authored
793
794 if ($export_type == 'server') {
6884f97 @nijel no more support for php3
nijel authored
795 $active_page = 'server_export.php';
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
796 include_once 'server_export.php';
c430dc8 @nijel export rework
nijel authored
797 } elseif ($export_type == 'database') {
cac4247 @nijel Rename db_* files to drop useless _details part.
nijel authored
798 $active_page = 'db_export.php';
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
799 include_once 'db_export.php';
c430dc8 @nijel export rework
nijel authored
800 } else {
ad06b4a @nijel Rename tbl_* files to drop useless _properties part.
nijel authored
801 $active_page = 'tbl_export.php';
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
802 include_once 'tbl_export.php';
c430dc8 @nijel export rework
nijel authored
803 }
804 exit();
1fdc8c0 @nijel Fixed saving compressed dumps on server.
nijel authored
805 } else {
eb98110 @roccivic Dropped footer.inc.php
authored
806 PMA_Response::getInstance()->disable();
1fdc8c0 @nijel Fixed saving compressed dumps on server.
nijel authored
807 echo $dump_buffer;
c430dc8 @nijel export rework
nijel authored
808 }
94c6836 @ruleant fix coding style : control structures
ruleant authored
809 } else {
c430dc8 @nijel export rework
nijel authored
810 /**
94c6836 @ruleant fix coding style : control structures
ruleant authored
811 * Displays the dump...
812 *
813 * Close the html tags and add the footers if dump is displayed on screen
c430dc8 @nijel export rework
nijel authored
814 */
0ab8b74 @lem9 bug #1193442, 8 extra spaces at end of export area
lem9 authored
815 echo '</textarea>' . "\n"
d9a2161 @lem9 redesign part 3
lem9 authored
816 . ' </form>' . "\n";
948abf1 @teekirol Added back button on the top of the page as well
teekirol authored
817 echo $back_button;
4482228 @teekirol Back button on export.php page
teekirol authored
818
819 echo "\n";
c430dc8 @nijel export rework
nijel authored
820 echo '</div>' . "\n";
821 echo "\n";
75a16f4 @nijel Use same script tag, use CDATA for scripts (RFE #995065).
nijel authored
822 ?>
d0ac1f2 XHTML standard: no language attribute in <script>
Sebastian Mendel authored
823 <script type="text/javascript">
75a16f4 @nijel Use same script tag, use CDATA for scripts (RFE #995065).
nijel authored
824 //<![CDATA[
3449d9f Fix html entities for astext export backlink, use jQuery for textSQLDUMP...
J.M authored
825 var $body = $("body");
826 $("#textSQLDUMP")
827 .width($body.width() - 50)
828 .height($body.height() - 100);
75a16f4 @nijel Use same script tag, use CDATA for scripts (RFE #995065).
nijel authored
829 //]]>
d9a2161 @lem9 redesign part 3
lem9 authored
830 </script>
831 <?php
c430dc8 @nijel export rework
nijel authored
832 } // end if
37d50c1 @derrabus Huge set of optimizations, please test!
derrabus authored
833 ?>
Something went wrong with that request. Please try again.