3 // vim: expandtab sw=4 ts=4 sts=4:
6 * Gets the variables sent to this script and send headers
8 $js_to_run = 'functions.js';
9 require('./libraries/grab_globals.lib.php3');
10 require('./header.inc.php3');
14 * Ensures the current user is super-user
16 if (!@PMA_mysql_query
('USE mysql', $userlink)) {
17 echo '<p><b>' . $strError . '</b></p>' . "\n";
18 echo '<p> ' . $strNoRights . '</p>' . "\n";
19 include('./footer.inc.php3');
25 * Drop databases if required
27 if ((!empty($submit_mult) && isset($selected_db))
28 ||
isset($mult_btn)) {
29 $err_url = 'db_stats.php3?' . PMA_generate_common_url();
30 $action = 'db_stats.php3';
32 include('./mult_submits.inc.php3');
37 * Sorts the databases array according to the user's choice
39 * @param array a record associated to a database
40 * @param array a record associated to a database
42 * @return integer a value representing whether $a should be before $b in the
45 * @global mixed the array to sort
46 * @global mixed 'key' if the table has to be sorted by key, the column
47 * number to use to sort the array else
51 function PMA_dbCmp($a, $b)
56 $is_asc = ($GLOBALS['sort_order'] == 'asc');
58 // Sort by key (the db names) if required
59 if (!is_int($col) && $col == 'key') {
60 return (($is_asc) ?
strcasecmp($a, $b) : -strcasecmp($a, $b));
62 // Sort by key (the db names) in ascending order if the columns' values are
64 else if ($dbs_array[$a][$col] == $dbs_array[$b][$col]) {
65 return strcasecmp($a, $b);
69 $tmp = (($dbs_array[$a][$col] < $dbs_array[$b][$col]) ?
-1 : 1);
70 return (($is_asc) ?
$tmp : -$tmp);
72 } // end of the 'PMA_dbCmp()' function
76 * Get the list and number of available databases.
77 * Skipped if no server selected: in this case no database should be displayed
78 * before the user choose among available ones at the welcome screen.
81 // Get the valid databases list
82 $num_dbs = count($dblist);
83 $dbs = @mysql_list_dbs
() or PMA_mysqlDie('', 'mysql_list_dbs()', '', 'main.php3?' . PMA_generate_common_url());
85 while ($a_db = PMA_mysql_fetch_object($dbs)) {
87 $dblist[] = $a_db->Database
;
89 $true_dblist[$a_db->Database
] = '';
92 mysql_free_result($dbs);
94 if ($num_dbs && empty($true_dblist)) {
96 } else if ($num_dbs) {
97 for ($i = 0; $i < $num_dbs; $i++
) {
98 if (isset($true_dblist[$dblist[$i]])) {
99 $dblist_valid[] = $dblist[$i];
102 if (isset($dblist_valid)) {
103 $dblist = $dblist_valid;
104 unset($dblist_valid);
110 // Get the valid databases count
111 $num_dbs = count($dblist);
123 <?php
echo $strDatabasesStats; ?
>
125 <table align
="center" border
="<?php echo $cfg['Border']; ?>" cellpadding
="5">
127 <th align
="<?php echo $cell_align_left; ?>"><big
><?php
echo $strHost . ' :'; ?
></big
></th
>
128 <th align
="<?php echo $cell_align_left; ?>"><big
><?php
echo $cfg['Server']['host']; ?
></big
></th
>
131 <th align
="<?php echo $cell_align_left; ?>"><big
><?php
echo $strGenTime . ' :'; ?
></big
></th
>
132 <th align
="<?php echo $cell_align_left; ?>"><big
><?php
echo PMA_localisedDate(); ?
></big
></th
>
140 * At least one db -> do the work
143 // Defines the urls used to sort the table
144 $common_url = 'db_stats.php3?' . PMA_generate_common_url();
145 if (empty($sort_by)) {
146 $sort_by = 'db_name';
149 else if (empty($sort_order)) {
150 $sort_order = (($sort_by == 'db_name') ?
'asc' : 'desc');
152 $img_tag = ' ' . "\n"
154 . '<img src="./images/' . $sort_order . '_order.gif" border="0" width="7" height="7"'
155 . ' alt="' . (($sort_order == 'asc') ?
$strAscending : $strDescending) . '"'
156 . ' title="' . (($sort_order == 'asc') ?
$strAscending : $strDescending) . '" />';
157 // Default order is ascending for db name, descending for sizes
158 for ($i = 0; $i < 5; $i++
) {
159 $url_sort[$i]['order'] = (($i == 0) ?
'asc' : 'desc');
160 $url_sort[$i]['img_tag'] = '';
162 if ($sort_by == 'db_name') {
163 $url_sort[0]['order'] = (($sort_order == 'asc') ?
'desc' : 'asc');
164 $url_sort[0]['img_tag'] = $img_tag;
165 $col = 'key'; // used in 'PMA_dbCmp()'
166 } else if ($sort_by == 'tbl_cnt') {
167 $url_sort[1]['order'] = (($sort_order == 'asc') ?
'desc' : 'asc');
168 $url_sort[1]['img_tag'] = $img_tag;
170 } else if ($sort_by == 'data_sz') {
171 $url_sort[2]['order'] = (($sort_order == 'asc') ?
'desc' : 'asc');
172 $url_sort[2]['img_tag'] = $img_tag;
174 } else if ($sort_by == 'idx_sz') {
175 $url_sort[3]['order'] = (($sort_order == 'asc') ?
'desc' : 'asc');
176 $url_sort[3]['img_tag'] = $img_tag;
179 $url_sort[4]['order'] = (($sort_order == 'asc') ?
'desc' : 'asc');
180 $url_sort[4]['img_tag'] = $img_tag;
184 <form action
="db_stats.php3" name
="dbStatsForm">
185 <?php
echo PMA_generate_common_hidden_inputs(); ?
>
187 <table align
="center" border
="<?php echo $cfg['Border']; ?>">
192 <a href
="<?php echo $common_url . '&sort_by=db_name&sort_order=' . $url_sort[0]['order']; ?>">
193 <?php
echo $strDatabase . $url_sort[0]['img_tag']; ?
></a
> 
;
197 <a href
="<?php echo $common_url . '&sort_by=tbl_cnt&sort_order=' . $url_sort[1]['order']; ?>">
198 <?php
echo $strNumTables . $url_sort[1]['img_tag']; ?
></a
> 
;
202 <a href
="<?php echo $common_url . '&sort_by=data_sz&sort_order=' . $url_sort[2]['order']; ?>">
203 <?php
echo $strData . $url_sort[2]['img_tag']; ?
></a
> 
;
207 <a href
="<?php echo $common_url . '&sort_by=idx_sz&sort_order=' . $url_sort[3]['order']; ?>">
208 <?php
echo $strIndexes . $url_sort[3]['img_tag']; ?
></a
> 
;
212 <a href
="<?php echo $common_url . '&sort_by=tot_sz&sort_order=' . $url_sort[4]['order']; ?>">
213 <?php
echo $strTotalUC . $url_sort[4]['img_tag']; ?
></a
> 
;
220 $total_array[0] = 0; // number of tables
221 $total_array[1] = 0; // total data size
222 $total_array[2] = 0; // total index size
223 $total_array[3] = 0; // big total size
225 // Gets the tables stats per database
226 for ($i = 0; $i < $num_dbs; $i++
) {
228 $tables = @PMA_mysql_list_tables
($db);
232 $dbs_array[$db][0] = mysql_numrows($tables);
233 mysql_free_result($tables);
235 $dbs_array[$db][0] = 0;
237 $total_array[0] +
= $dbs_array[$db][0];
239 // Size of data and indexes
240 $dbs_array[$db][1] = 0; // data size column
241 $dbs_array[$db][2] = 0; // index size column
242 $dbs_array[$db][3] = 0; // full size column
244 if (PMA_MYSQL_INT_VERSION
>= 32303) {
245 $local_query = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db);
246 $result = @PMA_mysql_query
($local_query);
247 // needs the "@" below otherwise, warnings in case of special DB names
248 if ($result && @mysql_num_rows
($result)) {
249 while ($row = PMA_mysql_fetch_array($result)) {
250 $dbs_array[$db][1] +
= $row['Data_length'];
251 $dbs_array[$db][2] +
= $row['Index_length'];
253 $dbs_array[$db][3] = $dbs_array[$db][1] +
$dbs_array[$db][2];
254 $total_array[1] +
= $dbs_array[$db][1];
255 $total_array[2] +
= $dbs_array[$db][2];
256 $total_array[3] +
= $dbs_array[$db][3];
257 mysql_free_result($result);
259 } // end if MySQL 3.23.03+
264 // Sorts the dbs arrays
265 uksort($dbs_array, 'PMA_dbCmp');
268 // Check/unchek all databases url
269 $checkall_url = 'db_stats.php3?'
270 . PMA_generate_common_url()
271 . (empty($sort_by) ?
'' : '&sort_by=' . $sort_by)
272 . (empty($sort_order) ?
'' : '&sort_order=' . $sort_order);
273 $do_check = (empty($checkall))
275 : ' checked="checked"';
277 // Displays the tables stats per database
279 while (list($db_name, $db_prop) = each($dbs_array)) {
280 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
282 list($data_size, $data_unit) = PMA_formatByteDown($dbs_array[$db_name][1], 3, 1);
283 list($idx_size, $idx_unit) = PMA_formatByteDown($dbs_array[$db_name][2], 3, 1);
284 list($tot_size, $tot_unit) = PMA_formatByteDown($dbs_array[$db_name][3], 3, 1);
287 echo ' <td align="center" bgcolor="'. $bgcolor . '">' . "\n";
288 echo ' <input type="checkbox" name="selected_db[]" value="' . urlencode($db_name) . '"' . $do_check . ' /> ' . "\n";
289 echo ' </td>' . "\n";
290 echo ' <td bgcolor="'. $bgcolor . '"> <a href="index.php3?' . PMA_generate_common_url($db_name) . '" target="_parent">' . htmlspecialchars($db_name) . '</a> </td>' . "\n";
291 echo ' <td align="right" bgcolor="'. $bgcolor . '"> ' . $dbs_array[$db_name][0] . ' </td>' . "\n";
292 echo ' <td align="right" bgcolor="'. $bgcolor . '"> ' . $data_size . '<bdo dir="' . $text_dir . '"> </bdo>' . $data_unit . ' </td>' . "\n";
293 echo ' <td align="right" bgcolor="'. $bgcolor . '"> ' . $idx_size . '<bdo dir="' . $text_dir . '"> </bdo>' . $idx_unit . ' </td>' . "\n";
294 echo ' <td align="right" bgcolor="'. $bgcolor . '"> <b>' . $tot_size . '<bdo dir="' . $text_dir . '"> </bdo>' . $tot_unit . '</b> </td>' . "\n";
295 echo ' </tr>' . "\n";
301 // Displays the server stats
302 list($data_size, $data_unit) = PMA_formatByteDown($total_array[1], 3, 1);
303 list($idx_size, $idx_unit) = PMA_formatByteDown($total_array[2], 3, 1);
304 list($tot_size, $tot_unit) = PMA_formatByteDown($total_array[3], 3, 1);
307 echo ' <th> </th>' . "\n";
308 echo ' <th> ' . $strSum . ': ' . $num_dbs . '</th>' . "\n";
309 echo ' <th align="right"> ' . $total_array[0] . ' </th>' . "\n";
310 echo ' <th align="right"> ' . $data_size . '<bdo dir="' . $text_dir . '"> </bdo>' . $data_unit . ' </th>' . "\n";
311 echo ' <th align="right"> ' . $idx_size . '<bdo dir="' . $text_dir . '"> </bdo>' . $idx_unit . ' </th>' . "\n";
312 echo ' <th align="right"> <b>' . $tot_size . '<bdo dir="' . $text_dir . '"> </bdo>' . $tot_unit . '</b> </th>' . "\n";
313 echo ' </tr>' . "\n\n";
316 echo ' <td colspan="6">' . "\n";
317 echo ' <img src="./images/arrow_' . $text_dir . '.gif" border="0" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n";
318 echo ' <a href="' . $checkall_url . '&checkall=1" onclick="setCheckboxes(\'dbStatsForm\', true); return false;">' . "\n";
319 echo ' ' . $strCheckAll . '</a>' . "\n";
320 echo ' / ' . "\n";
321 echo ' <a href="' . $checkall_url . '" onclick="setCheckboxes(\'dbStatsForm\', false); return false;">' . "\n";
322 echo ' ' . $strUncheckAll . '</a>' . "\n";
323 echo ' ' . "\n";
324 echo ' <i>' . $strWithChecked . '</i> <input type="submit" name="submit_mult" value="' . $strDrop . '" />' . "\n";
325 echo ' </td>' . "\n";
326 echo ' </tr>' . "\n";
328 echo ' </table>' . "\n\n";
330 echo '</form>' . "\n";
333 } // end if ($num_dbs > 0)
341 <p align
="center"><big
> 
; 
;<?php
echo $strNoDatabases; ?
></big
></p
>
343 } // end if ($num_dbs == 0)
348 * Displays the footer
350 require('./footer.inc.php3');