Translated using Weblate (Slovenian)
[phpmyadmin.git] / db_create.php
blob86cdf4bafd3ade1de44abade61aa3ec63178ca5f
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Database creating page
6 * @package PhpMyAdmin
7 */
9 /**
10 * Gets some core libraries
12 require_once 'libraries/common.inc.php';
14 require_once 'libraries/mysql_charsets.inc.php';
15 if (! PMA_DRIZZLE) {
16 include_once 'libraries/replication.inc.php';
18 require 'libraries/build_html_for_db.lib.php';
20 /**
21 * Defines the url to return to in case of error in a sql statement
23 $err_url = 'index.php' . PMA_URL_getCommon();
25 /**
26 * Builds and executes the db creation sql query
28 $sql_query = 'CREATE DATABASE ' . PMA_Util::backquote($_POST['new_db']);
29 if (! empty($_POST['db_collation'])) {
30 list($db_charset) = explode('_', $_POST['db_collation']);
31 if (in_array($db_charset, $mysql_charsets)
32 && in_array($_POST['db_collation'], $mysql_collations[$db_charset])
33 ) {
34 $sql_query .= ' DEFAULT'
35 . PMA_generateCharsetQueryPart($_POST['db_collation']);
37 $db_collation_for_ajax = $_POST['db_collation'];
38 unset($db_charset);
40 $sql_query .= ';';
42 $result = $GLOBALS['dbi']->tryQuery($sql_query);
44 if (! $result) {
45 $message = PMA_Message::rawError($GLOBALS['dbi']->getError());
46 // avoid displaying the not-created db name in header or navi panel
47 $GLOBALS['db'] = '';
48 $GLOBALS['table'] = '';
50 /**
51 * If in an Ajax request, just display the message with {@link PMA_Response}
53 if ($GLOBALS['is_ajax_request'] == true) {
54 $response = PMA_Response::getInstance();
55 $response->isSuccess(false);
56 $response->addJSON('message', $message);
57 } else {
58 include_once 'index.php';
60 } else {
61 $message = PMA_Message::success(__('Database %1$s has been created.'));
62 $message->addParam($_POST['new_db']);
63 $GLOBALS['db'] = $_POST['new_db'];
65 /**
66 * If in an Ajax request, build the output and send it
68 if ($GLOBALS['is_ajax_request'] == true) {
69 //Construct the html for the new database, so that it can be appended to
70 // the list of databases on server_databases.php
72 /**
73 * Build the array to be passed to {@link PMA_URL_getCommon}
74 * to generate the links
76 * @global array $GLOBALS['db_url_params']
77 * @name $db_url_params
79 $db_url_params['db'] = $_POST['new_db'];
81 $is_superuser = $GLOBALS['dbi']->isSuperuser();
82 $column_order = PMA_getColumnOrder();
83 $url_query = PMA_URL_getCommon(array('db' => $_POST['new_db']));
85 /**
86 * String that will contain the output HTML
87 * @name $new_db_string
89 $new_db_string = '<tr>';
91 if (empty($db_collation_for_ajax)) {
92 $db_collation_for_ajax = PMA_getServerCollation();
95 // $dbstats comes from the create table dialog
96 if (! empty($dbstats)) {
97 $current = array(
98 'SCHEMA_NAME' => $_POST['new_db'],
99 'DEFAULT_COLLATION_NAME' => $db_collation_for_ajax,
100 'SCHEMA_TABLES' => '0',
101 'SCHEMA_TABLE_ROWS' => '0',
102 'SCHEMA_DATA_LENGTH' => '0',
103 'SCHEMA_MAX_DATA_LENGTH' => '0',
104 'SCHEMA_INDEX_LENGTH' => '0',
105 'SCHEMA_LENGTH' => '0',
106 'SCHEMA_DATA_FREE' => '0'
108 } else {
109 $current = array(
110 'SCHEMA_NAME' => $_POST['new_db'],
111 'DEFAULT_COLLATION_NAME' => $db_collation_for_ajax
115 list($column_order, $generated_html) = PMA_buildHtmlForDb(
116 $current, $is_superuser, $url_query,
117 $column_order, $replication_types, $GLOBALS['replication_info']
119 $new_db_string .= $generated_html;
121 $new_db_string .= '</tr>';
123 $response = PMA_Response::getInstance();
124 $response->addJSON('message', $message);
125 $response->addJSON('new_db_string', $new_db_string);
126 $response->addJSON(
127 'sql_query',
128 PMA_Util::getMessage(
129 null, $sql_query, 'success'
132 $response->addJSON(
133 'url_query',
134 PMA_Util::getScriptNameForOption(
135 $GLOBALS['cfg']['DefaultTabDatabase'], 'database'
137 . $url_query . '&amp;db='
138 . urlencode($current['SCHEMA_NAME'])
140 } else {
141 include_once '' . $cfg['DefaultTabDatabase'];