From 0e7f140c2cebeac6b1640d8f2fe4b197b3002906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Chapeaux?= Date: Sat, 1 Sep 2001 14:25:53 +0000 Subject: [PATCH] Cleaned and improved the code of the db_stats.php3 script --- ChangeLog | 6 +- db_stats.php3 | 389 ++++++++++++++++++++++++++---------------------- header.inc.php3 | 1 + 3 files changed, 218 insertions(+), 178 deletions(-) diff --git a/ChangeLog b/ChangeLog index ecfbf575a..bc6320742 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,9 +5,13 @@ phpMyAdmin - Changelog $Id$ $Source$ +2001-09-01 Loïc Chapeaux + * db_stat.php3: cleaned and improved the code. + * header.php3: cosmetic change. + 2001-08-31 Marc Delisle * lang/norwegian.inc.php3 other updates, thanks to Sven-Erik Andersen. - * Documentation.html updates + * Documentation.html updates. 2001-08-31 Loïc Chapeaux * lib.inc.php3: diff --git a/db_stats.php3 b/db_stats.php3 index 00b881da4..431fdac60 100644 --- a/db_stats.php3 +++ b/db_stats.php3 @@ -6,14 +6,48 @@ * been defined as startup option and include a core library */ require('./grab_globals.inc.php3'); -if (!empty($db)) { - $db_start = $db; -} -// loic1: lib.inc.php3 will be loaded by header.inc.php3 -//require('./lib.inc.php3'); require('./header.inc.php3'); +/** + * Sorts the databases array according to the user's choice + * + * @param array a record associated to a database + * @param array a record associated to a database + * + * @return integer a value representing whether $a should be before $b in the + * sorted array or not + * + * @global mixed the array to sort + * @global mixed 'key' if the table has to be sorted by key, the column + * number to use to sort the array else + * + * @access private + */ +function pmaDbCmp($a, $b) +{ + global $dbs_array; + global $col; + + $is_asc = ($GLOBALS['sort_order'] == 'asc'); + + // Sort by key (the db names) if required + if (!is_int($col) && $col == 'key') { + return (($is_asc) ? strcasecmp($a, $b) : -strcasecmp($a, $b)); + } + // Sort by key (the db names) in ascending order if the columns' values are + // the same + else if ($dbs_array[$a][$col] == $dbs_array[$b][$col]) { + return strcasecmp($a, $b); + } + // Other cases + else { + $tmp = (($dbs_array[$a][$col] < $dbs_array[$b][$col]) ? -1 : 1); + return (($is_asc) ? $tmp : -$tmp); + } +} // end of the 'pmaDbCmp()' function + + /** * Get the list and number of available databases. * Skipped if no server selected: in this case no database should be displayed @@ -54,185 +88,186 @@ if ($server > 0) { /** - * Send http headers + * Displays the page */ -// Don't use cache (required for Opera) -$now = gmdate('D, d M Y H:i:s') . ' GMT'; -header('Expires: ' . $now); -header('Last-Modified: ' . $now); -header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1 -header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 -header('Pragma: no-cache'); // HTTP/1.0 -// Define the charset to be used -header('Content-Type: text/html; charset=' . $charset); +?> +

+ +

+ + + + + + + + + +
+

