acknowledgments update
[openemr.git] / phpmyadmin / db_create.php
blob48ce08468f63bdb69eed0b0a5afbecea351a21a2
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package PhpMyAdmin
6 */
8 /**
9 * Gets some core libraries
11 require_once 'libraries/common.inc.php';
13 require_once 'libraries/mysql_charsets.lib.php';
14 if (! PMA_DRIZZLE) {
15 include_once 'libraries/replication.inc.php';
17 require 'libraries/build_html_for_db.lib.php';
19 /**
20 * Sets globals from $_POST
22 $post_params = array(
23 'db_collation',
24 'new_db'
26 foreach ($post_params as $one_post_param) {
27 if (isset($_POST[$one_post_param])) {
28 $GLOBALS[$one_post_param] = $_POST[$one_post_param];
32 PMA_Util::checkParameters(array('new_db'));
34 /**
35 * Defines the url to return to in case of error in a sql statement
37 $err_url = 'index.php?' . PMA_generate_common_url();
39 /**
40 * Builds and executes the db creation sql query
42 $sql_query = 'CREATE DATABASE ' . PMA_Util::backquote($new_db);
43 if (! empty($db_collation)) {
44 list($db_charset) = explode('_', $db_collation);
45 if (in_array($db_charset, $mysql_charsets)
46 && in_array($db_collation, $mysql_collations[$db_charset])
47 ) {
48 $sql_query .= ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation);
50 $db_collation_for_ajax = $db_collation;
51 unset($db_charset, $db_collation);
53 $sql_query .= ';';
55 $result = PMA_DBI_try_query($sql_query);
57 if (! $result) {
58 $message = PMA_Message::rawError(PMA_DBI_getError());
59 // avoid displaying the not-created db name in header or navi panel
60 $GLOBALS['db'] = '';
61 $GLOBALS['table'] = '';
63 /**
64 * If in an Ajax request, just display the message with {@link PMA_Response}
66 if ($GLOBALS['is_ajax_request'] == true) {
67 $response = PMA_Response::getInstance();
68 $response->isSuccess(false);
69 $response->addJSON('message', $message);
70 } else {
71 include_once 'index.php';
73 } else {
74 $message = PMA_Message::success(__('Database %1$s has been created.'));
75 $message->addParam($new_db);
76 $GLOBALS['db'] = $new_db;
78 /**
79 * If in an Ajax request, build the output and send it
81 if ($GLOBALS['is_ajax_request'] == true) {
82 //Construct the html for the new database, so that it can be appended to
83 // the list of databases on server_databases.php
85 /**
86 * Build the array to be passed to {@link PMA_generate_common_url}
87 * to generate the links
89 * @global array $GLOBALS['db_url_params']
90 * @name $db_url_params
92 $db_url_params['db'] = $new_db;
94 $is_superuser = PMA_isSuperuser();
95 $column_order = PMA_getColumnOrder();
96 $url_query = PMA_generate_common_url($new_db);
98 /**
99 * String that will contain the output HTML
100 * @name $new_db_string
102 $new_db_string = '<tr>';
104 if (empty($db_collation_for_ajax)) {
105 $db_collation_for_ajax = PMA_getServerCollation();
108 // $dbstats comes from the create table dialog
109 if (! empty($dbstats)) {
110 $current = array(
111 'SCHEMA_NAME' => $new_db,
112 'DEFAULT_COLLATION_NAME' => $db_collation_for_ajax,
113 'SCHEMA_TABLES' => '0',
114 'SCHEMA_TABLE_ROWS' => '0',
115 'SCHEMA_DATA_LENGTH' => '0',
116 'SCHEMA_MAX_DATA_LENGTH' => '0',
117 'SCHEMA_INDEX_LENGTH' => '0',
118 'SCHEMA_LENGTH' => '0',
119 'SCHEMA_DATA_FREE' => '0'
121 } else {
122 $current = array(
123 'SCHEMA_NAME' => $new_db
127 list($column_order, $generated_html) = PMA_buildHtmlForDb(
128 $current, $is_superuser, $url_query,
129 $column_order, $replication_types, $replication_info
131 $new_db_string .= $generated_html;
133 $new_db_string .= '</tr>';
135 $response = PMA_Response::getInstance();
136 $response->addJSON('message', $message);
137 $response->addJSON('new_db_string', $new_db_string);
138 $response->addJSON(
139 'sql_query',
140 PMA_Util::getMessage(
141 null, $sql_query, 'success'
144 } else {
145 include_once '' . $cfg['DefaultTabDatabase'];