/db_export.php

https://gitlab.com/trungthao379/phpmyadmin · PHP · 158 lines · 127 code · 13 blank · 18 comment · 18 complexity · 6ca574ed3e26c362e87ac688ed3569f1 MD5 · raw file

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