Translated using Weblate (Spanish)
[phpmyadmin.git] / view_create.php
blob7178987ccbe5c4d09f4f3c5601e645aaf65e363c
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * handles creation of VIEWs
6 * @todo js error when view name is empty (strFormEmpty)
7 * @todo (also validate if js is disabled, after form submission?)
8 * @package PhpMyAdmin
9 */
11 /**
14 require_once './libraries/common.inc.php';
16 /**
17 * Runs common work
19 require './libraries/db_common.inc.php';
20 $url_params['goto'] = $cfg['DefaultTabDatabase'];
21 $url_params['back'] = 'view_create.php';
23 $view_algorithm_options = array(
24 'UNDEFINED',
25 'MERGE',
26 'TEMPTABLE',
29 $view_with_options = array(
30 'CASCADED CHECK OPTION',
31 'LOCAL CHECK OPTION'
34 if (isset($_REQUEST['createview'])) {
35 /**
36 * Creates the view
38 $sep = "\r\n";
40 $sql_query = 'CREATE';
42 if (isset($_REQUEST['view']['or_replace'])) {
43 $sql_query .= ' OR REPLACE';
46 if (PMA_isValid($_REQUEST['view']['algorithm'], $view_algorithm_options)) {
47 $sql_query .= $sep . ' ALGORITHM = ' . $_REQUEST['view']['algorithm'];
50 $sql_query .= $sep . ' VIEW ' . PMA_Util::backquote($_REQUEST['view']['name']);
52 if (! empty($_REQUEST['view']['column_names'])) {
53 $sql_query .= $sep . ' (' . $_REQUEST['view']['column_names'] . ')';
56 $sql_query .= $sep . ' AS ' . $_REQUEST['view']['as'];
58 if (isset($_REQUEST['view']['with'])) {
59 $options = array_intersect($_REQUEST['view']['with'], $view_with_options);
60 if (count($options)) {
61 $sql_query .= $sep . ' WITH ' . implode(' ', $options);
65 if (PMA_DBI_tryQuery($sql_query)) {
67 include_once './libraries/tbl_views.lib.php';
69 // If different column names defined for VIEW
70 $view_columns = array();
71 if (isset($_REQUEST['view']['column_names'])) {
72 $view_columns = explode(',', $_REQUEST['view']['column_names']);
75 $column_map = PMA_getColumnMap($_REQUEST['view']['as'], $view_columns);
76 $pma_tranformation_data = PMA_getExistingTranformationData($GLOBALS['db']);
78 if ($pma_tranformation_data !== false) {
80 // SQL for store new transformation details of VIEW
81 $new_transformations_sql = PMA_getNewTransformationDataSql(
82 $pma_tranformation_data, $column_map, $_REQUEST['view']['name'],
83 $GLOBALS['db']
84 );
86 // Store new transformations
87 if ($new_transformations_sql != '') {
88 PMA_DBI_tryQuery($new_transformations_sql);
92 unset($pma_tranformation_data);
94 if ($GLOBALS['is_ajax_request'] != true) {
95 $message = PMA_Message::success();
96 include './' . $cfg['DefaultTabDatabase'];
97 } else {
98 $response = PMA_Response::getInstance();
99 $response->addJSON(
100 'message',
101 PMA_Util::getMessage(
102 PMA_Message::success(), $sql_query
107 exit;
109 } else {
110 if ($GLOBALS['is_ajax_request'] != true) {
111 $message = PMA_Message::rawError(PMA_DBI_getError());
112 } else {
113 $response = PMA_Response::getInstance();
114 $response->addJSON(
115 'message',
116 PMA_Message::error(
117 "<i>$sql_query</i><br /><br />" . PMA_DBI_getError()
120 $response->isSuccess(false);
121 exit;
126 // prefill values if not already filled from former submission
127 $view = array(
128 'or_replace' => '',
129 'algorithm' => '',
130 'name' => '',
131 'column_names' => '',
132 'as' => $sql_query,
133 'with' => array(),
136 if (PMA_isValid($_REQUEST['view'], 'array')) {
137 $view = array_merge($view, $_REQUEST['view']);
140 $url_params['db'] = $GLOBALS['db'];
141 $url_params['reload'] = 1;
144 * Displays the page
146 $htmlString = '<!-- CREATE VIEW options -->'
147 . '<div id="div_view_options">'
148 . '<form method="post" action="view_create.php">'
149 . PMA_generate_common_hidden_inputs($url_params)
150 . '<fieldset>'
151 . '<legend>' . __('Create view')
152 . PMA_Util::showMySQLDocu('SQL-Syntax', 'CREATE_VIEW') . '</legend>'
153 . '<table class="rte_table">'
154 . '<tr><td><label for="or_replace">OR REPLACE</label></td>'
155 . '<td><input type="checkbox" name="view[or_replace]" id="or_replace"';
156 if ($view['or_replace']) {
157 $htmlString .= ' checked="checked"';
159 $htmlString .= ' value="1" />'
160 . '</td>'
161 . '</tr>'
162 . '<tr>'
163 . '<td><label for="algorithm">ALGORITHM</label></td>'
164 . '<td><select name="view[algorithm]" id="algorithm">';
166 foreach ($view_algorithm_options as $option) {
167 $htmlString .= '<option value="' . htmlspecialchars($option) . '"';
168 if ($view['algorithm'] === $option) {
169 $htmlString .= ' selected="selected"';
171 $htmlString .= '>' . htmlspecialchars($option) . '</option>';
174 $htmlString .= '</select>'
175 . '</td>'
176 . '</tr>'
177 . '<tr><td>' . __('VIEW name') . '</td>'
178 . '<td><input type="text" size="20" name="view[name]" onfocus="this.select()"'
179 . ' value="' . htmlspecialchars($view['name']) . '" />'
180 . '</td>'
181 . '</tr>'
182 . '<tr><td>' . __('Column names') . '</td>'
183 . '<td><input type="text" maxlength="100" size="50" name="view[column_names]"'
184 . ' onfocus="this.select()"'
185 . ' value="' . htmlspecialchars($view['column_names']) . '" />'
186 . '</td>'
187 . '</tr>'
188 . '<tr><td>AS</td>'
189 . '<td>'
190 . '<textarea name="view[as]" rows="' . $cfg['TextareaRows'] . '"'
191 . ' cols="' . $cfg['TextareaCols'] . '"'
192 . ' dir="' . $text_dir . '"';
194 if ($GLOBALS['cfg']['TextareaAutoSelect'] || true) {
195 $htmlString .= ' onclick="selectContent(this, sql_box_locked, true)"';
198 $htmlString .= '>' . htmlspecialchars($view['as']) . '</textarea>'
199 . '</td>'
200 . '</tr>'
201 . '<tr><td>WITH</td>'
202 . '<td>';
204 foreach ($view_with_options as $option) {
205 $htmlString .= '<input type="checkbox" name="view[with][]"';
206 if (in_array($option, $view['with'])) {
207 $htmlString .= ' checked="checked"';
209 $htmlString .= ' id="view_with_'
210 . str_replace(' ', '_', htmlspecialchars($option)) . '"'
211 . ' value="' . htmlspecialchars($option) . '" />'
212 . '<label for="view_with_' . str_replace(' ', '_', htmlspecialchars($option))
213 . '">&nbsp;'
214 . htmlspecialchars($option) . '</label><br />';
217 $htmlString .= '</td>'
218 . '</tr>'
219 . '</table>'
220 . '</fieldset>';
222 if ($GLOBALS['is_ajax_request'] != true) {
223 $htmlString .= '<fieldset class="tblFooters">'
224 . '<input type="submit" name="createview" value="' . __('Go') . '" />'
225 . '</fieldset>';
226 } else {
227 $htmlString .= '<input type="hidden" name="createview" value="1" />'
228 . '<input type="hidden" name="ajax_request" value="1" />';
231 $htmlString .= '</form>'
232 . '</div>';
234 echo $htmlString;