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.'
365 'content' => '<strong>' . "\n"
366 . __('Enable statistics')
367 . '</strong><br />' . "\n",
368 'class' => 'li_switch_dbstats',
370 'href' => 'server_databases.php' . $url_query . '&dbstats=1',
371 'title' => __('Enable statistics')
375 include_once './libraries/Template.class.php';
376 $html .= PMA\Template
::get('list/unordered')->render(
377 array('items' => $items,)
384 * Returns the html for database replication types
386 * @param bool $is_superuser User status
387 * @param Array $replication_types replication types
388 * @param bool $cfg_iconic cfg about Properties Iconic
392 function PMA_getHtmlForReplicationType(
393 $is_superuser, $replication_types, $cfg_iconic
396 foreach ($replication_types as $type) {
397 if ($type == "master") {
398 $name = __('Master replication');
399 } elseif ($type == "slave") {
400 $name = __('Slave replication');
403 if ($GLOBALS['replication_info'][$type]['status']) {
404 $html .= ' <th>' . $name . '</th>' . "\n";
408 if ($is_superuser && ! PMA_DRIZZLE
) {
409 $html .= ' <th>' . ($cfg_iconic ?
'' : __('Action')) . "\n"
416 * Returns the array about $sort_order and $sort_by
420 function PMA_getListForSortDatabase()
422 if (empty($_REQUEST['sort_by'])) {
423 $sort_by = 'SCHEMA_NAME';
425 $sort_by_whitelist = array(
427 'DEFAULT_COLLATION_NAME',
430 'SCHEMA_DATA_LENGTH',
431 'SCHEMA_INDEX_LENGTH',
435 if (in_array($_REQUEST['sort_by'], $sort_by_whitelist)) {
436 $sort_by = $_REQUEST['sort_by'];
438 $sort_by = 'SCHEMA_NAME';
442 if (isset($_REQUEST['sort_order'])
443 && /*overload*/mb_strtolower($_REQUEST['sort_order']) == 'desc'
445 $sort_order = 'desc';
450 return array($sort_by, $sort_order);
454 * Deal with Drops multiple databases
458 function PMA_dropMultiDatabases()
460 if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
461 $message = PMA_Message
::error(__('No databases selected.'));
463 $action = 'server_databases.php';
464 $submit_mult = 'drop_db';
465 $err_url = 'server_databases.php' . PMA_URL_getCommon();
466 if (isset($_REQUEST['selected_dbs'])
467 && !isset($_REQUEST['is_js_confirmed'])
469 $selected_db = $_REQUEST['selected_dbs'];
471 if (isset($_REQUEST['is_js_confirmed'])) {
473 'query_type' => $submit_mult,
474 'selected' => $_REQUEST['selected_dbs'],
475 'mult_btn' => __('Yes'),
476 'db' => $GLOBALS['db'],
477 'table' => $GLOBALS['table']);
479 //the following variables will be used on mult_submits.inc.php
480 global $query_type, $selected, $mult_btn;
482 include 'libraries/mult_submits.inc.php';
483 unset($action, $submit_mult, $err_url, $selected_db, $GLOBALS['db']);
484 if (empty($message)) {
485 if ($mult_btn == __('Yes')) {
486 $number_of_databases = count($selected);
488 $number_of_databases = 0;
490 $message = PMA_Message
::success(
492 '%1$d database has been dropped successfully.',
493 '%1$d databases have been dropped successfully.',
497 $message->addParam($number_of_databases);
500 if ($GLOBALS['is_ajax_request'] && $message instanceof PMA_Message
) {
501 $response = PMA_Response
::getInstance();
502 $response->isSuccess($message->isSuccess());
503 $response->addJSON('message', $message);