2 /* vim: set expandtab sw=4 ts=4 sts=4: */
5 * functions for displaying server databases
7 * @usedby server_databases.php
11 if (! defined('PHPMYADMIN')) {
16 * Returns the html for Database List
18 * @param Array $databases GBI return databases
19 * @param int $databases_count database count
20 * @param int $pos display pos
21 * @param Array $dbstats database status
22 * @param string $sort_by sort by string
23 * @param string $sort_order sort order string
24 * @param bool $is_superuser User status
25 * @param Array $cfg configuration
26 * @param string $replication_types replication types
27 * @param string $replication_info replication info
28 * @param string $url_query url query
32 function PMA_getHtmlForDatabase(
33 $databases, $databases_count, $pos, $dbstats,
34 $sort_by, $sort_order, $is_superuser, $cfg,
35 $replication_types, $replication_info, $url_query
37 $html = '<div id="tableslistcontainer">';
39 $first_database = current($databases);
41 $column_order = PMA_getColumnOrder();
45 'dbstats' => $dbstats,
46 'sort_by' => $sort_by,
47 'sort_order' => $sort_order,
50 $html .= PMA_Util
::getListNavigator(
51 $databases_count, $pos, $_url_params, 'server_databases.php',
52 'frame_content', $GLOBALS['cfg']['MaxDbList']
55 $_url_params['pos'] = $pos;
57 $html .= '<form class="ajax" action="server_databases.php" ';
58 $html .= 'method="post" name="dbStatsForm" id="dbStatsForm">' . "\n";
59 $html .= PMA_URL_getHiddenInputs($_url_params);
61 $_url_params['sort_by'] = 'SCHEMA_NAME';
62 $_url_params['sort_order']
63 = ($sort_by == 'SCHEMA_NAME' && $sort_order == 'asc') ?
'desc' : 'asc';
65 $html .= '<table id="tabledatabases" class="data">' . "\n"
69 $html .= PMA_getHtmlForColumnOrderWithSort(
71 $cfg['AllowUserDropDatabase'],
79 $html .= PMA_getHtmlForReplicationType(
82 $cfg['ActionLinksMode']
85 $html .= '</tr>' . "\n"
88 list($output, $column_order) = PMA_getHtmlAndColumnOrderForDatabaseList(
99 $html .= PMA_getHtmlForTableFooter(
100 $cfg['AllowUserDropDatabase'],
108 $html .= '</table>' . "\n";
110 $html .= PMA_getHtmlForTableFooterButtons(
111 $cfg['AllowUserDropDatabase'],
115 if (empty($dbstats)) {
116 //we should put notice above database list
117 $html = PMA_getHtmlForNoticeEnableStatistics($url_query, $html);
126 * Returns the html for Table footer buttons
128 * @param bool $is_allowUserDropDb Allow user drop database
129 * @param bool $is_superuser User status
133 function PMA_getHtmlForTableFooterButtons($is_allowUserDropDb, $is_superuser)
135 if (!$is_superuser && !$is_allowUserDropDb) {
139 $html = '<img class="selectallarrow" src="'
140 . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png"'
141 . ' width="38" height="22" alt="' . __('With selected:') . '" />' . "\n"
142 . '<input type="checkbox" id="dbStatsForm_checkall" '
143 . 'class="checkall_box" title="' . __('Check All') . '" /> '
144 . '<label for="dbStatsForm_checkall">' . __('Check All') . '</label> '
145 . '<i style="margin-left: 2em">' . __('With selected:') . '</i>' . "\n";
146 $html .= PMA_Util
::getButtonOrImage(
148 'mult_submit' . ' ajax',
150 __('Drop'), 'b_deltbl.png'
157 * Returns the html for Table footer
159 * @param bool $is_allowUserDropDb Allow user drop database
160 * @param bool $is_superuser User status
161 * @param Array $databases_count Database count
162 * @param string $column_order column order
163 * @param array $replication_types replication types
164 * @param string $first_database First database
168 function PMA_getHtmlForTableFooter(
169 $is_allowUserDropDb, $is_superuser,
170 $databases_count, $column_order,
171 $replication_types, $first_database
173 $html = '<tfoot><tr>' . "\n";
174 if ($is_superuser ||
$is_allowUserDropDb) {
175 $html .= ' <th></th>' . "\n";
177 $html .= ' <th>' . __('Total') . ': <span id="databases_count">'
178 . $databases_count . '</span></th>' . "\n";
180 $html .= PMA_getHtmlForColumnOrder($column_order, $first_database);
182 foreach ($replication_types as $type) {
183 if ($GLOBALS["server_" . $type . "_status"]) {
184 $html .= ' <th></th>' . "\n";
189 $html .= ' <th></th>' . "\n";
191 $html .= '</tr>' . "\n";
192 $html .= '</tfoot>' . "\n";
197 * Returns the html for Database List and Column order
199 * @param array $databases GBI return databases
200 * @param bool $is_superuser User status
201 * @param Array $url_query Url query
202 * @param string $column_order column order
203 * @param string $replication_types replication types
204 * @param string $replication_info replication info
208 function PMA_getHtmlAndColumnOrderForDatabaseList(
209 $databases, $is_superuser, $url_query,
210 $column_order, $replication_types, $replication_info
213 $html = '<tbody>' . "\n";
215 foreach ($databases as $current) {
216 $tr_class = $odd_row ?
'odd' : 'even';
217 if ($GLOBALS['dbi']->isSystemSchema($current['SCHEMA_NAME'], true)) {
218 $tr_class .= ' noclick';
220 $html .= '<tr class="' . $tr_class . '">' . "\n";
221 $odd_row = ! $odd_row;
223 list($column_order, $generated_html) = PMA_buildHtmlForDb(
232 $html .= $generated_html;
234 $html .= '</tr>' . "\n";
235 } // end foreach ($databases as $key => $current)
236 unset($current, $odd_row);
238 return array($html, $column_order);
242 * Returns the html for Column Order
244 * @param array $column_order Column order
245 * @param array $first_database The first display database
249 function PMA_getHtmlForColumnOrder($column_order, $first_database)
252 foreach ($column_order as $stat_name => $stat) {
253 if (array_key_exists($stat_name, $first_database)) {
254 if ($stat['format'] === 'byte') {
256 = PMA_Util
::formatByteDown($stat['footer'], 3, 1);
257 } elseif ($stat['format'] === 'number') {
258 $value = PMA_Util
::formatNumber($stat['footer'], 0);
260 $value = htmlentities($stat['footer'], 0);
262 $html .= ' <th class="value">';
263 if (isset($stat['description_function'])) {
264 $html .= '<dfn title="'
265 . $stat['description_function']($stat['footer']) . '">';
268 if (isset($stat['description_function'])) {
271 $html .= '</th>' . "\n";
272 if ($stat['format'] === 'byte') {
273 $html .= ' <th class="unit">' . $unit . '</th>' . "\n";
283 * Returns the html for Column Order with Sort
285 * @param bool $is_superuser User status
286 * @param bool $is_allowUserDropDb Allow user drop database
287 * @param Array $_url_params Url params
288 * @param string $sort_by sort colume name
289 * @param string $sort_order order
290 * @param array $column_order column order
291 * @param array $first_database database to show
295 function PMA_getHtmlForColumnOrderWithSort(
296 $is_superuser, $is_allowUserDropDb,
297 $_url_params, $sort_by, $sort_order,
298 $column_order, $first_database
300 $html = ($is_superuser ||
$is_allowUserDropDb
301 ?
' <th></th>' . "\n"
303 . ' <th><a href="server_databases.php'
304 . PMA_URL_getCommon($_url_params) . '">' . "\n"
305 . ' ' . __('Database') . "\n"
306 . ($sort_by == 'SCHEMA_NAME'
307 ?
' ' . PMA_Util
::getImage(
308 's_' . $sort_order . '.png',
309 ($sort_order == 'asc' ?
__('Ascending') : __('Descending'))
313 . ' </a></th>' . "\n";
315 foreach ($column_order as $stat_name => $stat) {
316 if (!array_key_exists($stat_name, $first_database)) {
320 if ($stat['format'] === 'byte') {
322 $colspan = ' colspan="2"';
327 $_url_params['sort_by'] = $stat_name;
328 $_url_params['sort_order']
329 = ($sort_by == $stat_name && $sort_order == 'desc') ?
'asc' : 'desc';
330 $html .= ' <th' . $colspan . '>'
331 . '<a href="server_databases.php'
332 . PMA_URL_getCommon($_url_params) . '">' . "\n"
333 . ' ' . $stat['disp_name'] . "\n"
334 . ($sort_by == $stat_name
335 ?
' ' . PMA_Util
::getImage(
336 's_' . $sort_order . '.png',
337 ($sort_order == 'asc' ?
__('Ascending') : __('Descending'))
341 . ' </a></th>' . "\n";
348 * Returns the html for Enable Statistics
350 * @param bool $url_query Url query
351 * @param string $html html for database list
355 function PMA_getHtmlForNoticeEnableStatistics($url_query, $html)
357 $notice = PMA_Message
::notice(
359 'Note: Enabling the database statistics here might cause '
360 . 'heavy traffic between the web server and the MySQL server.'
363 //we should put notice above database list
364 $html = $notice . $html;
365 $html .= '<ul><li id="li_switch_dbstats"><strong>' . "\n";
366 $html .= '<a href="server_databases.php?' . $url_query . '&dbstats=1"'
367 . ' title="' . __('Enable Statistics') . '">' . "\n"
368 . ' ' . __('Enable Statistics');
369 $html .= '</a></strong><br />' . "\n";
370 $html .= '</li>' . "\n" . '</ul>' . "\n";
376 * Returns the html for database replication types
378 * @param bool $is_superuser User status
379 * @param Array $replication_types replication types
380 * @param bool $cfg_inconic cfg about Properties Iconic
384 function PMA_getHtmlForReplicationType(
385 $is_superuser, $replication_types, $cfg_inconic
388 foreach ($replication_types as $type) {
389 if ($type == "master") {
390 $name = __('Master replication');
391 } elseif ($type == "slave") {
392 $name = __('Slave replication');
395 if ($GLOBALS["server_{$type}_status"]) {
396 $html .= ' <th>' . $name . '</th>' . "\n";
400 if ($is_superuser && ! PMA_DRIZZLE
) {
401 $html .= ' <th>' . ($cfg_inconic ?
'' : __('Action')) . "\n"
408 * Returns the array about $sort_order and $sort_by
412 function PMA_getListForSortDatabase()
415 * avoids 'undefined index' errors
419 if (empty($_REQUEST['sort_by'])) {
420 $sort_by = 'SCHEMA_NAME';
422 $sort_by_whitelist = array(
424 'DEFAULT_COLLATION_NAME',
427 'SCHEMA_DATA_LENGTH',
428 'SCHEMA_INDEX_LENGTH',
432 if (in_array($_REQUEST['sort_by'], $sort_by_whitelist)) {
433 $sort_by = $_REQUEST['sort_by'];
435 $sort_by = 'SCHEMA_NAME';
439 if (isset($_REQUEST['sort_order'])
440 && strtolower($_REQUEST['sort_order']) == 'desc'
442 $sort_order = 'desc';
447 return array($sort_by, $sort_order);
451 * Deal with Drops multiple databases
455 function PMA_dropMultiDatabases()
457 if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
458 $message = PMA_Message
::error(__('No databases selected.'));
460 $action = 'server_databases.php';
461 $submit_mult = 'drop_db';
462 $err_url = 'server_databases.php?' . PMA_URL_getCommon();
463 if (isset($_REQUEST['selected_dbs'])
464 && !isset($_REQUEST['is_js_confirmed'])
466 $selected_db = $_REQUEST['selected_dbs'];
468 if (isset($_REQUEST['is_js_confirmed'])) {
470 'query_type' => $submit_mult,
471 'selected' => $_REQUEST['selected_dbs'],
472 'mult_btn' => __('Yes'),
473 'db' => $GLOBALS['db'],
474 'table' => $GLOBALS['table']);
476 //the following variables will be used on mult_submits.inc.php
477 global $query_type, $selected, $mult_btn;
479 include 'libraries/mult_submits.inc.php';
480 unset($action, $submit_mult, $err_url, $selected_db, $GLOBALS['db']);
481 if (empty($message)) {
482 if ($mult_btn == __('Yes')) {
483 $number_of_databases = count($selected);
485 $number_of_databases = 0;
487 $message = PMA_Message
::success(
489 '%1$d database has been dropped successfully.',
490 '%1$d databases have been dropped successfully.',
494 $message->addParam($number_of_databases);
497 if ($GLOBALS['is_ajax_request'] && $message instanceof PMA_Message
) {
498 $response = PMA_Response
::getInstance();
499 $response->isSuccess($message->isSuccess());
500 $response->addJSON('message', $message);