2 /* vim: set expandtab sw=4 ts=4 sts=4: */
5 * functions for displaying server, database and table export
7 * @usedby display_export.inc.php
11 if (! defined('PHPMYADMIN')) {
16 * Outputs appropriate checked statement for checkbox.
18 * @param string $str option name
22 function PMA_exportCheckboxCheck($str)
24 if (isset($GLOBALS['cfg']['Export'][$str]) && $GLOBALS['cfg']['Export'][$str]) {
25 return ' checked="checked"';
30 * Prints Html For Export Selection Options
32 * @param String $tmp_select Tmp selected method of export
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'
68 if (isset($_GET['db_select'])) {
69 if (in_array($current_db, $_GET['db_select'])) {
70 $is_selected = ' selected="selected"';
74 } elseif (!empty($tmp_select)) {
75 if (strpos(' ' . $tmp_select, '|' . $current_db . '|')) {
76 $is_selected = ' selected="selected"';
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";
87 $multi_values .= "\n";
88 $multi_values .= '</select></div>';
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
104 function PMA_getHtmlForHiddenInput(
105 $export_type, $db, $table, $single_table, $sql_query
109 if ($export_type == 'server') {
110 $html .= PMA_URL_getHiddenInputs('', '', 1);
111 } elseif ($export_type == 'database') {
112 $html .= PMA_URL_getHiddenInputs($db, '', 1);
114 $html .= PMA_URL_getHiddenInputs($db, $table, 1);
117 // just to keep this value for possible next display of this form after saving
119 if (!empty($single_table)) {
120 $html .= '<input type="hidden" name="single_table" value="TRUE" />'
124 $html .= '<input type="hidden" name="export_type" value="'
125 . $export_type . '" />';
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";
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
159 function PMA_getHtmlForExportOptionHeader($export_type, $db, $table)
161 $html = '<div class="exportoptions" id="header">';
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') {
168 __('Exporting tables from "%s" database'),
169 htmlspecialchars($db)
173 __('Exporting rows from "%s" table'),
174 htmlspecialchars($table)
184 * Prints Html For Export Options Method
188 function PMA_getHtmlForExportOptionsMethod()
191 if (isset($_GET['quick_or_custom'])) {
192 $export_method = $_GET['quick_or_custom'];
194 $export_method = $cfg['Export']['method'];
197 $html = '<div class="exportoptions" id="quick_or_custom">';
198 $html .= '<h3>' . __('Export Method:') . '</h3>';
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"';
207 $html .= '<label for ="radio_quick_export">';
208 $html .= __('Quick - display only the minimal options');
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"';
219 $html .= '<label for="radio_custom_export">';
220 $html .= __('Custom - display all possible options');
231 * Prints Html For Export Options Selection
233 * @param String $export_type Selected Export Type
234 * @param String $multi_values Export Options
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;
255 * Prints Html For Export Options Format
257 * @param String $export_list Export List
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');
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">';
272 'Scroll down to fill in the options for the selected format '
273 . 'and ignore the options for other formats.'
276 $html .= PMA_pluginGetOptions('Export', $export_list);
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();
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" />';
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
308 function PMA_getHtmlForExportOptionsRows($db, $table, $unlim_num_rows)
310 $html = '<div class="exportoptions" id="rows">';
311 $html .= '<h3>' . __('Rows:') . '</h3>';
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"';
319 $html .= '<label for ="radio_allrows_0">' . __('Dump some row(s)') . '</label>';
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;
329 $html .= PMA_Table
::countRecords($db, $table);
331 $html .= '" onfocus="this.select()" />';
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']);
341 $html .= '" size="5" onfocus="this.select()" />';
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"';
351 $html .= ' <label for="radio_allrows_1">' . __('Dump all rows') . '</label>';
359 * Prints Html For Export Options Quick Export
363 function PMA_getHtmlForExportOptionsQuickExport()
366 $html = '<div class="exportoptions" id="output_quick_export">';
367 $html .= '<h3>' . __('Output:') . '</h3>';
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');
374 $html .= '<label for="checkbox_quick_dump_onserver">';
376 __('Save on server in the directory <b>%s</b>'),
377 htmlspecialchars(PMA_Util
::userDir($cfg['SaveDir']))
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');
386 $html .= '<label for="checkbox_quick_dump_onserverover">';
387 $html .= __('Overwrite existing file(s)');
397 * Prints Html For Export Options Save Dir
401 function PMA_getHtmlForExportOptionsOutputSaveDir()
405 $html .= '<input type="checkbox" name="onserver" value="saveit" ';
406 $html .= 'id="checkbox_dump_onserver" ';
407 $html .= PMA_exportCheckboxCheck('onserver');
409 $html .= '<label for="checkbox_dump_onserver">';
411 __('Save on server in the directory <b>%s</b>'),
412 htmlspecialchars(PMA_Util
::userDir($cfg['SaveDir']))
417 $html .= '<input type="checkbox" name="onserverover" value="saveitover"';
418 $html .= ' id="checkbox_dump_onserverover" ';
419 $html .= PMA_exportCheckboxCheck('onserver_overwrite');
421 $html .= '<label for="checkbox_dump_onserverover">';
422 $html .= __('Overwrite existing file(s)');
431 * Prints Html For Export Options
433 * @param String $export_type Selected Export Type
437 function PMA_getHtmlForExportOptionsOutputFormat($export_type)
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.'
460 '<a href="' . PMA_linkURL(PMA_getPHPDocLink('function.strftime.php'))
461 . '" target="documentation" title="' . __('Documentation') . '">',
464 $msg->addParam('</a>', false);
465 $msg->addParam($trans);
466 $doc_url = PMA_Util
::getDocuLink('faq', 'faq6-27');
468 '<a href="'. $doc_url . '" target="documentation">',
471 $msg->addParam('</a>', false);
473 $html .= PMA_Util
::showHint($msg);
475 $html .= '<input type="text" name="filename_template" id="filename_template" ';
477 if (isset($_GET['filename_template'])) {
478 $html .= htmlspecialchars($_GET['filename_template']);
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']
495 $html .= htmlspecialchars(
496 $GLOBALS['PMA_Config']->getUserValue(
497 'pma_server_filename_template',
498 $GLOBALS['cfg']['Export']['file_template_server']
505 $html .= '<input type="checkbox" name="remember_template" ';
506 $html .= 'id="checkbox_remember_template" ';
507 $html .= PMA_exportCheckboxCheck('remember_file_template');
509 $html .= '<label for="checkbox_remember_template">';
510 $html .= __('use this for future exports');
517 * Prints Html For Export Options Charset
521 function PMA_getHtmlForExportOptionsOutputCharset()
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)
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>';
541 $html .= '</select></li>';
547 * Prints Html For Export Options Compression
551 function PMA_getHtmlForExportOptionsOutputCompression()
554 if (isset($_GET['compression'])) {
555 $selected_compression = $_GET['compression'];
556 } elseif (isset($cfg['Export']['compression'])) {
557 $selected_compression = $cfg['Export']['compression'];
559 $selected_compression = "none";
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) {
569 $html .= '<label for="compression" class="desc">'
570 . __('Compression:') . '</label>';
571 $html .= '<select id="compression" name="compression">';
572 $html .= '<option value="none">' . __('None') . '</option>';
574 $html .= '<option value="zip" ';
575 if ($selected_compression == "zip") {
576 $html .= 'selected="selected"';
578 $html .= '>' . __('zipped') . '</option>';
581 $html .= '<option value="gzip" ';
582 if ($selected_compression == "gzip") {
583 $html .= 'selected="selected"';
585 $html .= '>' . __('gzipped') . '</option>';
588 $html .= '<option value="bzip2" ';
589 if ($selected_compression == "bzip2") {
590 $html .= 'selected="selected"';
592 $html .= '>' . __('bzipped') . '</option>';
594 $html .= '</select>';
597 $html .= '<input type="hidden" name="compression" value="'
598 . htmlspecialchars($selected_compression) . '" />';
605 * Prints Html For Export Options Radio
609 function PMA_getHtmlForExportOptionsOutputRadio()
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"';
618 $html .= '<label for="radio_view_as_text">'
619 . __('View output as text') . '</label></li>';
624 * Prints Html For Export Options
626 * @param String $export_type Selected Export Type
630 function PMA_getHtmlForExportOptionsOutput($export_type)
633 $html = '<div class="exportoptions" id="output">';
634 $html .= '<h3>' . __('Output:') . '</h3>';
635 $html .= '<ul id="ul_output">';
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');
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);
653 if ($GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE
) {
654 $html .= PMA_getHtmlForExportOptionsOutputCharset();
657 $html .= PMA_getHtmlForExportOptionsOutputCompression();
662 $html .= PMA_getHtmlForExportOptionsOutputRadio();
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
683 function PMA_getHtmlForExportOptions(
684 $export_type, $db, $table, $multi_values,
685 $num_tables, $export_list, $unlim_num_rows
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);