db_export.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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($_POST['structure_or_data_forced'])) {
  52. $force_val = htmlspecialchars($_POST['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. foreach ($tables as $each_table) {
  78. if (isset($_POST['table_select']) && is_array($_POST['table_select'])) {
  79. $is_checked = Export::getCheckedClause(
  80. $each_table['Name'], $_POST['table_select']
  81. );
  82. } elseif (isset($table_select)) {
  83. $is_checked = Export::getCheckedClause(
  84. $each_table['Name'], $table_select
  85. );
  86. } else {
  87. $is_checked = ' checked="checked"';
  88. }
  89. if (isset($_POST['table_structure']) && is_array($_POST['table_structure'])) {
  90. $structure_checked = Export::getCheckedClause(
  91. $each_table['Name'], $_POST['table_structure']
  92. );
  93. } else {
  94. $structure_checked = $is_checked;
  95. }
  96. if (isset($_POST['table_data']) && is_array($_POST['table_data'])) {
  97. $data_checked = Export::getCheckedClause(
  98. $each_table['Name'], $_POST['table_data']
  99. );
  100. } else {
  101. $data_checked = $is_checked;
  102. }
  103. $table_html = htmlspecialchars($each_table['Name']);
  104. $multi_values .= '<tr class="marked">';
  105. $multi_values .= '<td><input type="checkbox" name="table_select[]"'
  106. . ' value="' . $table_html . '"' . $is_checked . ' class="checkall"/></td>';
  107. $multi_values .= '<td class="export_table_name">'
  108. . str_replace(' ', '&nbsp;', $table_html) . '</td>';
  109. $multi_values .= '<td class="export_structure">'
  110. . '<input type="checkbox" name="table_structure[]"'
  111. . ' value="' . $table_html . '"' . $structure_checked . ' /></td>';
  112. $multi_values .= '<td class="export_data">'
  113. . '<input type="checkbox" name="table_data[]"'
  114. . ' value="' . $table_html . '"' . $data_checked . ' /></td>';
  115. $multi_values .= '</tr>';
  116. } // end for
  117. $multi_values .= "\n";
  118. $multi_values .= '</tbody></table></div>';
  119. if (! isset($sql_query)) {
  120. $sql_query = '';
  121. }
  122. if (! isset($num_tables)) {
  123. $num_tables = 0;
  124. }
  125. if (! isset($unlim_num_rows)) {
  126. $unlim_num_rows = 0;
  127. }
  128. if (! isset($multi_values)) {
  129. $multi_values = '';
  130. }
  131. $response = Response::getInstance();
  132. $displayExport = new DisplayExport();
  133. $response->addHTML(
  134. $displayExport->getDisplay(
  135. 'database', $db, $table, $sql_query, $num_tables,
  136. $unlim_num_rows, $multi_values
  137. )
  138. );