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');
13 * Does the common work
15 $js_to_run = 'functions.js';
16 require('./server_common.inc.php3');
20 * Sorts the databases array according to the user's choice
22 * @param array a record associated to a database
23 * @param array a record associated to a database
25 * @return integer a value representing whether $a should be before $b in the
28 * @global string the column the array shall be sorted by
29 * @global string the sorting order ('asc' or 'desc')
33 function PMA_dbCmp($a, $b)
35 global $sort_by, $sort_order;
36 if ($sort_by == 'db_name') {
37 return ($sort_order == 'asc' ?
1 : -1) * strcasecmp($a['db_name'], $b['db_name']);
38 } else if ($a[$sort_by] == $b[$sort_by]) {
39 return strcasecmp($a['db_name'], $b['db_name']);
41 return ($sort_order == 'asc' ?
1 : -1) * ((int)$a[$sort_by] > (int)$b[$sort_by] ?
1 : -1);
43 } // end of the 'PMA_dbCmp()' function
47 * Gets the databases list - if it has not been built yet
49 if ($server > 0 && empty($dblist)) {
50 PMA_availableDatabases();
55 * Drops multiple databases
57 if ((!empty($drop_selected_dbs) ||
isset($query_type)) && ($is_superuser ||
$cfg['AllowUserDropDatabase'])) {
58 if (empty($selected_db) && ! (isset($query_type) && !empty($selected))) {
59 $message = $strNoDatabasesSelected;
61 $action = 'server_databases.php3';
62 $submit_mult = 'drop_db' ;
63 $err_url = 'server_databases.php3?' . PMA_generate_common_url();
64 include('./mult_submits.inc.php3');
65 $message = sprintf($strDatabasesDropped, count($selected));
66 // we need to reload the database list now.
67 PMA_availableDatabases();
76 require('./server_links.inc.php3');
80 * Displays the sub-page heading
83 . ' ' . (empty($dbstats) ?
$strDatabases : $strDatabasesStats) . "\n"
88 * Checks if the user is allowed to do what he tries to...
90 if (!empty($dbstats) && (!$is_superuser || PMA_MYSQL_INT_VERSION
< 32303)) {
91 echo $strNoPrivileges . "\n";
92 include('./footer.inc.php3');
98 * Prepares the statistics
100 $statistics = array();
101 while (list(, $current_db) = each($dblist)) {
103 'db_name' => $current_db,
109 if (!empty($dbstats)) {
110 $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) . ';');
111 while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC
)) {
112 $tmp_array['tbl_cnt']++
;
113 $tmp_array['data_sz'] +
= $row['Data_length'];
114 $tmp_array['idx_sz'] +
= $row['Index_length'];
117 $tmp_array['tot_sz'] = $tmp_array['data_sz'] +
$tmp_array['idx_sz'];
118 $statistics[] = $tmp_array;
121 // avoids 'undefined index' errors
122 if (empty($sort_by)) {
123 $sort_by = 'db_name';
125 if (empty($sort_order)) {
126 if ($sort_by == 'db_name') {
129 $sort_order = 'desc';
134 usort($statistics, 'PMA_dbCmp');
140 if (count($statistics) > 0) {
141 echo '<form action="./server_databases.php3" method="post" name="dbStatsForm">' . "\n"
142 . PMA_generate_common_hidden_inputs('', '', 1)
143 . ' <input type="hidden" name="dbstats" value="' . (empty($dbstats) ?
'0' : '1') . '" />' . "\n"
144 . ' <input type="hidden" name="sort_by" value="' . $sort_by . '" />' . "\n"
145 . ' <input type="hidden" name="sort_order" value="' . $sort_order . '" />' . "\n"
146 . ' <table border="0">' . "\n"
148 . ($is_superuser ||
$cfg['AllowUserDropDatabase'] ?
' <th> </th>' . "\n" : '')
151 if (empty($dbstats)) {
152 echo $strDatabase . "\n"
153 . ' <img src="./images/asc_order.png" border="0" width="7" height="7" alt="' . $strAscending . '" />' . "\n"
158 . ' <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"
159 . ' ' . $strDatabase . "\n"
160 . ($sort_by == 'db_name' ?
' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
166 . ' <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"
167 . ' ' . $strNumTables . "\n"
168 . ($sort_by == 'tbl_cnt' ?
' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
172 . ' <th colspan="2">' . "\n"
174 . ' <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"
175 . ' ' . $strData . "\n"
176 . ($sort_by == 'data_sz' ?
' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
180 . ' <th colspan="2">' . "\n"
182 . ' <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"
183 . ' ' . $strIndexes . "\n"
184 . ($sort_by == 'idx_sz' ?
' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
188 . ' <th colspan="2">' . "\n"
190 . ' <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"
191 . ' ' . $strTotalUC . "\n"
192 . ($sort_by == 'tot_sz' ?
' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
199 . ' ' . $strAction . ' ' . "\n"
202 echo ' </tr>' . "\n";
203 $useBgcolorOne = TRUE;
211 while (list(, $current) = each($statistics)) {
212 list($data_size, $data_unit) = PMA_formatByteDown($current['data_sz'], 3, 1);
213 list($idx_size, $idx_unit) = PMA_formatByteDown($current['idx_sz'], 3, 1);
214 list($tot_size, $tot_unit) = PMA_formatByteDown($current['tot_sz'], 3, 1);
215 $total_calc['db_cnt']++
;
216 $total_calc['tbl_cnt'] +
= $current['tbl_cnt'];
217 $total_calc['data_sz'] +
= $current['data_sz'];
218 $total_calc['idx_sz'] +
= $current['idx_sz'];
219 $total_calc['tot_sz'] +
= $current['tot_sz'];
221 if ($is_superuser ||
$cfg['AllowUserDropDatabase']) {
222 echo ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
223 . ' <input type="checkbox" name="selected_db[]" title="' . htmlspecialchars($current['db_name']) . '" value="' . htmlspecialchars($current['db_name']) . '" ' . (empty($checkall) ?
'' : 'checked="checked" ') . '/>' . "\n"
226 echo ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
227 . ' <a href="' . $cfg['DefaultTabDatabase'] . '?' . $url_query . '&db=' . urlencode($current['db_name']) . '" title="' . sprintf($strJumpToDB, htmlspecialchars($current['db_name'])) . '">' . "\n"
228 . ' ' . htmlspecialchars($current['db_name']) . "\n"
231 if (!empty($dbstats)) {
232 echo ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
233 . ' ' . $current['tbl_cnt'] . "\n"
235 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
236 . ' ' . $data_size . "\n"
238 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
239 . ' ' . $data_unit . "\n"
241 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
242 . ' ' . $idx_size . "\n"
244 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
245 . ' ' . $idx_unit . "\n"
247 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
249 . ' ' . $tot_size . "\n"
252 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
254 . ' ' . $tot_unit . "\n"
259 echo ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
260 . ' <a href="./server_privileges.php3?' . $url_query . '&checkprivs=' . urlencode($current['db_name']) . '" title="' . sprintf($strCheckPrivsLong, htmlspecialchars($current['db_name'])) . '">'. "\n"
261 . ' ' . $strCheckPrivs . "\n"
265 echo ' </tr>' . "\n";
266 $useBgcolorOne = !$useBgcolorOne;
268 if (!empty($dbstats)) {
269 list($data_size, $data_unit) = PMA_formatByteDown($total_calc['data_sz'], 3, 1);
270 list($idx_size, $idx_unit) = PMA_formatByteDown($total_calc['idx_sz'], 3, 1);
271 list($tot_size, $tot_unit) = PMA_formatByteDown($total_calc['tot_sz'], 3, 1);
273 . ' <th> </th>' . "\n"
275 . ' ' . $strTotalUC . ': ' . $total_calc['db_cnt'] . ' ' . "\n"
277 . ' <th align="right">' . "\n"
278 . ' ' . $total_calc['tbl_cnt'] . ' ' . "\n"
280 . ' <th align="right">' . "\n"
281 . ' ' . $data_size . "\n"
283 . ' <th align="left">' . "\n"
284 . ' ' . $data_unit . ' ' . "\n"
286 . ' <th align="right">' . "\n"
287 . ' ' . $idx_size . "\n"
289 . ' <th align="left">' . "\n"
290 . ' ' . $idx_unit . ' ' . "\n"
292 . ' <th align="right">' . "\n"
293 . ' ' . $tot_size . "\n"
295 . ' <th align="left">' . "\n"
296 . ' ' . $tot_unit . ' ' . "\n"
298 . ' <th> </th>' . "\n"
301 if ($is_superuser ||
$cfg['AllowUserDropDatabase']) {
302 $common_url_query = PMA_generate_common_url() . '&sort_by=' . $sort_by . '&sort_order=' . $sort_order . '&dbstats=' . (empty($dbstats) ?
'10' : '3');
304 . ' <td colspan="' . (empty($dbstats) ?
'10' : '3') . '">' . "\n"
305 . ' <img src="./images/arrow_' . $text_dir . '.gif" border="0" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
306 . ' <a href="./server_databases.php3?' . $common_url_query . '&checkall=1" onclick="setCheckboxes(\'dbStatsForm\', true); return false;">' . "\n"
309 . ' / ' . "\n"
310 . ' <a href="./server_databases.php3?' . $common_url_query . '" onclick="setCheckboxes(\'dbStatsForm\', false); return false;">' . "\n"
311 . ' ' . $strUncheckAll
316 echo ' </table>' . "\n";
323 if ($is_superuser ||
$cfg['AllowUserDropDatabase']) {
326 if ($is_superuser && empty($dbstats) && PMA_MYSQL_INT_VERSION
>= 32303) {
329 . ' <a href="./server_databases.php3?' . $url_query . '&dbstats=1" title="' . $strDatabasesStatsEnable . '">' . "\n"
330 . ' ' . $strDatabasesStatsEnable . "\n"
334 . ' ' . $strDatabasesStatsHeavyTraffic . "\n"
335 . ' </li><br /><br />' . "\n";
336 } else if ($is_superuser && !empty($dbstats)) {
339 . ' <a href="./server_databases.php3?' . $url_query . '" title="' . $strDatabasesStatsDisable . '">'. "\n"
340 . ' ' . $strDatabasesStatsDisable . "\n"
343 . ' </li><br /><br />' . "\n";
345 if ($is_superuser ||
$cfg['AllowUserDropDatabase']) {
348 . ' ' . $strDropSelectedDatabases . "\n"
349 . ' </b><br />' . "\n"
350 . ' <input type="submit" name="drop_selected_dbs" value="' . $strGo . '" />' . "\n"
354 echo '</form>' . "\n";
356 echo $strNoDatabases . "\n";
363 require('./footer.inc.php3');