<?php
// $Header: /cvsroot/phptsmadmin/phpTSMadmin/htdocs/server.db.php,v 1.12 2009/04/19 04:00:59 wurley Exp $

# This page should return all information about tde TSM database.

# Required Libraries
require './common.php';

# Database Summary Information
$blockTitle['db'] = sprintf(_('Database Information for %s (%s) %s.%s.%s.%s'),
	$app['server']->GetStatusDetail('SERVER_NAME'),
	$app['server']->GetStatusDetail('PLATFORM'),
	$app['server']->GetStatusDetail('VERSION'),
	$app['server']->GetStatusDetail('RELEASE'),
	$app['server']->GetStatusDetail('LEVEL'),
	$app['server']->GetStatusDetail('SUBLEVEL'));

$blockBody['db'] = '<table class="blockcitem">';

$blockBody['db'] .= sprintf('<tr><td colspan=2 class="titlel">%s</td></tr>',_('Database Summary'));
$blockBody['db'] .= '<tr><td><table class="result" border=0>';

$blockBody['db'] .= sprintf('<tr><td colspan=2>'.classValue(_('%s DB volumes totaling %sMB (%s%% utilsed).'),'value').'</td></tr>',
	$app['server']->GetDBDetail('PHYSICAL_VOLUMES'),$app['server']->GetDBDetail('AVAIL_SPACE_MB'),
	$app['server']->GetDBDetail('PCT_UTILIZED'));

foreach ($app['server']->GetDBDetail('dbvols') as $key) {
	$blockBody['db'] .= sprintf('<tr><td>&nbsp;</td><td>'.classValue(_('%s (%sMB) (%sMB Free) (%s).'),'value').'</td></tr>',
		$key['COPY1_NAME'],$key['AVAIL_SPACE_MB'],$key['FREE_SPACE_MB'],$key['COPY1_STATUS']);

	if ($key['COPY2_NAME'])
		$blockBody['db'] .= sprintf('<tr><td>&nbsp;</td><td>'.classValue(_('%s (%s).'),'value').'</td></tr>',
			$key['COPY2_NAME'],$key['COPY2_STATUS']);

	if ($key['COPY3_NAME'])
		$blockBody['db'] .= sprintf('<tr><td>&nbsp;</td><td>'.classValue(_('%s (%s).'),'value').'</td></tr>',
			$key['COPY3_NAME'],$key['COPY3_STATUS']);
}

$blockBody['db'] .= '<tr><td colspan=2>&nbsp;</td></tr>';

$blockBody['db'] .= sprintf('<tr><td colspan=2>'.classValue(_('%s LOG volumes totaling %sMB (%s%% utilsed).'),'value').'</td></tr>',
	$app['server']->GetLogDetail('PHYSICAL_VOLUMES'),$app['server']->GetLogDetail('AVAIL_SPACE_MB'),
	$app['server']->GetLogDetail('PCT_UTILIZED'));

foreach ($app['server']->GetLogDetail('logvols') as $key) {
	$blockBody['db'] .= sprintf('<tr><td>&nbsp;</td><td>'.classValue(_('%s (%sMB) (%sMB Free) (%s).'),'value').'</td></tr>',
		$key['COPY1_NAME'],$key['AVAIL_SPACE_MB'],$key['FREE_SPACE_MB'],$key['COPY1_STATUS']);

	if ($key['COPY2_NAME'])
		$blockBody['db'] .= sprintf('<tr><td>&nbsp;</td><td>'.classValue(_('%s (%s).'),'value').'</td></tr>',
			$key['COPY2_NAME'],$key['COPY2_STATUS']);

	if ($key['COPY3_NAME'])
		$blockBody['db'] .= sprintf('<tr><td>&nbsp;</td><td>'.classValue(_('%s (%s).'),'value').'</td></tr>',
			$key['COPY3_NAME'],$key['COPY3_STATUS']);
}
$blockBody['db'] .= '<tr><td colspan=2>&nbsp;</td></tr>';

$blockBody['db'] .= sprintf('<tr><td colspan=2>'.classValue(_('Database REDO log mode %s.'),'value').'</td></tr>',
	$app['server']->GetStatusDetail('LOGMODE'));
$blockBody['db'] .= '<tr><td colspan=2>&nbsp;</td></tr>';


$blockBody['db'] .= sprintf('<tr><td colspan=2>'.classValue(_('%s%% database cache hit rate (%s%% cache wait).'),'value').'</td></tr>',
	$app['server']->GetDBDetail('CACHE_HIT_PCT'),$app['server']->GetDBDetail('CACHE_WAIT_PCT'));

