Fix format string.
[phpmyadmin-themes.git] / export.php
blob26154962e12be277b45d2299386165bcfcb29778
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * @todo too much die here, or?
5 * @package phpMyAdmin
6 */
8 /**
9 * Get the variables sent or posted to this script and a core script
11 require_once './libraries/common.inc.php';
12 require_once './libraries/zip.lib.php';
13 require_once './libraries/plugin_interface.lib.php';
15 PMA_checkParameters(array('what', 'export_type'));
17 // Scan plugins
18 $export_list = PMA_getPlugins('./libraries/export/', array('export_type' => $export_type, 'single_table' => isset($single_table)));
20 // Backward compatbility
21 $type = $what;
23 // Check export type
24 if (!isset($export_list[$type])) {
25 die('Bad type!');
28 /**
29 * valid compression methods
31 $compression_methods = array(
32 'zip',
33 'gzip',
34 'bzip',
37 /**
38 * init and variable checking
40 $compression = false;
41 $onserver = false;
42 $save_on_server = false;
43 $buffer_needed = false;
45 // Is it a quick or custom export?
46 if($_REQUEST['quick_or_custom'] == 'quick') {
47 $quick_export = true;
48 } else {
49 $quick_export = false;
52 if ($_REQUEST['output_format'] == 'astext') {
53 $asfile = false;
54 } else {
55 $asfile = true;
56 if (in_array($_REQUEST['compression'], $compression_methods)) {
57 $compression = $_REQUEST['compression'];
58 $buffer_needed = true;
60 if (($quick_export && !empty($_REQUEST['quick_export_onserver'])) || (!$quick_export && !empty($_REQUEST['onserver']))) {
61 if($quick_export) {
62 $onserver = $_REQUEST['quick_export_onserver'];
63 } else {
64 $onserver = $_REQUEST['onserver'];
66 // Will we save dump on server?
67 $save_on_server = ! empty($cfg['SaveDir']) && $onserver;
71 // Does export require to be into file?
72 if (isset($export_list[$type]['force_file']) && ! $asfile) {
73 $message = PMA_Message::error(__('Selected export type has to be saved in file!'));
74 require_once './libraries/header.inc.php';
75 if ($export_type == 'server') {
76 $active_page = 'server_export.php';
77 require './server_export.php';
78 } elseif ($export_type == 'database') {
79 $active_page = 'db_export.php';
80 require './db_export.php';
81 } else {
82 $active_page = 'tbl_export.php';
83 require './tbl_export.php';
85 exit();
88 // Generate error url and check for needed variables
89 if ($export_type == 'server') {
90 $err_url = 'server_export.php?' . PMA_generate_common_url();
91 } elseif ($export_type == 'database' && strlen($db)) {
92 $err_url = 'db_export.php?' . PMA_generate_common_url($db);
93 // Check if we have something to export
94 if (isset($table_select)) {
95 $tables = $table_select;
96 } else {
97 $tables = array();
99 } elseif ($export_type == 'table' && strlen($db) && strlen($table)) {
100 $err_url = 'tbl_export.php?' . PMA_generate_common_url($db, $table);
101 } else {
102 die('Bad parameters!');
105 // Get the functions specific to the export type
106 require './libraries/export/' . PMA_securePath($type) . '.php';
109 * Increase time limit for script execution and initializes some variables
111 @set_time_limit($cfg['ExecTimeLimit']);
112 if (!empty($cfg['MemoryLimit'])) {
113 @ini_set('memory_limit', $cfg['MemoryLimit']);
116 // Start with empty buffer
117 $dump_buffer = '';
118 $dump_buffer_len = 0;
120 // We send fake headers to avoid browser timeout when buffering
121 $time_start = time();
125 * Output handler for all exports, if needed buffering, it stores data into
126 * $dump_buffer, otherwise it prints thems out.
128 * @param string the insert statement
130 * @return bool Whether output suceeded
132 function PMA_exportOutputHandler($line)
134 global $time_start, $dump_buffer, $dump_buffer_len, $save_filename;
136 // Kanji encoding convert feature
137 if ($GLOBALS['output_kanji_conversion']) {
138 $line = PMA_kanji_str_conv($line, $GLOBALS['knjenc'], isset($GLOBALS['xkana']) ? $GLOBALS['xkana'] : '');
140 // If we have to buffer data, we will perform everything at once at the end
141 if ($GLOBALS['buffer_needed']) {
143 $dump_buffer .= $line;
144 if ($GLOBALS['onfly_compression']) {
146 $dump_buffer_len += strlen($line);
148 if ($dump_buffer_len > $GLOBALS['memory_limit']) {
149 if ($GLOBALS['output_charset_conversion']) {
150 $dump_buffer = PMA_convert_string($GLOBALS['charset'], $GLOBALS['charset_of_file'], $dump_buffer);
152 // as bzipped
153 if ($GLOBALS['compression'] == 'bzip' && @function_exists('bzcompress')) {
154 $dump_buffer = bzcompress($dump_buffer);
156 // as a gzipped file
157 elseif ($GLOBALS['compression'] == 'gzip' && @function_exists('gzencode')) {
158 // without the optional parameter level because it bug
159 $dump_buffer = gzencode($dump_buffer);
161 if ($GLOBALS['save_on_server']) {
162 $write_result = @fwrite($GLOBALS['file_handle'], $dump_buffer);
163 if (!$write_result || ($write_result != strlen($dump_buffer))) {
164 $GLOBALS['message'] = PMA_Message::error(__('Insufficient space to save the file %s.'));
165 $GLOBALS['message']->addParam($save_filename);
166 return false;
168 } else {
169 echo $dump_buffer;
171 $dump_buffer = '';
172 $dump_buffer_len = 0;
174 } else {
175 $time_now = time();
176 if ($time_start >= $time_now + 30) {
177 $time_start = $time_now;
178 header('X-pmaPing: Pong');
179 } // end if
181 } else {
182 if ($GLOBALS['asfile']) {
183 if ($GLOBALS['output_charset_conversion']) {
184 $line = PMA_convert_string($GLOBALS['charset'], $GLOBALS['charset_of_file'], $line);
186 if ($GLOBALS['save_on_server'] && strlen($line) > 0) {
187 $write_result = @fwrite($GLOBALS['file_handle'], $line);
188 if (!$write_result || ($write_result != strlen($line))) {
189 $GLOBALS['message'] = PMA_Message::error(__('Insufficient space to save the file %s.'));
190 $GLOBALS['message']->addParam($save_filename);
191 return false;
193 $time_now = time();
194 if ($time_start >= $time_now + 30) {
195 $time_start = $time_now;
196 header('X-pmaPing: Pong');
197 } // end if
198 } else {
199 // We export as file - output normally
200 echo $line;
202 } else {
203 // We export as html - replace special chars
204 echo htmlspecialchars($line);
207 return true;
208 } // end of the 'PMA_exportOutputHandler()' function
210 // Defines the default <CR><LF> format. For SQL always use \n as MySQL wants this on all platforms.
211 if ($what == 'sql') {
212 $crlf = "\n";
213 } else {
214 $crlf = PMA_whichCrlf();
217 $output_kanji_conversion = function_exists('PMA_kanji_str_conv') && $type != 'xls';
219 // Do we need to convert charset?
220 $output_charset_conversion = $asfile && $GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE
221 && isset($charset_of_file) && $charset_of_file != $charset
222 && $type != 'xls';
224 // Use on the fly compression?
225 $onfly_compression = $GLOBALS['cfg']['CompressOnFly'] && ($compression == 'gzip' || $compression == 'bzip');
226 if ($onfly_compression) {
227 $memory_limit = trim(@ini_get('memory_limit'));
228 // 2 MB as default
229 if (empty($memory_limit)) {
230 $memory_limit = 2 * 1024 * 1024;
233 if (strtolower(substr($memory_limit, -1)) == 'm') {
234 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024;
235 } elseif (strtolower(substr($memory_limit, -1)) == 'k') {
236 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024;
237 } elseif (strtolower(substr($memory_limit, -1)) == 'g') {
238 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024 * 1024;
239 } else {
240 $memory_limit = (int)$memory_limit;
243 // Some of memory is needed for other thins and as treshold.
244 // Nijel: During export I had allocated (see memory_get_usage function)
245 // approx 1.2MB so this comes from that.
246 if ($memory_limit > 1500000) {
247 $memory_limit -= 1500000;
250 // Some memory is needed for compression, assume 1/3
251 $memory_limit /= 8;
254 // Generate filename and mime type if needed
255 if ($asfile) {
256 $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']);
257 if ($export_type == 'server') {
258 if (isset($remember_template)) {
259 $GLOBALS['PMA_Config']->setUserValue('pma_server_filename_template',
260 'Export/file_template_server', $filename_template);
262 } elseif ($export_type == 'database') {
263 if (isset($remember_template)) {
264 $GLOBALS['PMA_Config']->setUserValue('pma_db_filename_template',
265 'Export/file_template_database', $filename_template);
267 } else {
268 if (isset($remember_template)) {
269 $GLOBALS['PMA_Config']->setUserValue('pma_table_filename_template',
270 'Export/file_template_table', $filename_template);
273 $filename = PMA_expandUserString($filename_template);
275 // convert filename to iso-8859-1, it is safer
276 $filename = PMA_convert_string($charset, 'iso-8859-1', $filename);
278 // Grab basic dump extension and mime type
279 // Check if the user already added extension; get the substring where the extension would be if it was included
280 $extension_start_pos = strlen($filename) - strlen($export_list[$type]['extension']) - 1;
281 $user_extension = substr($filename, $extension_start_pos, strlen($filename));
282 $required_extension = "." . $export_list[$type]['extension'];
283 if(strtolower($user_extension) != $required_extension) {
284 $filename .= $required_extension;
286 $mime_type = $export_list[$type]['mime_type'];
288 // If dump is going to be compressed, set correct mime_type and add
289 // compression to extension
290 if ($compression == 'bzip') {
291 $filename .= '.bz2';
292 $mime_type = 'application/x-bzip2';
293 } elseif ($compression == 'gzip') {
294 $filename .= '.gz';
295 $mime_type = 'application/x-gzip';
296 } elseif ($compression == 'zip') {
297 $filename .= '.zip';
298 $mime_type = 'application/zip';
302 // Open file on server if needed
303 if ($save_on_server) {
304 $save_filename = PMA_userDir($cfg['SaveDir']) . preg_replace('@[/\\\\]@', '_', $filename);
305 unset($message);
306 if (file_exists($save_filename) && ((!$quick_export && empty($onserverover)) || ($quick_export && $_REQUEST['quick_export_onserverover'] != 'saveitover'))) {
307 $message = PMA_Message::error(__('File %s already exists on server, change filename or check overwrite option.'));
308 $message->addParam($save_filename);
309 } else {
310 if (is_file($save_filename) && !is_writable($save_filename)) {
311 $message = PMA_Message::error(__('The web server does not have permission to save the file %s.'));
312 $message->addParam($save_filename);
313 } else {
314 if (!$file_handle = @fopen($save_filename, 'w')) {
315 $message = PMA_Message::error(__('The web server does not have permission to save the file %s.'));
316 $message->addParam($save_filename);
320 if (isset($message)) {
321 require_once './libraries/header.inc.php';
322 if ($export_type == 'server') {
323 $active_page = 'server_export.php';
324 require './server_export.php';
325 } elseif ($export_type == 'database') {
326 $active_page = 'db_export.php';
327 require './db_export.php';
328 } else {
329 $active_page = 'tbl_export.php';
330 require './tbl_export.php';
332 exit();
337 * Send headers depending on whether the user chose to download a dump file
338 * or not
340 if (!$save_on_server) {
341 if ($asfile) {
342 // Download
343 // (avoid rewriting data containing HTML with anchors and forms;
344 // this was reported to happen under Plesk)
345 @ini_set('url_rewriter.tags','');
347 header('Content-Type: ' . $mime_type);
348 header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
349 // Tested behavior of
350 // IE 5.50.4807.2300
351 // IE 6.0.2800.1106 (small glitch, asks twice when I click Open)
352 // IE 6.0.2900.2180
353 // Firefox 1.0.6
354 // in http and https
355 header('Content-Disposition: attachment; filename="' . $filename . '"');
356 if (PMA_USR_BROWSER_AGENT == 'IE') {
357 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
358 header('Pragma: public');
359 } else {
360 header('Pragma: no-cache');
361 // test case: exporting a database into a .gz file with Safari
362 // would produce files not having the current time
363 // (added this header for Safari but should not harm other browsers)
364 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
366 } else {
367 // HTML
368 if ($export_type == 'database') {
369 $num_tables = count($tables);
370 if ($num_tables == 0) {
371 $message = PMA_Message::error(__('No tables found in database.'));
372 require_once './libraries/header.inc.php';
373 $active_page = 'db_export.php';
374 require './db_export.php';
375 exit();
378 $backup_cfgServer = $cfg['Server'];
379 require_once './libraries/header.inc.php';
380 $cfg['Server'] = $backup_cfgServer;
381 unset($backup_cfgServer);
382 echo "\n" . '<div align="' . $cell_align_left . '">' . "\n";
383 //echo ' <pre>' . "\n";
386 * Displays a back button with all the $_REQUEST data in the URL (store in a variable to also display after the textarea)
388 $back_button = '<p>[ <a href="';
389 if ($export_type == 'server') {
390 $back_button .= 'server_export.php?' . PMA_generate_common_url();
391 } elseif ($export_type == 'database') {
392 $back_button .= 'db_export.php?' . PMA_generate_common_url($db);
393 } else {
394 $back_button .= 'tbl_export.php?' . PMA_generate_common_url($db, $table);
397 // Convert the multiple select elements from an array to a string
398 if($export_type == 'server' && isset($_REQUEST['db_select'])) {
399 $_REQUEST['db_select'] = implode(",", $_REQUEST['db_select']);
400 } elseif($export_type == 'database' && isset($_REQUEST['table_select'])) {
401 $_REQUEST['table_select'] = implode(",", $_REQUEST['table_select']);
404 foreach($_REQUEST as $name => $value) {
405 $back_button .= '&' . urlencode($name) . '=' . urlencode($value);
407 $back_button .= '&repopulate=1">Back</a> ]</p>';
409 echo $back_button;
410 echo ' <form name="nofunction">' . "\n"
411 // remove auto-select for now: there is no way to select
412 // only a part of the text; anyway, it should obey
413 // $cfg['TextareaAutoSelect']
414 //. ' <textarea name="sqldump" cols="50" rows="30" onclick="this.select();" id="textSQLDUMP" wrap="OFF">' . "\n";
415 . ' <textarea name="sqldump" cols="50" rows="30" id="textSQLDUMP" wrap="OFF">' . "\n";
416 } // end download
419 // Fake loop just to allow skip of remain of this code by break, I'd really
420 // need exceptions here :-)
421 do {
423 // Add possibly some comments to export
424 if (!PMA_exportHeader()) {
425 break;
428 // Will we need relation & co. setup?
429 $do_relation = isset($GLOBALS[$what . '_relation']);
430 $do_comments = isset($GLOBALS[$what . '_include_comments']);
431 $do_mime = isset($GLOBALS[$what . '_mime']);
432 if ($do_relation || $do_comments || $do_mime) {
433 $cfgRelation = PMA_getRelationsParam();
435 if ($do_mime) {
436 require_once './libraries/transformations.lib.php';
439 // Include dates in export?
440 $do_dates = isset($GLOBALS[$what . '_dates']);
443 * Builds the dump
445 // Gets the number of tables if a dump of a database has been required
446 if ($export_type == 'server') {
447 if (isset($db_select)) {
448 $tmp_select = implode($db_select, '|');
449 $tmp_select = '|' . $tmp_select . '|';
451 // Walk over databases
452 foreach ($GLOBALS['pma']->databases as $current_db) {
453 if ((isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|'))
454 || !isset($tmp_select)) {
455 if (!PMA_exportDBHeader($current_db)) {
456 break 2;
458 if (!PMA_exportDBCreate($current_db)) {
459 break 2;
461 $tables = PMA_DBI_get_tables($current_db);
462 $views = array();
463 foreach ($tables as $table) {
464 // if this is a view, collect it for later; views must be exported
465 // after the tables
466 $is_view = PMA_Table::isView($current_db, $table);
467 if ($is_view) {
468 $views[] = $table;
470 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
471 // for a view, export a stand-in definition of the table
472 // to resolve view dependencies
473 if (!PMA_exportStructure($current_db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, $is_view ? 'stand_in' : 'create_table', $export_type)) {
474 break 3;
477 // if this is a view or a merge table, don't export data
478 if (($GLOBALS[$what . '_structure_or_data'] == 'data' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') && !($is_view || PMA_Table::isMerge($current_db, $table))) {
479 $local_query = 'SELECT * FROM ' . PMA_backquote($current_db) . '.' . PMA_backquote($table);
480 if (!PMA_exportData($current_db, $table, $crlf, $err_url, $local_query)) {
481 break 3;
484 // now export the triggers (needs to be done after the data because
485 // triggers can modify already imported tables)
486 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
487 if (!PMA_exportStructure($current_db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'triggers', $export_type)) {
488 break 2;
492 foreach($views as $view) {
493 // no data export for a view
494 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
495 if (!PMA_exportStructure($current_db, $view, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'create_view', $export_type)) {
496 break 3;
500 if (!PMA_exportDBFooter($current_db)) {
501 break 2;
505 } elseif ($export_type == 'database') {
506 if (!PMA_exportDBHeader($db)) {
507 break;
509 $i = 0;
510 $views = array();
511 // $tables contains the choices from the user (via $table_select)
512 foreach ($tables as $table) {
513 // if this is a view, collect it for later; views must be exported after
514 // the tables
515 $is_view = PMA_Table::isView($db, $table);
516 if ($is_view) {
517 $views[] = $table;
519 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
520 // for a view, export a stand-in definition of the table
521 // to resolve view dependencies
522 if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, $is_view ? 'stand_in' : 'create_table', $export_type)) {
523 break 2;
526 // if this is a view or a merge table, don't export data
527 if (($GLOBALS[$what . '_structure_or_data'] == 'data' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') && !($is_view || PMA_Table::isMerge($db, $table))) {
528 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
529 if (!PMA_exportData($db, $table, $crlf, $err_url, $local_query)) {
530 break 2;
533 // now export the triggers (needs to be done after the data because
534 // triggers can modify already imported tables)
535 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
536 if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'triggers', $export_type)) {
537 break 2;
541 foreach ($views as $view) {
542 // no data export for a view
543 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
544 if (!PMA_exportStructure($db, $view, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'create_view', $export_type)) {
545 break 2;
550 if (!PMA_exportDBFooter($db)) {
551 break;
553 } else {
554 if (!PMA_exportDBHeader($db)) {
555 break;
557 // We export just one table
558 // $allrows comes from the form when "Dump all rows" has been selected
559 if ($allrows == '0' && $limit_to > 0 && $limit_from >= 0) {
560 $add_query = ' LIMIT '
561 . (($limit_from > 0) ? $limit_from . ', ' : '')
562 . $limit_to;
563 } else {
564 $add_query = '';
567 $is_view = PMA_Table::isView($db, $table);
568 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
569 if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, $is_view ? 'create_view' : 'create_table', $export_type)) {
570 break;
573 // If this is an export of a single view, we have to export data;
574 // for example, a PDF report
575 // if it is a merge table, no data is exported
576 if (($GLOBALS[$what . '_structure_or_data'] == 'data' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') && ! PMA_Table::isMerge($db, $table)) {
577 if (!empty($sql_query)) {
578 // only preg_replace if needed
579 if (!empty($add_query)) {
580 // remove trailing semicolon before adding a LIMIT
581 $sql_query = preg_replace('%;\s*$%', '', $sql_query);
583 $local_query = $sql_query . $add_query;
584 PMA_DBI_select_db($db);
585 } else {
586 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query;
588 if (!PMA_exportData($db, $table, $crlf, $err_url, $local_query)) {
589 break;
592 // now export the triggers (needs to be done after the data because
593 // triggers can modify already imported tables)
594 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
595 if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'triggers', $export_type)) {
596 break 2;
599 if (!PMA_exportDBFooter($db)) {
600 break;
603 if (!PMA_exportFooter()) {
604 break;
607 } while (false);
608 // End of fake loop
610 if ($save_on_server && isset($message)) {
611 require_once './libraries/header.inc.php';
612 if ($export_type == 'server') {
613 $active_page = 'server_export.php';
614 require './server_export.php';
615 } elseif ($export_type == 'database') {
616 $active_page = 'db_export.php';
617 require './db_export.php';
618 } else {
619 $active_page = 'tbl_export.php';
620 require './tbl_export.php';
622 exit();
626 * Send the dump as a file...
628 if (!empty($asfile)) {
629 // Convert the charset if required.
630 if ($output_charset_conversion) {
631 $dump_buffer = PMA_convert_string($GLOBALS['charset'], $GLOBALS['charset_of_file'], $dump_buffer);
634 // Do the compression
635 // 1. as a zipped file
636 if ($compression == 'zip') {
637 if (@function_exists('gzcompress')) {
638 $zipfile = new zipfile();
639 $zipfile -> addFile($dump_buffer, substr($filename, 0, -4));
640 $dump_buffer = $zipfile -> file();
643 // 2. as a bzipped file
644 elseif ($compression == 'bzip') {
645 if (@function_exists('bzcompress')) {
646 $dump_buffer = bzcompress($dump_buffer);
649 // 3. as a gzipped file
650 elseif ($compression == 'gzip') {
651 if (@function_exists('gzencode') && !@ini_get('zlib.output_compression')) {
652 // without the optional parameter level because it bug
653 $dump_buffer = gzencode($dump_buffer);
657 /* If ve saved on server, we have to close file now */
658 if ($save_on_server) {
659 $write_result = @fwrite($file_handle, $dump_buffer);
660 fclose($file_handle);
661 if (strlen($dump_buffer) !=0 && (!$write_result || ($write_result != strlen($dump_buffer)))) {
662 $message = new PMA_Message(__('Insufficient space to save the file %s.'), PMA_Message::ERROR, $save_filename);
663 } else {
664 $message = new PMA_Message(__('Dump has been saved to file %s.'), PMA_Message::SUCCESS, $save_filename);
667 require_once './libraries/header.inc.php';
668 if ($export_type == 'server') {
669 $active_page = 'server_export.php';
670 require_once './server_export.php';
671 } elseif ($export_type == 'database') {
672 $active_page = 'db_export.php';
673 require_once './db_export.php';
674 } else {
675 $active_page = 'tbl_export.php';
676 require_once './tbl_export.php';
678 exit();
679 } else {
680 echo $dump_buffer;
684 * Displays the dump...
686 else {
688 * Close the html tags and add the footers in dump is displayed on screen
690 echo '</textarea>' . "\n"
691 . ' </form>' . "\n";
692 echo $back_button;
694 echo "\n";
695 echo '</div>' . "\n";
696 echo "\n";
698 <script type="text/javascript">
699 //<![CDATA[
700 var bodyWidth=null; var bodyHeight=null;
701 if (document.getElementById('textSQLDUMP')) {
702 bodyWidth = self.innerWidth;
703 bodyHeight = self.innerHeight;
704 if (!bodyWidth && !bodyHeight) {
705 if (document.compatMode && document.compatMode == "BackCompat") {
706 bodyWidth = document.body.clientWidth;
707 bodyHeight = document.body.clientHeight;
708 } else if (document.compatMode && document.compatMode == "CSS1Compat") {
709 bodyWidth = document.documentElement.clientWidth;
710 bodyHeight = document.documentElement.clientHeight;
713 document.getElementById('textSQLDUMP').style.width=(bodyWidth-50) + 'px';
714 document.getElementById('textSQLDUMP').style.height=(bodyHeight-100) + 'px';
716 //]]>
717 </script>
718 <?php
719 require './libraries/footer.inc.php';
720 } // end if