1 | <?php
|
---|
2 | /* $Id: export.php 10408 2007-05-21 17:13:49Z lem9 $ */
|
---|
3 | // vim: expandtab sw=4 ts=4 sts=4:
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * Get the variables sent or posted to this script and a core script
|
---|
7 | */
|
---|
8 | require_once('./libraries/common.lib.php');
|
---|
9 | require_once('./libraries/zip.lib.php');
|
---|
10 | require_once('./libraries/plugin_interface.lib.php');
|
---|
11 |
|
---|
12 | PMA_checkParameters(array('what', 'export_type'));
|
---|
13 |
|
---|
14 | // Scan plugins
|
---|
15 | $export_list = PMA_getPlugins('./libraries/export/', array('export_type' => $export_type, 'single_table' => isset($single_table)));
|
---|
16 |
|
---|
17 | // Backward compatbility
|
---|
18 | $type = $what;
|
---|
19 |
|
---|
20 | // Check export type
|
---|
21 | if (!isset($export_list[$type])) {
|
---|
22 | die('Bad type!');
|
---|
23 | }
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * valid compression methods
|
---|
27 | */
|
---|
28 | $compression_methods = array(
|
---|
29 | 'zip',
|
---|
30 | 'gzip',
|
---|
31 | 'bzip',
|
---|
32 | );
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * init and variable checking
|
---|
36 | */
|
---|
37 | $compression = false;
|
---|
38 | $onserver = false;
|
---|
39 | $save_on_server = false;
|
---|
40 | $buffer_needed = false;
|
---|
41 | if (empty($_REQUEST['asfile'])) {
|
---|
42 | $asfile = false;
|
---|
43 | } else {
|
---|
44 | $asfile = true;
|
---|
45 | if (in_array($_REQUEST['compression'], $compression_methods)) {
|
---|
46 | $compression = $_REQUEST['compression'];
|
---|
47 | $buffer_needed = true;
|
---|
48 | }
|
---|
49 | if (!empty($_REQUEST['onserver'])) {
|
---|
50 | $onserver = $_REQUEST['onserver'];
|
---|
51 | // Will we save dump on server?
|
---|
52 | $save_on_server = ! empty($cfg['SaveDir']) && $onserver;
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | // Does export require to be into file?
|
---|
57 | if (isset($export_list[$type]['force_file']) && ! $asfile) {
|
---|
58 | $message = $strExportMustBeFile;
|
---|
59 | $GLOBALS['show_error_header'] = true;
|
---|
60 | $js_to_run = 'functions.js';
|
---|
61 | require_once('./libraries/header.inc.php');
|
---|
62 | if ($export_type == 'server') {
|
---|
63 | $active_page = 'server_export.php';
|
---|
64 | require('./server_export.php');
|
---|
65 | } elseif ($export_type == 'database') {
|
---|
66 | $active_page = 'db_export.php';
|
---|
67 | require('./db_export.php');
|
---|
68 | } else {
|
---|
69 | $active_page = 'tbl_export.php';
|
---|
70 | require('./tbl_export.php');
|
---|
71 | }
|
---|
72 | exit();
|
---|
73 | }
|
---|
74 |
|
---|
75 | // Generate error url and check for needed variables
|
---|
76 | if ($export_type == 'server') {
|
---|
77 | $err_url = 'server_export.php?' . PMA_generate_common_url();
|
---|
78 | } elseif ($export_type == 'database' && strlen($db)) {
|
---|
79 | $err_url = 'db_export.php?' . PMA_generate_common_url($db);
|
---|
80 | // Check if we have something to export
|
---|
81 | if (isset($table_select)) {
|
---|
82 | $tables = $table_select;
|
---|
83 | } else {
|
---|
84 | $tables = array();
|
---|
85 | }
|
---|
86 | } elseif ($export_type == 'table' && strlen($db) && strlen($table)) {
|
---|
87 | $err_url = 'tbl_export.php?' . PMA_generate_common_url($db, $table);
|
---|
88 | } else {
|
---|
89 | die('Bad parameters!');
|
---|
90 | }
|
---|
91 |
|
---|
92 | // Get the functions specific to the export type
|
---|
93 | require('./libraries/export/' . PMA_securePath($type) . '.php');
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Increase time limit for script execution and initializes some variables
|
---|
97 | */
|
---|
98 | @set_time_limit($cfg['ExecTimeLimit']);
|
---|
99 | if (!empty($cfg['MemoryLimit'])) {
|
---|
100 | @ini_set('memory_limit', $cfg['MemoryLimit']);
|
---|
101 | }
|
---|
102 |
|
---|
103 | // Start with empty buffer
|
---|
104 | $dump_buffer = '';
|
---|
105 | $dump_buffer_len = 0;
|
---|
106 |
|
---|
107 | // We send fake headers to avoid browser timeout when buffering
|
---|
108 | $time_start = time();
|
---|
109 |
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Output handler for all exports, if needed buffering, it stores data into
|
---|
113 | * $dump_buffer, otherwise it prints thems out.
|
---|
114 | *
|
---|
115 | * @param string the insert statement
|
---|
116 | *
|
---|
117 | * @return bool Whether output suceeded
|
---|
118 | */
|
---|
119 | function PMA_exportOutputHandler($line)
|
---|
120 | {
|
---|
121 | global $time_start, $dump_buffer, $dump_buffer_len, $save_filename;
|
---|
122 |
|
---|
123 | // Kanji encoding convert feature
|
---|
124 | if ($GLOBALS['output_kanji_conversion']) {
|
---|
125 | $line = PMA_kanji_str_conv($line, $GLOBALS['knjenc'], isset($GLOBALS['xkana']) ? $GLOBALS['xkana'] : '');
|
---|
126 | }
|
---|
127 | // If we have to buffer data, we will perform everything at once at the end
|
---|
128 | if ($GLOBALS['buffer_needed']) {
|
---|
129 |
|
---|
130 | $dump_buffer .= $line;
|
---|
131 | if ($GLOBALS['onfly_compression']) {
|
---|
132 |
|
---|
133 | $dump_buffer_len += strlen($line);
|
---|
134 |
|
---|
135 | if ($dump_buffer_len > $GLOBALS['memory_limit']) {
|
---|
136 | if ($GLOBALS['output_charset_conversion']) {
|
---|
137 | $dump_buffer = PMA_convert_string($GLOBALS['charset'], $GLOBALS['charset_of_file'], $dump_buffer);
|
---|
138 | }
|
---|
139 | // as bzipped
|
---|
140 | if ($GLOBALS['compression'] == 'bzip' && @function_exists('bzcompress')) {
|
---|
141 | $dump_buffer = bzcompress($dump_buffer);
|
---|
142 | }
|
---|
143 | // as a gzipped file
|
---|
144 | elseif ($GLOBALS['compression'] == 'gzip' && @function_exists('gzencode')) {
|
---|
145 | // without the optional parameter level because it bug
|
---|
146 | $dump_buffer = gzencode($dump_buffer);
|
---|
147 | }
|
---|
148 | if ($GLOBALS['save_on_server']) {
|
---|
149 | $write_result = @fwrite($GLOBALS['file_handle'], $dump_buffer);
|
---|
150 | if (!$write_result || ($write_result != strlen($dump_buffer))) {
|
---|
151 | $GLOBALS['message'] = sprintf($GLOBALS['strNoSpace'], htmlspecialchars($save_filename));
|
---|
152 | $GLOBALS['show_error_header'] = TRUE;
|
---|
153 | return FALSE;
|
---|
154 | }
|
---|
155 | } else {
|
---|
156 | echo $dump_buffer;
|
---|
157 | }
|
---|
158 | $dump_buffer = '';
|
---|
159 | $dump_buffer_len = 0;
|
---|
160 | }
|
---|
161 | } else {
|
---|
162 | $time_now = time();
|
---|
163 | if ($time_start >= $time_now + 30) {
|
---|
164 | $time_start = $time_now;
|
---|
165 | header('X-pmaPing: Pong');
|
---|
166 | } // end if
|
---|
167 | }
|
---|
168 | } else {
|
---|
169 | if ($GLOBALS['asfile']) {
|
---|
170 | if ($GLOBALS['save_on_server'] && strlen($line) > 0) {
|
---|
171 | $write_result = @fwrite($GLOBALS['file_handle'], $line);
|
---|
172 | if (!$write_result || ($write_result != strlen($line))) {
|
---|
173 | $GLOBALS['message'] = sprintf($GLOBALS['strNoSpace'], htmlspecialchars($save_filename));
|
---|
174 | $GLOBALS['show_error_header'] = TRUE;
|
---|
175 | return FALSE;
|
---|
176 | }
|
---|
177 | $time_now = time();
|
---|
178 | if ($time_start >= $time_now + 30) {
|
---|
179 | $time_start = $time_now;
|
---|
180 | header('X-pmaPing: Pong');
|
---|
181 | } // end if
|
---|
182 | } else {
|
---|
183 | // We export as file - output normally
|
---|
184 | if ($GLOBALS['output_charset_conversion']) {
|
---|
185 | $line = PMA_convert_string($GLOBALS['charset'], $GLOBALS['charset_of_file'], $line);
|
---|
186 | }
|
---|
187 | echo $line;
|
---|
188 | }
|
---|
189 | } else {
|
---|
190 | // We export as html - replace special chars
|
---|
191 | echo htmlspecialchars($line);
|
---|
192 | }
|
---|
193 | }
|
---|
194 | return TRUE;
|
---|
195 | } // end of the 'PMA_exportOutputHandler()' function
|
---|
196 |
|
---|
197 | // Defines the default <CR><LF> format. For SQL always use \n as MySQL wants this on all platforms.
|
---|
198 | if ($what == 'sql') {
|
---|
199 | $crlf = "\n";
|
---|
200 | } else {
|
---|
201 | $crlf = PMA_whichCrlf();
|
---|
202 | }
|
---|
203 |
|
---|
204 | $output_kanji_conversion = function_exists('PMA_kanji_str_conv') && $type != 'xls';
|
---|
205 |
|
---|
206 | // Do we need to convert charset?
|
---|
207 | $output_charset_conversion = $asfile &&
|
---|
208 | $cfg['AllowAnywhereRecoding'] && $allow_recoding
|
---|
209 | && isset($charset_of_file) && $charset_of_file != $charset
|
---|
210 | && $type != 'xls';
|
---|
211 |
|
---|
212 | // Use on fly compression?
|
---|
213 | $onfly_compression = $GLOBALS['cfg']['CompressOnFly'] && ($compression == 'gzip' | $compression == 'bzip');
|
---|
214 | if ($onfly_compression) {
|
---|
215 | $memory_limit = trim(@ini_get('memory_limit'));
|
---|
216 | // 2 MB as default
|
---|
217 | if (empty($memory_limit)) {
|
---|
218 | $memory_limit = 2 * 1024 * 1024;
|
---|
219 | }
|
---|
220 |
|
---|
221 | if (strtolower(substr($memory_limit, -1)) == 'm') {
|
---|
222 | $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024;
|
---|
223 | } elseif (strtolower(substr($memory_limit, -1)) == 'k') {
|
---|
224 | $memory_limit = (int)substr($memory_limit, 0, -1) * 1024;
|
---|
225 | } elseif (strtolower(substr($memory_limit, -1)) == 'g') {
|
---|
226 | $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024 * 1024;
|
---|
227 | } else {
|
---|
228 | $memory_limit = (int)$memory_limit;
|
---|
229 | }
|
---|
230 |
|
---|
231 | // Some of memory is needed for other thins and as treshold.
|
---|
232 | // Nijel: During export I had allocated (see memory_get_usage function)
|
---|
233 | // approx 1.2MB so this comes from that.
|
---|
234 | if ($memory_limit > 1500000) {
|
---|
235 | $memory_limit -= 1500000;
|
---|
236 | }
|
---|
237 |
|
---|
238 | // Some memory is needed for compression, assume 1/3
|
---|
239 | $memory_limit /= 8;
|
---|
240 | }
|
---|
241 |
|
---|
242 | // Generate filename and mime type if needed
|
---|
243 | if ($asfile) {
|
---|
244 | $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']);
|
---|
245 | if ($export_type == 'server') {
|
---|
246 | if (isset($remember_template)) {
|
---|
247 | PMA_setCookie('pma_server_filename_template', $filename_template);
|
---|
248 | }
|
---|
249 | $filename = str_replace('__SERVER__', $GLOBALS['cfg']['Server']['host'], strftime($filename_template));
|
---|
250 | } elseif ($export_type == 'database') {
|
---|
251 | if (isset($remember_template)) {
|
---|
252 | PMA_setCookie('pma_db_filename_template', $filename_template);
|
---|
253 | }
|
---|
254 | $filename = str_replace('__DB__', $db, str_replace('__SERVER__', $GLOBALS['cfg']['Server']['host'], strftime($filename_template)));
|
---|
255 | } else {
|
---|
256 | if (isset($remember_template)) {
|
---|
257 | PMA_setCookie('pma_table_filename_template', $filename_template);
|
---|
258 | }
|
---|
259 | $filename = str_replace('__TABLE__', $table, str_replace('__DB__', $db, str_replace('__SERVER__', $GLOBALS['cfg']['Server']['host'], strftime($filename_template))));
|
---|
260 | }
|
---|
261 |
|
---|
262 | // convert filename to iso-8859-1, it is safer
|
---|
263 | if (!(isset($cfg['AllowAnywhereRecoding']) && $cfg['AllowAnywhereRecoding'] && $allow_recoding)) {
|
---|
264 | $filename = PMA_convert_string($charset, 'iso-8859-1', $filename);
|
---|
265 | } else {
|
---|
266 | $filename = PMA_convert_string($convcharset, 'iso-8859-1', $filename);
|
---|
267 | }
|
---|
268 |
|
---|
269 | // Grab basic dump extension and mime type
|
---|
270 | $filename .= '.' . $export_list[$type]['extension'];
|
---|
271 | $mime_type = $export_list[$type]['mime_type'];
|
---|
272 |
|
---|
273 | // If dump is going to be compressed, set correct encoding or mime_type and add
|
---|
274 | // compression to extension
|
---|
275 | $content_encoding = '';
|
---|
276 | if ($compression == 'bzip') {
|
---|
277 | $filename .= '.bz2';
|
---|
278 | // browsers don't like this:
|
---|
279 | //$content_encoding = 'x-bzip2';
|
---|
280 | $mime_type = 'application/x-bzip2';
|
---|
281 | } elseif ($compression == 'gzip') {
|
---|
282 | $filename .= '.gz';
|
---|
283 | // Needed to avoid recompression by server modules like mod_gzip.
|
---|
284 | // It seems necessary to check about zlib.output_compression
|
---|
285 | // to avoid compressing twice
|
---|
286 | if (!@ini_get('zlib.output_compression')) {
|
---|
287 | $content_encoding = 'x-gzip';
|
---|
288 | $mime_type = 'application/x-gzip';
|
---|
289 | }
|
---|
290 | } elseif ($compression == 'zip') {
|
---|
291 | $filename .= '.zip';
|
---|
292 | $mime_type = 'application/zip';
|
---|
293 | }
|
---|
294 | }
|
---|
295 |
|
---|
296 | // Open file on server if needed
|
---|
297 | if ($save_on_server) {
|
---|
298 | $save_filename = PMA_userDir($cfg['SaveDir']) . preg_replace('@[/\\\\]@', '_', $filename);
|
---|
299 | unset($message);
|
---|
300 | if (file_exists($save_filename) && empty($onserverover)) {
|
---|
301 | $message = sprintf($strFileAlreadyExists, htmlspecialchars($save_filename));
|
---|
302 | $GLOBALS['show_error_header'] = TRUE;
|
---|
303 | } else {
|
---|
304 | if (is_file($save_filename) && !is_writable($save_filename)) {
|
---|
305 | $message = sprintf($strNoPermission, htmlspecialchars($save_filename));
|
---|
306 | $GLOBALS['show_error_header'] = TRUE;
|
---|
307 | } else {
|
---|
308 | if (!$file_handle = @fopen($save_filename, 'w')) {
|
---|
309 | $message = sprintf($strNoPermission, htmlspecialchars($save_filename));
|
---|
310 | $GLOBALS['show_error_header'] = TRUE;
|
---|
311 | }
|
---|
312 | }
|
---|
313 | }
|
---|
314 | if (isset($message)) {
|
---|
315 | $js_to_run = 'functions.js';
|
---|
316 | require_once('./libraries/header.inc.php');
|
---|
317 | if ($export_type == 'server') {
|
---|
318 | $active_page = 'server_export.php';
|
---|
319 | require('./server_export.php');
|
---|
320 | } elseif ($export_type == 'database') {
|
---|
321 | $active_page = 'db_export.php';
|
---|
322 | require('./db_export.php');
|
---|
323 | } else {
|
---|
324 | $active_page = 'tbl_export.php';
|
---|
325 | require('./tbl_export.php');
|
---|
326 | }
|
---|
327 | exit();
|
---|
328 | }
|
---|
329 | }
|
---|
330 |
|
---|
331 | /**
|
---|
332 | * Send headers depending on whether the user chose to download a dump file
|
---|
333 | * or not
|
---|
334 | */
|
---|
335 | if (!$save_on_server) {
|
---|
336 | if ($asfile ) {
|
---|
337 | // Download
|
---|
338 | if (!empty($content_encoding)) {
|
---|
339 | header('Content-Encoding: ' . $content_encoding);
|
---|
340 | }
|
---|
341 | header('Content-Type: ' . $mime_type);
|
---|
342 | header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
---|
343 | // lem9: Tested behavior of
|
---|
344 | // IE 5.50.4807.2300
|
---|
345 | // IE 6.0.2800.1106 (small glitch, asks twice when I click Open)
|
---|
346 | // IE 6.0.2900.2180
|
---|
347 | // Firefox 1.0.6
|
---|
348 | // in http and https
|
---|
349 | header('Content-Disposition: attachment; filename="' . $filename . '"');
|
---|
350 | if (PMA_USR_BROWSER_AGENT == 'IE') {
|
---|
351 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
---|
352 | header('Pragma: public');
|
---|
353 | } else {
|
---|
354 | header('Pragma: no-cache');
|
---|
355 | }
|
---|
356 | } else {
|
---|
357 | // HTML
|
---|
358 | if ($export_type == 'database') {
|
---|
359 | $num_tables = count($tables);
|
---|
360 | if ($num_tables == 0) {
|
---|
361 | $message = $strNoTablesFound;
|
---|
362 | $js_to_run = 'functions.js';
|
---|
363 | require_once('./libraries/header.inc.php');
|
---|
364 | $active_page = 'db_export.php';
|
---|
365 | require('./db_export.php');
|
---|
366 | exit();
|
---|
367 | }
|
---|
368 | }
|
---|
369 | $backup_cfgServer = $cfg['Server'];
|
---|
370 | require_once('./libraries/header.inc.php');
|
---|
371 | $cfg['Server'] = $backup_cfgServer;
|
---|
372 | unset($backup_cfgServer);
|
---|
373 | echo "\n" . '<div align="' . $cell_align_left . '">' . "\n";
|
---|
374 | //echo ' <pre>' . "\n";
|
---|
375 | echo ' <form name="nofunction">' . "\n"
|
---|
376 | // remove auto-select for now: there is no way to select
|
---|
377 | // only a part of the text; anyway, it should obey
|
---|
378 | // $cfg['TextareaAutoSelect']
|
---|
379 | //. ' <textarea name="sqldump" cols="50" rows="30" onclick="this.select();" id="textSQLDUMP" wrap="OFF">' . "\n";
|
---|
380 | . ' <textarea name="sqldump" cols="50" rows="30" id="textSQLDUMP" wrap="OFF">' . "\n";
|
---|
381 | } // end download
|
---|
382 | }
|
---|
383 |
|
---|
384 | // Fake loop just to allow skip of remain of this code by break, I'd really
|
---|
385 | // need exceptions here :-)
|
---|
386 | do {
|
---|
387 |
|
---|
388 | // Add possibly some comments to export
|
---|
389 | if (!PMA_exportHeader()) {
|
---|
390 | break;
|
---|
391 | }
|
---|
392 |
|
---|
393 | // Will we need relation & co. setup?
|
---|
394 | $do_relation = isset($GLOBALS[$what . '_relation']);
|
---|
395 | $do_comments = isset($GLOBALS[$what . '_comments']);
|
---|
396 | $do_mime = isset($GLOBALS[$what . '_mime']);
|
---|
397 | if ($do_relation || $do_comments || $do_mime) {
|
---|
398 | require_once('./libraries/relation.lib.php');
|
---|
399 | $cfgRelation = PMA_getRelationsParam();
|
---|
400 | }
|
---|
401 | if ($do_mime) {
|
---|
402 | require_once('./libraries/transformations.lib.php');
|
---|
403 | }
|
---|
404 |
|
---|
405 | // Include dates in export?
|
---|
406 | $do_dates = isset($GLOBALS[$what . '_dates']);
|
---|
407 |
|
---|
408 | /**
|
---|
409 | * Builds the dump
|
---|
410 | */
|
---|
411 | // Gets the number of tables if a dump of a database has been required
|
---|
412 | if ($export_type == 'server') {
|
---|
413 | if (isset($db_select)) {
|
---|
414 | $tmp_select = implode($db_select, '|');
|
---|
415 | $tmp_select = '|' . $tmp_select . '|';
|
---|
416 | }
|
---|
417 | // Walk over databases
|
---|
418 | foreach ($GLOBALS['PMA_List_Database']->items as $current_db) {
|
---|
419 | if ((isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|'))
|
---|
420 | || !isset($tmp_select)) {
|
---|
421 | if (!PMA_exportDBHeader($current_db)) {
|
---|
422 | break 2;
|
---|
423 | }
|
---|
424 | if (!PMA_exportDBCreate($current_db)) {
|
---|
425 | break 2;
|
---|
426 | }
|
---|
427 | $tables = PMA_DBI_get_tables($current_db);
|
---|
428 | $views = array();
|
---|
429 | foreach ($tables as $table) {
|
---|
430 | // if this is a view, collect it for later; views must be exported
|
---|
431 | // after the tables
|
---|
432 | $is_view = PMA_Table::isView($current_db, $table);
|
---|
433 | if ($is_view) {
|
---|
434 | $views[] = $table;
|
---|
435 | }
|
---|
436 | if (isset($GLOBALS[$what . '_structure'])) {
|
---|
437 | // for a view, export a stand-in definition of the table
|
---|
438 | // to resolve view dependencies
|
---|
439 | 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)) {
|
---|
440 | break 3;
|
---|
441 | }
|
---|
442 | }
|
---|
443 | if (isset($GLOBALS[$what . '_data']) && ! $is_view) {
|
---|
444 | $local_query = 'SELECT * FROM ' . PMA_backquote($current_db) . '.' . PMA_backquote($table);
|
---|
445 | if (!PMA_exportData($current_db, $table, $crlf, $err_url, $local_query)) {
|
---|
446 | break 3;
|
---|
447 | }
|
---|
448 | }
|
---|
449 | }
|
---|
450 | foreach($views as $view) {
|
---|
451 | // no data export for a view
|
---|
452 | if (isset($GLOBALS[$what . '_structure'])) {
|
---|
453 | if (!PMA_exportStructure($current_db, $view, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'create_view', $export_type)) {
|
---|
454 | break 3;
|
---|
455 | }
|
---|
456 | }
|
---|
457 | }
|
---|
458 | if (!PMA_exportDBFooter($current_db)) {
|
---|
459 | break 2;
|
---|
460 | }
|
---|
461 | }
|
---|
462 | }
|
---|
463 | } elseif ($export_type == 'database') {
|
---|
464 | if (!PMA_exportDBHeader($db)) {
|
---|
465 | break;
|
---|
466 | }
|
---|
467 | $i = 0;
|
---|
468 | $views = array();
|
---|
469 | // $tables contains the choices from the user (via $table_select)
|
---|
470 | foreach ($tables as $table) {
|
---|
471 | // if this is a view, collect it for later; views must be exported after
|
---|
472 | // the tables
|
---|
473 | $is_view = PMA_Table::isView($db, $table);
|
---|
474 | if ($is_view) {
|
---|
475 | $views[] = $table;
|
---|
476 | }
|
---|
477 | if (isset($GLOBALS[$what . '_structure'])) {
|
---|
478 | // for a view, export a stand-in definition of the table
|
---|
479 | // to resolve view dependencies
|
---|
480 | if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, $is_view ? 'stand_in' : 'create_table', $export_type)) {
|
---|
481 | break 2;
|
---|
482 | }
|
---|
483 | }
|
---|
484 | if (isset($GLOBALS[$what . '_data']) && ! $is_view) {
|
---|
485 | $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
|
---|
486 | if (!PMA_exportData($db, $table, $crlf, $err_url, $local_query)) {
|
---|
487 | break 2;
|
---|
488 | }
|
---|
489 | }
|
---|
490 | }
|
---|
491 | foreach ($views as $view) {
|
---|
492 | // no data export for a view
|
---|
493 | if (isset($GLOBALS[$what . '_structure'])) {
|
---|
494 | if (!PMA_exportStructure($db, $view, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'create_view', $export_type)) {
|
---|
495 | break 2;
|
---|
496 | }
|
---|
497 | }
|
---|
498 | }
|
---|
499 |
|
---|
500 | if (!PMA_exportDBFooter($db)) {
|
---|
501 | break;
|
---|
502 | }
|
---|
503 | } else {
|
---|
504 | if (!PMA_exportDBHeader($db)) {
|
---|
505 | break;
|
---|
506 | }
|
---|
507 | // We export just one table
|
---|
508 |
|
---|
509 | if ($limit_to > 0 && $limit_from >= 0) {
|
---|
510 | $add_query = ' LIMIT '
|
---|
511 | . (($limit_from > 0) ? $limit_from . ', ' : '')
|
---|
512 | . $limit_to;
|
---|
513 | } else {
|
---|
514 | $add_query = '';
|
---|
515 | }
|
---|
516 |
|
---|
517 | $is_view = PMA_Table::isView($db, $table);
|
---|
518 | if (isset($GLOBALS[$what . '_structure'])) {
|
---|
519 | if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, $is_view ? 'create_view' : 'create_table', $export_type)) {
|
---|
520 | break;
|
---|
521 | }
|
---|
522 | }
|
---|
523 | // If this is an export of a single view, we have to export data;
|
---|
524 | // for example, a PDF report
|
---|
525 | if (isset($GLOBALS[$what . '_data'])) {
|
---|
526 | if (!empty($sql_query)) {
|
---|
527 | // only preg_replace if needed
|
---|
528 | if (!empty($add_query)) {
|
---|
529 | // remove trailing semicolon before adding a LIMIT
|
---|
530 | $sql_query = preg_replace('%;\s*$%', '', $sql_query);
|
---|
531 | }
|
---|
532 | $local_query = $sql_query . $add_query;
|
---|
533 | PMA_DBI_select_db($db);
|
---|
534 | } else {
|
---|
535 | $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query;
|
---|
536 | }
|
---|
537 | if (!PMA_exportData($db, $table, $crlf, $err_url, $local_query)) {
|
---|
538 | break;
|
---|
539 | }
|
---|
540 | }
|
---|
541 | if (!PMA_exportDBFooter($db)) {
|
---|
542 | break;
|
---|
543 | }
|
---|
544 | }
|
---|
545 | if (!PMA_exportFooter()) {
|
---|
546 | break;
|
---|
547 | }
|
---|
548 |
|
---|
549 | } while (FALSE);
|
---|
550 | // End of fake loop
|
---|
551 |
|
---|
552 | if ($save_on_server && isset($message)) {
|
---|
553 | $js_to_run = 'functions.js';
|
---|
554 | require_once('./libraries/header.inc.php');
|
---|
555 | if ($export_type == 'server') {
|
---|
556 | $active_page = 'server_export.php';
|
---|
557 | require('./server_export.php');
|
---|
558 | } elseif ($export_type == 'database') {
|
---|
559 | $active_page = 'db_export.php';
|
---|
560 | require('./db_export.php');
|
---|
561 | } else {
|
---|
562 | $active_page = 'tbl_export.php';
|
---|
563 | require('./tbl_export.php');
|
---|
564 | }
|
---|
565 | exit();
|
---|
566 | }
|
---|
567 |
|
---|
568 | /**
|
---|
569 | * Send the dump as a file...
|
---|
570 | */
|
---|
571 | if (!empty($asfile)) {
|
---|
572 | // Convert the charset if required.
|
---|
573 | if ($output_charset_conversion) {
|
---|
574 | $dump_buffer = PMA_convert_string($GLOBALS['charset'], $GLOBALS['charset_of_file'], $dump_buffer);
|
---|
575 | }
|
---|
576 |
|
---|
577 | // Do the compression
|
---|
578 | // 1. as a gzipped file
|
---|
579 | if ($compression == 'zip') {
|
---|
580 | if (@function_exists('gzcompress')) {
|
---|
581 | $zipfile = new zipfile();
|
---|
582 | $zipfile -> addFile($dump_buffer, substr($filename, 0, -4));
|
---|
583 | $dump_buffer = $zipfile -> file();
|
---|
584 | }
|
---|
585 | }
|
---|
586 | // 2. as a bzipped file
|
---|
587 | elseif ($compression == 'bzip') {
|
---|
588 | if (@function_exists('bzcompress')) {
|
---|
589 | $dump_buffer = bzcompress($dump_buffer);
|
---|
590 | if ($dump_buffer === -8) {
|
---|
591 | require_once('./libraries/header.inc.php');
|
---|
592 | echo sprintf($strBzError, '<a href="http://bugs.php.net/bug.php?id=17300" target="_blank">17300</a>');
|
---|
593 | require_once('./libraries/footer.inc.php');
|
---|
594 | }
|
---|
595 | }
|
---|
596 | }
|
---|
597 | // 3. as a gzipped file
|
---|
598 | elseif ($compression == 'gzip') {
|
---|
599 | if (@function_exists('gzencode')) {
|
---|
600 | // without the optional parameter level because it bug
|
---|
601 | $dump_buffer = gzencode($dump_buffer);
|
---|
602 | }
|
---|
603 | }
|
---|
604 |
|
---|
605 | /* If ve saved on server, we have to close file now */
|
---|
606 | if ($save_on_server) {
|
---|
607 | $write_result = @fwrite($file_handle, $dump_buffer);
|
---|
608 | fclose($file_handle);
|
---|
609 | if (strlen($dump_buffer) !=0 && (!$write_result || ($write_result != strlen($dump_buffer)))) {
|
---|
610 | $message = sprintf($strNoSpace, htmlspecialchars($save_filename));
|
---|
611 | } else {
|
---|
612 | $message = sprintf($strDumpSaved, htmlspecialchars($save_filename));
|
---|
613 | }
|
---|
614 |
|
---|
615 | $js_to_run = 'functions.js';
|
---|
616 | require_once('./libraries/header.inc.php');
|
---|
617 | if ($export_type == 'server') {
|
---|
618 | $active_page = 'server_export.php';
|
---|
619 | require_once('./server_export.php');
|
---|
620 | } elseif ($export_type == 'database') {
|
---|
621 | $active_page = 'db_export.php';
|
---|
622 | require_once('./db_export.php');
|
---|
623 | } else {
|
---|
624 | $active_page = 'tbl_export.php';
|
---|
625 | require_once('./tbl_export.php');
|
---|
626 | }
|
---|
627 | exit();
|
---|
628 | } else {
|
---|
629 | echo $dump_buffer;
|
---|
630 | }
|
---|
631 | }
|
---|
632 | /**
|
---|
633 | * Displays the dump...
|
---|
634 | */
|
---|
635 | else {
|
---|
636 | /**
|
---|
637 | * Close the html tags and add the footers in dump is displayed on screen
|
---|
638 | */
|
---|
639 | //echo ' </pre>' . "\n";
|
---|
640 | echo '</textarea>' . "\n"
|
---|
641 | . ' </form>' . "\n";
|
---|
642 | echo '</div>' . "\n";
|
---|
643 | echo "\n";
|
---|
644 | ?>
|
---|
645 | <script type="text/javascript" language="javascript">
|
---|
646 | //<![CDATA[
|
---|
647 | var bodyWidth=null; var bodyHeight=null;
|
---|
648 | if (document.getElementById('textSQLDUMP')) {
|
---|
649 | bodyWidth = self.innerWidth;
|
---|
650 | bodyHeight = self.innerHeight;
|
---|
651 | if (!bodyWidth && !bodyHeight) {
|
---|
652 | if (document.compatMode && document.compatMode == "BackCompat") {
|
---|
653 | bodyWidth = document.body.clientWidth;
|
---|
654 | bodyHeight = document.body.clientHeight;
|
---|
655 | } else if (document.compatMode && document.compatMode == "CSS1Compat") {
|
---|
656 | bodyWidth = document.documentElement.clientWidth;
|
---|
657 | bodyHeight = document.documentElement.clientHeight;
|
---|
658 | }
|
---|
659 | }
|
---|
660 | document.getElementById('textSQLDUMP').style.width=(bodyWidth-50) + 'px';
|
---|
661 | document.getElementById('textSQLDUMP').style.height=(bodyHeight-100) + 'px';
|
---|
662 | }
|
---|
663 | //]]>
|
---|
664 | </script>
|
---|
665 | <?php
|
---|
666 | require_once('./libraries/footer.inc.php');
|
---|
667 | } // end if
|
---|
668 | ?>
|
---|