Hungarian update
[phpmyadmin/crack.git] / view_create.php
blob008f86dd12063b6f9b189877485f4739eb08e92c
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 */
11 /**
12 * do not import request variable into global scope
14 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
15 define('PMA_NO_VARIABLES_IMPORT', true);
18 /**
21 require_once './libraries/common.inc.php';
23 /**
24 * Runs common work
26 require './libraries/db_common.inc.php';
27 $url_params['goto'] = $cfg['DefaultTabDatabase'];
28 $url_params['back'] = 'view_create.php';
30 $view_algorithm_options = array(
31 'UNDEFINED',
32 'MERGE',
33 'TEMPTABLE',
36 $view_with_options = array(
37 'CASCADED CHECK OPTION',
38 'LOCAL CHECK OPTION'
41 if (isset($_REQUEST['createview'])) {
42 /**
43 * Creates the view
45 $sep = "\r\n";
47 $sql_query = 'CREATE';
49 if (isset($_REQUEST['view']['or_replace'])) {
50 $sql_query .= ' OR REPLACE';
53 if (PMA_isValid($_REQUEST['view']['algorithm'], $view_algorithm_options)) {
54 $sql_query .= $sep . ' ALGORITHM = ' . $_REQUEST['view']['algorithm'];
57 $sql_query .= $sep . ' VIEW ' . PMA_backquote($_REQUEST['view']['name']);
59 if (! empty($_REQUEST['view']['column_names'])) {
60 $sql_query .= $sep . ' (' . $_REQUEST['view']['column_names'] . ')';
63 $sql_query .= $sep . ' AS ' . $_REQUEST['view']['as'];
65 if (isset($_REQUEST['view']['with'])) {
66 $options = array_intersect($_REQUEST['view']['with'], $view_with_options);
67 if (count($options)) {
68 $sql_query .= $sep . ' WITH ' . implode(' ', $options);
72 if (PMA_DBI_try_query($sql_query)) {
73 $message = PMA_Message::success();
74 require './' . $cfg['DefaultTabDatabase'];
75 exit();
76 } else {
77 $message = PMA_Message::rawError(PMA_DBI_getError());
81 // prefill values if not already filled from former submission
82 $view = array(
83 'or_replace' => '',
84 'algorithm' => '',
85 'name' => '',
86 'column_names' => '',
87 'as' => $sql_query,
88 'with' => array(),
91 if (PMA_isValid($_REQUEST['view'], 'array')) {
92 $view = array_merge($view, $_REQUEST['view']);
95 /**
96 * Displays top menu links
97 * We use db links because a VIEW is not necessarily on a single table
99 $num_tables = 0;
100 require_once './libraries/db_links.inc.php';
102 $url_params['db'] = $GLOBALS['db'];
103 $url_params['reload'] = 1;
106 * Displays the page
109 <!-- CREATE VIEW options -->
110 <div id="div_view_options">
111 <form method="post" action="view_create.php">
112 <?php echo PMA_generate_common_hidden_inputs($url_params); ?>
113 <fieldset>
114 <legend>CREATE VIEW</legend>
116 <table>
117 <tr><td><label for="or_replace">OR REPLACE</label></td>
118 <td><input type="checkbox" name="view[or_replace]" id="or_replace"
119 <?php if ($view['or_replace']) { ?>
120 checked="checked"
121 <?php } ?>
122 value="1" />
123 </td>
124 </tr>
125 <tr>
126 <td><label for="algorithm">ALGORITHM</label></td>
127 <td><select name="view[algorithm]" id="algorithm">
128 <?php
129 foreach ($view_algorithm_options as $option) {
130 echo '<option value="' . htmlspecialchars($option) . '"';
131 if ($view['algorithm'] === $option) {
132 echo 'selected="selected"';
134 echo '>' . htmlspecialchars($option) . '</option>';
137 </select>
138 </td>
139 </tr>
140 <tr><td><?php echo $strViewName; ?></td>
141 <td><input type="text" size="20" name="view[name]" onfocus="this.select()"
142 value="<?php echo htmlspecialchars($view['name']); ?>" />
143 </td>
144 </tr>
146 <tr><td><?php echo $strColumnNames; ?></td>
147 <td><input type="text" maxlength="100" size="50" name="view[column_names]"
148 onfocus="this.select()"
149 value="<?php echo htmlspecialchars($view['column_names']); ?>" />
150 </td>
151 </tr>
153 <tr><td>AS</td>
154 <td>
155 <textarea name="view[as]" rows="<?php echo $cfg['TextareaRows']; ?>"
156 cols="<?php echo $cfg['TextareaCols']; ?>"
157 dir="<?php echo $text_dir; ?>" onfocus="this.select();"
158 ><?php echo htmlspecialchars($view['as']); ?></textarea>
159 </td>
160 </tr>
161 <tr><td>WITH</td>
162 <td>
163 <?php
164 foreach ($view_with_options as $option) {
165 echo '<input type="checkbox" name="view[with][]"';
166 if (in_array($option, $view['with'])) {
167 echo ' checked="checked"';
169 echo ' id="view_with_' . htmlspecialchars($option) . '"';
170 echo ' value="' . htmlspecialchars($option) . '" />';
171 echo '<label for="view_with_' . htmlspecialchars($option) . '">';
172 echo htmlspecialchars($option) . '</label>';
175 </td>
176 </tr>
177 </table>
178 </fieldset>
179 <fieldset class="tblFooters">
180 <input type="submit" name="createview" value="<?php echo $strGo; ?>" />
181 </fieldset>
182 </form>
183 </div>
184 <?php
186 * Displays the footer
188 require_once './libraries/footer.inc.php';