3 // vim: expandtab sw=4 ts=4 sts=4:
7 * Checks if the left frame has to be reloaded
9 require('./libraries/grab_globals.lib.php3');
10 if (!empty($drop_selected_dbs)) {
16 * Does the common work
18 $js_to_run = 'functions.js';
19 require('./server_common.inc.php3');
23 * Sorts the databases array according to the user's choice
25 * @param array a record associated to a database
26 * @param array a record associated to a database
28 * @return integer a value representing whether $a should be before $b in the
31 * @global string the column the array shall be sorted by
32 * @global string the sorting order ('asc' or 'desc')
36 function PMA_dbCmp($a, $b)
38 global $sort_by, $sort_order;
39 if ($sort_by == 'db_name') {
40 return ($sort_order == 'asc' ?
1 : -1) * strcasecmp($a['db_name'], $b['db_name']);
41 } else if ($a[$sort_by] == $b[$sort_by]) {
42 return strcasecmp($a['db_name'], $b['db_name']);
44 return ($sort_order == 'asc' ?
1 : -1) * ((int)$a[$sort_by] > (int)$b[$sort_by] ?
1 : -1);
46 } // end of the 'PMA_dbCmp()' function
50 * Gets the databases list - if it has not been built yet
52 if ($server > 0 && empty($dblist)) {
53 PMA_availableDatabases();
58 * Drops multiple databases
60 if (!empty($drop_selected_dbs)) {
61 if (empty($selected_db)) {
62 $message = $strNoDatabasesSelected;
65 while (list(, $current_db) = each($selected_db)) {
66 $current_query = 'DROP DATABASE ' . PMA_backquote($current_db) . ';';
67 $sql_query[] = $current_query;
68 PMA_mysql_query($current_query, $userlink)
69 // rabus: in case of an error, we display the full query in
70 // order to let the user know which databases have already been
72 or PMA_mysqlDie(PMA_mysql_error($userlink), join("\n", $sql_query));
74 // PMA_showMessage() needs a string...
75 $sql_query = join("\n", $sql_query);
76 $message = sprintf($strDatabasesDropped, count($selected_db));
77 // we need to reload the database list now.
78 PMA_availableDatabases();
86 require('./server_links.inc.php3');
90 * Displays the sub-page heading
93 . ' ' . (empty($dbstats) ?
$strDatabases : $strDatabasesStats) . "\n"
98 * Checks if the user is allowed to do what he tries to...
100 if (!empty($dbstats) && (!$is_superuser || PMA_MYSQL_INT_VERSION
< 32303)) {
101 echo $strNoPrivileges . "\n";
102 include('./footer.inc.php3');
108 * Prepares the statistics
110 $statistics = array();
111 while (list(, $current_db) = each($dblist)) {
113 'db_name' => $current_db,
119 if (!empty($dbstats)) {
120 $res = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($current_db) . ';', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW TABLE STATUS FROM ' . PMA_backquote($current_db) . ';');
121 while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC
)) {
122 $tmp_array['tbl_cnt']++
;
123 $tmp_array['data_sz'] +
= $row['Data_length'];
124 $tmp_array['idx_sz'] +
= $row['Index_length'];
127 $tmp_array['tot_sz'] = $tmp_array['data_sz'] +
$tmp_array['idx_sz'];
128 $statistics[] = $tmp_array;
131 // avoids 'undefined index' errors
132 if (empty($sort_by)) {
133 $sort_by = 'db_name';
135 if (empty($sort_order)) {
136 if ($sort_by == 'db_name') {
139 $sort_order = 'desc';
144 usort($statistics, 'PMA_dbCmp');
150 if (count($statistics) > 0) {
151 echo '<form action="./server_databases.php3" method="post" name="dbStatsForm">' . "\n"
152 . PMA_generate_common_hidden_inputs('', '', 1)
153 . ' <input type="hidden" name="dbstats" value="' . (empty($dbstats) ?
'0' : '1') . '" />' . "\n"
154 . ' <input type="hidden" name="sort_by" value="' . $sort_by . '" />' . "\n"
155 . ' <input type="hidden" name="sort_order" value="' . $sort_order . '" />' . "\n"
156 . ' <table border="0">' . "\n"
158 . ' <th> </th>' . "\n"
161 if (empty($dbstats)) {
162 echo $strDatabase . "\n"
163 . ' <img src="./images/asc_order.png" border="0" width="7" height="7" alt="' . $strAscending . '" />' . "\n"
168 . ' <a href="./server_databases.php3?' . $url_query . '&dbstats=1&sort_by=db_name&sort_order=' . (($sort_by == 'db_name' && $sort_order == 'asc') ?
'desc' : 'asc') . '">' . "\n"
169 . ' ' . $strDatabase . "\n"
170 . ($sort_by == 'db_name' ?
' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
176 . ' <a href="./server_databases.php3?' . $url_query . '&dbstats=1&sort_by=tbl_cnt&sort_order=' . (($sort_by == 'tbl_cnt' && $sort_order == 'desc') ?
'asc' : 'desc') . '">' . "\n"
177 . ' ' . $strNumTables . "\n"
178 . ($sort_by == 'tbl_cnt' ?
' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
182 . ' <th colspan="2">' . "\n"
184 . ' <a href="./server_databases.php3?' . $url_query . '&dbstats=1&sort_by=data_sz&sort_order=' . (($sort_by == 'data_sz' && $sort_order == 'desc') ?
'asc' : 'desc') . '">' . "\n"
185 . ' ' . $strData . "\n"
186 . ($sort_by == 'data_sz' ?
' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
190 . ' <th colspan="2">' . "\n"
192 . ' <a href="./server_databases.php3?' . $url_query . '&dbstats=1&sort_by=idx_sz&sort_order=' . (($sort_by == 'idx_sz' && $sort_order == 'desc') ?
'asc' : 'desc') . '">' . "\n"
193 . ' ' . $strIndexes . "\n"
194 . ($sort_by == 'idx_sz' ?
' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
198 . ' <th colspan="2">' . "\n"
200 . ' <a href="./server_databases.php3?' . $url_query . '&dbstats=1&sort_by=tot_sz&sort_order=' . (($sort_by == 'tot_sz' && $sort_order == 'desc') ?
'asc' : 'desc') . '">' . "\n"
201 . ' ' . $strTotalUC . "\n"
202 . ($sort_by == 'tot_sz' ?
' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
208 . ' ' . $strAction . ' ' . "\n"
211 $useBgcolorOne = TRUE;
219 while (list(, $current) = each($statistics)) {
220 list($data_size, $data_unit) = PMA_formatByteDown($current['data_sz'], 3, 1);
221 list($idx_size, $idx_unit) = PMA_formatByteDown($current['idx_sz'], 3, 1);
222 list($tot_size, $tot_unit) = PMA_formatByteDown($current['tot_sz'], 3, 1);
223 $total_calc['db_cnt']++
;
224 $total_calc['tbl_cnt'] +
= $current['tbl_cnt'];
225 $total_calc['data_sz'] +
= $current['data_sz'];
226 $total_calc['idx_sz'] +
= $current['idx_sz'];
227 $total_calc['tot_sz'] +
= $current['tot_sz'];
229 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
230 . ' <input type="checkbox" name="selected_db[]" title="' . htmlspecialchars($current['db_name']) . '" value="' . htmlspecialchars($current['db_name']) . '" ' . (empty($checkall) ?
'' : 'checked="checked" ') . '/>' . "\n"
232 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
233 . ' <a href="' . $cfg['DefaultTabDatabase'] . $url_query . '&db=' . urlencode($current['db_name']) . '" title="' . sprintf($strJumpToDB, htmlspecialchars($current['db_name'])) . '">' . "\n"
234 . ' ' . htmlspecialchars($current['db_name']) . "\n"
237 if (!empty($dbstats)) {
238 echo ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
239 . ' ' . $current['tbl_cnt'] . "\n"
241 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
242 . ' ' . $data_size . "\n"
244 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
245 . ' ' . $data_unit . "\n"
247 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
248 . ' ' . $idx_size . "\n"
250 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
251 . ' ' . $idx_unit . "\n"
253 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
255 . ' ' . $tot_size . "\n"
258 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
260 . ' ' . $tot_unit . "\n"
264 echo ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
265 . ' <a href="./server_privileges.php3?' . $url_query . '&checkprivs=' . urlencode($current['db_name']) . '" title="' . sprintf($strCheckPrivsLong, htmlspecialchars($current['db_name'])) . '">'. "\n"
266 . ' ' . $strCheckPrivs . "\n"
270 $useBgcolorOne = !$useBgcolorOne;
272 if (!empty($dbstats)) {
273 list($data_size, $data_unit) = PMA_formatByteDown($total_calc['data_sz'], 3, 1);
274 list($idx_size, $idx_unit) = PMA_formatByteDown($total_calc['idx_sz'], 3, 1);
275 list($tot_size, $tot_unit) = PMA_formatByteDown($total_calc['tot_sz'], 3, 1);
277 . ' <th> </th>' . "\n"
279 . ' ' . $strTotalUC . ': ' . $total_calc['db_cnt'] . ' ' . "\n"
281 . ' <th align="right">' . "\n"
282 . ' ' . $total_calc['tbl_cnt'] . ' ' . "\n"
284 . ' <th align="right">' . "\n"
285 . ' ' . $data_size . "\n"
287 . ' <th align="left">' . "\n"
288 . ' ' . $data_unit . ' ' . "\n"
290 . ' <th align="right">' . "\n"
291 . ' ' . $idx_size . "\n"
293 . ' <th align="left">' . "\n"
294 . ' ' . $idx_unit . ' ' . "\n"
296 . ' <th align="right">' . "\n"
297 . ' ' . $tot_size . "\n"
299 . ' <th align="left">' . "\n"
300 . ' ' . $tot_unit . ' ' . "\n"
302 . ' <th> </th>' . "\n"
305 $common_url_query = PMA_generate_common_url() . '&sort_by=' . $sort_by . '&sort_order=' . $sort_order . '&dbstats=' . (empty($dbstats) ?
'10' : '3');
307 . ' <td colspan="' . (empty($dbstats) ?
'10' : '3') . '">' . "\n"
308 . ' <img src="./images/arrow_' . $text_dir . '.gif" border="0" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
309 . ' <a href="./server_databases.php3?' . $common_url_query . '&checkall=1" onclick="setCheckboxes(\'dbStatsForm\', true); return false;">' . "\n"
312 . ' / ' . "\n"
313 . ' <a href="./server_databases.php3?' . $common_url_query . '" onclick="setCheckboxes(\'dbStatsForm\', false); return false;">' . "\n"
314 . ' ' . $strUncheckAll
328 if ($is_superuser && empty($dbstats) && PMA_MYSQL_INT_VERSION
>= 32303) {
329 echo ' <a href="./server_databases.php3?' . $url_query . '&dbstats=1" title="' . $strDatabasesStatsEnable . '">' . "\n"
330 . ' ' . $strDatabasesStatsEnable . "\n"
332 . ' </b><br />' . "\n"
333 . $strDatabasesStatsHeavyTraffic . "\n";
334 } else if (!empty($dbstats)) {
335 echo ' <a href="./server_databases.php3?' . $url_query . '" title="' . $strDatabasesStatsDisable . '">'. "\n"
336 . ' ' . $strDatabasesStatsDisable . "\n"
340 echo ' </li><br /><br />' . "\n"
343 . ' ' . $strDropSelectedDatabases . "\n"
344 . ' </b><br />' . "\n"
345 . ' <input type="submit" name="drop_selected_dbs" value="' . $strGo . '" />' . "\n"
350 echo $strNoDatabases . "\n";
357 require('./footer.inc.php3');