tbl_row_action.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * handle row specific actions like edit, delete, export
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. use PhpMyAdmin\Response;
  9. use PhpMyAdmin\Sql;
  10. use PhpMyAdmin\Url;
  11. /**
  12. *
  13. */
  14. require_once 'libraries/common.inc.php';
  15. if (isset($_POST['submit_mult'])) {
  16. $submit_mult = $_POST['submit_mult'];
  17. // workaround for IE problem:
  18. } elseif (isset($_POST['submit_mult_delete_x'])) {
  19. $submit_mult = 'row_delete';
  20. } elseif (isset($_POST['submit_mult_change_x'])) {
  21. $submit_mult = 'row_edit';
  22. } elseif (isset($_POST['submit_mult_export_x'])) {
  23. $submit_mult = 'row_export';
  24. }
  25. // If the 'Ask for confirmation' button was pressed, this can only come
  26. // from 'delete' mode, so we set it straight away.
  27. if (isset($_POST['mult_btn'])) {
  28. $submit_mult = 'row_delete';
  29. }
  30. if (! isset($submit_mult)) {
  31. $submit_mult = 'row_edit';
  32. }
  33. switch($submit_mult) {
  34. case 'row_delete':
  35. case 'row_edit':
  36. case 'row_copy':
  37. case 'row_export':
  38. // leave as is
  39. break;
  40. case 'export':
  41. $submit_mult = 'row_export';
  42. break;
  43. case 'delete':
  44. $submit_mult = 'row_delete';
  45. break;
  46. case 'copy':
  47. $submit_mult = 'row_copy';
  48. break;
  49. case 'edit':
  50. default:
  51. $submit_mult = 'row_edit';
  52. break;
  53. }
  54. if (!empty($submit_mult)) {
  55. if (isset($_POST['goto'])
  56. && (! isset($_POST['rows_to_delete'])
  57. || ! is_array($_POST['rows_to_delete']))
  58. ) {
  59. $response = Response::getInstance();
  60. $response->setRequestStatus(false);
  61. $response->addJSON('message', __('No row selected.'));
  62. }
  63. switch($submit_mult) {
  64. /** @noinspection PhpMissingBreakStatementInspection */
  65. case 'row_copy':
  66. $_POST['default_action'] = 'insert';
  67. // no break to allow for fallthough
  68. case 'row_edit':
  69. // As we got the rows to be edited from the
  70. // 'rows_to_delete' checkbox, we use the index of it as the
  71. // indicating WHERE clause. Then we build the array which is used
  72. // for the tbl_change.php script.
  73. $where_clause = array();
  74. if (isset($_POST['rows_to_delete'])
  75. && is_array($_POST['rows_to_delete'])
  76. ) {
  77. foreach ($_POST['rows_to_delete'] as $i => $i_where_clause) {
  78. $where_clause[] = $i_where_clause;
  79. }
  80. }
  81. $active_page = 'tbl_change.php';
  82. include 'tbl_change.php';
  83. break;
  84. case 'row_export':
  85. // Needed to allow SQL export
  86. $single_table = true;
  87. // As we got the rows to be exported from the
  88. // 'rows_to_delete' checkbox, we use the index of it as the
  89. // indicating WHERE clause. Then we build the array which is used
  90. // for the tbl_change.php script.
  91. $where_clause = array();
  92. if (isset($_POST['rows_to_delete'])
  93. && is_array($_POST['rows_to_delete'])
  94. ) {
  95. foreach ($_POST['rows_to_delete'] as $i => $i_where_clause) {
  96. $where_clause[] = $i_where_clause;
  97. }
  98. }
  99. $active_page = 'tbl_export.php';
  100. include 'tbl_export.php';
  101. break;
  102. case 'row_delete':
  103. default:
  104. $action = 'tbl_row_action.php';
  105. $err_url = 'tbl_row_action.php'
  106. . Url::getCommon($GLOBALS['url_params']);
  107. if (! isset($_POST['mult_btn'])) {
  108. $original_sql_query = $sql_query;
  109. if (! empty($url_query)) {
  110. $original_url_query = $url_query;
  111. }
  112. }
  113. include 'libraries/mult_submits.inc.php';
  114. $_url_params = $GLOBALS['url_params'];
  115. $_url_params['goto'] = 'tbl_sql.php';
  116. $url_query = Url::getCommon($_url_params);
  117. /**
  118. * Show result of multi submit operation
  119. */
  120. // sql_query is not set when user does not confirm multi-delete
  121. if ((! empty($submit_mult) || isset($_POST['mult_btn']))
  122. && ! empty($sql_query)
  123. ) {
  124. $disp_message = __('Your SQL query has been executed successfully.');
  125. $disp_query = $sql_query;
  126. }
  127. if (isset($original_sql_query)) {
  128. $sql_query = $original_sql_query;
  129. }
  130. if (isset($original_url_query)) {
  131. $url_query = $original_url_query;
  132. }
  133. $active_page = 'sql.php';
  134. $sql = new Sql();
  135. $sql->executeQueryAndSendQueryResponse(
  136. null, // analyzed_sql_results
  137. false, // is_gotofile
  138. $db, // db
  139. $table, // table
  140. null, // find_real_end
  141. null, // sql_query_for_bookmark
  142. null, // extra_data
  143. null, // message_to_show
  144. null, // message
  145. null, // sql_data
  146. $goto, // goto
  147. $pmaThemeImage, // pmaThemeImage
  148. null, // disp_query
  149. null, // disp_message
  150. null, // query_type
  151. $sql_query, // sql_query
  152. null, // selectedTables
  153. null // complete_query
  154. );
  155. }
  156. }