Merge remote-tracking branch 'origin/master'
[phpmyadmin.git] / view_operations.php
blob10079dee8395ca6764d11286b541a7b054c03810
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * View manipulations
6 * @package PhpMyAdmin
7 */
8 use PMA\libraries\Table;
10 /**
13 require_once './libraries/common.inc.php';
15 $pma_table = new Table($GLOBALS['table'], $GLOBALS['db']);
17 /**
18 * functions implementation for this script
20 require_once 'libraries/operations.lib.php';
22 /**
23 * Runs common work
25 require './libraries/tbl_common.inc.php';
26 $url_query .= '&amp;goto=view_operations.php&amp;back=view_operations.php';
27 $url_params['goto'] = $url_params['back'] = 'view_operations.php';
29 /**
30 * Gets tables information
33 require './libraries/tbl_info.inc.php';
34 $reread_info = false;
36 /**
37 * Updates if required
39 if (isset($_REQUEST['submitoptions'])) {
40 $_message = '';
41 $warning_messages = array();
43 if (isset($_REQUEST['new_name'])) {
44 if ($pma_table->rename($_REQUEST['new_name'])) {
45 $_message .= $pma_table->getLastMessage();
46 $result = true;
47 $GLOBALS['table'] = $pma_table->getName();
48 $reread_info = true;
49 $reload = true;
50 } else {
51 $_message .= $pma_table->getLastError();
52 $result = false;
57 if (isset($result)) {
58 // set to success by default, because result set could be empty
59 // (for example, a table rename)
60 $_type = 'success';
61 if (empty($_message)) {
62 $_message = $result
63 ? __('Your SQL query has been executed successfully.')
64 : __('Error');
65 // $result should exist, regardless of $_message
66 $_type = $result ? 'success' : 'error';
68 if (! empty($warning_messages)) {
69 $_message = new PMA\libraries\Message;
70 $_message->addMessages($warning_messages);
71 $_message->isError(true);
72 unset($warning_messages);
74 echo PMA\libraries\Util::getMessage(
75 $_message, $sql_query, $_type
77 unset($_message, $_type);
80 $url_params['goto'] = 'view_operations.php';
81 $url_params['back'] = 'view_operations.php';
83 /**
84 * Displays the page
87 <!-- Table operations -->
88 <div class="operations_half_width">
89 <form method="post" action="view_operations.php">
90 <?php echo PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']); ?>
91 <input type="hidden" name="reload" value="1" />
92 <fieldset>
93 <legend><?php echo __('Operations'); ?></legend>
95 <table>
96 <!-- Change view name -->
97 <tr><td><?php echo __('Rename view to'); ?></td>
98 <td><input type="text" size="20" name="new_name" onfocus="this.select()"
99 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>"
100 required />
101 </td>
102 </tr>
103 </table>
104 </fieldset>
105 <fieldset class="tblFooters">
106 <input type="hidden" name="submitoptions" value="1" />
107 <input type="submit" value="<?php echo __('Go'); ?>" />
108 </fieldset>
109 </form>
110 </div>
111 <?php
112 $drop_view_url_params = array_merge(
113 $url_params,
114 array(
115 'sql_query' => 'DROP VIEW ' . PMA\libraries\Util::backquote(
116 $GLOBALS['table']
118 'goto' => 'tbl_structure.php',
119 'reload' => '1',
120 'purge' => '1',
121 'message_to_show' => sprintf(
122 __('View %s has been dropped.'),
123 htmlspecialchars($GLOBALS['table'])
125 'table' => $GLOBALS['table']
128 echo '<div class="operations_half_width">';
129 echo '<fieldset class="caution">';
130 echo '<legend>' , __('Delete data or table') , '</legend>';
132 echo '<ul>';
133 echo PMA_getDeleteDataOrTableLink(
134 $drop_view_url_params,
135 'DROP VIEW',
136 __('Delete the view (DROP)'),
137 'drop_view_anchor'
139 echo '</ul>';
140 echo '</fieldset>';
141 echo '</div>';