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 array $replication_types replication types
27 * @param array $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 = PMA_Util
::getWithSelected(
140 $GLOBALS['pmaThemeImage'], $GLOBALS['text_dir'], "dbStatsForm"
142 $html .= PMA_Util
::getButtonOrImage(
144 'mult_submit' . ' ajax',
146 __('Drop'), 'b_deltbl.png'
153 * Returns the html for Table footer
155 * @param bool $is_allowUserDropDb Allow user drop database
156 * @param bool $is_superuser User status
157 * @param int $databases_count Database count
158 * @param string $column_order column order
159 * @param array $replication_types replication types
160 * @param string $first_database First database
164 function PMA_getHtmlForTableFooter(
165 $is_allowUserDropDb, $is_superuser,
166 $databases_count, $column_order,
167 $replication_types, $first_database
169 $html = '<tfoot><tr>' . "\n";
170 if ($is_superuser ||
$is_allowUserDropDb) {
171 $html .= ' <th></th>' . "\n";
173 $html .= ' <th>' . __('Total') . ': <span id="databases_count">'
174 . $databases_count . '</span></th>' . "\n";
176 $html .= PMA_getHtmlForColumnOrder($column_order, $first_database);
178 foreach ($replication_types as $type) {
179 if ($GLOBALS['replication_info'][$type]['status']) {
180 $html .= ' <th></th>' . "\n";
185 $html .= ' <th></th>' . "\n";
187 $html .= '</tr>' . "\n";
188 $html .= '</tfoot>' . "\n";
193 * Returns the html for Database List and Column order
195 * @param array $databases GBI return databases
196 * @param bool $is_superuser User status
197 * @param string $url_query Url query
198 * @param array $column_order column order
199 * @param array $replication_types replication types
200 * @param array $replication_info replication info
204 function PMA_getHtmlAndColumnOrderForDatabaseList(
205 $databases, $is_superuser, $url_query,
206 $column_order, $replication_types, $replication_info
209 $html = '<tbody>' . "\n";
211 foreach ($databases as $current) {
212 $tr_class = $odd_row ?
'odd' : 'even';
213 if ($GLOBALS['dbi']->isSystemSchema($current['SCHEMA_NAME'], true)) {
214 $tr_class .= ' noclick';
216 $html .= '<tr class="' . $tr_class . '">' . "\n";
217 $odd_row = ! $odd_row;
219 list($column_order, $generated_html) = PMA_buildHtmlForDb(
228 $html .= $generated_html;
230 $html .= '</tr>' . "\n";
231 } // end foreach ($databases as $key => $current)
232 unset($current, $odd_row);
234 return array($html, $column_order);
238 * Returns the html for Column Order
240 * @param array $column_order Column order
241 * @param array $first_database The first display database
245 function PMA_getHtmlForColumnOrder($column_order, $first_database)
248 // avoid execution path notice
250 foreach ($column_order as $stat_name => $stat) {
251 if (array_key_exists($stat_name, $first_database)) {
252 if ($stat['format'] === 'byte') {
254 = PMA_Util
::formatByteDown($stat['footer'], 3, 1);
255 } elseif ($stat['format'] === 'number') {
256 $value = PMA_Util
::formatNumber($stat['footer'], 0);
258 $value = htmlentities($stat['footer'], 0);
260 $html .= ' <th class="value">';
261 if (isset($stat['description_function'])) {
262 $html .= '<dfn title="'
263 . $stat['description_function']($stat['footer']) . '">';
266 if (isset($stat['description_function'])) {
269 $html .= '</th>' . "\n";
270 if ($stat['format'] === 'byte') {
271 $html .= ' <th class="unit">' . $unit . '</th>' . "\n";
281 * Returns the html for Column Order with Sort
283 * @param bool $is_superuser User status
284 * @param bool $is_allowUserDropDb Allow user drop database
285 * @param Array $_url_params Url params
286 * @param string $sort_by sort column name
287 * @param string $sort_order order
288 * @param array $column_order column order
289 * @param array $first_database database to show
293 function PMA_getHtmlForColumnOrderWithSort(
294 $is_superuser, $is_allowUserDropDb,
295 $_url_params, $sort_by, $sort_order,
296 $column_order, $first_database
298 $html = ($is_superuser ||
$is_allowUserDropDb
299 ?
' <th></th>' . "\n"
301 . ' <th><a href="server_databases.php'
302 . PMA_URL_getCommon($_url_params) . '">' . "\n"
303 . ' ' . __('Database') . "\n"
304 . ($sort_by == 'SCHEMA_NAME'
305 ?
' ' . PMA_Util
::getImage(
306 's_' . $sort_order . '.png',
307 ($sort_order == 'asc' ?
__('Ascending') : __('Descending'))
311 . ' </a></th>' . "\n";
313 foreach ($column_order as $stat_name => $stat) {
314 if (!array_key_exists($stat_name, $first_database)) {
318 if ($stat['format'] === 'byte') {
320 $colspan = ' colspan="2"';
325 $_url_params['sort_by'] = $stat_name;
326 $_url_params['sort_order']
327 = ($sort_by == $stat_name && $sort_order == 'desc') ?
'asc' : 'desc';
328 $html .= ' <th' . $colspan . '>'
329 . '<a href="server_databases.php'
330 . PMA_URL_getCommon($_url_params) . '">' . "\n"
331 . ' ' . $stat['disp_name'] . "\n"
332 . ($sort_by == $stat_name
333 ?
' ' . PMA_Util
::getImage(
334 's_' . $sort_order . '.png',
335 ($sort_order == 'asc' ?
__('Ascending') : __('Descending'))
339 . ' </a></th>' . "\n";
346 * Returns the html for Enable Statistics
348 * @param string $url_query Url query
349 * @param string $html html for database list
353 function PMA_getHtmlForNoticeEnableStatistics($url_query, $html)
355 $notice = PMA_Message
::notice(
357 'Note: Enabling the database statistics here might cause '
358 . 'heavy traffic between the web server and the MySQL server.'
361 $html = $html . $notice;
362 $html .= '<ul><li id="li_switch_dbstats"><strong>' . "\n";
363 $html .= '<a href="server_databases.php' . $url_query . '&dbstats=1"'
364 . ' title="' . __('Enable Statistics') . '">' . "\n"
365 . ' ' . __('Enable Statistics');
366 $html .= '</a></strong><br />' . "\n";
367 $html .= '</li>' . "\n" . '</ul>' . "\n";
373 * Returns the html for database replication types
375 * @param bool $is_superuser User status
376 * @param Array $replication_types replication types
377 * @param bool $cfg_iconic cfg about Properties Iconic
381 function PMA_getHtmlForReplicationType(
382 $is_superuser, $replication_types, $cfg_iconic
385 foreach ($replication_types as $type) {
386 if ($type == "master") {
387 $name = __('Master replication');
388 } elseif ($type == "slave") {
389 $name = __('Slave replication');
392 if ($GLOBALS['replication_info'][$type]['status']) {
393 $html .= ' <th>' . $name . '</th>' . "\n";
397 if ($is_superuser && ! PMA_DRIZZLE
) {
398 $html .= ' <th>' . ($cfg_iconic ?
'' : __('Action')) . "\n"
405 * Returns the array about $sort_order and $sort_by
409 function PMA_getListForSortDatabase()
411 if (empty($_REQUEST['sort_by'])) {
412 $sort_by = 'SCHEMA_NAME';
414 $sort_by_whitelist = array(
416 'DEFAULT_COLLATION_NAME',
419 'SCHEMA_DATA_LENGTH',
420 'SCHEMA_INDEX_LENGTH',
424 if (in_array($_REQUEST['sort_by'], $sort_by_whitelist)) {
425 $sort_by = $_REQUEST['sort_by'];
427 $sort_by = 'SCHEMA_NAME';
431 if (isset($_REQUEST['sort_order'])
432 && /*overload*/mb_strtolower($_REQUEST['sort_order']) == 'desc'
434 $sort_order = 'desc';
439 return array($sort_by, $sort_order);
443 * Deal with Drops multiple databases
447 function PMA_dropMultiDatabases()
449 if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
450 $message = PMA_Message
::error(__('No databases selected.'));
452 $action = 'server_databases.php';
453 $submit_mult = 'drop_db';
454 $err_url = 'server_databases.php' . PMA_URL_getCommon();
455 if (isset($_REQUEST['selected_dbs'])
456 && !isset($_REQUEST['is_js_confirmed'])
458 $selected_db = $_REQUEST['selected_dbs'];
460 if (isset($_REQUEST['is_js_confirmed'])) {
462 'query_type' => $submit_mult,
463 'selected' => $_REQUEST['selected_dbs'],
464 'mult_btn' => __('Yes'),
465 'db' => $GLOBALS['db'],
466 'table' => $GLOBALS['table']);
468 //the following variables will be used on mult_submits.inc.php
469 global $query_type, $selected, $mult_btn;
471 include 'libraries/mult_submits.inc.php';
472 unset($action, $submit_mult, $err_url, $selected_db, $GLOBALS['db']);
473 if (empty($message)) {
474 if ($mult_btn == __('Yes')) {
475 $number_of_databases = count($selected);
477 $number_of_databases = 0;
479 $message = PMA_Message
::success(
481 '%1$d database has been dropped successfully.',
482 '%1$d databases have been dropped successfully.',
486 $message->addParam($number_of_databases);
489 if ($GLOBALS['is_ajax_request'] && $message instanceof PMA_Message
) {
490 $response = PMA_Response
::getInstance();
491 $response->isSuccess($message->isSuccess());
492 $response->addJSON('message', $message);