Export.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Common functions for the export functionality for Routines, Triggers and Events.
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. namespace PhpMyAdmin\Rte;
  9. use PhpMyAdmin\Message;
  10. use PhpMyAdmin\Response;
  11. use PhpMyAdmin\Rte\Words;
  12. use PhpMyAdmin\Util;
  13. /**
  14. * PhpMyAdmin\Rte\Export class
  15. *
  16. * @package PhpMyAdmin
  17. */
  18. class Export
  19. {
  20. /**
  21. * This function is called from one of the other functions in this file
  22. * and it completes the handling of the export functionality.
  23. *
  24. * @param string $export_data The SQL query to create the requested item
  25. *
  26. * @return void
  27. */
  28. private static function handle($export_data)
  29. {
  30. global $db;
  31. $response = Response::getInstance();
  32. $item_name = htmlspecialchars(Util::backquote($_GET['item_name']));
  33. if ($export_data !== false) {
  34. $export_data = htmlspecialchars(trim($export_data));
  35. $title = sprintf(Words::get('export'), $item_name);
  36. if ($response->isAjax()) {
  37. $response->addJSON('message', $export_data);
  38. $response->addJSON('title', $title);
  39. exit;
  40. } else {
  41. $export_data = '<textarea cols="40" rows="15" style="width: 100%;">'
  42. . $export_data . '</textarea>';
  43. echo "<fieldset>\n"
  44. , "<legend>$title</legend>\n"
  45. , $export_data
  46. , "</fieldset>\n";
  47. }
  48. } else {
  49. $_db = htmlspecialchars(Util::backquote($db));
  50. $message = __('Error in processing request:') . ' '
  51. . sprintf(Words::get('no_view'), $item_name, $_db);
  52. $message = Message::error($message);
  53. if ($response->isAjax()) {
  54. $response->setRequestStatus(false);
  55. $response->addJSON('message', $message);
  56. exit;
  57. } else {
  58. $message->display();
  59. }
  60. }
  61. } // end self::handle()
  62. /**
  63. * If necessary, prepares event information and passes
  64. * it to self::handle() for the actual export.
  65. *
  66. * @return void
  67. */
  68. public static function events()
  69. {
  70. global $_GET, $db;
  71. if (! empty($_GET['export_item']) && ! empty($_GET['item_name'])) {
  72. $item_name = $_GET['item_name'];
  73. $export_data = $GLOBALS['dbi']->getDefinition($db, 'EVENT', $item_name);
  74. if (! $export_data) {
  75. $export_data = false;
  76. }
  77. self::handle($export_data);
  78. }
  79. } // end self::events()
  80. /**
  81. * If necessary, prepares routine information and passes
  82. * it to self::handle() for the actual export.
  83. *
  84. * @return void
  85. */
  86. public static function routines()
  87. {
  88. global $_GET, $db;
  89. if (! empty($_GET['export_item'])
  90. && ! empty($_GET['item_name'])
  91. && ! empty($_GET['item_type'])
  92. ) {
  93. if ($_GET['item_type'] == 'FUNCTION' || $_GET['item_type'] == 'PROCEDURE') {
  94. $rtn_definition
  95. = $GLOBALS['dbi']->getDefinition(
  96. $db,
  97. $_GET['item_type'],
  98. $_GET['item_name']
  99. );
  100. if (! $rtn_definition) {
  101. $export_data = false;
  102. } else {
  103. $export_data = "DELIMITER $$\n"
  104. . $rtn_definition
  105. . "$$\nDELIMITER ;\n";
  106. }
  107. self::handle($export_data);
  108. }
  109. }
  110. } // end self::routines()
  111. /**
  112. * If necessary, prepares trigger information and passes
  113. * it to self::handle() for the actual export.
  114. *
  115. * @return void
  116. */
  117. public static function triggers()
  118. {
  119. global $_GET, $db, $table;
  120. if (! empty($_GET['export_item']) && ! empty($_GET['item_name'])) {
  121. $item_name = $_GET['item_name'];
  122. $triggers = $GLOBALS['dbi']->getTriggers($db, $table, '');
  123. $export_data = false;
  124. foreach ($triggers as $trigger) {
  125. if ($trigger['name'] === $item_name) {
  126. $export_data = $trigger['create'];
  127. break;
  128. }
  129. }
  130. self::handle($export_data);
  131. }
  132. } // end self::triggers()
  133. }