3 // vim: expandtab sw=4 ts=4 sts=4:
7 * Checks if the left frame has to be reloaded
9 require_once('./libraries/grab_globals.lib.php');
13 * Does the common work
15 $js_to_run = 'functions.js';
16 require('./server_common.inc.php');
19 <script type
="text/javascript" language
="javascript1.2">
21 function reload_window(db
) {
22 if (typeof(window
.parent
) != 'undefined'
23 && typeof(window
.parent
.frames
['nav']) != 'undefined') {
24 window
.parent
.frames
['nav'].location
.replace('./left.php?<?php echo PMA_generate_common_url('','','&');?>&db=' + db +
'&hash=' +
<?php
echo (($cfg['QueryFrame'] && $cfg['QueryFrameJS']) ?
'window.parent.frames[\'queryframe\'].document.hashform.hash.value' : "'" . md5($cfg['PmaAbsoluteUri']) . "'"); ?
>);
33 * Sorts the databases array according to the user's choice
35 * @param array a record associated to a database
36 * @param array a record associated to a database
38 * @return integer a value representing whether $a should be before $b in the
41 * @global string the column the array shall be sorted by
42 * @global string the sorting order ('asc' or 'desc')
46 function PMA_dbCmp($a, $b)
48 global $sort_by, $sort_order;
49 if ($sort_by == 'db_name') {
50 return ($sort_order == 'asc' ?
1 : -1) * strcasecmp($a['db_name'], $b['db_name']);
51 } else if ($a[$sort_by] == $b[$sort_by]) {
52 return strcasecmp($a['db_name'], $b['db_name']);
54 return ($sort_order == 'asc' ?
1 : -1) * ((int)$a[$sort_by] > (int)$b[$sort_by] ?
1 : -1);
56 } // end of the 'PMA_dbCmp()' function
60 * Gets the databases list - if it has not been built yet
62 if ($server > 0 && empty($dblist)) {
63 PMA_availableDatabases();
68 * Drops multiple databases
70 if ((!empty($drop_selected_dbs) ||
isset($query_type)) && ($is_superuser ||
$cfg['AllowUserDropDatabase'])) {
71 if (empty($selected_db) && ! (isset($query_type) && !empty($selected))) {
72 $message = $strNoDatabasesSelected;
74 $action = 'server_databases.php';
75 $submit_mult = 'drop_db' ;
76 $err_url = 'server_databases.php?' . PMA_generate_common_url();
77 require('./mult_submits.inc.php');
78 $message = sprintf($strDatabasesDropped, count($selected));
79 // we need to reload the database list now.
80 PMA_availableDatabases();
89 require('./server_links.inc.php');
93 * Displays the sub-page heading
96 . ' ' . (empty($dbstats) ?
$strDatabases : $strDatabasesStats) . "\n"
101 * Checks if the user is allowed to do what he tries to...
103 if (!empty($dbstats) && !$is_superuser) {
104 echo $strNoPrivileges . "\n";
105 require_once('./footer.inc.php');
110 * Prepares the statistics
112 $statistics = array();
113 foreach($dblist AS $current_db) {
115 'db_name' => $current_db,
121 if (!empty($dbstats)) {
122 $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) . ';');
123 while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC
)) {
124 $tmp_array['tbl_cnt']++
;
125 $tmp_array['data_sz'] +
= $row['Data_length'];
126 $tmp_array['idx_sz'] +
= $row['Index_length'];
129 $tmp_array['tot_sz'] = $tmp_array['data_sz'] +
$tmp_array['idx_sz'];
130 $statistics[] = $tmp_array;
133 // avoids 'undefined index' errors
134 if (empty($sort_by)) {
135 $sort_by = 'db_name';
137 if (empty($sort_order)) {
138 if ($sort_by == 'db_name') {
141 $sort_order = 'desc';
146 usort($statistics, 'PMA_dbCmp');
152 if (count($statistics) > 0) {
153 echo '<form action="./server_databases.php" method="post" name="dbStatsForm">' . "\n"
154 . PMA_generate_common_hidden_inputs('', '', 1)
155 . ' <input type="hidden" name="dbstats" value="' . (empty($dbstats) ?
'0' : '1') . '" />' . "\n"
156 . ' <input type="hidden" name="sort_by" value="' . $sort_by . '" />' . "\n"
157 . ' <input type="hidden" name="sort_order" value="' . $sort_order . '" />' . "\n"
158 . ' <table border="0">' . "\n"
160 . ($is_superuser ||
$cfg['AllowUserDropDatabase'] ?
' <th> </th>' . "\n" : '')
163 if (empty($dbstats)) {
164 echo $strDatabase . "\n"
165 . ' <img src="./images/asc_order.png" border="0" width="7" height="7" alt="' . $strAscending . '" />' . "\n"
170 . ' <a href="./server_databases.php?' . $url_query . '&dbstats=1&sort_by=db_name&sort_order=' . (($sort_by == 'db_name' && $sort_order == 'asc') ?
'desc' : 'asc') . '">' . "\n"
171 . ' ' . $strDatabase . "\n"
172 . ($sort_by == 'db_name' ?
' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
178 . ' <a href="./server_databases.php?' . $url_query . '&dbstats=1&sort_by=tbl_cnt&sort_order=' . (($sort_by == 'tbl_cnt' && $sort_order == 'desc') ?
'asc' : 'desc') . '">' . "\n"
179 . ' ' . $strNumTables . "\n"
180 . ($sort_by == 'tbl_cnt' ?
' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
184 . ' <th colspan="2">' . "\n"
186 . ' <a href="./server_databases.php?' . $url_query . '&dbstats=1&sort_by=data_sz&sort_order=' . (($sort_by == 'data_sz' && $sort_order == 'desc') ?
'asc' : 'desc') . '">' . "\n"
187 . ' ' . $strData . "\n"
188 . ($sort_by == 'data_sz' ?
' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
192 . ' <th colspan="2">' . "\n"
194 . ' <a href="./server_databases.php?' . $url_query . '&dbstats=1&sort_by=idx_sz&sort_order=' . (($sort_by == 'idx_sz' && $sort_order == 'desc') ?
'asc' : 'desc') . '">' . "\n"
195 . ' ' . $strIndexes . "\n"
196 . ($sort_by == 'idx_sz' ?
' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
200 . ' <th colspan="2">' . "\n"
202 . ' <a href="./server_databases.php?' . $url_query . '&dbstats=1&sort_by=tot_sz&sort_order=' . (($sort_by == 'tot_sz' && $sort_order == 'desc') ?
'asc' : 'desc') . '">' . "\n"
203 . ' ' . $strTotalUC . "\n"
204 . ($sort_by == 'tot_sz' ?
' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ?
$strAscending : $strDescending) . '" />' . "\n" : '')
211 . ' ' . $strAction . ' ' . "\n"
214 echo ' </tr>' . "\n";
215 $useBgcolorOne = TRUE;
223 foreach ($statistics as $current) {
224 list($data_size, $data_unit) = PMA_formatByteDown($current['data_sz'], 3, 1);
225 list($idx_size, $idx_unit) = PMA_formatByteDown($current['idx_sz'], 3, 1);
226 list($tot_size, $tot_unit) = PMA_formatByteDown($current['tot_sz'], 3, 1);
227 $total_calc['db_cnt']++
;
228 $total_calc['tbl_cnt'] +
= $current['tbl_cnt'];
229 $total_calc['data_sz'] +
= $current['data_sz'];
230 $total_calc['idx_sz'] +
= $current['idx_sz'];
231 $total_calc['tot_sz'] +
= $current['tot_sz'];
233 if ($is_superuser ||
$cfg['AllowUserDropDatabase']) {
234 echo ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
235 . ' <input type="checkbox" name="selected_db[]" title="' . htmlspecialchars($current['db_name']) . '" value="' . htmlspecialchars($current['db_name']) . '" ' . (empty($checkall) ?
'' : 'checked="checked" ') . '/>' . "\n"
238 echo ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
239 . ' <a onclick="reload_window(\'' . urlencode($current['db_name']) . '\'); return true;" href="' . $cfg['DefaultTabDatabase'] . '?' . $url_query . '&db=' . urlencode($current['db_name']) . '" title="' . sprintf($strJumpToDB, htmlspecialchars($current['db_name'])) . '">' . "\n"
240 . ' ' . htmlspecialchars($current['db_name']) . "\n"
243 if (!empty($dbstats)) {
244 echo ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
245 . ' ' . $current['tbl_cnt'] . "\n"
247 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
248 . ' ' . $data_size . "\n"
250 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
251 . ' ' . $data_unit . "\n"
253 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
254 . ' ' . $idx_size . "\n"
256 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
257 . ' ' . $idx_unit . "\n"
259 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
261 . ' ' . $tot_size . "\n"
264 . ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
266 . ' ' . $tot_unit . "\n"
271 echo ' <td bgcolor="' . ($useBgcolorOne ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
272 . ' <a onclick="reload_window(\'' . urlencode($current['db_name']) . '\'); return true;" href="./server_privileges.php?' . $url_query . '&checkprivs=' . urlencode($current['db_name']) . '" title="' . sprintf($strCheckPrivsLong, htmlspecialchars($current['db_name'])) . '">'. "\n"
273 . ' ' . $strCheckPrivs . "\n"
277 echo ' </tr>' . "\n";
278 $useBgcolorOne = !$useBgcolorOne;
280 if (!empty($dbstats)) {
281 list($data_size, $data_unit) = PMA_formatByteDown($total_calc['data_sz'], 3, 1);
282 list($idx_size, $idx_unit) = PMA_formatByteDown($total_calc['idx_sz'], 3, 1);
283 list($tot_size, $tot_unit) = PMA_formatByteDown($total_calc['tot_sz'], 3, 1);
285 . ' <th> </th>' . "\n"
287 . ' ' . $strTotalUC . ': ' . $total_calc['db_cnt'] . ' ' . "\n"
289 . ' <th align="right">' . "\n"
290 . ' ' . $total_calc['tbl_cnt'] . ' ' . "\n"
292 . ' <th align="right">' . "\n"
293 . ' ' . $data_size . "\n"
295 . ' <th align="left">' . "\n"
296 . ' ' . $data_unit . ' ' . "\n"
298 . ' <th align="right">' . "\n"
299 . ' ' . $idx_size . "\n"
301 . ' <th align="left">' . "\n"
302 . ' ' . $idx_unit . ' ' . "\n"
304 . ' <th align="right">' . "\n"
305 . ' ' . $tot_size . "\n"
307 . ' <th align="left">' . "\n"
308 . ' ' . $tot_unit . ' ' . "\n"
310 . ' <th> </th>' . "\n"
313 if ($is_superuser ||
$cfg['AllowUserDropDatabase']) {
314 $common_url_query = PMA_generate_common_url() . '&sort_by=' . $sort_by . '&sort_order=' . $sort_order . '&dbstats=' . (empty($dbstats) ?
'10' : '3');
316 . ' <td colspan="' . (empty($dbstats) ?
'10' : '3') . '">' . "\n"
317 . ' <img src="./images/arrow_' . $text_dir . '.gif" border="0" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
318 . ' <a href="./server_databases.php?' . $common_url_query . '&checkall=1" onclick="setCheckboxes(\'dbStatsForm\', true); return false;">' . "\n"
321 . ' / ' . "\n"
322 . ' <a href="./server_databases.php?' . $common_url_query . '" onclick="setCheckboxes(\'dbStatsForm\', false); return false;">' . "\n"
323 . ' ' . $strUncheckAll
328 echo ' </table>' . "\n";
335 if ($is_superuser ||
$cfg['AllowUserDropDatabase']) {
338 if ($is_superuser && empty($dbstats)) {
341 . ' <a href="./server_databases.php?' . $url_query . '&dbstats=1" title="' . $strDatabasesStatsEnable . '">' . "\n"
342 . ' ' . $strDatabasesStatsEnable . "\n"
346 . ' ' . $strDatabasesStatsHeavyTraffic . "\n"
347 . ' </li><br /><br />' . "\n";
348 } else if ($is_superuser && !empty($dbstats)) {
351 . ' <a href="./server_databases.php?' . $url_query . '" title="' . $strDatabasesStatsDisable . '">'. "\n"
352 . ' ' . $strDatabasesStatsDisable . "\n"
355 . ' </li><br /><br />' . "\n";
357 if ($is_superuser ||
$cfg['AllowUserDropDatabase']) {
360 . ' ' . $strDropSelectedDatabases . "\n"
361 . ' </b><br />' . "\n"
362 . ' <input type="submit" name="drop_selected_dbs" value="' . $strGo . '" />' . "\n"
366 echo '</form>' . "\n";
368 echo $strNoDatabases . "\n";
375 require_once('./footer.inc.php');