2 /* vim: set expandtab sw=4 ts=4 sts=4: */
11 require_once 'libraries/common.inc.php';
12 $response = PMA_Response
::getInstance();
13 $header = $response->getHeader();
14 $scripts = $header->getScripts();
15 $scripts->addFile('server_databases.js');
17 require 'libraries/server_common.inc.php';
19 include_once 'libraries/replication.inc.php';
21 $replication_types = array();
22 $replication_info = null;
24 require 'libraries/build_html_for_db.lib.php';
27 * Sets globals from $_POST
34 foreach ($post_params as $one_post_param) {
35 if (isset($_POST[$one_post_param])) {
36 $GLOBALS[$one_post_param] = $_POST[$one_post_param];
41 * avoids 'undefined index' errors
43 if (empty($_REQUEST['sort_by'])) {
44 $sort_by = 'SCHEMA_NAME';
46 $sort_by_whitelist = array(
48 'DEFAULT_COLLATION_NAME',
52 'SCHEMA_INDEX_LENGTH',
56 if (in_array($_REQUEST['sort_by'], $sort_by_whitelist)) {
57 $sort_by = $_REQUEST['sort_by'];
59 $sort_by = 'SCHEMA_NAME';
63 if (isset($_REQUEST['sort_order'])
64 && strtolower($_REQUEST['sort_order']) == 'desc'
71 $dbstats = empty($_REQUEST['dbstats']) ?
0 : 1;
72 $pos = empty($_REQUEST['pos']) ?
0 : (int) $_REQUEST['pos'];
76 * Drops multiple databases
79 // workaround for IE behavior (it returns some coordinates based on where
80 // the mouse was on the Drop image):
81 if (isset($_REQUEST['drop_selected_dbs_x'])) {
82 $_REQUEST['drop_selected_dbs'] = true;
85 if ((isset($_REQUEST['drop_selected_dbs']) ||
isset($_REQUEST['query_type']))
86 && ($is_superuser ||
$cfg['AllowUserDropDatabase'])
88 if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
89 $message = PMA_Message
::error(__('No databases selected.'));
91 $action = 'server_databases.php';
92 $submit_mult = 'drop_db';
93 $err_url = 'server_databases.php?' . PMA_generate_common_url();
94 if (isset($_REQUEST['selected_dbs'])
95 && !isset($_REQUEST['is_js_confirmed'])
97 $selected_db = $_REQUEST['selected_dbs'];
99 if (isset($_REQUEST['is_js_confirmed'])) {
101 'query_type' => $submit_mult,
102 'selected' => $_REQUEST['selected_dbs'],
103 'mult_btn' => __('Yes'),
104 'db' => $GLOBALS['db'],
105 'table' => $GLOBALS['table']);
107 include 'libraries/mult_submits.inc.php';
108 unset($action, $submit_mult, $err_url, $selected_db, $GLOBALS['db']);
109 if (empty($message)) {
110 if ($mult_btn == __('Yes')) {
111 $number_of_databases = count($selected);
113 $number_of_databases = 0;
115 $message = PMA_Message
::success(
117 '%1$d database has been dropped successfully.',
118 '%1$d databases have been dropped successfully.',
122 $message->addParam($number_of_databases);
125 if ($GLOBALS['is_ajax_request'] && $message instanceof PMA_Message
) {
126 $response = PMA_Response
::getInstance();
127 $response->isSuccess($message->isSuccess());
128 $response->addJSON('message', $message);
134 * Displays the sub-page heading
137 . PMA_Util
::getImage('s_db.png')
138 . ($dbstats ?
__('Databases statistics') : __('Databases')) . "\n"
144 if ($cfg['ShowCreateDb']) {
145 echo '<ul><li id="li_create_database" class="no_bullets">' . "\n";
146 include 'libraries/display_create_database.lib.php';
147 echo ' </li>' . "\n";
152 * Gets the databases list
155 $databases = PMA_DBI_get_databases_full(
156 null, $dbstats, null, $sort_by, $sort_order, $pos, true
158 $databases_count = count($GLOBALS['pma']->databases
);
160 $databases_count = 0;
167 if ($databases_count > 0) {
168 echo '<div id="tableslistcontainer">';
170 $first_database = current($databases);
172 $column_order = PMA_getColumnOrder();
174 $_url_params = array(
176 'dbstats' => $dbstats,
177 'sort_by' => $sort_by,
178 'sort_order' => $sort_order,
181 echo PMA_Util
::getListNavigator(
182 $databases_count, $pos, $_url_params, 'server_databases.php',
183 'frame_content', $GLOBALS['cfg']['MaxDbList']
186 $_url_params['pos'] = $pos;
187 $_url_params['drop_selected_dbs'] = 1;
189 echo '<form class="ajax" action="server_databases.php" ';
190 echo 'method="post" name="dbStatsForm" id="dbStatsForm">' . "\n";
191 echo PMA_generate_common_hidden_inputs($_url_params);
193 $_url_params['sort_by'] = 'SCHEMA_NAME';
194 $_url_params['sort_order'] = ($sort_by == 'SCHEMA_NAME' && $sort_order == 'asc') ?
'desc' : 'asc';
196 echo '<table id="tabledatabases" class="data">' . "\n"
199 . ($is_superuser ||
$cfg['AllowUserDropDatabase'] ?
' <th></th>' . "\n" : '')
200 . ' <th><a href="server_databases.php' . PMA_generate_common_url($_url_params) . '">' . "\n"
201 . ' ' . __('Database') . "\n"
202 . ($sort_by == 'SCHEMA_NAME' ?
' ' . PMA_Util
::getImage('s_' . $sort_order . '.png', ($sort_order == 'asc' ?
__('Ascending') : __('Descending'))) . "\n" : '')
203 . ' </a></th>' . "\n";
205 foreach ($column_order as $stat_name => $stat) {
206 if (array_key_exists($stat_name, $first_database)) {
207 if ($stat['format'] === 'byte') {
209 $colspan = ' colspan="2"';
214 $_url_params['sort_by'] = $stat_name;
215 $_url_params['sort_order'] = ($sort_by == $stat_name && $sort_order == 'desc') ?
'asc' : 'desc';
216 echo ' <th' . $colspan . '>'
217 . '<a href="server_databases.php' . PMA_generate_common_url($_url_params) . '">' . "\n"
218 . ' ' . $stat['disp_name'] . "\n"
219 . ($sort_by == $stat_name ?
' ' . PMA_Util
::getImage('s_' . $sort_order . '.png', ($sort_order == 'asc' ?
__('Ascending') : __('Descending'))) . "\n" : '')
220 . ' </a></th>' . "\n";
224 foreach ($replication_types as $type) {
225 if ($type=="master") {
226 $name = __('Master replication');
227 } elseif ($type == "slave") {
228 $name = __('Slave replication');
230 if ($
{"server_{$type}_status"}) {
231 echo ' <th>'. $name .'</th>' . "\n";
235 if ($is_superuser && ! PMA_DRIZZLE
) {
236 echo ' <th>' . ($cfg['PropertiesIconic'] ?
'' : __('Action')) . "\n"
244 foreach ($databases as $current) {
245 $tr_class = $odd_row ?
'odd' : 'even';
246 if (PMA_is_system_schema($current['SCHEMA_NAME'], true)) {
247 $tr_class .= ' noclick';
249 echo '<tr class="' . $tr_class . '">' . "\n";
250 $odd_row = ! $odd_row;
252 list($column_order, $generated_html) = PMA_buildHtmlForDb(
261 echo $generated_html;
264 } // end foreach ($databases as $key => $current)
265 unset($current, $odd_row);
267 echo '</tbody><tfoot><tr>' . "\n";
268 if ($is_superuser ||
$cfg['AllowUserDropDatabase']) {
269 echo ' <th></th>' . "\n";
271 echo ' <th>' . __('Total') . ': <span id="databases_count">' . $databases_count . '</span></th>' . "\n";
272 foreach ($column_order as $stat_name => $stat) {
273 if (array_key_exists($stat_name, $first_database)) {
274 if ($stat['format'] === 'byte') {
275 list($value, $unit) = PMA_Util
::formatByteDown($stat['footer'], 3, 1);
276 } elseif ($stat['format'] === 'number') {
277 $value = PMA_Util
::formatNumber($stat['footer'], 0);
279 $value = htmlentities($stat['footer'], 0);
281 echo ' <th class="value">';
282 if (isset($stat['description_function'])) {
283 echo '<dfn title="' . $stat['description_function']($stat['footer']) . '">';
286 if (isset($stat['description_function'])) {
290 if ($stat['format'] === 'byte') {
291 echo ' <th class="unit">' . $unit . '</th>' . "\n";
296 foreach ($replication_types as $type) {
297 if ($
{"server_{$type}_status"}) {
298 echo ' <th></th>' . "\n";
303 echo ' <th></th>' . "\n";
306 echo '</tfoot>' . "\n"
308 unset($column_order, $stat_name, $stat, $databases, $table_columns);
310 if ($is_superuser ||
$cfg['AllowUserDropDatabase']) {
311 $common_url_query = PMA_generate_common_url(
313 'sort_by' => $sort_by,
314 'sort_order' => $sort_order,
315 'dbstats' => $dbstats
318 echo '<img class="selectallarrow" src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png"'
319 . ' width="38" height="22" alt="' . __('With selected:') . '" />' . "\n"
320 . '<input type="checkbox" id="checkall" title="' . __('Check All') . '" /> '
321 . '<label for="checkall">' . __('Check All') . '</label> '
322 . '<i style="margin-left: 2em">' . __('With selected:') . '</i>' . "\n";
323 echo PMA_Util
::getButtonOrImage(
325 'mult_submit' . ' ajax',
327 __('Drop'), 'b_deltbl.png'
331 if (empty($dbstats)) {
332 echo '<ul><li id="li_switch_dbstats"><strong>' . "\n";
333 echo '<a href="server_databases.php?' . $url_query . '&dbstats=1"'
334 . ' title="' . __('Enable Statistics') . '">' . "\n"
335 . ' ' . __('Enable Statistics');
336 echo '</a></strong><br />' . "\n";
338 __('Note: Enabling the database statistics here might cause heavy traffic between the web server and the MySQL server.')
340 echo '</li>' . "\n" . '</ul>' . "\n";
345 echo __('No databases');
347 unset($databases_count);