<?php
/*
 * This file is part of the easy-CMS project.
 * easy-CMS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * easy-CMS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with easy-CMS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

// define the path context
chdir('..');
define('EASY_GUI_APP_DIR', '../');


include_once('config.inc.php');
include_once('classes/core/Site.class.php');

include_once('classes/system/DiskUsage.class.php');

include_once('interface/egScript.class.php');
include_once('interface/egManager.class.php');
include_once('interface/egContainer.class.php');
include_once('interface/egMenuItem.class.php');
include_once('interface/egFrame.class.php');
include_once('interface/egToolTip.class.php');
include_once('interface/egRichText.class.php');
include_once('interface/egLink.class.php');
include_once('interface/egStatic.class.php');
include_once('interface/egEdit.class.php');
include_once('interface/egCheckBox.class.php');
include_once('interface/egRadioButton.class.php');
include_once('interface/egPressButton.class.php');
include_once('interface/egDropDownListBox.class.php');
include_once('interface/egPropertyList.class.php');
include_once('interface/egPropertySheet.class.php');
include_once('interface/egPropertyPage.class.php');
include_once('interface/egTreeNode.class.php');
include_once('interface/egTreeList.class.php');
include_once('interface/egSubWindow.class.php');

$site = &Site::getInstance();

//security check : user must be identified to browse repositories
$user = $site->getCurrentUser();
if(!$user || $user->getUserId() == USER_ID_ANONYMOUS) {
	die("access denied");
	exit();
}

$langId = $site->getCurrentLangId();

$diskUsage = &new DiskUsage('Repositories');


$manager = &egManager::getInstance();
$main = &new egContainer("main_ctn", 0, 0, 0, 0);

$vpos = 1;

$dbManipulator = &$site->getDBManipulator();
$query = "select * from ".INFOS_TABLE.";";
$result = $dbManipulator->sendQuery($query);

if($row = $dbManipulator->fetchArray($result)){
	$version = $row['version'];
	$released = $row['released'];
	$installed = $row['installed'];
	$codename = $row['codename'];

  $versionStatic = &new egStatic("version_static", "easy-CMS $version ($codename)", 10, $vpos, 250, 0);
  $releaseStatic = &new egStatic("release_static", "released on $released", 10, $vpos+15, 150, 0);
  $installedStatic = &new egStatic("installed_static", "installed on $installed", 10, $vpos+30, 150, 0);
  $main->addObject($versionStatic);
  $main->addObject($releaseStatic);
  $main->addObject($installedStatic);
}


$query = "show table status;";
$result = $dbManipulator->sendQuery($query);
$size = 0;
while($row = mysql_fetch_array($result)) {
	$size += $row["Data_length"];
}
$db_usage = round(($size/1024)/1024, 2);

$repo_usage = $diskUsage->getUsage(1024*1024);

$total_use = $db_usage + $repo_usage;

$vpos = 70;


$totalUsageStatic = &new egStatic("total_usage_static", LANG_DISK_MANAGER_DISK_USE.LANG_COLON, 10, $vpos, 150, 0, true);
$totalUsageValue  = &new egStatic("total_usage_value", $total_use." Mo", 160, $vpos, 350, 0, false);
$vpos += 40;

$totalRepoStatic = &new egStatic("total_repo_static", LANG_DISK_MANAGER_FILES." & ".LANG_DISK_MANAGER_DIRECTORIES.LANG_COLON, 10, $vpos, 150, 0, true);
$totalRepoValue  = &new egStatic("total_repo_value", $repo_usage." Mo", 160, $vpos, 350, 0, false);
$vpos += 20;

$totalFilesStatic = &new egStatic("total_files_static", LANG_DISK_MANAGER_FILES.LANG_COLON, 10, $vpos, 150, 0, false);
$totalFilesValue  = &new egStatic("total_files_value", $diskUsage->getFilesCount(), 160, $vpos, 350, 0, false);
$vpos += 20;

$totalDirectoriesStatic = &new egStatic("total_directories_static", LANG_DISK_MANAGER_DIRECTORIES.LANG_COLON, 10, $vpos, 150, 0, false);
$totalDirectoriesValue  = &new egStatic("total_directories_value", $diskUsage->getDirectoriesCount(), 160, $vpos, 350, 0, false);
$vpos += 20;

$vpos += 20;

$totalDBStatic = &new egStatic("total_db_static", LANG_DISK_MANAGER_DATABASE.LANG_COLON, 10, $vpos, 150, 0, true);
$totalDBValue  = &new egStatic("total_db_value", $db_usage." Mo", 160, $vpos, 350, 0, false);
$vpos += 20;

$main->addObject($totalUsageStatic);
$main->addObject($totalUsageValue);

$main->addObject($totalRepoStatic);
$main->addObject($totalRepoValue);

$main->addObject($totalFilesStatic);
$main->addObject($totalFilesValue);
$main->addObject($totalDirectoriesStatic);
$main->addObject($totalDirectoriesValue);

$main->addObject($totalDBStatic);
$main->addObject($totalDBValue);



$manager->addContainer($main);

echo $manager->getHTML();

?>