Translated using Weblate (Hungarian)
[phpmyadmin.git] / libraries / server_databases.lib.php
blobd66e0dbf2ab5fb2259330f15bc53700e809a8622
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 /**
5 * functions for displaying server databases
7 * @usedby server_databases.php
9 * @package PhpMyAdmin
11 if (! defined('PHPMYADMIN')) {
12 exit;
15 /**
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
30 * @return string
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
36 ) {
37 $html = '<div id="tableslistcontainer">';
38 reset($databases);
39 $first_database = current($databases);
40 // table col order
41 $column_order = PMA_getColumnOrder();
43 $_url_params = array(
44 'pos' => $pos,
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"
66 . '<thead>' . "\n"
67 . '<tr>' . "\n";
69 $html .= PMA_getHtmlForColumnOrderWithSort(
70 $is_superuser,
71 $cfg['AllowUserDropDatabase'],
72 $_url_params,
73 $sort_by,
74 $sort_order,
75 $column_order,
76 $first_database
79 $html .= PMA_getHtmlForReplicationType(
80 $is_superuser,
81 $replication_types,
82 $cfg['ActionLinksMode']
85 $html .= '</tr>' . "\n"
86 . '</thead>' . "\n";
88 list($output, $column_order) = PMA_getHtmlAndColumnOrderForDatabaseList(
89 $databases,
90 $is_superuser,
91 $url_query,
92 $column_order,
93 $replication_types,
94 $replication_info
96 $html .= $output;
97 unset($output);
99 $html .= PMA_getHtmlForTableFooter(
100 $cfg['AllowUserDropDatabase'],
101 $is_superuser,
102 $databases_count,
103 $column_order,
104 $replication_types,
105 $first_database
108 $html .= '</table>' . "\n";
110 $html .= PMA_getHtmlForTableFooterButtons(
111 $cfg['AllowUserDropDatabase'],
112 $is_superuser
115 if (empty($dbstats)) {
116 //we should put notice above database list
117 $html = PMA_getHtmlForNoticeEnableStatistics($url_query, $html);
119 $html .= '</form>';
120 $html .= '</div>';
122 return $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
131 * @return string
133 function PMA_getHtmlForTableFooterButtons($is_allowUserDropDb, $is_superuser)
135 if (!$is_superuser && !$is_allowUserDropDb) {
136 return '';
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',
149 'drop_selected_dbs',
150 __('Drop'), 'b_deltbl.png'
153 return $html;
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
166 * @return string
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";
188 if ($is_superuser) {
189 $html .= ' <th></th>' . "\n";
191 $html .= '</tr>' . "\n";
192 $html .= '</tfoot>' . "\n";
193 return $html;
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
206 * @return Array
208 function PMA_getHtmlAndColumnOrderForDatabaseList(
209 $databases, $is_superuser, $url_query,
210 $column_order, $replication_types, $replication_info
212 $odd_row = true;
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(
224 $current,
225 $is_superuser,
226 $url_query,
227 $column_order,
228 $replication_types,
229 $replication_info
232 $html .= $generated_html;
234 $html .= '</tr>' . "\n";
235 } // end foreach ($databases as $key => $current)
236 unset($current, $odd_row);
237 $html .= '</tbody>';
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
247 * @return string
249 function PMA_getHtmlForColumnOrder($column_order, $first_database)
251 $html = "";
252 // avoid execution path notice
253 $unit = "";
254 foreach ($column_order as $stat_name => $stat) {
255 if (array_key_exists($stat_name, $first_database)) {
256 if ($stat['format'] === 'byte') {
257 list($value, $unit)
258 = PMA_Util::formatByteDown($stat['footer'], 3, 1);
259 } elseif ($stat['format'] === 'number') {
260 $value = PMA_Util::formatNumber($stat['footer'], 0);
261 } else {
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']) . '">';
269 $html .= $value;
270 if (isset($stat['description_function'])) {
271 $html .= '</dfn>';
273 $html .= '</th>' . "\n";
274 if ($stat['format'] === 'byte') {
275 $html .= ' <th class="unit">' . $unit . '</th>' . "\n";
280 return $html;
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
295 * @return string
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"
304 : '')
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'))
312 ) . "\n"
313 : ''
315 . ' </a></th>' . "\n";
316 $table_columns = 3;
317 foreach ($column_order as $stat_name => $stat) {
318 if (!array_key_exists($stat_name, $first_database)) {
319 continue;
322 if ($stat['format'] === 'byte') {
323 $table_columns += 2;
324 $colspan = ' colspan="2"';
325 } else {
326 $table_columns++;
327 $colspan = '';
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'))
340 ) . "\n"
341 : ''
343 . ' </a></th>' . "\n";
345 return $html;
350 * Returns the html for Enable Statistics
352 * @param bool $url_query Url query
353 * @param string $html html for database list
355 * @return string
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.'
364 )->getDisplay();
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 . '&amp;dbstats=1"'
369 . ' title="' . __('Enable Statistics') . '">' . "\n"
370 . ' ' . __('Enable Statistics');
371 $html .= '</a></strong><br />' . "\n";
372 $html .= '</li>' . "\n" . '</ul>' . "\n";
374 return $html;
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
384 * @return string
386 function PMA_getHtmlForReplicationType(
387 $is_superuser, $replication_types, $cfg_iconic
389 $html = '';
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"
404 . ' </th>' . "\n";
406 return $html;
410 * Returns the array about $sort_order and $sort_by
412 * @return Array
414 function PMA_getListForSortDatabase()
416 if (empty($_REQUEST['sort_by'])) {
417 $sort_by = 'SCHEMA_NAME';
418 } else {
419 $sort_by_whitelist = array(
420 'SCHEMA_NAME',
421 'DEFAULT_COLLATION_NAME',
422 'SCHEMA_TABLES',
423 'SCHEMA_TABLE_ROWS',
424 'SCHEMA_DATA_LENGTH',
425 'SCHEMA_INDEX_LENGTH',
426 'SCHEMA_LENGTH',
427 'SCHEMA_DATA_FREE'
429 if (in_array($_REQUEST['sort_by'], $sort_by_whitelist)) {
430 $sort_by = $_REQUEST['sort_by'];
431 } else {
432 $sort_by = 'SCHEMA_NAME';
436 if (isset($_REQUEST['sort_order'])
437 && /*overload*/mb_strtolower($_REQUEST['sort_order']) == 'desc'
439 $sort_order = 'desc';
440 } else {
441 $sort_order = 'asc';
444 return array($sort_by, $sort_order);
448 * Deal with Drops multiple databases
450 * @return null
452 function PMA_dropMultiDatabases()
454 if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
455 $message = PMA_Message::error(__('No databases selected.'));
456 } else {
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'])) {
466 $_REQUEST = array(
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);
481 } else {
482 $number_of_databases = 0;
484 $message = PMA_Message::success(
485 _ngettext(
486 '%1$d database has been dropped successfully.',
487 '%1$d databases have been dropped successfully.',
488 $number_of_databases
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);
498 exit;