summaryrefslogtreecommitdiffstats
path: root/old/admin/mysql_info.php
blob: 7993cc0740eb83d9b95ecf9923e5d2b9d34889a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/******************************
 * EQdkp
 * Copyright 2002-2003
 * Licensed under the GNU GPL.  See COPYING for full terms.
 * ------------------
 * mysql_info.php
 * Began: Sat April 5 2003
 * 
 * $Id: mysql_info.php 46 2007-06-19 07:29:11Z tsigo $
 * 
 ******************************/

define('EQDKP_INC', true);
define('IN_ADMIN', true);
$eqdkp_root_path = './../';
include_once($eqdkp_root_path . 'common.php');

class MySQL_Info extends EQdkp_Admin
{
    var $mysql_version = '';
    var $table_size    = 0;
    var $index_size    = 0;
    var $num_tables    = 0;
    
    function mysql_info()
    {
        global $db, $eqdkp, $user, $tpl, $pm;
        global $SID;
        
        parent::eqdkp_admin();
        
        $this->assoc_buttons(array(
            'form' => array(
                'name'    => '',
                'process' => 'display_form',
                'check'   => 'a_'))
        );
        
        $result = $db->query('SELECT VERSION() AS mysql_version');
        if ( $row = $db->fetch_record($result) )
        {
            $this->mysql_version = $row['mysql_version'];
        }
    }
    
    // ---------------------------------------------------------
    // Display form
    // ---------------------------------------------------------
    function display_form()
    {
        global $db, $eqdkp, $user, $tpl, $pm;
        global $SID, $dbname, $table_prefix;
            
        if ( preg_match('/^(3\.23|4\.)/', $this->mysql_version) )
        {
            $db_name = ( preg_match('/^(3\.23\.[6-9])|(3\.23\.[1-9][1-9])|(4\.)/', $this->mysql_version) ) ? "`$dbname`" : $dbname;
            
            // Get table status
            $sql = 'SHOW TABLE STATUS
                    FROM ' . $db_name;
            $result = $db->query($sql);
                
            $dbsize = 0;
            while ( $row = $db->fetch_record($result) )
            {
                if ( $row['Type'] != 'MRG_MyISAM' )
                {
                    if ( $table_prefix != '' )
                    {
                        // Current row is an EQdkp table, get info for it
                        if ( strstr($row['Name'], $table_prefix) )
                        {
                            $tpl->assign_block_vars('table_row', array(
                                'ROW_CLASS'  => $eqdkp->switch_row_class(),
                                'TABLE_NAME' => $row['Name'],
                                'ROWS'       => number_format($row['Rows'], ','),
                                'TABLE_SIZE' => $this->db_size($row['Data_length']),
                                'INDEX_SIZE' => $this->db_size($row['Index_length']))
                            );
                            
                            $this->num_tables++;
                            $this->table_size += $row['Data_length'];
                            $this->index_size += $row['Index_length'];
                        } // name match
                    } // table_prefix != ''
                } // type != MRG_MyISAM
            } // while
            
            $tpl->assign_vars(array(
                'NUM_TABLES'       => sprintf($user->lang['num_tables'], $this->num_tables),
                'TOTAL_TABLE_SIZE' => $this->db_size($this->table_size),
                'TOTAL_INDEX_SIZE' => $this->db_size($this->index_size),
                'TOTAL_SIZE'       => $this->db_size($this->table_size + $this->index_size),
                
                'L_EQDKP_TABLES' => $user->lang['eqdkp_tables'],
                'L_TABLE_NAME'   => $user->lang['table_name'],
                'L_ROWS'         => $user->lang['rows'],
                'L_TABLE_SIZE'   => $user->lang['table_size'],
                'L_INDEX_SIZE'   => $user->lang['index_size'],
                'L_TOTALS'       => $user->lang['totals'])
            );
            
            $eqdkp->set_vars(array(
                'page_title'    => 'MySQL Info',
                'template_file' => 'admin/mysql_info.html',
                'display'       => true)
            );
        } // version match
    }
    
    function db_size($size)
    {
        if ( $size >= 1048576 )
        {
            return sprintf('%.2f MB', ($size / 1048576));
        }
        elseif ( $size >= 1024 )
        {
            return sprintf('%.2f KB', ($size / 1024));
        }
        else
        {
            return sprintf('%.2f B', $size);
        }
    }
}

$info = new MySQL_Info;
$info->process();
?>