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 int $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['replication_info'][$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 // avoid execution path notice
254 foreach ($column_order as $stat_name => $stat) {
255 if (array_key_exists($stat_name, $first_database)) {
256 if ($stat['format'] === 'byte') {
258 = PMA_Util
::formatByteDown($stat['footer'], 3, 1);
259 } elseif ($stat['format'] === 'number') {
260 $value = PMA_Util
::formatNumber($stat['footer'], 0);
262 $value = htmlentities($stat['footer'], 0);
264 $html .= ' <th class="value">';
265 if (isset($stat['description_function'])) {
266 $html .= '<dfn title="'
267 . $stat['description_function']($stat['footer']) . '">';
270 if (isset($stat['description_function'])) {
273 $html .= '</th>' . "\n";
274 if ($stat['format'] === 'byte') {
275 $html .= ' <th class="unit">' . $unit . '</th>' . "\n";
285 * Returns the html for Column Order with Sort
287 * @param bool $is_superuser User status
288 * @param bool $is_allowUserDropDb Allow user drop database
289 * @param Array $_url_params Url params
290 * @param string $sort_by sort column name
291 * @param string $sort_order order
292 * @param array $column_order column order
293 * @param array $first_database database to show
297 function PMA_getHtmlForColumnOrderWithSort(
298 $is_superuser, $is_allowUserDropDb,
299 $_url_params, $sort_by, $sort_order,
300 $column_order, $first_database
302 $html = ($is_superuser ||
$is_allowUserDropDb
303 ?
' <th></th>' . "\n"
305 . ' <th><a href="server_databases.php'
306 . PMA_URL_getCommon($_url_params) . '">' . "\n"
307 . ' ' . __('Database') . "\n"
308 . ($sort_by == 'SCHEMA_NAME'
309 ?
' ' . PMA_Util
::getImage(
310 's_' . $sort_order . '.png',
311 ($sort_order == 'asc' ?
__('Ascending') : __('Descending'))
315 . ' </a></th>' . "\n";
317 foreach ($column_order as $stat_name => $stat) {
318 if (!array_key_exists($stat_name, $first_database)) {
322 if ($stat['format'] === 'byte') {
324 $colspan = ' colspan="2"';
329 $_url_params['sort_by'] = $stat_name;
330 $_url_params['sort_order']
331 = ($sort_by == $stat_name && $sort_order == 'desc') ?
'asc' : 'desc';
332 $html .= ' <th' . $colspan . '>'
333 . '<a href="server_databases.php'
334 . PMA_URL_getCommon($_url_params) . '">' . "\n"
335 . ' ' . $stat['disp_name'] . "\n"
336 . ($sort_by == $stat_name
337 ?
' ' . PMA_Util
::getImage(
338 's_' . $sort_order . '.png',
339 ($sort_order == 'asc' ?
__('Ascending') : __('Descending'))
343 . ' </a></th>' . "\n";
350 * Returns the html for Enable Statistics
352 * @param bool $url_query Url query
353 * @param string $html html for database list
357 function PMA_getHtmlForNoticeEnableStatistics($url_query, $html)
359 $notice = PMA_Message
::notice(
361 'Note: Enabling the database statistics here might cause '
362 . 'heavy traffic between the web server and the MySQL server.'
365 //we should put notice above database list
366 $html = $notice . $html;
367 $html .= '<ul><li id="li_switch_dbstats"><strong>' . "\n";
368 $html .= '<a href="server_databases.php' . $url_query . '&dbstats=1"'
369 . ' title="' . __('Enable Statistics') . '">' . "\n"
370 . ' ' . __('Enable Statistics');
371 $html .= '</a></strong><br />' . "\n";
372 $html .= '</li>' . "\n" . '</ul>' . "\n";
378 * Returns the html for database replication types
380 * @param bool $is_superuser User status
381 * @param Array $replication_types replication types
382 * @param bool $cfg_iconic cfg about Properties Iconic
386 function PMA_getHtmlForReplicationType(
387 $is_superuser, $replication_types, $cfg_iconic
390 foreach ($replication_types as $type) {
391 if ($type == "master") {
392 $name = __('Master replication');
393 } elseif ($type == "slave") {
394 $name = __('Slave replication');
397 if ($GLOBALS['replication_info'][$type]['status']) {
398 $html .= ' <th>' . $name . '</th>' . "\n";
402 if ($is_superuser && ! PMA_DRIZZLE
) {
403 $html .= ' <th>' . ($cfg_iconic ?
'' : __('Action')) . "\n"
410 * Returns the array about $sort_order and $sort_by
414 function PMA_getListForSortDatabase()
416 if (empty($_REQUEST['sort_by'])) {
417 $sort_by = 'SCHEMA_NAME';
419 $sort_by_whitelist = array(
421 'DEFAULT_COLLATION_NAME',
424 'SCHEMA_DATA_LENGTH',
425 'SCHEMA_INDEX_LENGTH',
429 if (in_array($_REQUEST['sort_by'], $sort_by_whitelist)) {
430 $sort_by = $_REQUEST['sort_by'];
432 $sort_by = 'SCHEMA_NAME';
436 if (isset($_REQUEST['sort_order'])
437 && /*overload*/mb_strtolower($_REQUEST['sort_order']) == 'desc'
439 $sort_order = 'desc';
444 return array($sort_by, $sort_order);
448 * Deal with Drops multiple databases
452 function PMA_dropMultiDatabases()
454 if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
455 $message = PMA_Message
::error(__('No databases selected.'));
457 $action = 'server_databases.php';
458 $submit_mult = 'drop_db';
459 $err_url = 'server_databases.php' . PMA_URL_getCommon();
460 if (isset($_REQUEST['selected_dbs'])
461 && !isset($_REQUEST['is_js_confirmed'])
463 $selected_db = $_REQUEST['selected_dbs'];
465 if (isset($_REQUEST['is_js_confirmed'])) {
467 'query_type' => $submit_mult,
468 'selected' => $_REQUEST['selected_dbs'],
469 'mult_btn' => __('Yes'),
470 'db' => $GLOBALS['db'],
471 'table' => $GLOBALS['table']);
473 //the following variables will be used on mult_submits.inc.php
474 global $query_type, $selected, $mult_btn;
476 include 'libraries/mult_submits.inc.php';
477 unset($action, $submit_mult, $err_url, $selected_db, $GLOBALS['db']);
478 if (empty($message)) {
479 if ($mult_btn == __('Yes')) {
480 $number_of_databases = count($selected);
482 $number_of_databases = 0;
484 $message = PMA_Message
::success(
486 '%1$d database has been dropped successfully.',
487 '%1$d databases have been dropped successfully.',
491 $message->addParam($number_of_databases);
494 if ($GLOBALS['is_ajax_request'] && $message instanceof PMA_Message
) {
495 $response = PMA_Response
::getInstance();
496 $response->isSuccess($message->isSuccess());
497 $response->addJSON('message', $message);