addJSON(
'message',
$message
);
$response->setRequestStatus(false);
exit;
}
if (isset($_REQUEST['createview']) || isset($_REQUEST['alterview'])) {
/**
* Creates the view
*/
$sep = "\r\n";
if (isset($_REQUEST['createview'])) {
$sql_query = 'CREATE';
if (isset($_REQUEST['view']['or_replace'])) {
$sql_query .= ' OR REPLACE';
}
} else {
$sql_query = 'ALTER';
}
if (PMA_isValid($_REQUEST['view']['algorithm'], $view_algorithm_options)) {
$sql_query .= $sep . ' ALGORITHM = ' . $_REQUEST['view']['algorithm'];
}
if (! empty($_REQUEST['view']['definer'])) {
if (strpos($_REQUEST['view']['definer'], '@') === FALSE) {
$sql_query .= $sep . 'DEFINER='
. PMA\libraries\Util::backquote($_REQUEST['view']['definer']);
} else {
$arr = explode('@', $_REQUEST['view']['definer']);
$sql_query .= $sep . 'DEFINER=' . PMA\libraries\Util::backquote($arr[0]);
$sql_query .= '@' . PMA\libraries\Util::backquote($arr[1]) . ' ';
}
}
if (isset($_REQUEST['view']['sql_security'])) {
if (in_array($_REQUEST['view']['sql_security'], $view_security_options)) {
$sql_query .= $sep . ' SQL SECURITY '
. $_REQUEST['view']['sql_security'];
}
}
$sql_query .= $sep . ' VIEW '
. PMA\libraries\Util::backquote($_REQUEST['view']['name']);
if (! empty($_REQUEST['view']['column_names'])) {
$sql_query .= $sep . ' (' . $_REQUEST['view']['column_names'] . ')';
}
$sql_query .= $sep . ' AS ' . $_REQUEST['view']['as'];
if (isset($_REQUEST['view']['with'])) {
if (in_array($_REQUEST['view']['with'], $view_with_options)) {
$sql_query .= $sep . ' WITH ' . $_REQUEST['view']['with']
. ' CHECK OPTION';
}
}
if (!$GLOBALS['dbi']->tryQuery($sql_query)) {
if (! isset($_REQUEST['ajax_dialog'])) {
$message = PMA\libraries\Message::rawError($GLOBALS['dbi']->getError());
return;
}
$response = PMA\libraries\Response::getInstance();
$response->addJSON(
'message',
PMA\libraries\Message::error(
"" . htmlspecialchars($sql_query) . "
"
. $GLOBALS['dbi']->getError()
)
);
$response->setRequestStatus(false);
exit;
}
// If different column names defined for VIEW
$view_columns = array();
if (isset($_REQUEST['view']['column_names'])) {
$view_columns = explode(',', $_REQUEST['view']['column_names']);
}
$column_map = $GLOBALS['dbi']->getColumnMapFromSql(
$_REQUEST['view']['as'], $view_columns
);
$systemDb = $GLOBALS['dbi']->getSystemDatabase();
$pma_transformation_data = $systemDb->getExistingTransformationData(
$GLOBALS['db']
);
if ($pma_transformation_data !== false) {
// SQL for store new transformation details of VIEW
$new_transformations_sql = $systemDb->getNewTransformationDataSql(
$pma_transformation_data, $column_map,
$_REQUEST['view']['name'], $GLOBALS['db']
);
// Store new transformations
if ($new_transformations_sql != '') {
$GLOBALS['dbi']->tryQuery($new_transformations_sql);
}
}
unset($pma_transformation_data);
if (! isset($_REQUEST['ajax_dialog'])) {
$message = PMA\libraries\Message::success();
include 'tbl_structure.php';
} else {
$response = PMA\libraries\Response::getInstance();
$response->addJSON(
'message',
PMA\libraries\Util::getMessage(
PMA\libraries\Message::success(),
$sql_query
)
);
$response->setRequestStatus(true);
}
exit;
}
// prefill values if not already filled from former submission
$view = array(
'operation' => 'create',
'or_replace' => '',
'algorithm' => '',
'definer' => '',
'sql_security' => '',
'name' => '',
'column_names' => '',
'as' => $sql_query,
'with' => '',
);
if (PMA_isValid($_REQUEST['view'], 'array')) {
$view = array_merge($view, $_REQUEST['view']);
}
$url_params['db'] = $GLOBALS['db'];
$url_params['reload'] = 1;
/**
* Displays the page
*/
$htmlString = ''
. '