if ($trigger = $app['server']->GetDBBackupDetail('trigger')) {
	$blockBody['db'] .= '<tr><td colspan=2>&nbsp;</td></tr>';

	$blockBody['db'] .= sprintf('<tr><td colspan=2>'.classValue(_('TSM will automatically backup the database to %s when the logs reach %s%% full.'),'value').'</td></tr>',
		sprintf('<a href="cmd.php?cmd=devclass.info&index=%s&devclass=%s">%s</a>',$app['server']->getIndex(),$trigger['INCRDEVCLASS'],$trigger['INCRDEVCLASS']),
		$trigger['LOGFULLPCT']);
	$blockBody['db'] .= sprintf('<tr><td colspan=2>'.classValue(_('After %s INCREMENTAL backups, a full backup will be performed to %s.'),'value').'</td></tr>',
		$trigger['NUMICREMENTAL'],
		sprintf('<a href="cmd.php?cmd=devclass.info&index=%s&devclass=%s">%s</a>',$app['server']->getIndex(),$trigger['DEVCLASS'],$trigger['DEVCLASS']));
}

$blockBody['db'] .= '</table></td>';

# Show our dbbackup graph
$blockBody['db'] .= sprintf('<td align="right"><img src="image.dbbackuphistory.php?index=%s" /></td></tr>',
	$app['server']->getIndex());
$blockBody['db'] .= '</table>';

# Database Backup Information
$blockTitle['backup'] = sprintf(_('Database backup information for %s'),$app['server']->getValue('server','name'));
$blockBody['backup'] = '<table class="result">';

if ($app['server']->GetDBDetail('LAST_BACKUP_DATE')) {
	$blockBody['backup'] .= sprintf('<tr><td colspan=6>'.classValue(_('%sMB (%s%%) has changed since the last backup on %s'),'value').'</td></tr>',
		$app['server']->GetDBDetail('BACKUP_CHG_MB'),$app['server']->GetDBDetail('BACKUP_CHG_PCT'),
		tsmDate($app['server']->GetDBDetail('LAST_BACKUP_DATE')));

	$blockBody['backup'] .= '<tr><td colspan=6>&nbsp;</td></tr>';

	## Show DB Vols
	$blockBody['backup'] .= sprintf('<tr><td colspan=6>'.classValue(_('%s backups between %s and %s available for TSM DB restore.'),'value').'</td></tr>',
		tsmDate($app['server']->GetDBBackupDetail('count'),'nosec'),
		tsmDate($app['server']->GetDBBackupDetail('first'),'nosec'),
		tsmDate($app['server']->GetDBBackupDetail('last'),'nosec'));

	$blockBody['backup'] .= sprintf('<tr><td class="titlel">&nbsp;</td><td class="titlel">%s</td><td class="titlel">%s</td><td class="titlel">%s</td><td class="titlel">%s</td><td class="titlel">%s</td><td class="titlel">%s</td><td class="titlel">%s</td></tr>',
		'SEQ #','DATE','TYPE','DEVICE','VOLUME','LOCATION','STATUS');

	$counter = 0;
	$lastseries = 0;
	foreach ($app['server']->GetDBBackupDetail('vols') as $volname => $voldetails) {
		if (! is_array($voldetails))
			continue;

		if ($lastseries != $voldetails['BACKUP_SERIES']) {
			$lastseries = $voldetails['BACKUP_SERIES'];
			$counter ++;
		}

		$blockBody['backup'] .= sprintf('<tr %s><td>&nbsp;</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
			($voldetails['STATUS'] == 'InValid' ? 'class="shadow"' : ($counter%2==0?'class="even"':'class="odd"')),
			sprintf('%s-%s-%s',$voldetails['BACKUP_SERIES'],$voldetails['BACKUP_OPERATION'],$voldetails['VOLUME_SEQ']),
			tsmDate($voldetails['DATE_TIME'],'nosec'),
			tsmBackupType($voldetails['TYPE']),
			$voldetails['DEVCLASS'],
			$volname,
			$app['server']->GetVolLocation($volname),
			$voldetails['STATUS']);
	}

	$blockBody['backup'] .= '<tr><td colspan=4>&nbsp;</td></tr>';

} else {
	$blockBody['backup'] .= sprintf('<tr><td colspan=6>%s</td></tr>',_('It looks like you have NOT yet run a TSM backup.'));
}


if ($app['server']->GetDBDetail('BACKUP_RUNNING') == 'YES')
	$blockBody['backup'] .= sprintf('<tr><td colspan=6>%s</td></tr>',_('Database backup IS currently running.'));
else
	$blockBody['backup'] .= sprintf('<tr><td colspan=6>%s</td></tr>',_('Database backup is NOT currently running.'));

$blockBody['backup'] .= '<tr><td colspan=6>&nbsp;</td></tr>';
$blockBody['backup'] .= '</table>';

# End
render_page($blockTitle,$blockBody);
?>