+ + + do the work + */ +if ($num_dbs > 0) { + // Defines the urls used to sort the table + $common_url = 'db_stats.php3?lang=' . $lang . '&server=' . $server; + if (empty($sort_order)) { + $sort_order = ((empty($sort_by) || $sort_by == 'db_name') ? 'asc' : 'desc'); + } + $img_tag = ' ' . "\n" + . ' ' + . '' . $sort_order . ''; + // Default order is ascending for db name, descending for sizes + for ($i = 0; $i < 5; $i++) { + $url_sort[$i]['order'] = (($i == 0) ? 'asc' : 'desc'); + $url_sort[$i]['img_tag'] = ''; + } + if (empty($sort_by) || $sort_by == 'db_name') { + $url_sort[0]['order'] = (($sort_order == 'asc') ? 'desc' : 'asc'); + $url_sort[0]['img_tag'] = $img_tag; + $col = 'key'; // used in 'pmaDbCmp()' + } else if ($sort_by == 'tbl_cnt') { + $url_sort[1]['order'] = (($sort_order == 'asc') ? 'desc' : 'asc'); + $url_sort[1]['img_tag'] = $img_tag; + $col = 0; + } else if ($sort_by == 'data_sz') { + $url_sort[2]['order'] = (($sort_order == 'asc') ? 'desc' : 'asc'); + $url_sort[2]['img_tag'] = $img_tag; + $col = 1; + } else if ($sort_by == 'idx_sz') { + $url_sort[3]['order'] = (($sort_order == 'asc') ? 'desc' : 'asc'); + $url_sort[3]['img_tag'] = $img_tag; + $col = 2; + } else { + $url_sort[4]['order'] = (($sort_order == 'asc') ? 'desc' : 'asc'); + $url_sort[4]['img_tag'] = $img_tag; + $col = 3; + } + ?> + + + + + + + + + + ' . "\n"; + echo ' ' . "\n"; + echo ' ' . "\n"; + echo ' ' . "\n"; + echo ' ' . "\n"; + echo ' ' . "\n"; + echo ' ' . "\n"; + echo '' . "\n"; + + $i++; + } // end while + unset($dbs_array); + + // Displays the server stats + list($data_size, $data_unit) = format_byte_down($total_array[1], 3, 1); + list($idx_size, $idx_unit) = format_byte_down($total_array[2], 3, 1); + list($tot_size, $tot_unit) = format_byte_down($total_array[3], 3, 1); + + echo '' . "\n"; + echo ' ' . "\n"; + echo ' ' . "\n"; + echo ' ' . "\n"; + echo ' ' . "\n"; + echo ' ' . "\n"; + echo ' ' . "\n"; + echo '' . "\n"; + echo '
  +   + +   + +   + +   + +   + +   + +   + +   + +   + +   +
 ' . ($i + 1) . '  ' . htmlentities($db_name) . '  ' . $dbs_array[$db_name][0] . '  ' . $data_size . ' ' . $data_unit . '  ' . $idx_size . ' ' . $idx_unit . '  ' . $tot_size . ' ' . $tot_unit . ' 
  ' . $strSum . ': ' . $num_dbs . ' ' . $total_array[0] . '  ' . $data_size . ' ' . $data_unit . '  ' . $idx_size . ' ' . $idx_unit . '  ' . $tot_size . ' ' . $tot_unit . ' 
' . "\n"; + + unset($total_array); +} // end if ($num_dbs > 0) /** - * Displays the frame + * No database case */ -?> - - - - - phpMyAdmin - - - - - -

- - - -

-

- - - - - - - - - - - -
- - - - - - - - - - - - - 1) { - $selected_db = 0; - $tot_tables = 0; - $big_tot_all = 0; - $big_tot_idx = 0; - $big_tot_data = 0; - $results_array = array(); - - // Gets and displays the tables stats per database - for ($i = 0; $i < $num_dbs; $i++) { - $db = $dblist[$i]; - $j = $i + 2; - $bgcolor = ($i % 2) ? $cfgBgcolorOne : $cfgBgcolorTwo; - - if (!empty($db_start) && $db == $db_start) { - $selected_db = $j; - } - $tables = @mysql_list_tables($db); - $num_tables = @mysql_numrows($tables); - $tot_tables += $num_tables; - $common_url_query = 'lang=' . $lang - . '&server=' . $server - . '&db=' . urlencode($db); - - // Gets size of data and indexes - - $db_clean = backquote($db); - $tot_data = 0; - $tot_idx = 0; - $tot_all = 0; - $local_query = 'SHOW TABLE STATUS FROM ' . $db_clean; - $result = @mysql_query($local_query); - if (@mysql_num_rows($result)) { - // needs the "@": otherwise, warnings in case of special DB names: - // Warning: Supplied argument is not a valid MySQL result resource in db_stats.php3 on line 140 - while ($row = mysql_fetch_array($result)) { - $tot_data += $row['Data_length']; - $tot_idx += $row['Index_length']; - } - $tot_all = $tot_data + $tot_idx; - $big_tot_all += $tot_all; - $big_tot_idx += $tot_idx; - $big_tot_data += $tot_data; - $results_array[$db] = $tot_all; - } - - list($tot_data_format,$unit_data) = format_byte_down($tot_data,3,1); - list($tot_idx_format,$unit_idx) = format_byte_down($tot_idx,3,1); - list($tot_all_format,$unit_all) = format_byte_down($tot_all,3,1); - - echo ' ' . "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - } // end for - - // Gets and displays the server stats - list($tot_data_format,$unit_data) = format_byte_down($big_tot_data,3,1); - list($tot_idx_format,$unit_idx) = format_byte_down($big_tot_idx,3,1); - list($tot_all_format,$unit_all) = format_byte_down($big_tot_all,3,1); - - echo ' ' . "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - - echo '
   - ASC        
 ' . htmlentities($db) . '  ' . $num_tables . '  ' . $tot_data_format . ' ' . $unit_data . '  ' . $tot_idx_format . ' ' . $unit_idx . '  ' . $tot_all_format . ' ' . $unit_all . ' 
 ' . $strSum . ': ' . $num_dbs . ' ' . $tot_tables . '  ' . $tot_data_format . ' ' . $unit_data . '  ' . $tot_idx_format . ' ' . $unit_idx . '  ' . $tot_all_format . ' ' . $unit_all . ' 
' . "\n"; - - // Displays 20 biggest db's - ?> -
      - - - - - - - ' . "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - } - ?> -
       - ASC 
 ' . $j . '  ' . urlencode($key) . '  ' . $disp_val . ' ' . $unit . ' 
-
- - - - - - - -

  

+

  

+