Gazelle/sections/tools/data/database_specifics.php

143 lines
4.9 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
2013-05-02 08:00:23 +00:00
if (!check_perms('site_debug')) {
error(403);
}
2011-03-28 14:21:28 +00:00
//View schemas
if (!empty($_GET['table'])) {
$DB->query('SHOW TABLES');
$Tables =$DB->collect('Tables_in_'.SQLDB);
if (!in_array($_GET['table'], $Tables)) {
error(0);
}
$DB->query('SHOW CREATE TABLE '.db_string($_GET['table']));
list(,$Schema) = $DB->next_record(MYSQLI_NUM, false);
header('Content-type: text/plain');
die($Schema);
}
//Cache the tables for 4 hours, makes sorting faster
if (!$Tables = $Cache->get_value('database_table_stats')) {
$DB->query('SHOW TABLE STATUS');
$Tables =$DB->to_array();
2013-05-02 08:00:23 +00:00
$Cache->cache_value('database_table_stats', $Tables, 3600 * 4);
2011-03-28 14:21:28 +00:00
}
2013-05-27 08:00:58 +00:00
require(SERVER_ROOT.'/classes/charts.class.php');
2011-03-28 14:21:28 +00:00
$Pie = new PIE_CHART(750,400,array('Other'=>1,'Percentage'=>1,'Sort'=>1));
//Begin sorting
$Sort = array();
2013-05-02 08:00:23 +00:00
switch (empty($_GET['order_by']) ? '' : $_GET['order_by']) {
2011-03-28 14:21:28 +00:00
case 'name':
foreach ($Tables as $Key => $Value) {
$Pie->add($Value[0], $Value[6] + $Value[8]);
$Sort[$Key] = $Value[0];
}
break;
case 'engine':
foreach ($Tables as $Key => $Value) {
$Pie->add($Value[0], $Value[6] + $Value[8]);
$Sort[$Key] = $Value[1];
}
break;
case 'rows':
foreach ($Tables as $Key => $Value) {
$Pie->add($Value[0], $Value[4]);
$Sort[$Key] = $Value[4];
}
break;
case 'rowsize':
foreach ($Tables as $Key => $Value) {
$Pie->add($Value[0], $Value[5]);
$Sort[$Key] = $Value[5];
}
break;
case 'datasize':
foreach ($Tables as $Key => $Value) {
$Pie->add($Value[0], $Value[6]);
$Sort[$Key] = $Value[6];
}
break;
case 'indexsize':
foreach ($Tables as $Key => $Value) {
$Pie->add($Value[0], $Value[8]);
$Sort[$Key] = $Value[8];
}
break;
case 'totalsize':
default:
foreach ($Tables as $Key => $Value) {
$Pie->add($Value[0], $Value[6] + $Value[8]);
$Sort[$Key] = $Value[6] + $Value[8];
}
}
$Pie->generate();
if (!empty ($_GET['order_way']) && $_GET['order_way'] == 'asc') {
$SortWay = SORT_ASC;
} else {
$SortWay = SORT_DESC;
}
array_multisort($Sort, $SortWay, $Tables);
//End sorting
2012-10-11 08:00:15 +00:00
View::show_header('Database Specifics');
2011-03-28 14:21:28 +00:00
?>
<h3>Breakdown</h3>
<div class="box pad center">
<img src="<?=$Pie->url()?>" />
</div>
<br />
<table>
<tr class="colhead">
2013-05-02 08:00:23 +00:00
<td><a href="tools.php?action=database_specifics&amp;order_by=name&amp;order_way=<?=(!empty($_GET['order_by']) && $_GET['order_by'] == 'name' && !empty($_GET['order_way']) && $_GET['order_way'] == 'desc') ? 'asc' : 'desc'?>">Name</a></td>
<td><a href="tools.php?action=database_specifics&amp;order_by=engine&amp;order_way=<?=(!empty($_GET['order_by']) && $_GET['order_by'] == 'engine' && !empty($_GET['order_way']) && $_GET['order_way'] == 'desc') ? 'asc' : 'desc'?>">Engine</a></td>
<td><a href="tools.php?action=database_specifics&amp;order_by=rows&amp;order_way=<?=(!empty($_GET['order_by']) && $_GET['order_by'] == 'rows' && !empty($_GET['order_way']) && $_GET['order_way'] == 'desc') ? 'asc' : 'desc'?>">Rows</td>
<td><a href="tools.php?action=database_specifics&amp;order_by=rowsize&amp;order_way=<?=(!empty($_GET['order_by']) && $_GET['order_by'] == 'rowsize' && !empty($_GET['order_way']) && $_GET['order_way'] == 'desc') ? 'asc' : 'desc'?>">Row Size</a></td>
<td><a href="tools.php?action=database_specifics&amp;order_by=datasize&amp;order_way=<?=(!empty($_GET['order_by']) && $_GET['order_by'] == 'datasize' && !empty($_GET['order_way']) && $_GET['order_way'] == 'desc') ? 'asc' : 'desc'?>">Data Size</a></td>
<td><a href="tools.php?action=database_specifics&amp;order_by=indexsize&amp;order_way=<?=(!empty($_GET['order_by']) && $_GET['order_by'] == 'indexsize' && !empty($_GET['order_way']) && $_GET['order_way'] == 'desc') ? 'asc' : 'desc'?>">Index Size</a></td>
<td><a href="tools.php?action=database_specifics&amp;order_by=totalsize&amp;order_way=<?=(!empty($_GET['order_by']) && $_GET['order_by'] == 'totalsize' && !empty($_GET['order_way']) && $_GET['order_way'] == 'desc') ? 'asc' : 'desc'?>">Total Size</td>
2011-03-28 14:21:28 +00:00
<td>Tools</td>
</tr>
<?
$TotalRows = 0;
$TotalDataSize = 0;
$TotalIndexSize = 0;
$Row = 'a';
foreach ($Tables as $Table) {
list($Name,$Engine,,,$Rows,$RowSize,$DataSize,,$IndexSize) = $Table;
$Row = ($Row == 'a') ? 'b' : 'a';
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$TotalRows += $Rows;
$TotalDataSize += $DataSize;
$TotalIndexSize += $IndexSize;
?>
<tr class="row<?=$Row?>">
<td><?=display_str($Name)?></td>
<td><?=display_str($Engine)?></td>
<td><?=number_format($Rows)?></td>
2012-10-11 08:00:15 +00:00
<td><?=Format::get_size($RowSize)?></td>
<td><?=Format::get_size($DataSize)?></td>
<td><?=Format::get_size($IndexSize)?></td>
<td><?=Format::get_size($DataSize + $IndexSize)?></td>
2013-02-09 08:01:01 +00:00
<td><a href="tools.php?action=database_specifics&amp;table=<?=display_str($Name)?>" class="brackets">Schema</a></td>
2011-03-28 14:21:28 +00:00
</tr>
<?
}
?>
<tr>
<td></td>
<td></td>
<td><?=number_format($TotalRows)?></td>
<td></td>
2012-10-11 08:00:15 +00:00
<td><?=Format::get_size($TotalDataSize)?></td>
<td><?=Format::get_size($TotalIndexSize)?></td>
<td><?=Format::get_size($TotalDataSize + $TotalIndexSize)?></td>
2011-03-28 14:21:28 +00:00
<td></td>
</tr>
</table>
<?
2012-10-11 08:00:15 +00:00
View::show_footer();