<?php
// $Header: /cvsroot/phptsmadmin/phpTSMadmin/htdocs/image.dbbackuphistory.php,v 1.7 2009/04/19 03:54:40 wurley Exp $

# Required Libraries
require './common.php';
initJPGraph(true);

$history = $app['server']->GetDBBackupDetail('history');
if (! $history)
	exit;

$graph = new Graph(400,200,'auto');
$graph->SetScale('textlin');

$fulldata = array();
$incrdata = array();
$xtitles = array();

foreach ($app['server']->GetDBBackupDetail('history') as $index => $backupdetails) {
	switch ($backupdetails['type']) {
		case 'FULL' :
			$fulldata[] = $backupdetails['size'];
			$incrdata[] = 0;
			break;

		case 'INCR' :
			$fulldata[] = 0;
			$incrdata[] = $backupdetails['size'];
			break;
	}
	$xtitles[] = preg_replace('/ /',"\n",tsmDate($backupdetails['date'],'daytime'));
	$maxdata[] = $app['server']->GetDBDetail('USABLE_PAGES');
	$curdata[] = $app['server']->GetDBDetail('USED_PAGES');
}

$cplot = new LinePlot($maxdata);
$cplot->SetLegend('Max DB Size');
$cplot->SetColor('red');
$cplot->SetWeight(2);
if (count($maxdata) == 1)
	$cplot->mark->SetType(MARK_IMG_MBALL,'red',0.5);
$graph->Add($cplot);

$dplot = new LinePlot($curdata);
$dplot->SetLegend('Cur Size');
$dplot->SetColor('lightred');
$dplot->SetWeight(2);
$graph->Add($dplot);

$aplot = new BarPlot($fulldata);
$aplot->SetLegend('Full');
$aplot->SetFillColor('blue');
$aplot->value->Show();
$aplot->value->SetFormat('%5.0f');
$graph->Add($aplot);

$bplot = new BarPlot($incrdata);
$bplot->SetLegend('Incremental');
$bplot->SetFillColor('lightblue');
$bplot->value->Show();
$bplot->value->SetFormat('%5.0f');
$graph->Add($bplot);

$graph->img->SetMargin(60,110,20,40);
$graph->legend->Pos(0.01,0.80,'right','center');
$graph->legend->SetFillColor('azure');
$graph->xaxis->SetTickLabels($xtitles);
$graph->xaxis->SetLabelAngle(90);
$graph->xgrid->Show(true);
$graph->yaxis->title->Set('Database Pages \'000s'); 
$graph->yaxis->SetLabelFormatCallback('labelformat');
$graph->yaxis->SetTitleMargin(45);
$graph->SetMarginColor('azure2');
$graph->title->Set(sprintf('Database Backups %s',$app['server']->GetStatusDetail('SERVER_NAME')));

# Display the Gantt chart
$graph->Stroke();

function labelformat($label) {
    return number_format($label/1000);
}

?>
