Translation update done using Pootle.
[phpmyadmin/dkf.git] / view_create.php
blob6797919c0cd28f24a0348841943d90adec1c71fa
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 * @version $Id$
9 * @package phpMyAdmin
12 /**
13 * do not import request variable into global scope
14 * @ignore
16 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
17 define('PMA_NO_VARIABLES_IMPORT', true);
20 /**
23 require_once './libraries/common.inc.php';
25 /**
26 * Runs common work
28 require './libraries/db_common.inc.php';
29 $url_params['goto'] = $cfg['DefaultTabDatabase'];
30 $url_params['back'] = 'view_create.php';
32 $view_algorithm_options = array(
33 'UNDEFINED',
34 'MERGE',
35 'TEMPTABLE',
38 $view_with_options = array(
39 'CASCADED CHECK OPTION',
40 'LOCAL CHECK OPTION'
43 if (isset($_REQUEST['createview'])) {
44 /**
45 * Creates the view
47 $sep = "\r\n";
49 $sql_query = 'CREATE';
51 if (isset($_REQUEST['view']['or_replace'])) {
52 $sql_query .= ' OR REPLACE';
55 if (PMA_isValid($_REQUEST['view']['algorithm'], $view_algorithm_options)) {
56 $sql_query .= $sep . ' ALGORITHM = ' . $_REQUEST['view']['algorithm'];
59 $sql_query .= $sep . ' VIEW ' . PMA_backquote($_REQUEST['view']['name']);
61 if (! empty($_REQUEST['view']['column_names'])) {
62 $sql_query .= $sep . ' (' . $_REQUEST['view']['column_names'] . ')';
65 $sql_query .= $sep . ' AS ' . $_REQUEST['view']['as'];
67 if (isset($_REQUEST['view']['with'])) {
68 $options = array_intersect($_REQUEST['view']['with'], $view_with_options);
69 if (count($options)) {
70 $sql_query .= $sep . ' WITH ' . implode(' ', $options);
74 if (PMA_DBI_try_query($sql_query)) {
75 $message = PMA_Message::success();
76 require './' . $cfg['DefaultTabDatabase'];
77 exit();
78 } else {
79 $message = PMA_Message::rawError(PMA_DBI_getError());
83 // prefill values if not already filled from former submission
84 $view = array(
85 'or_replace' => '',
86 'algorithm' => '',
87 'name' => '',
88 'column_names' => '',
89 'as' => $sql_query,
90 'with' => array(),
93 if (PMA_isValid($_REQUEST['view'], 'array')) {
94 $view = array_merge($view, $_REQUEST['view']);
97 /**
98 * Displays top menu links
99 * We use db links because a VIEW is not necessarily on a single table
101 $num_tables = 0;
102 require_once './libraries/db_links.inc.php';
104 $url_params['db'] = $GLOBALS['db'];
105 $url_params['reload'] = 1;
108 * Displays the page
111 <!-- CREATE VIEW options -->
112 <div id="div_view_options">
113 <form method="post" action="view_create.php">
114 <?php echo PMA_generate_common_hidden_inputs($url_params); ?>
115 <fieldset>
116 <legend>CREATE VIEW</legend>
118 <table>
119 <tr><td><label for="or_replace">OR REPLACE</label></td>
120 <td><input type="checkbox" name="view[or_replace]" id="or_replace"
121 <?php if ($view['or_replace']) { ?>
122 checked="checked"
123 <?php } ?>
124 value="1" />
125 </td>
126 </tr>
127 <tr>
128 <td><label for="algorithm">ALGORITHM</label></td>
129 <td><select name="view[algorithm]" id="algorithm">
130 <?php
131 foreach ($view_algorithm_options as $option) {
132 echo '<option value="' . htmlspecialchars($option) . '"';
133 if ($view['algorithm'] === $option) {
134 echo 'selected="selected"';
136 echo '>' . htmlspecialchars($option) . '</option>';
139 </select>
140 </td>
141 </tr>
142 <tr><td><?php echo __('VIEW name'); ?></td>
143 <td><input type="text" size="20" name="view[name]" onfocus="this.select()"
144 value="<?php echo htmlspecialchars($view['name']); ?>" />
145 </td>
146 </tr>
148 <tr><td><?php echo __('Column names'); ?></td>
149 <td><input type="text" maxlength="100" size="50" name="view[column_names]"
150 onfocus="this.select()"
151 value="<?php echo htmlspecialchars($view['column_names']); ?>" />
152 </td>
153 </tr>
155 <tr><td>AS</td>
156 <td>
157 <textarea name="view[as]" rows="<?php echo $cfg['TextareaRows']; ?>"
158 cols="<?php echo $cfg['TextareaCols']; ?>"
159 dir="<?php echo $text_dir; ?>" onfocus="this.select();"
160 ><?php echo htmlspecialchars($view['as']); ?></textarea>
161 </td>
162 </tr>
163 <tr><td>WITH</td>
164 <td>
165 <?php
166 foreach ($view_with_options as $option) {
167 echo '<input type="checkbox" name="view[with][]"';
168 if (in_array($option, $view['with'])) {
169 echo ' checked="checked"';
171 echo ' id="view_with_' . str_replace(' ', '_', htmlspecialchars($option)) . '"';
172 echo ' value="' . htmlspecialchars($option) . '" />';
173 echo '<label for="view_with_' . str_replace(' ', '_', htmlspecialchars($option)) . '">';
174 echo htmlspecialchars($option) . '</label>&nbsp;';
177 </td>
178 </tr>
179 </table>
180 </fieldset>
181 <fieldset class="tblFooters">
182 <input type="submit" name="createview" value="<?php echo __('Go'); ?>" />
183 </fieldset>
184 </form>
185 </div>
186 <?php
188 * Displays the footer
190 require_once './libraries/footer.inc.php';