3 // vim: expandtab sw=4 ts=4 sts=4:
8 require_once './libraries/common.lib.php';
11 $js_to_run = 'functions.js';
12 require './libraries/server_common.inc.php';
15 * Sorts the databases array according to the user's choice
17 * @param array a record associated to a database
18 * @param array a record associated to a database
20 * @return integer a value representing whether $a should be before $b in the
23 * @global string the column the array shall be sorted by
24 * @global string the sorting order ('asc' or 'desc')
28 function PMA_dbCmp($a, $b) {
29 global $sort_by, $sort_order;
30 if ($GLOBALS['cfg']['NaturalOrder']) {
31 $sorter = 'strnatcmp';
33 $sorter = 'strcasecmp';
35 if ($sort_by == 'SCHEMA_NAME') {
36 return ($sort_order == 'asc' ?
1 : -1) * $sorter($a['SCHEMA_NAME'], $b['SCHEMA_NAME']);
37 } elseif ($a[$sort_by] == $b[$sort_by]) {
38 return $sorter($a['SCHEMA_NAME'], $b['SCHEMA_NAME']);
40 return ($sort_order == 'asc' ?
1 : -1) * ((int)$a[$sort_by] > (int)$b[$sort_by] ?
1 : -1);
42 } // end of the 'PMA_dbCmp()' function
46 * avoids 'undefined index' errors
48 if (empty($_REQUEST['sort_by'])) {
49 $sort_by = 'SCHEMA_NAME';
51 $sort_by = PMA_sanitize($_REQUEST['sort_by']);
53 if (empty($_REQUEST['sort_order'])) {
54 if ($sort_by == 'SCHEMA_NAME') {
60 $sort_order = PMA_sanitize($_REQUEST['sort_order']);
63 $dbstats = empty($dbstats) ?
0 : 1;
67 * Drops multiple databases
70 // workaround for IE behavior (it returns some coordinates based on where
71 // the mouse was on the Drop image):
72 if (isset($_REQUEST['drop_selected_dbs_x'])) {
73 $_REQUEST['drop_selected_dbs'] = true;
76 if ((isset($_REQUEST['drop_selected_dbs']) ||
isset($_REQUEST['query_type']))
77 && ($is_superuser ||
$cfg['AllowUserDropDatabase'])) {
78 if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
79 $message = $strNoDatabasesSelected;
81 $action = 'server_databases.php';
82 $submit_mult = 'drop_db' ;
83 $err_url = 'server_databases.php?' . PMA_generate_common_url();
84 if (isset($_REQUEST['selected_dbs'])) {
85 $selected_db = $_REQUEST['selected_dbs'];
87 require './libraries/mult_submits.inc.php';
88 unset($action, $submit_mult, $err_url, $selected_db);
89 if ($mult_btn == $strYes) {
90 $message = sprintf($strDatabasesDropped, count($selected));
92 $message = sprintf($strDatabasesDropped, 0);
100 require './libraries/server_links.inc.php';
104 * Displays the sub-page heading
107 . ( $GLOBALS['cfg']['MainPageIconic']
108 ?
'<img class="icon" src="' . $pmaThemeImage . 's_db.png" width="16"'
109 .' height="16" alt="" />'
111 . ( $dbstats ?
$strDatabasesStats : $strDatabases ) . "\n"
115 * Gets the databases list
118 $databases = PMA_DBI_get_databases_full(null, $dbstats);
120 $databases = array();
128 $tmp_count = count($databases);
129 if ($tmp_count > 0) {
130 if ($tmp_count > 1) {
132 usort( $databases, 'PMA_dbCmp' );
134 // when there is only one database, the sort would not happen and
135 // the index would not become numeric (reproduced in MySQL 3.23.52)
136 $tmp_each = each($databases);
137 $databases = array();
138 $databases[0] = $tmp_each['value'];
143 // there is no db specific collation or charset prior 4.1.0
144 if (PMA_MYSQL_INT_VERSION
>= 40100) {
145 $column_order['DEFAULT_COLLATION_NAME'] = array(
146 'disp_name' => $strCollation,
147 'description_function' => 'PMA_getCollationDescr',
148 'format' => 'string',
149 'footer' => PMA_getServerCollation(),
152 $column_order['SCHEMA_TABLES'] = array(
153 'disp_name' => $strNumTables,
154 'format' => 'number',
157 $column_order['SCHEMA_TABLE_ROWS'] = array(
158 'disp_name' => $strRows,
159 'format' => 'number',
162 $column_order['SCHEMA_DATA_LENGTH'] = array(
163 'disp_name' => $strData,
167 $column_order['SCHEMA_INDEX_LENGTH'] = array(
168 'disp_name' => $strIndexes,
172 $column_order['SCHEMA_LENGTH'] = array(
173 'disp_name' => $strTotalUC,
177 $column_order['SCHEMA_DATA_FREE'] = array(
178 'disp_name' => $strOverhead,
183 echo '<form action="./server_databases.php" method="post" name="dbStatsForm" id="dbStatsForm">' . "\n"
184 . PMA_generate_common_hidden_inputs('', '', 1)
185 . '<input type="hidden" name="dbstats" value="' . $dbstats . '" />' . "\n"
186 . '<input type="hidden" name="sort_by" value="' . $sort_by . '" />' . "\n"
187 . '<input type="hidden" name="sort_order" value="' . $sort_order . '" />' . "\n"
188 . '<table id="tabledatabases" class="data">' . "\n"
191 . ($is_superuser ||
$cfg['AllowUserDropDatabase'] ?
' <th> </th>' . "\n" : '')
192 . ' <th><a href="./server_databases.php?' . $url_query . '&dbstats=' . $dbstats . '&sort_by=SCHEMA_NAME&sort_order=' . (($sort_by == 'SCHEMA_NAME' && $sort_order == 'asc') ?
'desc' : 'asc') . '">' . "\n"
193 . ' ' . $strDatabase . "\n"
194 . ($sort_by == 'SCHEMA_NAME' ?
' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
195 . ' </a></th>' . "\n";
197 foreach ( $column_order as $stat_name => $stat ) {
198 if ( array_key_exists( $stat_name, $databases[0] ) ) {
199 if ( $stat['format'] === 'byte' ) {
201 $colspan = ' colspan="2"';
206 echo ' <th' . $colspan . '>'
207 .'<a href="./server_databases.php?' . $url_query . '&dbstats=' . (int) $dbstats . '&sort_by=' . urlencode( $stat_name ) . '&sort_order=' . (($sort_by == $stat_name && $sort_order == 'desc') ?
'asc' : 'desc') . '">' . "\n"
208 .' ' . $stat['disp_name'] . "\n"
209 .($sort_by == $stat_name ?
' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
210 .' </a></th>' . "\n";
214 echo ' <th>' . ($cfg['PropertiesIconic'] ?
' ' : $strAction ) . "\n"
222 foreach ( $databases as $key => $current ) {
224 echo '<tr class="' . ( $odd_row ?
'odd' : 'even' ) . '">' . "\n";
225 $odd_row = ! $odd_row;
227 if ( $is_superuser ||
$cfg['AllowUserDropDatabase'] ) {
228 echo ' <td class="tool">' . "\n";
229 if ($current['SCHEMA_NAME'] != 'mysql' && (PMA_MYSQL_INT_VERSION
< 50002 ||
$current['SCHEMA_NAME'] != 'information_schema')) {
230 echo ' <input type="checkbox" name="selected_dbs[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" ' . (empty($checkall) ?
'' : 'checked="checked" ') . '/>' . "\n";
232 echo ' <input type="checkbox" name="selected_dbs[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" disabled="disabled"/>' . "\n";
234 echo ' </td>' . "\n";
236 echo ' <td class="name">' . "\n"
237 . ' <a onclick="if ( window.parent.openDb(\'' . urlencode($current['SCHEMA_NAME']) . '\') ) return false;" href="index.php?' . $url_query . '&db=' . urlencode($current['SCHEMA_NAME']) . '" title="' . sprintf($strJumpToDB, htmlspecialchars($current['SCHEMA_NAME'])) . '" target="_parent">' . "\n"
238 . ' ' . htmlspecialchars($current['SCHEMA_NAME']) . "\n"
242 foreach ( $column_order as $stat_name => $stat ) {
243 if ( array_key_exists( $stat_name, $current ) ) {
244 if ( is_numeric( $stat['footer'] ) ) {
245 $column_order[$stat_name]['footer'] +
= $current[$stat_name];
247 if ( $stat['format'] === 'byte' ) {
248 list( $value, $unit ) = PMA_formatByteDown( $current[$stat_name], 3, 1 );
249 } elseif ( $stat['format'] === 'number' ) {
250 $value = PMA_formatNumber( $current[$stat_name], 0 );
252 $value = htmlentities( $current[$stat_name], 0 );
254 echo ' <td class="value">';
255 if ( isset( $stat['description_function'] ) ) {
256 echo '<dfn title="' . $stat['description_function']( $current[$stat_name] ) . '">';
259 if ( isset( $stat['description_function'] ) ) {
263 if ( $stat['format'] === 'byte' ) {
264 echo ' <td class="unit">' . $unit . '</td>' . "\n";
270 echo ' <td class="tool">' . "\n"
271 . ' <a onclick="window.parent.setDb(\'' . urlencode($current['SCHEMA_NAME']) . '\');" href="./server_privileges.php?' . $url_query . '&checkprivs=' . urlencode($current['SCHEMA_NAME']) . '" title="' . sprintf($strCheckPrivsLong, htmlspecialchars($current['SCHEMA_NAME'])) . '">'. "\n"
272 . ' ' .($cfg['PropertiesIconic'] ?
'<img class="icon" src="' . $pmaThemeImage . 's_rights.png" width="16" height="16" alt=" ' .$strCheckPrivs . '" /> ' : $strCheckPrivs ). "\n"
273 . ' </a></td>' . "\n";
276 } // end foreach ( $databases as $key => $current )
277 unset( $key, $current, $odd_row );
280 if ( $is_superuser ||
$cfg['AllowUserDropDatabase'] ) {
281 echo ' <th> </th>' . "\n";
283 echo ' <th>' . $strTotalUC . ': ' . count( $databases ) . '</th>' . "\n";
284 foreach ( $column_order as $stat_name => $stat ) {
285 if ( array_key_exists( $stat_name, $databases[0] ) ) {
286 if ( $stat['format'] === 'byte' ) {
287 list( $value, $unit ) = PMA_formatByteDown( $stat['footer'], 3, 1 );
288 } elseif ( $stat['format'] === 'number' ) {
289 $value = PMA_formatNumber( $stat['footer'], 0 );
291 $value = htmlentities( $stat['footer'], 0 );
293 echo ' <th class="value">';
294 if ( isset( $stat['description_function'] ) ) {
295 echo '<dfn title="' . $stat['description_function']( $stat['footer'] ) . '">';
298 if ( isset( $stat['description_function'] ) ) {
302 if ( $stat['format'] === 'byte' ) {
303 echo ' <th class="unit">' . $unit . '</th>' . "\n";
307 if ( $is_superuser ) {
308 echo ' <th> </th>' . "\n";
311 echo '</tbody>' . "\n"
313 unset( $column_order, $stat_name, $stat, $databases, $table_columns );
315 if ($is_superuser ||
$cfg['AllowUserDropDatabase']) {
316 $common_url_query = PMA_generate_common_url() . '&sort_by=' . $sort_by . '&sort_order=' . $sort_order . '&dbstats=' . $dbstats;
317 echo '<img class="selectallarrow" src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
318 . '<a href="./server_databases.php?' . $common_url_query . '&checkall=1" onclick="if ( markAllRows(\'tabledatabases\') ) return false;">' . "\n"
319 . ' ' . $strCheckAll . '</a> / ' . "\n"
320 . '<a href="./server_databases.php?' . $common_url_query . '" onclick="if ( unMarkAllRows(\'tabledatabases\') ) return false;">' . "\n"
321 . ' ' . $strUncheckAll . '</a>' . "\n"
322 . '<i>' . $strWithChecked . '</i>' . "\n";
323 PMA_buttonOrImage( 'drop_selected_dbs', 'mult_submit', 'drop_selected_dbs', $strDrop, 'b_deltbl.png' );
326 if ( PMA_MYSQL_INT_VERSION
< 50002 ) {
327 echo '<ul><li id="li_switch_dbstats"><strong>' . "\n";
328 if ( empty( $dbstats ) ) {
329 echo ' <a href="./server_databases.php?' . $url_query . '&dbstats=1"'
330 .' title="' . $strDatabasesStatsEnable . '">' . "\n"
331 .' ' . $strDatabasesStatsEnable;
333 echo ' <a href="./server_databases.php?' . $url_query . '"'
334 .' title="' . $strDatabasesStatsDisable . '">' . "\n"
335 .' ' . $strDatabasesStatsDisable;
337 echo '</a></strong><br />' . "\n"
338 .' <div class="warning">'
339 . $strDatabasesStatsHeavyTraffic . '</div></li>' . "\n"
344 echo $strNoDatabases;
349 * Create new database.
351 echo '<ul><li id="li_create_database">' . "\n";
352 require './libraries/display_create_database.lib.php';
353 echo ' </li>' . "\n";
359 require_once './libraries/footer.inc.php';