Translated using Weblate (Norwegian Bokmål)
[phpmyadmin.git] / libraries / display_export.lib.php
blobc4a1614e4142f6b9d5689c8e3cd0b94fb78b2c86
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 /**
5 * functions for displaying server, database and table export
7 * @package PhpMyAdmin
8 */
9 use PMA\libraries\Encoding;
10 use PMA\libraries\Message;
11 use PMA\libraries\plugins\ExportPlugin;
12 use PMA\libraries\Response;
13 use PMA\libraries\Table;
14 use PMA\libraries\Template;
15 use PMA\libraries\URL;
17 /**
18 * Outputs appropriate checked statement for checkbox.
20 * @param string $str option name
22 * @return string
24 function PMA_exportCheckboxCheck($str)
26 if (isset($GLOBALS['cfg']['Export'][$str]) && $GLOBALS['cfg']['Export'][$str]) {
27 return ' checked="checked"';
30 return null;
33 /**
34 * Prints Html For Export Selection Options
36 * @param String $tmp_select Tmp selected method of export
38 * @return string
40 function PMA_getHtmlForExportSelectOptions($tmp_select = '')
42 $multi_values = '<div>';
43 $multi_values .= '<a href="#"';
44 $multi_values .= ' onclick="setSelectOptions'
45 . '(\'dump\', \'db_select[]\', true); return false;">';
46 $multi_values .= __('Select all');
47 $multi_values .= '</a>';
48 $multi_values .= ' / ';
49 $multi_values .= '<a href="#"';
50 $multi_values .= ' onclick="setSelectOptions'
51 . '(\'dump\', \'db_select[]\', false); return false;">';
52 $multi_values .= __('Unselect all') . '</a><br />';
54 $multi_values .= '<select name="db_select[]" '
55 . 'id="db_select" size="10" multiple="multiple">';
56 $multi_values .= "\n";
58 // Check if the selected databases are defined in $_GET
59 // (from clicking Back button on export.php)
60 if (isset($_GET['db_select'])) {
61 $_GET['db_select'] = urldecode($_GET['db_select']);
62 $_GET['db_select'] = explode(",", $_GET['db_select']);
65 foreach ($GLOBALS['dblist']->databases as $current_db) {
66 if ($GLOBALS['dbi']->isSystemSchema($current_db, true)) {
67 continue;
69 if (isset($_GET['db_select'])) {
70 if (in_array($current_db, $_GET['db_select'])) {
71 $is_selected = ' selected="selected"';
72 } else {
73 $is_selected = '';
75 } elseif (!empty($tmp_select)) {
76 if (mb_strpos(
77 ' ' . $tmp_select,
78 '|' . $current_db . '|'
79 )) {
80 $is_selected = ' selected="selected"';
81 } else {
82 $is_selected = '';
84 } else {
85 $is_selected = ' selected="selected"';
87 $current_db = htmlspecialchars($current_db);
88 $multi_values .= ' <option value="' . $current_db . '"'
89 . $is_selected . '>' . $current_db . '</option>' . "\n";
90 } // end while
91 $multi_values .= "\n";
92 $multi_values .= '</select></div>';
94 return $multi_values;
97 /**
98 * Prints Html For Export Hidden Input
100 * @param String $export_type Selected Export Type
101 * @param String $db Selected DB
102 * @param String $table Selected Table
103 * @param String $single_table Single Table
104 * @param String $sql_query Sql Query
106 * @return string
108 function PMA_getHtmlForHiddenInput(
109 $export_type, $db, $table, $single_table, $sql_query
111 global $cfg;
112 $html = "";
113 if ($export_type == 'server') {
114 $html .= URL::getHiddenInputs('', '', 1);
115 } elseif ($export_type == 'database') {
116 $html .= URL::getHiddenInputs($db, '', 1);
117 } else {
118 $html .= URL::getHiddenInputs($db, $table, 1);
121 // just to keep this value for possible next display of this form after saving
122 // on server
123 if (!empty($single_table)) {
124 $html .= '<input type="hidden" name="single_table" value="TRUE" />'
125 . "\n";
128 $html .= '<input type="hidden" name="export_type" value="'
129 . $export_type . '" />';
130 $html .= "\n";
132 // If the export method was not set, the default is quick
133 if (isset($_GET['export_method'])) {
134 $cfg['Export']['method'] = $_GET['export_method'];
135 } elseif (! isset($cfg['Export']['method'])) {
136 $cfg['Export']['method'] = 'quick';
138 // The export method (quick, custom or custom-no-form)
139 $html .= '<input type="hidden" name="export_method" value="'
140 . htmlspecialchars($cfg['Export']['method']) . '" />';
142 if (! empty($sql_query)) {
143 $html .= '<input type="hidden" name="sql_query" value="'
144 . htmlspecialchars($sql_query) . '" />' . "\n";
145 } elseif (isset($_GET['sql_query'])) {
146 $html .= '<input type="hidden" name="sql_query" value="'
147 . htmlspecialchars($_GET['sql_query']) . '" />' . "\n";
150 $html .= '<input type="hidden" name="template_id"' . ' value="'
151 . (isset($_GET['template_id'])
152 ? htmlspecialchars($_GET['template_id'])
153 : '')
154 . '" />';
156 return $html;
160 * Prints Html For Export Options Header
162 * @param String $export_type Selected Export Type
163 * @param String $db Selected DB
164 * @param String $table Selected Table
166 * @return string
168 function PMA_getHtmlForExportOptionHeader($export_type, $db, $table)
170 $html = '<div class="exportoptions" id="header">';
171 $html .= '<h2>';
172 $html .= PMA\libraries\Util::getImage('b_export.png', __('Export'));
173 if ($export_type == 'server') {
174 $html .= __('Exporting databases from the current server');
175 } elseif ($export_type == 'database') {
176 $html .= sprintf(
177 __('Exporting tables from "%s" database'),
178 htmlspecialchars($db)
180 } else {
181 $html .= sprintf(
182 __('Exporting rows from "%s" table'),
183 htmlspecialchars($table)
186 $html .= '</h2>';
187 $html .= '</div>';
189 return $html;
193 * Returns HTML for export template operations
195 * @param string $export_type export type - server, database, or table
197 * @return string HTML for export template operations
199 function PMA_getHtmlForExportTemplateLoading($export_type)
201 $html = '<div class="exportoptions" id="export_templates">';
202 $html .= '<h3>' . __('Export templates:') . '</h3>';
204 $html .= '<div class="floatleft">';
205 $html .= '<form method="post" action="tbl_export.php" id="newTemplateForm"'
206 . ' class="ajax">';
207 $html .= '<h4>' . __('New template:') . '</h4>';
208 $html .= '<input type="text" name="templateName" id="templateName" '
209 . 'maxlength="64"' . 'required="required" '
210 . 'placeholder="' . __('Template name') . '" />';
211 $html .= '<input type="submit" name="createTemplate" id="createTemplate" '
212 . 'value="' . __('Create') . '" />';
213 $html .= '</form>';
214 $html .= '</div>';
216 $html .= '<div class="floatleft" style="margin-left: 50px;">';
217 $html .= '<form method="post" action="tbl_export.php"'
218 . ' id="existingTemplatesForm" class="ajax">';
219 $html .= '<h4>' . __('Existing templates:') . '</h4>';
220 $html .= '<label for="template">' . __('Template:') . '</label>';
221 $html .= '<select required="required" name="template" id="template">';
222 $html .= PMA_getOptionsForExportTemplates($export_type);
223 $html .= '</select>';
224 $html .= '<input type="submit" name="updateTemplate" '
225 . 'id="updateTemplate" value="' . __('Update') . '" />';
226 $html .= '<input type="submit" name="deleteTemplate" '
227 . 'id="deleteTemplate" value="' . __('Delete') . '" />';
228 $html .= '</form>';
229 $html .= '</div>';
231 $html .= '<div class="clearfloat"></div>';
233 $html .= '</div>';
235 return $html;
239 * Returns HTML for the options in teplate dropdown
241 * @param string $export_type export type - server, database, or table
243 * @return string HTML for the options in teplate dropdown
245 function PMA_getOptionsForExportTemplates($export_type)
247 $ret = '<option value="">-- ' . __('Select a template') . ' --</option>';
249 // Get the relation settings
250 $cfgRelation = PMA_getRelationsParam();
252 $query = "SELECT `id`, `template_name` FROM "
253 . PMA\libraries\Util::backquote($cfgRelation['db']) . '.'
254 . PMA\libraries\Util::backquote($cfgRelation['export_templates'])
255 . " WHERE `username` = "
256 . "'" . $GLOBALS['dbi']->escapeString($GLOBALS['cfg']['Server']['user'])
257 . "' AND `export_type` = '" . $GLOBALS['dbi']->escapeString($export_type) . "'"
258 . " ORDER BY `template_name`;";
260 $result = PMA_queryAsControlUser($query);
261 if (!$result) {
262 return $ret;
265 while ($row = $GLOBALS['dbi']->fetchAssoc($result, $GLOBALS['controllink'])) {
266 $ret .= '<option value="' . htmlspecialchars($row['id']) . '"';
267 if (!empty($_GET['template_id']) && $_GET['template_id'] == $row['id']) {
268 $ret .= ' selected="selected"';
270 $ret .= '>';
271 $ret .= htmlspecialchars($row['template_name']) . '</option>';
274 return $ret;
278 * Prints Html For Export Options Method
280 * @return string
282 function PMA_getHtmlForExportOptionsMethod()
284 global $cfg;
285 if (isset($_GET['quick_or_custom'])) {
286 $export_method = $_GET['quick_or_custom'];
287 } else {
288 $export_method = $cfg['Export']['method'];
291 if ($export_method == 'custom-no-form') {
292 return '';
295 $html = '<div class="exportoptions" id="quick_or_custom">';
296 $html .= '<h3>' . __('Export method:') . '</h3>';
297 $html .= '<ul>';
298 $html .= '<li>';
299 $html .= '<input type="radio" name="quick_or_custom" value="quick" '
300 . ' id="radio_quick_export"';
301 if ($export_method == 'quick') {
302 $html .= ' checked="checked"';
304 $html .= ' />';
305 $html .= '<label for ="radio_quick_export">';
306 $html .= __('Quick - display only the minimal options');
307 $html .= '</label>';
308 $html .= '</li>';
310 $html .= '<li>';
311 $html .= '<input type="radio" name="quick_or_custom" value="custom" '
312 . ' id="radio_custom_export"';
313 if ($export_method == 'custom') {
314 $html .= ' checked="checked"';
316 $html .= ' />';
317 $html .= '<label for="radio_custom_export">';
318 $html .= __('Custom - display all possible options');
319 $html .= '</label>';
320 $html .= '</li>';
322 $html .= '</ul>';
323 $html .= '</div>';
325 return $html;
329 * Prints Html For Export Options Selection
331 * @param String $export_type Selected Export Type
332 * @param String $multi_values Export Options
334 * @return string
336 function PMA_getHtmlForExportOptionsSelection($export_type, $multi_values)
338 $html = '<div class="exportoptions" id="databases_and_tables">';
339 if ($export_type == 'server') {
340 $html .= '<h3>' . __('Databases:') . '</h3>';
341 } else if ($export_type == 'database') {
342 $html .= '<h3>' . __('Tables:') . '</h3>';
344 if (! empty($multi_values)) {
345 $html .= $multi_values;
347 $html .= '</div>';
349 return $html;
353 * Prints Html For Export Options Format dropdown
355 * @param ExportPlugin[] $export_list Export List
357 * @return string
359 function PMA_getHtmlForExportOptionsFormatDropdown($export_list)
361 $html = '<div class="exportoptions" id="format">';
362 $html .= '<h3>' . __('Format:') . '</h3>';
363 $html .= PMA_pluginGetChoice('Export', 'what', $export_list, 'format');
364 $html .= '</div>';
365 return $html;
369 * Prints Html For Export Options Format-specific options
371 * @param ExportPlugin[] $export_list Export List
373 * @return string
375 function PMA_getHtmlForExportOptionsFormat($export_list)
377 $html = '<div class="exportoptions" id="format_specific_opts">';
378 $html .= '<h3>' . __('Format-specific options:') . '</h3>';
379 $html .= '<p class="no_js_msg" id="scroll_to_options_msg">';
380 $html .= __(
381 'Scroll down to fill in the options for the selected format '
382 . 'and ignore the options for other formats.'
384 $html .= '</p>';
385 $html .= PMA_pluginGetOptions('Export', $export_list);
386 $html .= '</div>';
388 if (Encoding::canConvertKanji()) {
389 // Japanese encoding setting
390 $html .= '<div class="exportoptions" id="kanji_encoding">';
391 $html .= '<h3>' . __('Encoding Conversion:') . '</h3>';
392 $html .= Encoding::kanjiEncodingForm();
393 $html .= '</div>';
396 $html .= '<div class="exportoptions" id="submit">';
398 $html .= PMA\libraries\Util::getExternalBug(
399 __('SQL compatibility mode'), 'mysql', '50027', '14515'
401 global $cfg;
402 if ($cfg['ExecTimeLimit'] > 0) {
403 $html .= '<input type="submit" value="' . __('Go')
404 . '" id="buttonGo" onclick="check_time_out('
405 . $cfg['ExecTimeLimit'] . ')"/>';
406 } else {
407 // if the time limit set is zero, then time out won't occur
408 // So no need to check for time out.
409 $html .= '<input type="submit" value="' . __('Go') . '" id="buttonGo" />';
411 $html .= '</div>';
413 return $html;
416 * Prints Html For Export Options Rows
418 * @param String $db Selected DB
419 * @param String $table Selected Table
420 * @param String $unlim_num_rows Num of Rows
422 * @return string
424 function PMA_getHtmlForExportOptionsRows($db, $table, $unlim_num_rows)
426 $html = '<div class="exportoptions" id="rows">';
427 $html .= '<h3>' . __('Rows:') . '</h3>';
428 $html .= '<ul>';
429 $html .= '<li>';
430 $html .= '<input type="radio" name="allrows" value="0" id="radio_allrows_0"';
431 if (isset($_GET['allrows']) && $_GET['allrows'] == 0) {
432 $html .= ' checked="checked"';
434 $html .= '/>';
435 $html .= '<label for ="radio_allrows_0">' . __('Dump some row(s)') . '</label>';
436 $html .= '<ul>';
437 $html .= '<li>';
438 $html .= '<label for="limit_to">' . __('Number of rows:') . '</label>';
439 $html .= '<input type="text" id="limit_to" name="limit_to" size="5" value="';
440 if (isset($_GET['limit_to'])) {
441 $html .= htmlspecialchars($_GET['limit_to']);
442 } elseif (!empty($unlim_num_rows)) {
443 $html .= $unlim_num_rows;
444 } else {
445 $_table = new Table($table, $db);
446 $html .= $_table->countRecords();
448 $html .= '" onfocus="this.select()" />';
449 $html .= '</li>';
450 $html .= '<li>';
451 $html .= '<label for="limit_from">' . __('Row to begin at:') . '</label>';
452 $html .= '<input type="text" id="limit_from" name="limit_from" value="';
453 if (isset($_GET['limit_from'])) {
454 $html .= htmlspecialchars($_GET['limit_from']);
455 } else {
456 $html .= '0';
458 $html .= '" size="5" onfocus="this.select()" />';
459 $html .= '</li>';
460 $html .= '</ul>';
461 $html .= '</li>';
462 $html .= '<li>';
463 $html .= '<input type="radio" name="allrows" value="1" id="radio_allrows_1"';
464 if (! isset($_GET['allrows']) || $_GET['allrows'] == 1) {
465 $html .= ' checked="checked"';
467 $html .= '/>';
468 $html .= ' <label for="radio_allrows_1">' . __('Dump all rows') . '</label>';
469 $html .= '</li>';
470 $html .= '</ul>';
471 $html .= '</div>';
472 return $html;
476 * Prints Html For Export Options Quick Export
478 * @return string
480 function PMA_getHtmlForExportOptionsQuickExport()
482 global $cfg;
483 $html = '<div class="exportoptions" id="output_quick_export">';
484 $html .= '<h3>' . __('Output:') . '</h3>';
485 $html .= '<ul>';
486 $html .= '<li>';
487 $html .= '<input type="checkbox" name="quick_export_onserver" value="saveit" ';
488 $html .= 'id="checkbox_quick_dump_onserver" ';
489 $html .= PMA_exportCheckboxCheck('quick_export_onserver');
490 $html .= '/>';
491 $html .= '<label for="checkbox_quick_dump_onserver">';
492 $html .= sprintf(
493 __('Save on server in the directory <b>%s</b>'),
494 htmlspecialchars(PMA\libraries\Util::userDir($cfg['SaveDir']))
496 $html .= '</label>';
497 $html .= '</li>';
498 $html .= '<li>';
499 $html .= '<input type="checkbox" name="quick_export_onserver_overwrite" ';
500 $html .= 'value="saveitover" id="checkbox_quick_dump_onserver_overwrite" ';
501 $html .= PMA_exportCheckboxCheck('quick_export_onserver_overwrite');
502 $html .= '/>';
503 $html .= '<label for="checkbox_quick_dump_onserver_overwrite">';
504 $html .= __('Overwrite existing file(s)');
505 $html .= '</label>';
506 $html .= '</li>';
507 $html .= '</ul>';
508 $html .= '</div>';
510 return $html;
514 * Prints Html For Export Options Save Dir
516 * @return string
518 function PMA_getHtmlForExportOptionsOutputSaveDir()
520 global $cfg;
521 $html = '<li>';
522 $html .= '<input type="checkbox" name="onserver" value="saveit" ';
523 $html .= 'id="checkbox_dump_onserver" ';
524 $html .= PMA_exportCheckboxCheck('onserver');
525 $html .= '/>';
526 $html .= '<label for="checkbox_dump_onserver">';
527 $html .= sprintf(
528 __('Save on server in the directory <b>%s</b>'),
529 htmlspecialchars(PMA\libraries\Util::userDir($cfg['SaveDir']))
531 $html .= '</label>';
532 $html .= '</li>';
533 $html .= '<li>';
534 $html .= '<input type="checkbox" name="onserver_overwrite" value="saveitover"';
535 $html .= ' id="checkbox_dump_onserver_overwrite" ';
536 $html .= PMA_exportCheckboxCheck('onserver_overwrite');
537 $html .= '/>';
538 $html .= '<label for="checkbox_dump_onserver_overwrite">';
539 $html .= __('Overwrite existing file(s)');
540 $html .= '</label>';
541 $html .= '</li>';
543 return $html;
548 * Prints Html For Export Options
550 * @param String $export_type Selected Export Type
552 * @return string
554 function PMA_getHtmlForExportOptionsOutputFormat($export_type)
556 $html = '<li>';
557 $html .= '<label for="filename_template" class="desc">';
558 $html .= __('File name template:');
559 $trans = new Message;
560 $trans->addText(__('@SERVER@ will become the server name'));
561 if ($export_type == 'database' || $export_type == 'table') {
562 $trans->addText(__(', @DATABASE@ will become the database name'));
563 if ($export_type == 'table') {
564 $trans->addText(__(', @TABLE@ will become the table name'));
568 $msg = new Message(
570 'This value is interpreted using %1$sstrftime%2$s, '
571 . 'so you can use time formatting strings. '
572 . 'Additionally the following transformations will happen: %3$s. '
573 . 'Other text will be kept as is. See the %4$sFAQ%5$s for details.'
576 $msg->addParamHtml(
577 '<a href="' . PMA_linkURL(PMA_getPHPDocLink('function.strftime.php'))
578 . '" target="documentation" title="' . __('Documentation') . '">'
580 $msg->addParamHtml('</a>');
581 $msg->addParam($trans);
582 $doc_url = PMA\libraries\Util::getDocuLink('faq', 'faq6-27');
583 $msg->addParamHtml(
584 '<a href="' . $doc_url . '" target="documentation">'
586 $msg->addParamHtml('</a>');
588 $html .= PMA\libraries\Util::showHint($msg);
589 $html .= '</label>';
590 $html .= '<input type="text" name="filename_template" id="filename_template" ';
591 $html .= ' value="';
592 if (isset($_GET['filename_template'])) {
593 $html .= htmlspecialchars($_GET['filename_template']);
594 } else {
595 if ($export_type == 'database') {
596 $html .= htmlspecialchars(
597 $GLOBALS['PMA_Config']->getUserValue(
598 'pma_db_filename_template',
599 $GLOBALS['cfg']['Export']['file_template_database']
602 } elseif ($export_type == 'table') {
603 $html .= htmlspecialchars(
604 $GLOBALS['PMA_Config']->getUserValue(
605 'pma_table_filename_template',
606 $GLOBALS['cfg']['Export']['file_template_table']
609 } else {
610 $html .= htmlspecialchars(
611 $GLOBALS['PMA_Config']->getUserValue(
612 'pma_server_filename_template',
613 $GLOBALS['cfg']['Export']['file_template_server']
618 $html .= '"';
619 $html .= '/>';
620 $html .= '<input type="checkbox" name="remember_template" ';
621 $html .= 'id="checkbox_remember_template" ';
622 $html .= PMA_exportCheckboxCheck('remember_file_template');
623 $html .= '/>';
624 $html .= '<label for="checkbox_remember_template">';
625 $html .= __('use this for future exports');
626 $html .= '</label>';
627 $html .= '</li>';
628 return $html;
632 * Prints Html For Export Options Charset
634 * @return string
636 function PMA_getHtmlForExportOptionsOutputCharset()
638 global $cfg;
639 $html = ' <li><label for="select_charset" class="desc">'
640 . __('Character set of the file:') . '</label>' . "\n";
641 $html .= '<select id="select_charset" name="charset" size="1">';
642 foreach (Encoding::listEncodings() as $temp_charset) {
643 $html .= '<option value="' . $temp_charset . '"';
644 if (isset($_GET['charset'])
645 && ($_GET['charset'] != $temp_charset)
647 $html .= '';
648 } elseif ((empty($cfg['Export']['charset']) && $temp_charset == 'utf-8')
649 || $temp_charset == $cfg['Export']['charset']
651 $html .= ' selected="selected"';
653 $html .= '>' . $temp_charset . '</option>';
654 } // end foreach
655 $html .= '</select></li>';
657 return $html;
661 * Prints Html For Export Options Compression
663 * @return string
665 function PMA_getHtmlForExportOptionsOutputCompression()
667 global $cfg;
668 if (isset($_GET['compression'])) {
669 $selected_compression = $_GET['compression'];
670 } elseif (isset($cfg['Export']['compression'])) {
671 $selected_compression = $cfg['Export']['compression'];
672 } else {
673 $selected_compression = "none";
676 // Since separate files export works with ZIP only
677 if (isset($cfg['Export']['as_separate_files'])
678 && $cfg['Export']['as_separate_files']
680 $selected_compression = "zip";
683 $html = "";
684 // zip and gzip encode features
685 $is_zip = ($cfg['ZipDump'] && @function_exists('gzcompress'));
686 $is_gzip = ($cfg['GZipDump'] && @function_exists('gzencode'));
687 if ($is_zip || $is_gzip) {
688 $html .= '<li>';
689 $html .= '<label for="compression" class="desc">'
690 . __('Compression:') . '</label>';
691 $html .= '<select id="compression" name="compression">';
692 $html .= '<option value="none">' . __('None') . '</option>';
693 if ($is_zip) {
694 $html .= '<option value="zip" ';
695 if ($selected_compression == "zip") {
696 $html .= 'selected="selected"';
698 $html .= '>' . __('zipped') . '</option>';
700 if ($is_gzip) {
701 $html .= '<option value="gzip" ';
702 if ($selected_compression == "gzip") {
703 $html .= 'selected="selected"';
705 $html .= '>' . __('gzipped') . '</option>';
707 $html .= '</select>';
708 $html .= '</li>';
709 } else {
710 $html .= '<input type="hidden" name="compression" value="'
711 . htmlspecialchars($selected_compression) . '" />';
714 return $html;
718 * Prints Html For Export Options Radio
720 * @return string
722 function PMA_getHtmlForExportOptionsOutputRadio()
724 $html = '<li>';
725 $html .= '<input type="radio" id="radio_view_as_text" '
726 . ' name="output_format" value="astext" ';
727 if (isset($_GET['repopulate']) || $GLOBALS['cfg']['Export']['asfile'] == false) {
728 $html .= 'checked="checked"';
730 $html .= '/>';
731 $html .= '<label for="radio_view_as_text">'
732 . __('View output as text') . '</label></li>';
733 return $html;
737 * Prints Html For Export Options Checkbox - Separate files
739 * @param String $export_type Selected Export Type
741 * @return string
743 function PMA_getHtmlForExportOptionsOutputSeparateFiles($export_type)
745 $html = '<li>';
746 $html .= '<input type="checkbox" id="checkbox_as_separate_files" '
747 . PMA_exportCheckboxCheck('as_separate_files')
748 . ' name="as_separate_files" value="' . $export_type . '" />';
749 $html .= '<label for="checkbox_as_separate_files">';
751 if ($export_type == 'server') {
752 $html .= __('Export databases as separate files');
753 } elseif ($export_type == 'database') {
754 $html .= __('Export tables as separate files');
757 $html .= '</label></li>';
759 return $html;
763 * Prints Html For Export Options
765 * @param String $export_type Selected Export Type
767 * @return string
769 function PMA_getHtmlForExportOptionsOutput($export_type)
771 global $cfg;
772 $html = '<div class="exportoptions" id="output">';
773 $html .= '<h3>' . __('Output:') . '</h3>';
774 $html .= '<ul id="ul_output">';
775 $html .= '<li><input type="checkbox" id="btn_alias_config" ';
776 if (isset($_SESSION['tmpval']['aliases'])
777 && !PMA_emptyRecursive($_SESSION['tmpval']['aliases'])
779 $html .= 'checked="checked"';
781 unset($_SESSION['tmpval']['aliases']);
782 $html .= '/>';
783 $html .= '<label for="btn_alias_config">';
784 $html .= __('Rename exported databases/tables/columns');
785 $html .= '</label></li>';
787 if ($export_type != 'server') {
788 $html .= '<li>';
789 $html .= '<input type="checkbox" name="lock_tables"';
790 $html .= ' value="something" id="checkbox_lock_tables"';
791 if (! isset($_GET['repopulate'])) {
792 $html .= PMA_exportCheckboxCheck('lock_tables') . '/>';
793 } elseif (isset($_GET['lock_tables'])) {
794 $html .= ' checked="checked"';
796 $html .= '<label for="checkbox_lock_tables">';
797 $html .= sprintf(__('Use %s statement'), '<code>LOCK TABLES</code>');
798 $html .= '</label></li>';
801 $html .= '<li>';
802 $html .= '<input type="radio" name="output_format" value="sendit" ';
803 $html .= 'id="radio_dump_asfile" ';
804 if (!isset($_GET['repopulate'])) {
805 $html .= PMA_exportCheckboxCheck('asfile');
807 $html .= '/>';
808 $html .= '<label for="radio_dump_asfile">'
809 . __('Save output to a file') . '</label>';
810 $html .= '<ul id="ul_save_asfile">';
811 if (isset($cfg['SaveDir']) && !empty($cfg['SaveDir'])) {
812 $html .= PMA_getHtmlForExportOptionsOutputSaveDir();
815 $html .= PMA_getHtmlForExportOptionsOutputFormat($export_type);
817 // charset of file
818 if (Encoding::isSupported()) {
819 $html .= PMA_getHtmlForExportOptionsOutputCharset();
820 } // end if
822 $html .= PMA_getHtmlForExportOptionsOutputCompression();
824 if ($export_type == 'server'
825 || $export_type == 'database'
827 $html .= PMA_getHtmlForExportOptionsOutputSeparateFiles($export_type);
830 $html .= '</ul>';
831 $html .= '</li>';
833 $html .= PMA_getHtmlForExportOptionsOutputRadio();
835 $html .= '</ul>';
838 * @todo use sprintf() for better translatability, while keeping the
839 * <label></label> principle (for screen readers)
841 $html .= '<label for="maxsize">'
842 . __('Skip tables larger than') . '</label>';
843 $html .= '<input type="text" id="maxsize" name="maxsize" size="4">' . __('MiB');
845 $html .= '</div>';
847 return $html;
851 * Prints Html For Export Options
853 * @param String $export_type Selected Export Type
854 * @param String $db Selected DB
855 * @param String $table Selected Table
856 * @param String $multi_values Export selection
857 * @param String $num_tables number of tables
858 * @param ExportPlugin[] $export_list Export List
859 * @param String $unlim_num_rows Number of Rows
861 * @return string
863 function PMA_getHtmlForExportOptions(
864 $export_type, $db, $table, $multi_values,
865 $num_tables, $export_list, $unlim_num_rows
867 global $cfg;
868 $html = PMA_getHtmlForExportOptionsMethod();
869 $html .= PMA_getHtmlForExportOptionsFormatDropdown($export_list);
870 $html .= PMA_getHtmlForExportOptionsSelection($export_type, $multi_values);
872 $_table = new Table($table, $db);
873 if (strlen($table) > 0 && empty($num_tables) && ! $_table->isMerge()) {
874 $html .= PMA_getHtmlForExportOptionsRows($db, $table, $unlim_num_rows);
877 if (isset($cfg['SaveDir']) && !empty($cfg['SaveDir'])) {
878 $html .= PMA_getHtmlForExportOptionsQuickExport();
881 $html .= PMA_getHtmlForAliasModalDialog();
882 $html .= PMA_getHtmlForExportOptionsOutput($export_type);
883 $html .= PMA_getHtmlForExportOptionsFormat($export_list);
884 return $html;
888 * Generate Html For currently defined aliases
890 * @return string
892 function PMA_getHtmlForCurrentAlias()
894 $result = '<table id="alias_data"><thead><tr><th colspan="4">'
895 . __('Defined aliases')
896 . '</th></tr></thead><tbody>';
898 $template = Template::get('export/alias_item');
899 if (isset($_SESSION['tmpval']['aliases'])) {
900 foreach ($_SESSION['tmpval']['aliases'] as $db => $db_data) {
901 if (isset($db_data['alias'])) {
902 $result .= $template->render(array(
903 'type' => _pgettext('Alias', 'Database'),
904 'name' => $db,
905 'field' => 'aliases[' . $db . '][alias]',
906 'value' => $db_data['alias'],
909 if (! isset($db_data['tables'])) {
910 continue;
912 foreach ($db_data['tables'] as $table => $table_data) {
913 if (isset($table_data['alias'])) {
914 $result .= $template->render(array(
915 'type' => _pgettext('Alias', 'Table'),
916 'name' => $db . '.' . $table,
917 'field' => 'aliases[' . $db . '][tables][' . $table . '][alias]',
918 'value' => $table_data['alias'],
921 if (! isset($table_data['columns'])) {
922 continue;
924 foreach ($table_data['columns'] as $column => $column_name) {
925 $result .= $template->render(array(
926 'type' => _pgettext('Alias', 'Column'),
927 'name' => $db . '.' . $table . '.'. $column,
928 'field' => 'aliases[' . $db . '][tables][' . $table . '][colums][' . $column . ']',
929 'value' => $column_name,
936 // Empty row for javascript manipulations
937 $result .= '</tbody><tfoot class="hide">' . $template->render(array(
938 'type' => '', 'name' => '', 'field' => 'aliases_new', 'value' => ''
939 )) . '</tfoot>';
941 return $result . '</table>';
945 * Generate Html For Alias Modal Dialog
947 * @return string
949 function PMA_getHtmlForAliasModalDialog()
951 // In case of server export, the following list of
952 // databases are not shown in the list.
953 $dbs_not_allowed = array(
954 'information_schema',
955 'performance_schema',
956 'mysql'
958 // Fetch Columns info
959 // Server export does not have db set.
960 $title = __('Rename exported databases/tables/columns');
962 $html = '<div id="alias_modal" class="hide" title="' . $title . '">';
963 $html .= PMA_getHtmlForCurrentAlias();
964 $html .= Template::get('export/alias_add')->render();
966 $html .= '</div>';
967 return $html;
971 * Gets HTML to display export dialogs
973 * @param String $export_type export type: server|database|table
974 * @param String $db selected DB
975 * @param String $table selected table
976 * @param String $sql_query SQL query
977 * @param Int $num_tables number of tables
978 * @param Int $unlim_num_rows unlimited number of rows
979 * @param String $multi_values selector options
981 * @return string $html
983 function PMA_getExportDisplay(
984 $export_type, $db, $table, $sql_query, $num_tables,
985 $unlim_num_rows, $multi_values
987 $cfgRelation = PMA_getRelationsParam();
989 if (isset($_REQUEST['single_table'])) {
990 $GLOBALS['single_table'] = $_REQUEST['single_table'];
993 include_once './libraries/file_listing.lib.php';
994 include_once './libraries/plugin_interface.lib.php';
995 include_once './libraries/display_export.lib.php';
997 /* Scan for plugins */
998 /* @var $export_list ExportPlugin[] */
999 $export_list = PMA_getPlugins(
1000 "export",
1001 'libraries/plugins/export/',
1002 array(
1003 'export_type' => $export_type,
1004 'single_table' => isset($GLOBALS['single_table'])
1008 /* Fail if we didn't find any plugin */
1009 if (empty($export_list)) {
1010 Message::error(
1011 __('Could not load export plugins, please check your installation!')
1012 )->display();
1013 exit;
1016 $html = PMA_getHtmlForExportOptionHeader($export_type, $db, $table);
1018 if ($cfgRelation['exporttemplateswork']) {
1019 $html .= PMA_getHtmlForExportTemplateLoading($export_type);
1022 $html .= '<form method="post" action="export.php" '
1023 . ' name="dump" class="disableAjax">';
1025 //output Hidden Inputs
1026 $single_table_str = isset($GLOBALS['single_table']) ? $GLOBALS['single_table']
1027 : '';
1028 $html .= PMA_getHtmlForHiddenInput(
1029 $export_type,
1030 $db,
1031 $table,
1032 $single_table_str,
1033 $sql_query
1036 //output Export Options
1037 $html .= PMA_getHtmlForExportOptions(
1038 $export_type,
1039 $db,
1040 $table,
1041 $multi_values,
1042 $num_tables,
1043 $export_list,
1044 $unlim_num_rows
1047 $html .= '</form>';
1048 return $html;
1052 * Handles export template actions
1054 * @param array $cfgRelation Relation configuration
1056 * @return void
1058 function PMA_handleExportTemplateActions($cfgRelation)
1060 if (isset($_REQUEST['templateId'])) {
1061 $id = $GLOBALS['dbi']->escapeString($_REQUEST['templateId']);
1062 } else {
1063 $id = '';
1066 $templateTable = PMA\libraries\Util::backquote($cfgRelation['db']) . '.'
1067 . PMA\libraries\Util::backquote($cfgRelation['export_templates']);
1068 $user = $GLOBALS['dbi']->escapeString($GLOBALS['cfg']['Server']['user']);
1070 switch ($_REQUEST['templateAction']) {
1071 case 'create':
1072 $query = "INSERT INTO " . $templateTable . "("
1073 . " `username`, `export_type`,"
1074 . " `template_name`, `template_data`"
1075 . ") VALUES ("
1076 . "'" . $user . "', "
1077 . "'" . $GLOBALS['dbi']->escapeString($_REQUEST['exportType'])
1078 . "', '" . $GLOBALS['dbi']->escapeString($_REQUEST['templateName'])
1079 . "', '" . $GLOBALS['dbi']->escapeString($_REQUEST['templateData'])
1080 . "');";
1081 break;
1082 case 'load':
1083 $query = "SELECT `template_data` FROM " . $templateTable
1084 . " WHERE `id` = " . $id . " AND `username` = '" . $user . "'";
1085 break;
1086 case 'update':
1087 $query = "UPDATE " . $templateTable . " SET `template_data` = "
1088 . "'" . $GLOBALS['dbi']->escapeString($_REQUEST['templateData']) . "'"
1089 . " WHERE `id` = " . $id . " AND `username` = '" . $user . "'";
1090 break;
1091 case 'delete':
1092 $query = "DELETE FROM " . $templateTable
1093 . " WHERE `id` = " . $id . " AND `username` = '" . $user . "'";
1094 break;
1095 default:
1096 $query = '';
1097 break;
1100 $result = PMA_queryAsControlUser($query, false);
1102 $response = Response::getInstance();
1103 if (! $result) {
1104 $error = $GLOBALS['dbi']->getError($GLOBALS['controllink']);
1105 $response->setRequestStatus(false);
1106 $response->addJSON('message', $error);
1107 exit;
1110 $response->setRequestStatus(true);
1111 if ('create' == $_REQUEST['templateAction']) {
1112 $response->addJSON(
1113 'data',
1114 PMA_getOptionsForExportTemplates($_REQUEST['exportType'])
1116 } elseif ('load' == $_REQUEST['templateAction']) {
1117 $data = null;
1118 while ($row = $GLOBALS['dbi']->fetchAssoc(
1119 $result, $GLOBALS['controllink']
1120 )) {
1121 $data = $row['template_data'];
1123 $response->addJSON('data', $data);
1125 $GLOBALS['dbi']->freeResult($result);