Refactored ConfigFile class so that it is no longer a singleton
[phpmyadmin.git] / libraries / display_export.lib.php
blobe3fecb5fe4f225f0a60cdd75218a56e76db2f873
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 /**
5 * functions for displaying server, database and table export
7 * @usedby display_export.inc.php
9 * @package PhpMyAdmin
11 if (! defined('PHPMYADMIN')) {
12 exit;
15 /**
16 * Outputs appropriate checked statement for checkbox.
18 * @param string $str option name
20 * @return void
22 function PMA_exportCheckboxCheck($str)
24 if (isset($GLOBALS['cfg']['Export'][$str]) && $GLOBALS['cfg']['Export'][$str]) {
25 return ' checked="checked"';
29 /**
30 * Prints Html For Export Selection Options
32 * @param String $tmp_select Tmp selected method of export
34 * @return string
36 function PMA_getHtmlForExportSelectOptions($tmp_select = '')
38 $multi_values = '<div style="text-align: left">';
39 $multi_values .= '<a href="#"';
40 $multi_values .= ' onclick="setSelectOptions'
41 . '(\'dump\', \'db_select[]\', true); return false;">';
42 $multi_values .= __('Select All');
43 $multi_values .= '</a>';
44 $multi_values .= ' / ';
45 $multi_values .= '<a href="#"';
46 $multi_values .= ' onclick="setSelectOptions'
47 . '(\'dump\', \'db_select[]\', false); return false;">';
48 $multi_values .= __('Unselect All') . '</a><br />';
50 $multi_values .= '<select name="db_select[]" '
51 . 'id="db_select" size="10" multiple="multiple">';
52 $multi_values .= "\n";
54 // Check if the selected databases are defined in $_GET
55 // (from clicking Back button on export.php)
56 if (isset($_GET['db_select'])) {
57 $_GET['db_select'] = urldecode($_GET['db_select']);
58 $_GET['db_select'] = explode(",", $_GET['db_select']);
61 foreach ($GLOBALS['pma']->databases as $current_db) {
62 if ($current_db == 'information_schema'
63 || $current_db == 'performance_schema'
64 || $current_db == 'mysql'
65 ) {
66 continue;
68 if (isset($_GET['db_select'])) {
69 if (in_array($current_db, $_GET['db_select'])) {
70 $is_selected = ' selected="selected"';
71 } else {
72 $is_selected = '';
74 } elseif (!empty($tmp_select)) {
75 if (strpos(' ' . $tmp_select, '|' . $current_db . '|')) {
76 $is_selected = ' selected="selected"';
77 } else {
78 $is_selected = '';
80 } else {
81 $is_selected = ' selected="selected"';
83 $current_db = htmlspecialchars($current_db);
84 $multi_values .= ' <option value="' . $current_db . '"'
85 . $is_selected . '>' . $current_db . '</option>' . "\n";
86 } // end while
87 $multi_values .= "\n";
88 $multi_values .= '</select></div>';
90 return $multi_values;
93 /**
94 * Prints Html For Export Hidden Input
96 * @param String $export_type Selected Export Type
97 * @param String $db Selected DB
98 * @param String $table Selected Table
99 * @param String $single_table Single Table
100 * @param String $sql_query Sql Query
102 * @return string
104 function PMA_getHtmlForHiddenInput(
105 $export_type, $db, $table, $single_table, $sql_query
107 global $cfg;
108 $html = "";
109 if ($export_type == 'server') {
110 $html .= PMA_URL_getHiddenInputs('', '', 1);
111 } elseif ($export_type == 'database') {
112 $html .= PMA_URL_getHiddenInputs($db, '', 1);
113 } else {
114 $html .= PMA_URL_getHiddenInputs($db, $table, 1);
117 // just to keep this value for possible next display of this form after saving
118 // on server
119 if (!empty($single_table)) {
120 $html .= '<input type="hidden" name="single_table" value="TRUE" />'
121 . "\n";
124 $html .= '<input type="hidden" name="export_type" value="'
125 . $export_type . '" />';
126 $html .= "\n";
128 // If the export method was not set, the default is quick
129 if (isset($_GET['export_method'])) {
130 $cfg['Export']['method'] = $_GET['export_method'];
131 } elseif (! isset($cfg['Export']['method'])) {
132 $cfg['Export']['method'] = 'quick';
134 // The export method (quick, custom or custom-no-form)
135 $html .= '<input type="hidden" name="export_method" value="'
136 . htmlspecialchars($cfg['Export']['method']) . '" />';
139 if (isset($_GET['sql_query'])) {
140 $html .= '<input type="hidden" name="sql_query" value="'
141 . htmlspecialchars($_GET['sql_query']) . '" />' . "\n";
142 } elseif (! empty($sql_query)) {
143 $html .= '<input type="hidden" name="sql_query" value="'
144 . htmlspecialchars($sql_query) . '" />' . "\n";
147 return $html;
151 * Prints Html For Export Options Header
153 * @param String $export_type Selected Export Type
154 * @param String $db Selected DB
155 * @param String $table Selected Table
157 * @return string
159 function PMA_getHtmlForExportOptionHeader($export_type, $db, $table)
161 $html = '<div class="exportoptions" id="header">';
162 $html .= '<h2>';
163 $html .= PMA_Util::getImage('b_export.png', __('Export'));
164 if ($export_type == 'server') {
165 $html .= __('Exporting databases from the current server');
166 } elseif ($export_type == 'database') {
167 $html .= sprintf(
168 __('Exporting tables from "%s" database'),
169 htmlspecialchars($db)
171 } else {
172 $html .= sprintf(
173 __('Exporting rows from "%s" table'),
174 htmlspecialchars($table)
177 $html .= '</h2>';
178 $html .= '</div>';
180 return $html;
184 * Prints Html For Export Options Method
186 * @return string
188 function PMA_getHtmlForExportOptionsMethod()
190 global $cfg;
191 if (isset($_GET['quick_or_custom'])) {
192 $export_method = $_GET['quick_or_custom'];
193 } else {
194 $export_method = $cfg['Export']['method'];
197 $html = '<div class="exportoptions" id="quick_or_custom">';
198 $html .= '<h3>' . __('Export Method:') . '</h3>';
199 $html .= '<ul>';
200 $html .= '<li>';
201 $html .= '<input type="radio" name="quick_or_custom" value="quick" '
202 . ' id="radio_quick_export"';
203 if ($export_method == 'quick' || $export_method == 'quick_no_form') {
204 $html .= ' checked="checked"';
206 $html .= ' />';
207 $html .= '<label for ="radio_quick_export">';
208 $html .= __('Quick - display only the minimal options');
209 $html .= '</label>';
210 $html .= '</li>';
212 $html .= '<li>';
213 $html .= '<input type="radio" name="quick_or_custom" value="custom" '
214 . ' id="radio_custom_export"';
215 if ($export_method == 'custom' || $export_method == 'custom_no_form') {
216 $html .= ' checked="checked"';
218 $html .= ' />';
219 $html .= '<label for="radio_custom_export">';
220 $html .= __('Custom - display all possible options');
221 $html .= '</label>';
222 $html .= '</li>';
224 $html .= '</ul>';
225 $html .= '</div>';
227 return $html;
231 * Prints Html For Export Options Selection
233 * @param String $export_type Selected Export Type
234 * @param String $multi_values Export Options
236 * @return string
238 function PMA_getHtmlForExportOptionsSelection($export_type, $multi_values)
240 $html = '<div class="exportoptions" id="databases_and_tables">';
241 if ($export_type == 'server') {
242 $html .= '<h3>' . __('Database(s):') . '</h3>';
243 } else if ($export_type == 'database') {
244 $html .= '<h3>' . __('Table(s):') . '</h3>';
246 if (! empty($multi_values)) {
247 $html .= $multi_values;
249 $html .= '</div>';
251 return $html;
255 * Prints Html For Export Options Format
257 * @param String $export_list Export List
259 * @return string
261 function PMA_getHtmlForExportOptionsFormat($export_list)
263 $html = '<div class="exportoptions" id="format">';
264 $html .= '<h3>' . __('Format:') . '</h3>';
265 $html .= PMA_pluginGetChoice('Export', 'what', $export_list, 'format');
266 $html .= '</div>';
268 $html .= '<div class="exportoptions" id="format_specific_opts">';
269 $html .= '<h3>' . __('Format-specific options:') . '</h3>';
270 $html .= '<p class="no_js_msg" id="scroll_to_options_msg">';
271 $html .= __(
272 'Scroll down to fill in the options for the selected format '
273 . 'and ignore the options for other formats.'
275 $html .= '</p>';
276 $html .= PMA_pluginGetOptions('Export', $export_list);
277 $html .= '</div>';
279 if (function_exists('PMA_Kanji_encodingForm')) {
280 // Encoding setting form appended by Y.Kawada
281 // Japanese encoding setting
282 $html .= '<div class="exportoptions" id="kanji_encoding">';
283 $html .= '<h3>' . __('Encoding Conversion:') . '</h3>';
284 $html .= PMA_Kanji_encodingForm();
285 $html .= '</div>';
288 $html .= '<div class="exportoptions" id="submit">';
290 $html .= PMA_Util::getExternalBug(
291 __('SQL compatibility mode'), 'mysql', '50027', '14515'
294 $html .= '<input type="submit" value="' . __('Go') . '" id="buttonGo" />';
295 $html .= '</div>';
297 return $html;
300 * Prints Html For Export Options Rows
302 * @param String $db Selected DB
303 * @param String $table Selected Table
304 * @param String $unlim_num_rows Num of Rows
306 * @return string
308 function PMA_getHtmlForExportOptionsRows($db, $table, $unlim_num_rows)
310 $html = '<div class="exportoptions" id="rows">';
311 $html .= '<h3>' . __('Rows:') . '</h3>';
312 $html .= '<ul>';
313 $html .= '<li>';
314 $html .= '<input type="radio" name="allrows" value="0" id="radio_allrows_0"';
315 if (isset($_GET['allrows']) && $_GET['allrows'] == 0) {
316 $html .= ' checked="checked"';
318 $html .= '/>';
319 $html .= '<label for ="radio_allrows_0">' . __('Dump some row(s)') . '</label>';
320 $html .= '<ul>';
321 $html .= '<li>';
322 $html .= '<label for="limit_to">' . __('Number of rows:') . '</label>';
323 $html .= '<input type="text" id="limit_to" name="limit_to" size="5" value="';
324 if (isset($_GET['limit_to'])) {
325 $html .= htmlspecialchars($_GET['limit_to']);
326 } elseif (!empty($unlim_num_rows)) {
327 $html .= $unlim_num_rows;
328 } else {
329 $html .= PMA_Table::countRecords($db, $table);
331 $html .= '" onfocus="this.select()" />';
332 $html .= '</li>';
333 $html .= '<li>';
334 $html .= '<label for="limit_from">' . __('Row to begin at:') . '</label>';
335 $html .= '<input type="text" id="limit_from" name="limit_from" value="';
336 if (isset($_GET['limit_from'])) {
337 $html .= htmlspecialchars($_GET['limit_from']);
338 } else {
339 $html .= '0';
341 $html .= '" size="5" onfocus="this.select()" />';
342 $html .= '</li>';
343 $html .= '</ul>';
344 $html .= '</li>';
345 $html .= '<li>';
346 $html .= '<input type="radio" name="allrows" value="1" id="radio_allrows_1"';
347 if (! isset($_GET['allrows']) || $_GET['allrows'] == 1) {
348 $html .= ' checked="checked"';
350 $html .= '/>';
351 $html .= ' <label for="radio_allrows_1">' . __('Dump all rows') . '</label>';
352 $html .= '</li>';
353 $html .= '</ul>';
354 $html .= '</div>';
355 return $html;
359 * Prints Html For Export Options Quick Export
361 * @return string
363 function PMA_getHtmlForExportOptionsQuickExport()
365 global $cfg;
366 $html = '<div class="exportoptions" id="output_quick_export">';
367 $html .= '<h3>' . __('Output:') . '</h3>';
368 $html .= '<ul>';
369 $html .= '<li>';
370 $html .= '<input type="checkbox" name="quick_export_onserver" value="saveit" ';
371 $html .= 'id="checkbox_quick_dump_onserver" ';
372 $html .= PMA_exportCheckboxCheck('quick_export_onserver');
373 $html .= '/>';
374 $html .= '<label for="checkbox_quick_dump_onserver">';
375 $html .= sprintf(
376 __('Save on server in the directory <b>%s</b>'),
377 htmlspecialchars(PMA_Util::userDir($cfg['SaveDir']))
379 $html .= '</label>';
380 $html .= '</li>';
381 $html .= '<li>';
382 $html .= '<input type="checkbox" name="quick_export_onserverover" ';
383 $html .= 'value="saveitover" id="checkbox_quick_dump_onserverover" ';
384 $html .= PMA_exportCheckboxCheck('quick_export_onserver_overwrite');
385 $html .= '/>';
386 $html .= '<label for="checkbox_quick_dump_onserverover">';
387 $html .= __('Overwrite existing file(s)');
388 $html .= '</label>';
389 $html .= '</li>';
390 $html .= '</ul>';
391 $html .= '</div>';
393 return $html;
397 * Prints Html For Export Options Save Dir
399 * @return string
401 function PMA_getHtmlForExportOptionsOutputSaveDir()
403 global $cfg;
404 $html = '<li>';
405 $html .= '<input type="checkbox" name="onserver" value="saveit" ';
406 $html .= 'id="checkbox_dump_onserver" ';
407 $html .= PMA_exportCheckboxCheck('onserver');
408 $html .= '/>';
409 $html .= '<label for="checkbox_dump_onserver">';
410 $html .= sprintf(
411 __('Save on server in the directory <b>%s</b>'),
412 htmlspecialchars(PMA_Util::userDir($cfg['SaveDir']))
414 $html .= '</label>';
415 $html .= '</li>';
416 $html .= '<li>';
417 $html .= '<input type="checkbox" name="onserverover" value="saveitover"';
418 $html .= ' id="checkbox_dump_onserverover" ';
419 $html .= PMA_exportCheckboxCheck('onserver_overwrite');
420 $html .= '/>';
421 $html .= '<label for="checkbox_dump_onserverover">';
422 $html .= __('Overwrite existing file(s)');
423 $html .= '</label>';
424 $html .= '</li>';
426 return $html;
431 * Prints Html For Export Options
433 * @param String $export_type Selected Export Type
435 * @return string
437 function PMA_getHtmlForExportOptionsOutputFormat($export_type)
439 $html = '<li>';
440 $html .= '<label for="filename_template" class="desc">';
441 $html .= __('File name template:');
442 $trans = new PMA_Message;
443 $trans->addMessage(__('@SERVER@ will become the server name'));
444 if ($export_type == 'database' || $export_type == 'table') {
445 $trans->addMessage(__(', @DATABASE@ will become the database name'));
446 if ($export_type == 'table') {
447 $trans->addMessage(__(', @TABLE@ will become the table name'));
451 $msg = new PMA_Message(
453 'This value is interpreted using %1$sstrftime%2$s, '
454 . 'so you can use time formatting strings. '
455 . 'Additionally the following transformations will happen: %3$s. '
456 . 'Other text will be kept as is. See the %4$sFAQ%5$s for details.'
459 $msg->addParam(
460 '<a href="' . PMA_linkURL(PMA_getPHPDocLink('function.strftime.php'))
461 . '" target="documentation" title="' . __('Documentation') . '">',
462 false
464 $msg->addParam('</a>', false);
465 $msg->addParam($trans);
466 $doc_url = PMA_Util::getDocuLink('faq', 'faq6-27');
467 $msg->addParam(
468 '<a href="'. $doc_url . '" target="documentation">',
469 false
471 $msg->addParam('</a>', false);
473 $html .= PMA_Util::showHint($msg);
474 $html .= '</label>';
475 $html .= '<input type="text" name="filename_template" id="filename_template" ';
476 $html .= ' value="';
477 if (isset($_GET['filename_template'])) {
478 $html .= htmlspecialchars($_GET['filename_template']);
479 } else {
480 if ($export_type == 'database') {
481 $html .= htmlspecialchars(
482 $GLOBALS['PMA_Config']->getUserValue(
483 'pma_db_filename_template',
484 $GLOBALS['cfg']['Export']['file_template_database']
487 } elseif ($export_type == 'table') {
488 $html .= htmlspecialchars(
489 $GLOBALS['PMA_Config']->getUserValue(
490 'pma_table_filename_template',
491 $GLOBALS['cfg']['Export']['file_template_table']
494 } else {
495 $html .= htmlspecialchars(
496 $GLOBALS['PMA_Config']->getUserValue(
497 'pma_server_filename_template',
498 $GLOBALS['cfg']['Export']['file_template_server']
503 $html .= '"';
504 $html .= '/>';
505 $html .= '<input type="checkbox" name="remember_template" ';
506 $html .= 'id="checkbox_remember_template" ';
507 $html .= PMA_exportCheckboxCheck('remember_file_template');
508 $html .= '/>';
509 $html .= '<label for="checkbox_remember_template">';
510 $html .= __('use this for future exports');
511 $html .= '</label>';
512 $html .= '</li>';
513 return $html;
517 * Prints Html For Export Options Charset
519 * @return string
521 function PMA_getHtmlForExportOptionsOutputCharset()
523 global $cfg;
524 $html = ' <li><label for="select_charset_of_file" class="desc">'
525 . __('Character set of the file:') . '</label>' . "\n";
526 reset($cfg['AvailableCharsets']);
527 $html .= '<select id="select_charset_of_file" name="charset_of_file" size="1">';
528 foreach ($cfg['AvailableCharsets'] as $temp_charset) {
529 $html .= '<option value="' . $temp_charset . '"';
530 if (isset($_GET['charset_of_file'])
531 && ($_GET['charset_of_file'] != $temp_charset)
533 $html .= '';
534 } elseif ((empty($cfg['Export']['charset']) && $temp_charset == 'utf-8')
535 || $temp_charset == $cfg['Export']['charset']
537 $html .= ' selected="selected"';
539 $html .= '>' . $temp_charset . '</option>';
540 } // end foreach
541 $html .= '</select></li>';
543 return $html;
547 * Prints Html For Export Options Compression
549 * @return string
551 function PMA_getHtmlForExportOptionsOutputCompression()
553 global $cfg;
554 if (isset($_GET['compression'])) {
555 $selected_compression = $_GET['compression'];
556 } elseif (isset($cfg['Export']['compression'])) {
557 $selected_compression = $cfg['Export']['compression'];
558 } else {
559 $selected_compression = "none";
562 $html = "";
563 // zip, gzip and bzip2 encode features
564 $is_zip = ($cfg['ZipDump'] && @function_exists('gzcompress'));
565 $is_gzip = ($cfg['GZipDump'] && @function_exists('gzencode'));
566 $is_bzip2 = ($cfg['BZipDump'] && @function_exists('bzcompress'));
567 if ($is_zip || $is_gzip || $is_bzip2) {
568 $html .= '<li>';
569 $html .= '<label for="compression" class="desc">'
570 . __('Compression:') . '</label>';
571 $html .= '<select id="compression" name="compression">';
572 $html .= '<option value="none">' . __('None') . '</option>';
573 if ($is_zip) {
574 $html .= '<option value="zip" ';
575 if ($selected_compression == "zip") {
576 $html .= 'selected="selected"';
578 $html .= '>' . __('zipped') . '</option>';
580 if ($is_gzip) {
581 $html .= '<option value="gzip" ';
582 if ($selected_compression == "gzip") {
583 $html .= 'selected="selected"';
585 $html .= '>' . __('gzipped') . '</option>';
587 if ($is_bzip2) {
588 $html .= '<option value="bzip2" ';
589 if ($selected_compression == "bzip2") {
590 $html .= 'selected="selected"';
592 $html .= '>' . __('bzipped') . '</option>';
594 $html .= '</select>';
595 $html .= '</li>';
596 } else {
597 $html .= '<input type="hidden" name="compression" value="'
598 . htmlspecialchars($selected_compression) . '" />';
601 return $html;
605 * Prints Html For Export Options Radio
607 * @return string
609 function PMA_getHtmlForExportOptionsOutputRadio()
611 $html = '<li>';
612 $html .= '<input type="radio" id="radio_view_as_text" '
613 . ' name="output_format" value="astext" ';
614 if (isset($_GET['repopulate']) || $GLOBALS['cfg']['Export']['asfile'] == false) {
615 $html .= 'checked="checked"';
617 $html .= '/>';
618 $html .= '<label for="radio_view_as_text">'
619 . __('View output as text') . '</label></li>';
620 return $html;
624 * Prints Html For Export Options
626 * @param String $export_type Selected Export Type
628 * @return string
630 function PMA_getHtmlForExportOptionsOutput($export_type)
632 global $cfg;
633 $html = '<div class="exportoptions" id="output">';
634 $html .= '<h3>' . __('Output:') . '</h3>';
635 $html .= '<ul id="ul_output">';
636 $html .= '<li>';
637 $html .= '<input type="radio" name="output_format" value="sendit" ';
638 $html .= 'id="radio_dump_asfile" ';
639 if (!isset($_GET['repopulate'])) {
640 $html .= PMA_exportCheckboxCheck('asfile');
642 $html .= '/>';
643 $html .= '<label for="radio_dump_asfile">'
644 . __('Save output to a file') . '</label>';
645 $html .= '<ul id="ul_save_asfile">';
646 if (isset($cfg['SaveDir']) && !empty($cfg['SaveDir'])) {
647 $html .= PMA_getHtmlForExportOptionsOutputSaveDir();
650 $html .= PMA_getHtmlForExportOptionsOutputFormat($export_type);
652 // charset of file
653 if ($GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE) {
654 $html .= PMA_getHtmlForExportOptionsOutputCharset();
655 } // end if
657 $html .= PMA_getHtmlForExportOptionsOutputCompression();
659 $html .= '</ul>';
660 $html .= '</li>';
662 $html .= PMA_getHtmlForExportOptionsOutputRadio();
664 $html .= '</ul>';
665 $html .= '</div>';
667 return $html;
671 * Prints Html For Export Options
673 * @param String $export_type Selected Export Type
674 * @param String $db Selected DB
675 * @param String $table Selected Table
676 * @param String $multi_values Export selection
677 * @param String $num_tables number of tables
678 * @param String $export_list Export List
679 * @param String $unlim_num_rows Number of Rows
681 * @return string
683 function PMA_getHtmlForExportOptions(
684 $export_type, $db, $table, $multi_values,
685 $num_tables, $export_list, $unlim_num_rows
687 global $cfg;
688 $html = PMA_getHtmlForExportOptionHeader($export_type, $db, $table);
689 $html .= PMA_getHtmlForExportOptionsMethod();
690 $html .= PMA_getHtmlForExportOptionsSelection($export_type, $multi_values);
692 if (strlen($table) && empty($num_tables) && ! PMA_Table::isMerge($db, $table)) {
693 $html .= PMA_getHtmlForExportOptionsRows($db, $table, $unlim_num_rows);
696 if (isset($cfg['SaveDir']) && !empty($cfg['SaveDir'])) {
697 $html .= PMA_getHtmlForExportOptionsQuickExport();
700 $html .= PMA_getHtmlForExportOptionsOutput($export_type);
702 $html .= PMA_getHtmlForExportOptionsFormat($export_list);
703 return $html;