in case of error, display form again prefilled with previous values and the error occurred

This commit is contained in:
Sebastian Mendel
2007-10-12 10:10:59 +00:00
parent f8b5b6e94a
commit 3f943b4704

View File

@@ -1,10 +1,20 @@
<?php <?php
/* vim: set expandtab sw=4 ts=4 sts=4: */ /* vim: set expandtab sw=4 ts=4 sts=4: */
/** /**
* handles creation of VIEWs
* *
* @todo js error when view name is empty (strFormEmpty)
* @todo (also validate if js is disabled, after form submission?)
* @version $Id$ * @version $Id$
*/ */
/**
* do not import request variable into global scope
*/
if (! defined('PMA_NO_VARIABLES_IMPORT')) {
define('PMA_NO_VARIABLES_IMPORT', true);
}
/** /**
* *
*/ */
@@ -14,126 +24,162 @@ require_once './libraries/common.inc.php';
* Runs common work * Runs common work
*/ */
require './libraries/db_common.inc.php'; require './libraries/db_common.inc.php';
$url_params['goto'] = $url_params['back'] = 'view_create.php'; $url_params['goto'] = $cfg['DefaultTabDatabase'];
$url_params['back'] = 'view_create.php';
if (isset($_POST['submitoptions'])) { $view_algorithm_options = array(
'UNDEFINED',
'MERGE',
'TEMPTABLE',
);
$view_with_options = array(
'CASCADED',
'LOCAL',
'CHECK OPTION',
);
if (isset($_REQUEST['createview'])) {
/** /**
* Creates the view * Creates the view
*/ */
$message = '';
$sep = "\r\n"; $sep = "\r\n";
$create_query = 'CREATE' . $sep;
if (isset($_POST['or_replace'])) {
$create_query .= ' OR REPLACE' . $sep;
}
if (isset($_POST['algorithm'])) {
$create_query .= ' ALGORITHM = ' . $_POST['algorithm'] . $sep;
}
$create_query .= ' VIEW ' . $_POST['view_name'] . $sep;
if (!empty($_POST['column_names'])) { $sql_query = 'CREATE';
$create_query .= ' (' . $_POST['column_names'] . ')' . $sep;
if (isset($_REQUEST['view']['or_replace'])) {
$sql_query .= ' OR REPLACE';
} }
$create_query .= ' AS ' . $_POST['sql_statement'] . $sep; if (PMA_isValid($_REQUEST['view']['algorithm'], $view_algorithm_options)) {
$sql_query .= $sep . ' ALGORITHM = ' . $_REQUEST['view']['algorithm'];
if (isset($_POST['cascaded']) || isset($_POST['local']) || isset($_POST['check_option'])) {
$create_query .= ' WITH ';
} }
if (isset($_POST['cascaded'])) { $sql_query .= $sep . ' VIEW ' . PMA_backquote($_REQUEST['view']['name']);
$create_query .= ' CASCADED ';
if (! empty($_REQUEST['view']['column_names'])) {
$sql_query .= $sep . ' (' . $_REQUEST['view']['column_names'] . ')';
} }
if (isset($_POST['local'])) { $sql_query .= $sep . ' AS ' . $_REQUEST['view']['as'];
$create_query .= ' LOCAL ';
if (isset($_REQUEST['view']['with'])) {
$options = array_intersect($_REQUEST['view']['with'], $view_with_options);
if (count($options)) {
$sql_query .= $sep . ' WITH ' . implode(' ', $options);
}
} }
if (isset($_POST['check_option'])) { if (PMA_DBI_try_query($sql_query)) {
$create_query .= ' CHECK OPTION '; $message = PMA_Message::success();
require './' . $cfg['DefaultTabDatabase'];
exit();
} else {
$message = PMA_Message::error();
$message->setMessage(PMA_DBI_getError());
} }
}
$message .= PMA_DBI_query($create_query) ? $strSuccess : $strError; // prefill values if not already filled from former submission
$view = array(
'or_replace' => '',
'algorithm' => '',
'name' => '',
'column_names' => '',
'as' => $sql_query,
'with' => array(),
);
// to display the CREATE VIEW query if (PMA_isValid($_REQUEST['view'], 'array')) {
$sql_query = $create_query; $view = array_merge($view, $_REQUEST['view']);
}
require './' . $cfg['DefaultTabDatabase']; /**
exit(); * Displays top menu links
* We use db links because a VIEW is not necessarily on a single table
*/
$num_tables = 0;
require_once './libraries/db_links.inc.php';
} else { $url_params['db'] = $GLOBALS['db'];
/** $url_params['reload'] = 1;
* Displays top menu links
* We use db links because a VIEW is not necessarily on a single table
*/
$num_tables = 0;
require_once './libraries/db_links.inc.php';
$url_params['goto'] = 'view_create.php';
$url_params['back'] = 'view_create.php';
/**
* Displays the page
*
* @todo js error when view name is empty (strFormEmpty)
* @todo (also validate if js is disabled, after form submission?)
*/
/**
* Displays the page
*/
?> ?>
<!-- CREATE VIEW options --> <!-- CREATE VIEW options -->
<div id="div_view_options"> <div id="div_view_options">
<form method="post" action="view_create.php"> <form method="post" action="view_create.php">
<?php echo PMA_generate_common_hidden_inputs($GLOBALS['db']); ?> <?php echo PMA_generate_common_hidden_inputs($url_params); ?>
<input type="hidden" name="reload" value="1" />
<fieldset> <fieldset>
<legend>CREATE VIEW</legend> <legend>CREATE VIEW</legend>
<table> <table>
<tr><td><label for="or_replace">OR REPLACE</label></td> <tr><td><label for="or_replace">OR REPLACE</label></td>
<td><input type="checkbox" name="or_replace" id="or_replace" <td><input type="checkbox" name="view[or_replace]" id="or_replace"
<?php if ($view['or_replace']) { ?>
checked="checked"
<?php } ?>
value="1" /> value="1" />
</td> </td>
</tr> </tr>
<tr> <tr>
<td><label for="algorithm">ALGORITHM</label></td> <td><label for="algorithm">ALGORITHM</label></td>
<td><select name="algorithm" id="algorithm"> <td><select name="view[algorithm]" id="algorithm">
<option value="UNDEFINED">UNDEFINED</option> <?php
<option value="MERGE">MERGE</option> foreach ($view_algorithm_options as $option) {
<option value="TEMPTABLE">TEMPTABLE</option> echo '<option value="' . htmlspecialchars($option) . '"';
if ($view['algorithm'] === $option) {
echo 'selected="selected"';
}
echo '>' . htmlspecialchars($option) . '</option>';
}
?>
</select> </select>
</td> </td>
</tr> </tr>
<tr><td><?php echo $strViewName; ?></td> <tr><td><?php echo $strViewName; ?></td>
<td><input type="text" size="20" name="view_name" onfocus="this.select()" <td><input type="text" size="20" name="view[name]" onfocus="this.select()"
value="" /> value="<?php echo htmlspecialchars($view['name']); ?>" />
</td> </td>
</tr> </tr>
<tr><td><?php echo $strColumnNames; ?></td> <tr><td><?php echo $strColumnNames; ?></td>
<td><input type="text" maxlength="100" size="50" name="column_names" onfocus="this.select()" <td><input type="text" maxlength="100" size="50" name="view[column_names]"
value="" /> onfocus="this.select()"
value="<?php echo htmlspecialchars($view['column_names']); ?>" />
</td> </td>
</tr> </tr>
<tr><td><?php echo 'AS' ?></td> <tr><td>AS</td>
<td> <td>
<textarea name="sql_statement" rows="<?php echo $cfg['TextareaRows']; ?>" cols="<?php echo $cfg['TextareaCols']; ?>" dir="<?php echo $text_dir; ?>" onfocus="this.select();"><?php echo htmlspecialchars($sql_query); ?></textarea> <textarea name="view[as]" rows="<?php echo $cfg['TextareaRows']; ?>"
cols="<?php echo $cfg['TextareaCols']; ?>"
dir="<?php echo $text_dir; ?>" onfocus="this.select();"
><?php echo htmlspecialchars($view['as']); ?></textarea>
</td> </td>
</tr> </tr>
<tr><td>WITH</td> <tr><td>WITH</td>
<td> <td>
<input type="checkbox" name="cascaded" id="cascaded" value="1" /> <?php
<label for="cascaded">CASCADED</label> foreach ($view_with_options as $option) {
<input type="checkbox" name="local" id="local" value="1" /> echo '<input type="checkbox" name="view[with][]"';
<label for="local">LOCAL</label> if (in_array($option, $view['with'])) {
<input type="checkbox" name="check_option" id="check_option" value="1" /> echo ' checked="checked"';
<label for="check_option">CHECK OPTION</label> }
echo ' id="view_with_' . htmlspecialchars($option) . '"';
echo ' value="' . htmlspecialchars($option) . '" />';
echo '<label for="view_with_' . htmlspecialchars($option) . '">';
echo htmlspecialchars($option) . '</label>';
}
?>
</td> </td>
</tr> </tr>
</table> </table>
</fieldset> </fieldset>
<fieldset class="tblFooters"> <fieldset class="tblFooters">
<input type="submit" name="submitoptions" value="<?php echo $strGo; ?>" /> <input type="submit" name="createview" value="<?php echo $strGo; ?>" />
</fieldset> </fieldset>
</form> </form>
</div> </div>
@@ -143,5 +189,4 @@ if (isset($_POST['submitoptions'])) {
*/ */
require_once './libraries/footer.inc.php'; require_once './libraries/footer.inc.php';
} // end if
?> ?>