Translation update done using Pootle.
[phpmyadmin.git] / view_create.php
blob3e36efbf194a15bf8177fe107b6fe41f5090413e
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 /**
12 * do not import request variable into global scope
13 * @ignore
15 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
16 define('PMA_NO_VARIABLES_IMPORT', true);
19 /**
22 require_once './libraries/common.inc.php';
24 /**
25 * Runs common work
27 require './libraries/db_common.inc.php';
28 $url_params['goto'] = $cfg['DefaultTabDatabase'];
29 $url_params['back'] = 'view_create.php';
31 $view_algorithm_options = array(
32 'UNDEFINED',
33 'MERGE',
34 'TEMPTABLE',
37 $view_with_options = array(
38 'CASCADED CHECK OPTION',
39 'LOCAL CHECK OPTION'
42 if (isset($_REQUEST['createview'])) {
43 /**
44 * Creates the view
46 $sep = "\r\n";
48 $sql_query = 'CREATE';
50 if (isset($_REQUEST['view']['or_replace'])) {
51 $sql_query .= ' OR REPLACE';
54 if (PMA_isValid($_REQUEST['view']['algorithm'], $view_algorithm_options)) {
55 $sql_query .= $sep . ' ALGORITHM = ' . $_REQUEST['view']['algorithm'];
58 $sql_query .= $sep . ' VIEW ' . PMA_backquote($_REQUEST['view']['name']);
60 if (! empty($_REQUEST['view']['column_names'])) {
61 $sql_query .= $sep . ' (' . $_REQUEST['view']['column_names'] . ')';
64 $sql_query .= $sep . ' AS ' . $_REQUEST['view']['as'];
66 if (isset($_REQUEST['view']['with'])) {
67 $options = array_intersect($_REQUEST['view']['with'], $view_with_options);
68 if (count($options)) {
69 $sql_query .= $sep . ' WITH ' . implode(' ', $options);
73 if (PMA_DBI_try_query($sql_query)) {
74 $message = PMA_Message::success();
75 include './' . $cfg['DefaultTabDatabase'];
76 exit();
77 } else {
78 $message = PMA_Message::rawError(PMA_DBI_getError());
82 // prefill values if not already filled from former submission
83 $view = array(
84 'or_replace' => '',
85 'algorithm' => '',
86 'name' => '',
87 'column_names' => '',
88 'as' => $sql_query,
89 'with' => array(),
92 if (PMA_isValid($_REQUEST['view'], 'array')) {
93 $view = array_merge($view, $_REQUEST['view']);
96 /**
97 * Displays top menu links
98 * We use db links because a VIEW is not necessarily on a single table
100 $num_tables = 0;
101 require_once './libraries/db_links.inc.php';
103 $url_params['db'] = $GLOBALS['db'];
104 $url_params['reload'] = 1;
107 * Displays the page
110 <!-- CREATE VIEW options -->
111 <div id="div_view_options">
112 <form method="post" action="view_create.php">
113 <?php echo PMA_generate_common_hidden_inputs($url_params); ?>
114 <fieldset>
115 <legend>CREATE VIEW</legend>
117 <table>
118 <tr><td><label for="or_replace">OR REPLACE</label></td>
119 <td><input type="checkbox" name="view[or_replace]" id="or_replace"
120 <?php if ($view['or_replace']) { ?>
121 checked="checked"
122 <?php } ?>
123 value="1" />
124 </td>
125 </tr>
126 <tr>
127 <td><label for="algorithm">ALGORITHM</label></td>
128 <td><select name="view[algorithm]" id="algorithm">
129 <?php
130 foreach ($view_algorithm_options as $option) {
131 echo '<option value="' . htmlspecialchars($option) . '"';
132 if ($view['algorithm'] === $option) {
133 echo 'selected="selected"';
135 echo '>' . htmlspecialchars($option) . '</option>';
138 </select>
139 </td>
140 </tr>
141 <tr><td><?php echo __('VIEW name'); ?></td>
142 <td><input type="text" size="20" name="view[name]" onfocus="this.select()"
143 value="<?php echo htmlspecialchars($view['name']); ?>" />
144 </td>
145 </tr>
147 <tr><td><?php echo __('Column names'); ?></td>
148 <td><input type="text" maxlength="100" size="50" name="view[column_names]"
149 onfocus="this.select()"
150 value="<?php echo htmlspecialchars($view['column_names']); ?>" />
151 </td>
152 </tr>
154 <tr><td>AS</td>
155 <td>
156 <textarea name="view[as]" rows="<?php echo $cfg['TextareaRows']; ?>"
157 cols="<?php echo $cfg['TextareaCols']; ?>"
158 dir="<?php echo $text_dir; ?>" onfocus="this.select();"
159 ><?php echo htmlspecialchars($view['as']); ?></textarea>
160 </td>
161 </tr>
162 <tr><td>WITH</td>
163 <td>
164 <?php
165 foreach ($view_with_options as $option) {
166 echo '<input type="checkbox" name="view[with][]"';
167 if (in_array($option, $view['with'])) {
168 echo ' checked="checked"';
170 echo ' id="view_with_' . str_replace(' ', '_', htmlspecialchars($option)) . '"';
171 echo ' value="' . htmlspecialchars($option) . '" />';
172 echo '<label for="view_with_' . str_replace(' ', '_', htmlspecialchars($option)) . '">';
173 echo htmlspecialchars($option) . '</label>&nbsp;';
176 </td>
177 </tr>
178 </table>
179 </fieldset>
180 <fieldset class="tblFooters">
181 <input type="submit" name="createview" value="<?php echo __('Go'); ?>" />
182 </fieldset>
183 </form>
184 </div>
185 <?php
187 * Displays the footer
189 require './libraries/footer.inc.php';