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
14 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
15 define('PMA_NO_VARIABLES_IMPORT', true);
21 require_once './libraries/common.inc.php';
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(
36 $view_with_options = array(
37 'CASCADED CHECK OPTION',
41 if (isset($_REQUEST['createview'])) {
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'];
77 $message = PMA_Message
::rawError(PMA_DBI_getError());
81 // prefill values if not already filled from former submission
91 if (PMA_isValid($_REQUEST['view'], 'array')) {
92 $view = array_merge($view, $_REQUEST['view']);
96 * Displays top menu links
97 * We use db links because a VIEW is not necessarily on a single table
100 require_once './libraries/db_links.inc.php';
102 $url_params['db'] = $GLOBALS['db'];
103 $url_params['reload'] = 1;
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); ?
>
114 <legend
>CREATE VIEW
</legend
>
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']) { ?
>
126 <td
><label
for="algorithm">ALGORITHM
</label
></td
>
127 <td
><select name
="view[algorithm]" id
="algorithm">
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>';
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']); ?>" />
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']); ?>" />
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
>
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>';
179 <fieldset
class="tblFooters">
180 <input type
="submit" name
="createview" value
="<?php echo $strGo; ?>" />
186 * Displays the footer
188 require_once './libraries/footer.inc.php';