view_operations.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * View manipulations
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. use PhpMyAdmin\Message;
  9. use PhpMyAdmin\Operations;
  10. use PhpMyAdmin\Response;
  11. use PhpMyAdmin\Table;
  12. use PhpMyAdmin\Url;
  13. use PhpMyAdmin\Util;
  14. /**
  15. *
  16. */
  17. require_once './libraries/common.inc.php';
  18. $pma_table = new Table($GLOBALS['table'], $GLOBALS['db']);
  19. /**
  20. * Load JavaScript files
  21. */
  22. $response = Response::getInstance();
  23. $header = $response->getHeader();
  24. $scripts = $header->getScripts();
  25. $scripts->addFile('tbl_operations.js');
  26. /**
  27. * Runs common work
  28. */
  29. require './libraries/tbl_common.inc.php';
  30. $url_query .= '&amp;goto=view_operations.php&amp;back=view_operations.php';
  31. $url_params['goto'] = $url_params['back'] = 'view_operations.php';
  32. $operations = new Operations();
  33. /**
  34. * Updates if required
  35. */
  36. $_message = new Message;
  37. $_type = 'success';
  38. if (isset($_POST['submitoptions'])) {
  39. if (isset($_POST['new_name'])) {
  40. if ($pma_table->rename($_POST['new_name'])) {
  41. $_message->addText($pma_table->getLastMessage());
  42. $result = true;
  43. $GLOBALS['table'] = $pma_table->getName();
  44. /* Force reread after rename */
  45. $pma_table->getStatusInfo(null, true);
  46. $reload = true;
  47. } else {
  48. $_message->addText($pma_table->getLastError());
  49. $result = false;
  50. }
  51. }
  52. $warning_messages = $operations->getWarningMessagesArray();
  53. }
  54. if (isset($result)) {
  55. // set to success by default, because result set could be empty
  56. // (for example, a table rename)
  57. if (empty($_message->getString())) {
  58. if ($result) {
  59. $_message->addText(
  60. __('Your SQL query has been executed successfully.')
  61. );
  62. } else {
  63. $_message->addText(__('Error'));
  64. }
  65. // $result should exist, regardless of $_message
  66. $_type = $result ? 'success' : 'error';
  67. }
  68. if (! empty($warning_messages)) {
  69. $_message->addMessagesString($warning_messages);
  70. $_message->isError(true);
  71. unset($warning_messages);
  72. }
  73. echo Util::getMessage(
  74. $_message, $sql_query, $_type
  75. );
  76. }
  77. unset($_message, $_type);
  78. $url_params['goto'] = 'view_operations.php';
  79. $url_params['back'] = 'view_operations.php';
  80. /**
  81. * Displays the page
  82. */
  83. ?>
  84. <!-- Table operations -->
  85. <div>
  86. <form method="post" action="view_operations.php">
  87. <?php echo Url::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']); ?>
  88. <input type="hidden" name="reload" value="1" />
  89. <fieldset>
  90. <legend><?php echo __('Operations'); ?></legend>
  91. <table>
  92. <!-- Change view name -->
  93. <tr><td><?php echo __('Rename view to'); ?></td>
  94. <td><input type="text" name="new_name" onfocus="this.select()"
  95. value="<?php echo htmlspecialchars($GLOBALS['table']); ?>"
  96. required />
  97. </td>
  98. </tr>
  99. </table>
  100. </fieldset>
  101. <fieldset class="tblFooters">
  102. <input type="hidden" name="submitoptions" value="1" />
  103. <input type="submit" value="<?php echo __('Go'); ?>" />
  104. </fieldset>
  105. </form>
  106. </div>
  107. <?php
  108. $drop_view_url_params = array_merge(
  109. $url_params,
  110. array(
  111. 'sql_query' => 'DROP VIEW ' . Util::backquote(
  112. $GLOBALS['table']
  113. ),
  114. 'goto' => 'tbl_structure.php',
  115. 'reload' => '1',
  116. 'purge' => '1',
  117. 'message_to_show' => sprintf(
  118. __('View %s has been dropped.'),
  119. htmlspecialchars($GLOBALS['table'])
  120. ),
  121. 'table' => $GLOBALS['table']
  122. )
  123. );
  124. echo '<div>';
  125. echo '<fieldset class="caution">';
  126. echo '<legend>' , __('Delete data or table') , '</legend>';
  127. echo '<ul>';
  128. echo $operations->getDeleteDataOrTablelink(
  129. $drop_view_url_params,
  130. 'DROP VIEW',
  131. __('Delete the view (DROP)'),
  132. 'drop_view_anchor'
  133. );
  134. echo '</ul>';
  135. echo '</fieldset>';
  136. echo '</div>';