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) && ($is_superuser ||
$cfg['AllowUserDropDatabase'])) {
58 if (empty($selected_db)) {
59 $message = $strNoDatabasesSelected;
62 while (list(, $current_db) = each($selected_db)) {
63 $current_query = 'DROP DATABASE ' . PMA_backquote($current_db) . ';';
64 $sql_query[] = $current_query;
65 PMA_mysql_query($current_query, $userlink)
66 // rabus: in case of an error, we display the full query in
67 // order to let the user know which databases have already been
69 or PMA_mysqlDie(PMA_mysql_error($userlink), join("\n", $sql_query));
71 // PMA_showMessage() needs a string...
72 $sql_query = join("\n", $sql_query);
73 $message = sprintf($strDatabasesDropped, count($selected_db));
74 // we need to reload the database list now.
75 PMA_availableDatabases();
84 require('./server_links.inc.php3');
88 * Displays the sub-page heading
91 . ' ' . (empty($dbstats) ?
$strDatabases : $strDatabasesStats) . "\n"
96 * Checks if the user is allowed to do what he tries to...
98 if (!empty($dbstats) && (!$is_superuser || PMA_MYSQL_INT_VERSION
< 32303)) {
99 echo $strNoPrivileges . "\n";
100 include('./footer.inc.php3');
106 * Prepares the statistics
108 $statistics = array();
109 while (list(, $current_db) = each($dblist)) {
111 'db_name' => $current_db,
117 if (!empty($dbstats)) {
118 $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) . ';');
119 while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC
)) {
120 $tmp_array['tbl_cnt']++
;
121 $tmp_array['data_sz'] +
= $row['Data_length'];
122 $tmp_array['idx_sz'] +
= $row['Index_length'];
125 $tmp_array['tot_sz'] = $tmp_array['data_sz'] +
$tmp_array['idx_sz'];
126 $statistics[] = $tmp_array;
129 // avoids 'undefined index' errors
130 if (empty($sort_by)) {
131 $sort_by = 'db_name';
133 if (empty($sort_order)) {
134 if ($sort_by == 'db_name') {
137 $sort_order = 'desc';
142 usort($statistics, 'PMA_dbCmp');
148 if (count($statistics) > 0) {
149 echo '<form action="./server_databases.php3" method="post" name="dbStatsForm">' . "\n"
150 . PMA_generate_common_hidden_inputs('', '', 1)
151 . ' <input type="hidden" name="dbstats" value="' . (empty($dbstats) ?
'0' : '1') . '" />' . "\n"
152 . ' <input type="hidden" name="sort_by" value="' . $sort_by . '" />' . "\n"
153 . ' <input type="hidden" name="sort_order" value="' . $sort_order . '" />' . "\n"
154 . ' <table border="0">' . "\n"
156 . ($is_superuser ||
$cfg['AllowUserDropDatabase'] ?
' <th> </th>' . "\n" : '')
159 if (empty($dbstats)) {
160 echo $strDatabase . "\n"
161 . ' <img src="./images/asc_order.png" border="0" width="7" height="7" alt="' . $strAscending . '" />' . "\n"
166 . ' <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"
167 . ' ' . $strDatabase . "\n"
168 . ($sort_by == 'db_name' ?
' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
174 . ' <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"
175 . ' ' . $strNumTables . "\n"
176 . ($sort_by == 'tbl_cnt' ?
' <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=data_sz&sort_order=' . (($sort_by == 'data_sz' && $sort_order == 'desc') ?
'asc' : 'desc') . '">' . "\n"
183 . ' ' . $strData . "\n"
184 . ($sort_by == 'data_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=idx_sz&sort_order=' . (($sort_by == 'idx_sz' && $sort_order == 'desc') ?
'asc' : 'desc') . '">' . "\n"
191 . ' ' . $strIndexes . "\n"
192 . ($sort_by == 'idx_sz' ?
' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
196 . ' <th colspan="2">' . "\n"
198 . ' <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"
199 . ' ' . $strTotalUC . "\n"
200 . ($sort_by == 'tot_sz' ?
' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
207 . ' ' . $strAction . ' ' . "\n"
210 echo ' </tr>' . "\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 if ($is_superuser ||
$cfg['AllowUserDropDatabase']) {
230 echo ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
231 . ' <input type="checkbox" name="selected_db[]" title="' . htmlspecialchars($current['db_name']) . '" value="' . htmlspecialchars($current['db_name']) . '" ' . (empty($checkall) ?
'' : 'checked="checked" ') . '/>' . "\n"
234 echo ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
235 . ' <a href="' . $cfg['DefaultTabDatabase'] . '?' . $url_query . '&db=' . urlencode($current['db_name']) . '" title="' . sprintf($strJumpToDB, htmlspecialchars($current['db_name'])) . '">' . "\n"
236 . ' ' . htmlspecialchars($current['db_name']) . "\n"
239 if (!empty($dbstats)) {
240 echo ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
241 . ' ' . $current['tbl_cnt'] . "\n"
243 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
244 . ' ' . $data_size . "\n"
246 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
247 . ' ' . $data_unit . "\n"
249 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
250 . ' ' . $idx_size . "\n"
252 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
253 . ' ' . $idx_unit . "\n"
255 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
257 . ' ' . $tot_size . "\n"
260 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
262 . ' ' . $tot_unit . "\n"
267 echo ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
268 . ' <a href="./server_privileges.php3?' . $url_query . '&checkprivs=' . urlencode($current['db_name']) . '" title="' . sprintf($strCheckPrivsLong, htmlspecialchars($current['db_name'])) . '">'. "\n"
269 . ' ' . $strCheckPrivs . "\n"
273 echo ' </tr>' . "\n";
274 $useBgcolorOne = !$useBgcolorOne;
276 if (!empty($dbstats)) {
277 list($data_size, $data_unit) = PMA_formatByteDown($total_calc['data_sz'], 3, 1);
278 list($idx_size, $idx_unit) = PMA_formatByteDown($total_calc['idx_sz'], 3, 1);
279 list($tot_size, $tot_unit) = PMA_formatByteDown($total_calc['tot_sz'], 3, 1);
281 . ' <th> </th>' . "\n"
283 . ' ' . $strTotalUC . ': ' . $total_calc['db_cnt'] . ' ' . "\n"
285 . ' <th align="right">' . "\n"
286 . ' ' . $total_calc['tbl_cnt'] . ' ' . "\n"
288 . ' <th align="right">' . "\n"
289 . ' ' . $data_size . "\n"
291 . ' <th align="left">' . "\n"
292 . ' ' . $data_unit . ' ' . "\n"
294 . ' <th align="right">' . "\n"
295 . ' ' . $idx_size . "\n"
297 . ' <th align="left">' . "\n"
298 . ' ' . $idx_unit . ' ' . "\n"
300 . ' <th align="right">' . "\n"
301 . ' ' . $tot_size . "\n"
303 . ' <th align="left">' . "\n"
304 . ' ' . $tot_unit . ' ' . "\n"
306 . ' <th> </th>' . "\n"
309 if ($is_superuser ||
$cfg['AllowUserDropDatabase']) {
310 $common_url_query = PMA_generate_common_url() . '&sort_by=' . $sort_by . '&sort_order=' . $sort_order . '&dbstats=' . (empty($dbstats) ?
'10' : '3');
312 . ' <td colspan="' . (empty($dbstats) ?
'10' : '3') . '">' . "\n"
313 . ' <img src="./images/arrow_' . $text_dir . '.gif" border="0" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
314 . ' <a href="./server_databases.php3?' . $common_url_query . '&checkall=1" onclick="setCheckboxes(\'dbStatsForm\', true); return false;">' . "\n"
317 . ' / ' . "\n"
318 . ' <a href="./server_databases.php3?' . $common_url_query . '" onclick="setCheckboxes(\'dbStatsForm\', false); return false;">' . "\n"
319 . ' ' . $strUncheckAll
324 echo ' </table>' . "\n";
331 if ($is_superuser ||
$cfg['AllowUserDropDatabase']) {
334 if ($is_superuser && empty($dbstats) && PMA_MYSQL_INT_VERSION
>= 32303) {
337 . ' <a href="./server_databases.php3?' . $url_query . '&dbstats=1" title="' . $strDatabasesStatsEnable . '">' . "\n"
338 . ' ' . $strDatabasesStatsEnable . "\n"
341 . ' </li><br /><br />' . "\n"
342 . $strDatabasesStatsHeavyTraffic . "\n";
343 } else if ($is_superuser && !empty($dbstats)) {
346 . ' <a href="./server_databases.php3?' . $url_query . '" title="' . $strDatabasesStatsDisable . '">'. "\n"
347 . ' ' . $strDatabasesStatsDisable . "\n"
350 . ' </li><br /><br />' . "\n";
352 if ($is_superuser ||
$cfg['AllowUserDropDatabase']) {
355 . ' ' . $strDropSelectedDatabases . "\n"
356 . ' </b><br />' . "\n"
357 . ' <input type="submit" name="drop_selected_dbs" value="' . $strGo . '" />' . "\n"
361 echo '</form>' . "\n";
363 echo $strNoDatabases . "\n";
370 require('./footer.inc.php3');