tbl_export.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Table export
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. use PhpMyAdmin\Config\PageSettings;
  9. use PhpMyAdmin\Display\Export;
  10. use PhpMyAdmin\Relation;
  11. use PhpMyAdmin\Response;
  12. /**
  13. *
  14. */
  15. require_once 'libraries/common.inc.php';
  16. PageSettings::showGroup('Export');
  17. $response = Response::getInstance();
  18. $header = $response->getHeader();
  19. $scripts = $header->getScripts();
  20. $scripts->addFile('export.js');
  21. // Get the relation settings
  22. $relation = new Relation();
  23. $cfgRelation = $relation->getRelationsParam();
  24. $displayExport = new Export();
  25. // handling export template actions
  26. if (isset($_POST['templateAction']) && $cfgRelation['exporttemplateswork']) {
  27. $displayExport->handleTemplateActions($cfgRelation);
  28. exit;
  29. }
  30. /**
  31. * Gets tables information and displays top links
  32. */
  33. require_once 'libraries/tbl_common.inc.php';
  34. $url_query .= '&amp;goto=tbl_export.php&amp;back=tbl_export.php';
  35. // Dump of a table
  36. $export_page_title = __('View dump (schema) of table');
  37. // When we have some query, we need to remove LIMIT from that and possibly
  38. // generate WHERE clause (if we are asked to export specific rows)
  39. if (! empty($sql_query)) {
  40. $parser = new PhpMyAdmin\SqlParser\Parser($sql_query);
  41. if ((!empty($parser->statements[0]))
  42. && ($parser->statements[0] instanceof PhpMyAdmin\SqlParser\Statements\SelectStatement)
  43. ) {
  44. // Checking if the WHERE clause has to be replaced.
  45. if ((!empty($where_clause)) && (is_array($where_clause))) {
  46. $replaces[] = array(
  47. 'WHERE', 'WHERE (' . implode(') OR (', $where_clause) . ')'
  48. );
  49. }
  50. // Preparing to remove the LIMIT clause.
  51. $replaces[] = array('LIMIT', '');
  52. // Replacing the clauses.
  53. $sql_query = PhpMyAdmin\SqlParser\Utils\Query::replaceClauses(
  54. $parser->statements[0],
  55. $parser->list,
  56. $replaces
  57. );
  58. }
  59. echo PhpMyAdmin\Util::getMessage(PhpMyAdmin\Message::success());
  60. }
  61. if (! isset($sql_query)) {
  62. $sql_query = '';
  63. }
  64. if (! isset($num_tables)) {
  65. $num_tables = 0;
  66. }
  67. if (! isset($unlim_num_rows)) {
  68. $unlim_num_rows = 0;
  69. }
  70. if (! isset($multi_values)) {
  71. $multi_values = '';
  72. }
  73. $response = Response::getInstance();
  74. $response->addHTML(
  75. $displayExport->getDisplay(
  76. 'table', $db, $table, $sql_query, $num_tables,
  77. $unlim_num_rows, $multi_values
  78. )
  79. );