Merge pull request #431 from xmujay/0609_monitor
[phpmyadmin/aamir.git] / libraries / display_export.lib.php
blobbe3c3bc43333f1f1dc5fae9b77d3f6cb22239d86
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Displays export tab.
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 // Get relations & co. status
13 $cfgRelation = PMA_getRelationsParam();
15 if (isset($_REQUEST['single_table'])) {
16 $GLOBALS['single_table'] = $_REQUEST['single_table'];
19 require_once './libraries/file_listing.lib.php';
20 require_once './libraries/plugin_interface.lib.php';
22 /**
23 * Outputs appropriate checked statement for checkbox.
25 * @param string $str option name
27 * @return void
29 function PMA_exportCheckboxCheck($str)
31 if (isset($GLOBALS['cfg']['Export'][$str]) && $GLOBALS['cfg']['Export'][$str]) {
32 return ' checked="checked"';
36 /* Scan for plugins */
37 $export_list = PMA_getPlugins(
38 "export",
39 'libraries/plugins/export/',
40 array(
41 'export_type' => $export_type,
42 'single_table' => isset($single_table)
46 /* Fail if we didn't find any plugin */
47 if (empty($export_list)) {
48 PMA_Message::error(
49 __('Could not load export plugins, please check your installation!')
50 )->display();
51 exit;
54 $html = "";
55 $html .= '<form method="post" action="export.php" '
56 . ' name="dump" class="disableAjax">';
58 if ($export_type == 'server') {
59 $html .= PMA_generate_common_hidden_inputs('', '', 1);
60 } elseif ($export_type == 'database') {
61 $html .= PMA_generate_common_hidden_inputs($db, '', 1);
62 } else {
63 $html .= PMA_generate_common_hidden_inputs($db, $table, 1);
66 // just to keep this value for possible next display of this form after saving
67 // on server
68 if (isset($single_table)) {
69 $html .= '<input type="hidden" name="single_table" value="TRUE" />'
70 . "\n";
73 $html .= '<input type="hidden" name="export_type" value="'
74 . $export_type . '" />';
75 $html .= "\n";
77 // If the export method was not set, the default is quick
78 if (isset($_GET['export_method'])) {
79 $cfg['Export']['method'] = $_GET['export_method'];
80 } elseif (! isset($cfg['Export']['method'])) {
81 $cfg['Export']['method'] = 'quick';
83 // The export method (quick, custom or custom-no-form)
84 $html .= '<input type="hidden" name="export_method" value="'
85 . htmlspecialchars($cfg['Export']['method']) . '" />';
88 if (isset($_GET['sql_query'])) {
89 $html .= '<input type="hidden" name="sql_query" value="'
90 . htmlspecialchars($_GET['sql_query']) . '" />' . "\n";
91 } elseif (! empty($sql_query)) {
92 $html .= '<input type="hidden" name="sql_query" value="'
93 . htmlspecialchars($sql_query) . '" />' . "\n";
96 $html .= '<div class="exportoptions" id="header">';
97 $html .= '<h2>';
98 $html .= PMA_Util::getImage('b_export.png', __('Export'));
99 if ($export_type == 'server') {
100 $html .= __('Exporting databases from the current server');
101 } elseif ($export_type == 'database') {
102 $html .= sprintf(
103 __('Exporting tables from "%s" database'),
104 htmlspecialchars($db)
106 } else {
107 $html .= sprintf(
108 __('Exporting rows from "%s" table'),
109 htmlspecialchars($table)
112 $html .= '</h2>';
113 $html .= '</div>';
115 if (isset($_GET['quick_or_custom'])) {
116 $export_method = $_GET['quick_or_custom'];
117 } else {
118 $export_method = $cfg['Export']['method'];
121 $html .= '<div class="exportoptions" id="quick_or_custom">';
122 $html .= '<h3>' . __('Export Method:') . '</h3>';
123 $html .= '<ul>';
124 $html .= '<li>';
125 $html .= '<input type="radio" name="quick_or_custom" value="quick" '
126 . ' id="radio_quick_export"';
127 if ($export_method == 'quick' || $export_method == 'quick_no_form') {
128 $html .= ' checked="checked"';
130 $html .= ' />';
131 $html .= '<label for ="radio_quick_export">';
132 $html .= __('Quick - display only the minimal options');
133 $html .= '</label>';
134 $html .= '</li>';
136 $html .= '<li>';
137 $html .= '<input type="radio" name="quick_or_custom" value="custom" '
138 . ' id="radio_custom_export"';
139 if ($export_method == 'custom' || $export_method == 'custom_no_form') {
140 $html .= ' checked="checked"';
142 $html .= ' />';
143 $html .= '<label for="radio_custom_export">';
144 $html .= __('Custom - display all possible options');
145 $html .= '</label>';
146 $html .= '</li>';
148 $html .= '</ul>';
149 $html .= '</div>';
151 $html .= '<div class="exportoptions" id="databases_and_tables">';
152 if ($export_type == 'server') {
153 $html .= '<h3>' . __('Database(s):') . '</h3>';
154 } else if ($export_type == 'database') {
155 $html .= '<h3>' . __('Table(s):') . '</h3>';
157 if (! empty($multi_values)) {
158 $html .= $multi_values;
160 $html .= '</div>';
162 if (strlen($table) && ! isset($num_tables) && ! PMA_Table::isMerge($db, $table)) {
163 $html .= '<div class="exportoptions" id="rows">';
164 $html .= '<h3>' . __('Rows:') . '</h3>';
165 $html .= '<ul>';
166 $html .= '<li>';
167 $html .= '<input type="radio" name="allrows" value="0" id="radio_allrows_0"';
168 if (isset($_GET['allrows']) && $_GET['allrows'] == 0) {
169 $html .= ' checked="checked"';
171 $html .= '/>';
172 $html .= '<label for ="radio_allrows_0">' . __('Dump some row(s)') . '</label>';
173 $html .= '<ul>';
174 $html .= '<li>';
175 $html .= '<label for="limit_to">' . __('Number of rows:') . '</label>';
176 $html .= '<input type="text" id="limit_to" name="limit_to" size="5" value="';
177 if (isset($_GET['limit_to'])) {
178 $html .= htmlspecialchars($_GET['limit_to']);
179 } elseif (isset($unlim_num_rows)) {
180 $html .= $unlim_num_rows;
181 } else {
182 $html .= PMA_Table::countRecords($db, $table);
184 $html .= '" onfocus="this.select()" />';
185 $html .= '</li>';
186 $html .= '<li>';
187 $html .= '<label for="limit_from">' . __('Row to begin at:') . '</label>';
188 $html .= '<input type="text" id="limit_from" name="limit_from" value="';
189 if (isset($_GET['limit_from'])) {
190 $html .= htmlspecialchars($_GET['limit_from']);
191 } else {
192 $html .= '0';
194 $html .= '" size="5" onfocus="this.select()" />';
195 $html .= '</li>';
196 $html .= '</ul>';
197 $html .= '</li>';
198 $html .= '<li>';
199 $html .= '<input type="radio" name="allrows" value="1" id="radio_allrows_1"';
200 if (! isset($_GET['allrows']) || $_GET['allrows'] == 1) {
201 $html .= ' checked="checked"';
203 $html .= '/>';
204 $html .= ' <label for="radio_allrows_1">' . __('Dump all rows') . '</label>';
205 $html .= '</li>';
206 $html .= '</ul>';
207 $html .= '</div>';
210 if (isset($cfg['SaveDir']) && !empty($cfg['SaveDir'])) {
211 $html .= '<div class="exportoptions" id="output_quick_export">';
212 $html .= '<h3>' . __('Output:') . '</h3>';
213 $html .= '<ul>';
214 $html .= '<li>';
215 $html .= '<input type="checkbox" name="quick_export_onserver" value="saveit" ';
216 $html .= 'id="checkbox_quick_dump_onserver" ';
217 $html .= PMA_exportCheckboxCheck('quick_export_onserver');
218 $html .= '/>';
219 $html .= '<label for="checkbox_quick_dump_onserver">';
220 $html .= sprintf(
221 __('Save on server in the directory <b>%s</b>'),
222 htmlspecialchars(PMA_Util::userDir($cfg['SaveDir']))
224 $html .= '</label>';
225 $html .= '</li>';
226 $html .= '<li>';
227 $html .= '<input type="checkbox" name="quick_export_onserverover" ';
228 $html .= 'value="saveitover" id="checkbox_quick_dump_onserverover" ';
229 $html .= PMA_exportCheckboxCheck('quick_export_onserver_overwrite');
230 $html .= '/>';
231 $html .= '<label for="checkbox_quick_dump_onserverover">';
232 $html .= __('Overwrite existing file(s)');
233 $html .= '</label>';
234 $html .= '</li>';
235 $html .= '</ul>';
236 $html .= '</div>';
239 $html .= '<div class="exportoptions" id="output">';
240 $html .= '<h3>' . __('Output:') . '</h3>';
241 $html .= '<ul id="ul_output">';
242 $html .= '<li>';
243 $html .= '<input type="radio" name="output_format" value="sendit" ';
244 $html .= 'id="radio_dump_asfile" ';
245 if (!isset($_GET['repopulate'])) {
246 $html .= PMA_exportCheckboxCheck('asfile');
248 $html .= '/>';
249 $html .= '<label for="radio_dump_asfile">'
250 . __('Save output to a file') . '</label>';
251 $html .= '<ul id="ul_save_asfile">';
252 if (isset($cfg['SaveDir']) && !empty($cfg['SaveDir'])) {
253 $html .= '<li>';
254 $html .= '<input type="checkbox" name="onserver" value="saveit" ';
255 $html .= 'id="checkbox_dump_onserver" ';
256 $html .= PMA_exportCheckboxCheck('onserver');
257 $html .= '/>';
258 $html .= '<label for="checkbox_dump_onserver">';
259 $html .= sprintf(
260 __('Save on server in the directory <b>%s</b>'),
261 htmlspecialchars(PMA_Util::userDir($cfg['SaveDir']))
263 $html .= '</label>';
264 $html .= '</li>';
265 $html .= '<li>';
266 $html .= '<input type="checkbox" name="onserverover" value="saveitover"';
267 $html .= ' id="checkbox_dump_onserverover" ';
268 $html .= PMA_exportCheckboxCheck('onserver_overwrite');
269 $html .= '/>';
270 $html .= '<label for="checkbox_dump_onserverover">';
271 $html .= __('Overwrite existing file(s)');
272 $html .= '</label>';
273 $html .= '</li>';
275 $html .= '<li>';
276 $html .= '<label for="filename_template" class="desc">';
277 $html .= __('File name template:');
278 $trans = new PMA_Message;
279 $trans->addMessage(__('@SERVER@ will become the server name'));
280 if ($export_type == 'database' || $export_type == 'table') {
281 $trans->addMessage(__(', @DATABASE@ will become the database name'));
282 if ($export_type == 'table') {
283 $trans->addMessage(__(', @TABLE@ will become the table name'));
287 $msg = new PMA_Message(
288 __('This value is interpreted using %1$sstrftime%2$s, so you can use time formatting strings. Additionally the following transformations will happen: %3$s. Other text will be kept as is. See the %4$sFAQ%5$s for details.')
290 $msg->addParam(
291 '<a href="' . PMA_linkURL(PMA_getPHPDocLink('function.strftime.php'))
292 . '" target="documentation" title="' . __('Documentation') . '">',
293 false
295 $msg->addParam('</a>', false);
296 $msg->addParam($trans);
297 $doc_url = PMA_Util::getDocuLink('faq', 'faq6-27');
298 $msg->addParam(
299 '<a href="'. $doc_url . '" target="documentation">',
300 false
302 $msg->addParam('</a>', false);
304 $html .= PMA_Util::showHint($msg);
305 $html .= '</label>';
306 $html .= '<input type="text" name="filename_template" id="filename_template" ';
307 $html .= ' value="';
308 if (isset($_GET['filename_template'])) {
309 $html .= htmlspecialchars($_GET['filename_template']);
310 } else {
311 if ($export_type == 'database') {
312 $html .= htmlspecialchars(
313 $GLOBALS['PMA_Config']->getUserValue(
314 'pma_db_filename_template',
315 $GLOBALS['cfg']['Export']['file_template_database']
318 } elseif ($export_type == 'table') {
319 $html .= htmlspecialchars(
320 $GLOBALS['PMA_Config']->getUserValue(
321 'pma_table_filename_template',
322 $GLOBALS['cfg']['Export']['file_template_table']
325 } else {
326 $html .= htmlspecialchars(
327 $GLOBALS['PMA_Config']->getUserValue(
328 'pma_server_filename_template',
329 $GLOBALS['cfg']['Export']['file_template_server']
334 $html .= '"';
335 $html .= '/>';
336 $html .= '<input type="checkbox" name="remember_template" ';
337 $html .= 'id="checkbox_remember_template" ';
338 $html .= PMA_exportCheckboxCheck('remember_file_template');
339 $html .= '/>';
340 $html .= '<label for="checkbox_remember_template">';
341 $html .= __('use this for future exports');
342 $html .= '</label>';
343 $html .= '</li>';
344 // charset of file
345 if ($GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE) {
346 $html .= ' <li><label for="select_charset_of_file" class="desc">'
347 . __('Character set of the file:') . '</label>' . "\n";
348 reset($cfg['AvailableCharsets']);
349 $html .= '<select id="select_charset_of_file" name="charset_of_file" size="1">';
350 foreach ($cfg['AvailableCharsets'] as $temp_charset) {
351 $html .= '<option value="' . $temp_charset . '"';
352 if (isset($_GET['charset_of_file'])
353 && ($_GET['charset_of_file'] != $temp_charset)
355 $html .= '';
356 } elseif ((empty($cfg['Export']['charset']) && $temp_charset == 'utf-8')
357 || $temp_charset == $cfg['Export']['charset']
359 $html .= ' selected="selected"';
361 $html .= '>' . $temp_charset . '</option>';
362 } // end foreach
363 $html .= '</select></li>';
364 } // end if
366 if (isset($_GET['compression'])) {
367 $selected_compression = $_GET['compression'];
368 } elseif (isset($cfg['Export']['compression'])) {
369 $selected_compression = $cfg['Export']['compression'];
370 } else {
371 $selected_compression = "none";
374 // zip, gzip and bzip2 encode features
375 $is_zip = ($cfg['ZipDump'] && @function_exists('gzcompress'));
376 $is_gzip = ($cfg['GZipDump'] && @function_exists('gzencode'));
377 $is_bzip2 = ($cfg['BZipDump'] && @function_exists('bzcompress'));
378 if ($is_zip || $is_gzip || $is_bzip2) {
379 $html .= '<li>';
380 $html .= '<label for="compression" class="desc">'
381 . __('Compression:') . '</label>';
382 $html .= '<select id="compression" name="compression">';
383 $html .= '<option value="none">' . __('None') . '</option>';
384 if ($is_zip) {
385 $html .= '<option value="zip" ';
386 if ($selected_compression == "zip") {
387 $html .= 'selected="selected"';
389 $html .= '>' . __('zipped') . '</option>';
391 if ($is_gzip) {
392 $html .= '<option value="gzip" ';
393 if ($selected_compression == "gzip") {
394 $html .= 'selected="selected"';
396 $html .= '>' . __('gzipped') . '</option>';
398 if ($is_bzip2) {
399 $html .= '<option value="bzip2" ';
400 if ($selected_compression == "bzip2") {
401 $html .= 'selected="selected"';
403 $html .= '>' . __('bzipped') . '</option>';
405 $html .= '</select>';
406 $html .= '</li>';
407 } else {
408 $html .= '<input type="hidden" name="compression" value="'
409 . htmlspecialchars($selected_compression) . '" />';
411 $html .= '</ul>';
412 $html .= '</li>';
413 $html .= '<li>';
414 $html .= '<input type="radio" id="radio_view_as_text" '
415 . ' name="output_format" value="astext" ';
416 if (isset($_GET['repopulate']) || $GLOBALS['cfg']['Export']['asfile'] == false) {
417 $html .= 'checked="checked"';
419 $html .= '/>';
420 $html .= '<label for="radio_view_as_text">'
421 . __('View output as text') . '</label></li>';
422 $html .= '</ul>';
423 $html .= '</div>';
425 $html .= '<div class="exportoptions" id="format">';
426 $html .= '<h3>' . __('Format:') . '</h3>';
427 $html .= PMA_pluginGetChoice('Export', 'what', $export_list, 'format');
428 $html .= '</div>';
430 $html .= '<div class="exportoptions" id="format_specific_opts">';
431 $html .= '<h3>' . __('Format-specific options:') . '</h3>';
432 $html .= '<p class="no_js_msg" id="scroll_to_options_msg">';
433 $html .= __('Scroll down to fill in the options for the selected format and ignore the options for other formats.');
434 $html .= '</p>';
435 $html .= PMA_pluginGetOptions('Export', $export_list);
436 $html .= '</div>';
438 if (function_exists('PMA_Kanji_encodingForm')) {
439 // Encoding setting form appended by Y.Kawada
440 // Japanese encoding setting
441 $html .= '<div class="exportoptions" id="kanji_encoding">';
442 $html .= '<h3>' . __('Encoding Conversion:') . '</h3>';
443 $html .= PMA_Kanji_encodingForm();
444 $html .= '</div>';
447 $html .= '<div class="exportoptions" id="submit">';
449 $html .= PMA_Util::getExternalBug(
450 __('SQL compatibility mode'), 'mysql', '50027', '14515'
453 $html .= '<input type="submit" value="' . __('Go') . '" id="buttonGo" />';
454 $html .= '</div>';
455 $html .= '</form>';
457 $response = PMA_Response::getInstance();
458 $response->addHTML($html);