2 /* vim: set expandtab sw=4 ts=4 sts=4: */
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?)
12 * do not import request variable into global scope
15 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
16 define('PMA_NO_VARIABLES_IMPORT', true);
22 require_once './libraries/common.inc.php';
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(
37 $view_with_options = array(
38 'CASCADED CHECK OPTION',
42 if (isset($_REQUEST['createview'])) {
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'];
78 $message = PMA_Message
::rawError(PMA_DBI_getError());
82 // prefill values if not already filled from former submission
92 if (PMA_isValid($_REQUEST['view'], 'array')) {
93 $view = array_merge($view, $_REQUEST['view']);
97 * Displays top menu links
98 * We use db links because a VIEW is not necessarily on a single table
101 require_once './libraries/db_links.inc.php';
103 $url_params['db'] = $GLOBALS['db'];
104 $url_params['reload'] = 1;
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); ?
>
115 <legend
>CREATE VIEW
</legend
>
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']) { ?
>
127 <td
><label
for="algorithm">ALGORITHM
</label
></td
>
128 <td
><select name
="view[algorithm]" id
="algorithm">
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>';
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']); ?>" />
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']); ?>" />
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
>
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> ';
180 <fieldset
class="tblFooters">
181 <input type
="submit" name
="createview" value
="<?php echo __('Go'); ?>" />
187 * Displays the footer
189 require './libraries/footer.inc.php';