display_export.lib.php 14 KB

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