<?php

$accessControl = array("Admin" => true);
require_once '../../AccessControl.php';

function GetDBSize() {
	global $db, $DatabaseName;
	$now = date("d M Y H:i:s", time());
	$query = "SELECT table_schema, SUM( data_length + index_length) / 1024 / 1024  as size FROM information_schema.TABLES where table_schema='$DatabaseName' and ENGINE='MyISAM '";
	$res = $db->Execute($query);
	$data = $res->FetchRow();
	$result = '{ "Status": "Success", "data": "'.round($data[1]).' MB ('. _LAST_UPDATED .' '.$now.')"}';
	setGlobalSetting("DatabaseInfoSize",$result);
	return $result;
}


if (isset($_REQUEST['estimatedbsize'])) {
	echo GetDBSize();
}

if (isset($_REQUEST['getdbsize'])) {
	$res = getGlobalSetting("DatabaseInfoSize",false);
	if ($res == false) {
		echo '{ "Status": "Success", "data": "'. _NO_ESTIMATE_AVAILABLE .'"}';
	} else {
		echo $res;
	}
}

if (isset($_REQUEST["globalstats"])=="yes") { 
    
    include "../../includes/globalstats.php";
    $g = new Globalstats();
    $g->json=true;
    $g->version=6;
    $data["data"] = $g->GetData();
    echo json_encode($data);
    exit();
}

?>