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?)
13 * do not import request variable into global scope
16 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
17 define('PMA_NO_VARIABLES_IMPORT', true);
23 require_once './libraries/common.inc.php';
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(
38 $view_with_options = array(
39 'CASCADED CHECK OPTION',
43 if (isset($_REQUEST['createview'])) {
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'];
79 $message = PMA_Message
::rawError(PMA_DBI_getError());
83 // prefill values if not already filled from former submission
93 if (PMA_isValid($_REQUEST['view'], 'array')) {
94 $view = array_merge($view, $_REQUEST['view']);
98 * Displays top menu links
99 * We use db links because a VIEW is not necessarily on a single table
102 require_once './libraries/db_links.inc.php';
104 $url_params['db'] = $GLOBALS['db'];
105 $url_params['reload'] = 1;
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); ?
>
116 <legend
>CREATE VIEW
</legend
>
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']) { ?
>
128 <td
><label
for="algorithm">ALGORITHM
</label
></td
>
129 <td
><select name
="view[algorithm]" id
="algorithm">
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>';
142 <tr
><td
><?php
echo $strViewName; ?
></td
>
143 <td
><input type
="text" size
="20" name
="view[name]" onfocus
="this.select()"
144 value
="<?php echo htmlspecialchars($view['name']); ?>" />
148 <tr
><td
><?php
echo $strColumnNames; ?
></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']); ?>" />
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
>
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>';
181 <fieldset
class="tblFooters">
182 <input type
="submit" name
="createview" value
="<?php echo $strGo; ?>" />
188 * Displays the footer
190 require_once './libraries/footer.inc.php';