rte_export.lib.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /**
  12. * This function is called from one of the other functions in this file
  13. * and it completes the handling of the export functionality.
  14. *
  15. * @param string $item_name The name of the item that we are exporting
  16. * @param string $export_data The SQL query to create the requested item
  17. *
  18. * @return void
  19. */
  20. function PMA_RTE_handleExport($item_name, $export_data)
  21. {
  22. global $db;
  23. $item_name = htmlspecialchars(PMA_Util::backquote($_GET['item_name']));
  24. if ($export_data !== false) {
  25. $export_data = '<textarea cols="40" rows="15" style="width: 100%;">'
  26. . htmlspecialchars(trim($export_data)) . '</textarea>';
  27. $title = sprintf(PMA_RTE_getWord('export'), $item_name);
  28. if ($GLOBALS['is_ajax_request'] == true) {
  29. $response = PMA_Response::getInstance();
  30. $response->addJSON('message', $export_data);
  31. $response->addJSON('title', $title);
  32. exit;
  33. } else {
  34. echo "<fieldset>\n"
  35. . "<legend>$title</legend>\n"
  36. . $export_data
  37. . "</fieldset>\n";
  38. }
  39. } else {
  40. $_db = htmlspecialchars(PMA_Util::backquote($db));
  41. $response = __('Error in Processing Request') . ' : '
  42. . sprintf(PMA_RTE_getWord('not_found'), $item_name, $_db);
  43. $response = PMA_message::error($response);
  44. if ($GLOBALS['is_ajax_request'] == true) {
  45. $response = PMA_Response::getInstance();
  46. $response->isSuccess(false);
  47. $response->addJSON('message', $response);
  48. exit;
  49. } else {
  50. $response->display();
  51. }
  52. }
  53. } // end PMA_RTE_handleExport()
  54. /**
  55. * If necessary, prepares event information and passes
  56. * it to PMA_RTE_handleExport() for the actual export.
  57. *
  58. * @return void
  59. */
  60. function PMA_EVN_handleExport()
  61. {
  62. global $_GET, $db;
  63. if (! empty($_GET['export_item']) && ! empty($_GET['item_name'])) {
  64. $item_name = $_GET['item_name'];
  65. $export_data = PMA_DBI_get_definition($db, 'EVENT', $item_name);
  66. PMA_RTE_handleExport($item_name, $export_data);
  67. }
  68. } // end PMA_EVN_handleExport()
  69. /**
  70. * If necessary, prepares routine information and passes
  71. * it to PMA_RTE_handleExport() for the actual export.
  72. *
  73. * @return void
  74. */
  75. function PMA_RTN_handleExport()
  76. {
  77. global $_GET, $db;
  78. if ( ! empty($_GET['export_item'])
  79. && ! empty($_GET['item_name'])
  80. && ! empty($_GET['item_type'])
  81. ) {
  82. if ($_GET['item_type'] == 'FUNCTION' || $_GET['item_type'] == 'PROCEDURE') {
  83. $export_data = PMA_DBI_get_definition(
  84. $db,
  85. $_GET['item_type'],
  86. $_GET['item_name']
  87. );
  88. PMA_RTE_handleExport($_GET['item_name'], $export_data);
  89. }
  90. }
  91. } // end PMA_RTN_handleExport()
  92. /**
  93. * If necessary, prepares trigger information and passes
  94. * it to PMA_RTE_handleExport() for the actual export.
  95. *
  96. * @return void
  97. */
  98. function PMA_TRI_handleExport()
  99. {
  100. global $_GET, $db, $table;
  101. if (! empty($_GET['export_item']) && ! empty($_GET['item_name'])) {
  102. $item_name = $_GET['item_name'];
  103. $triggers = PMA_DBI_get_triggers($db, $table, '');
  104. $export_data = false;
  105. foreach ($triggers as $trigger) {
  106. if ($trigger['name'] === $item_name) {
  107. $export_data = $trigger['create'];
  108. break;
  109. }
  110. }
  111. PMA_RTE_handleExport($item_name, $export_data);
  112. }
  113. } // end PMA_TRI_handleExport()
  114. ?>