added japanese language
[openemr.git] / phpmyadmin / libraries / server_databases.lib.php
blob393f49a089a61d1d7d22ebccaaeeda4189ba7d20
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 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
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["server_" . $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 foreach ($column_order as $stat_name => $stat) {
253 if (array_key_exists($stat_name, $first_database)) {
254 if ($stat['format'] === 'byte') {
255 list($value, $unit)
256 = PMA_Util::formatByteDown($stat['footer'], 3, 1);
257 } elseif ($stat['format'] === 'number') {
258 $value = PMA_Util::formatNumber($stat['footer'], 0);
259 } else {
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']) . '">';
267 $html .= $value;
268 if (isset($stat['description_function'])) {
269 $html .= '</dfn>';
271 $html .= '</th>' . "\n";
272 if ($stat['format'] === 'byte') {
273 $html .= ' <th class="unit">' . $unit . '</th>' . "\n";
278 return $html;
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
293 * @return string
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"
302 : '')
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'))
310 ) . "\n"
311 : ''
313 . ' </a></th>' . "\n";
314 $table_columns = 3;
315 foreach ($column_order as $stat_name => $stat) {
316 if (!array_key_exists($stat_name, $first_database)) {
317 continue;
320 if ($stat['format'] === 'byte') {
321 $table_columns += 2;
322 $colspan = ' colspan="2"';
323 } else {
324 $table_columns++;
325 $colspan = '';
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'))
338 ) . "\n"
339 : ''
341 . ' </a></th>' . "\n";
343 return $html;
348 * Returns the html for Enable Statistics
350 * @param bool $url_query Url query
351 * @param string $html html for database list
353 * @return string
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.'
362 )->getDisplay();
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 . '&amp;dbstats=1"'
367 . ' title="' . __('Enable Statistics') . '">' . "\n"
368 . ' ' . __('Enable Statistics');
369 $html .= '</a></strong><br />' . "\n";
370 $html .= '</li>' . "\n" . '</ul>' . "\n";
372 return $html;
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
382 * @return string
384 function PMA_getHtmlForReplicationType(
385 $is_superuser, $replication_types, $cfg_inconic
387 $html = '';
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"
402 . ' </th>' . "\n";
404 return $html;
408 * Returns the array about $sort_order and $sort_by
410 * @return Array
412 function PMA_getListForSortDatabase()
415 * avoids 'undefined index' errors
417 $sort_by = '';
418 $sort_order = '';
419 if (empty($_REQUEST['sort_by'])) {
420 $sort_by = 'SCHEMA_NAME';
421 } else {
422 $sort_by_whitelist = array(
423 'SCHEMA_NAME',
424 'DEFAULT_COLLATION_NAME',
425 'SCHEMA_TABLES',
426 'SCHEMA_TABLE_ROWS',
427 'SCHEMA_DATA_LENGTH',
428 'SCHEMA_INDEX_LENGTH',
429 'SCHEMA_LENGTH',
430 'SCHEMA_DATA_FREE'
432 if (in_array($_REQUEST['sort_by'], $sort_by_whitelist)) {
433 $sort_by = $_REQUEST['sort_by'];
434 } else {
435 $sort_by = 'SCHEMA_NAME';
439 if (isset($_REQUEST['sort_order'])
440 && strtolower($_REQUEST['sort_order']) == 'desc'
442 $sort_order = 'desc';
443 } else {
444 $sort_order = 'asc';
447 return array($sort_by, $sort_order);
451 * Deal with Drops multiple databases
453 * @return null
455 function PMA_dropMultiDatabases()
457 if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
458 $message = PMA_Message::error(__('No databases selected.'));
459 } else {
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'])) {
469 $_REQUEST = array(
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);
484 } else {
485 $number_of_databases = 0;
487 $message = PMA_Message::success(
488 _ngettext(
489 '%1$d database has been dropped successfully.',
490 '%1$d databases have been dropped successfully.',
491 $number_of_databases
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);
501 exit;