db_export.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * dumps a database
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. use PhpMyAdmin\Config\PageSettings;
  9. use PhpMyAdmin\Display\Export as DisplayExport;
  10. use PhpMyAdmin\Export;
  11. use PhpMyAdmin\Message;
  12. use PhpMyAdmin\Response;
  13. use PhpMyAdmin\Util;
  14. /**
  15. * Gets some core libraries
  16. */
  17. require_once 'libraries/common.inc.php';
  18. PageSettings::showGroup('Export');
  19. $response = Response::getInstance();
  20. $header = $response->getHeader();
  21. $scripts = $header->getScripts();
  22. $scripts->addFile('export.js');
  23. // $sub_part is used in Util::getDbInfo() to see if we are coming from
  24. // db_export.php, in which case we don't obey $cfg['MaxTableList']
  25. $sub_part = '_export';
  26. require_once 'libraries/db_common.inc.php';
  27. $url_query .= '&amp;goto=db_export.php';
  28. list(
  29. $tables,
  30. $num_tables,
  31. $total_num_tables,
  32. $sub_part,
  33. $is_show_stats,
  34. $db_is_system_schema,
  35. $tooltip_truename,
  36. $tooltip_aliasname,
  37. $pos
  38. ) = Util::getDbInfo($db, isset($sub_part) ? $sub_part : '');
  39. /**
  40. * Displays the form
  41. */
  42. $export_page_title = __('View dump (schema) of database');
  43. // exit if no tables in db found
  44. if ($num_tables < 1) {
  45. $response->addHTML(
  46. Message::error(__('No tables found in database.'))->getDisplay()
  47. );
  48. exit;
  49. } // end if
  50. $multi_values = '<div class="export_table_list_container">';
  51. if (isset($_GET['structure_or_data_forced'])) {
  52. $force_val = htmlspecialchars($_GET['structure_or_data_forced']);
  53. } else {
  54. $force_val = 0;
  55. }
  56. $multi_values .= '<input type="hidden" name="structure_or_data_forced" value="'
  57. . $force_val . '">';
  58. $multi_values .= '<table class="export_table_select">'
  59. . '<thead><tr><th></th>'
  60. . '<th>' . __('Tables') . '</th>'
  61. . '<th class="export_structure">' . __('Structure') . '</th>'
  62. . '<th class="export_data">' . __('Data') . '</th>'
  63. . '</tr><tr>'
  64. . '<td></td>'
  65. . '<td class="export_table_name all">' . __('Select all') . '</td>'
  66. . '<td class="export_structure all">'
  67. . '<input type="checkbox" id="table_structure_all" /></td>'
  68. . '<td class="export_data all"><input type="checkbox" id="table_data_all" />'
  69. . '</td>'
  70. . '</tr></thead>'
  71. . '<tbody>';
  72. $multi_values .= "\n";
  73. // when called by libraries/mult_submits.inc.php
  74. if (!empty($_POST['selected_tbl']) && empty($table_select)) {
  75. $table_select = $_POST['selected_tbl'];
  76. }
  77. // Check if the selected tables are defined in $_GET
  78. // (from clicking Back button on export.php)
  79. foreach (array('table_select', 'table_structure', 'table_data') as $one_key) {
  80. if (isset($_GET[$one_key])) {
  81. $_GET[$one_key] = urldecode($_GET[$one_key]);
  82. $_GET[$one_key] = explode(",", $_GET[$one_key]);
  83. }
  84. }
  85. foreach ($tables as $each_table) {
  86. if (isset($_GET['table_select']) && is_array($_GET['table_select'])) {
  87. $is_checked = Export::getCheckedClause(
  88. $each_table['Name'], $_GET['table_select']
  89. );
  90. } elseif (isset($table_select)) {
  91. $is_checked = Export::getCheckedClause(
  92. $each_table['Name'], $table_select
  93. );
  94. } else {
  95. $is_checked = ' checked="checked"';
  96. }
  97. if (isset($_GET['table_structure']) && is_array($_GET['table_structure'])) {
  98. $structure_checked = Export::getCheckedClause(
  99. $each_table['Name'], $_GET['table_structure']
  100. );
  101. } else {
  102. $structure_checked = $is_checked;
  103. }
  104. if (isset($_GET['table_data']) && is_array($_GET['table_data'])) {
  105. $data_checked = Export::getCheckedClause(
  106. $each_table['Name'], $_GET['table_data']
  107. );
  108. } else {
  109. $data_checked = $is_checked;
  110. }
  111. $table_html = htmlspecialchars($each_table['Name']);
  112. $multi_values .= '<tr class="marked">';
  113. $multi_values .= '<td><input type="checkbox" name="table_select[]"'
  114. . ' value="' . $table_html . '"' . $is_checked . ' class="checkall"/></td>';
  115. $multi_values .= '<td class="export_table_name">'
  116. . str_replace(' ', '&nbsp;', $table_html) . '</td>';
  117. $multi_values .= '<td class="export_structure">'
  118. . '<input type="checkbox" name="table_structure[]"'
  119. . ' value="' . $table_html . '"' . $structure_checked . ' /></td>';
  120. $multi_values .= '<td class="export_data">'
  121. . '<input type="checkbox" name="table_data[]"'
  122. . ' value="' . $table_html . '"' . $data_checked . ' /></td>';
  123. $multi_values .= '</tr>';
  124. } // end for
  125. $multi_values .= "\n";
  126. $multi_values .= '</tbody></table></div>';
  127. if (! isset($sql_query)) {
  128. $sql_query = '';
  129. }
  130. if (! isset($num_tables)) {
  131. $num_tables = 0;
  132. }
  133. if (! isset($unlim_num_rows)) {
  134. $unlim_num_rows = 0;
  135. }
  136. if (! isset($multi_values)) {
  137. $multi_values = '';
  138. }
  139. $response = Response::getInstance();
  140. $displayExport = new DisplayExport();
  141. $response->addHTML(
  142. $displayExport->getDisplay(
  143. 'database', $db, $table, $sql_query, $num_tables,
  144. $unlim_num_rows, $multi_values
  145. )
  146. );