<?php
// $Header: /cvsroot/phptsmadmin/phpTSMadmin/htdocs/cmd.php,v 1.2 2009/04/19 03:52:21 wurley Exp $

/**
 * Main command page for this application
 * All pages are rendered through this script.
 *
 * @package leenooksApp
 * @subpackage Page
 */

/**
 */

require_once './common.php';

$www['cmd'] = get_request('cmd','REQUEST');
$www['meth'] = get_request('meth','REQUEST');

ob_start();

switch ($www['cmd']) {
	case '_debug' :
		debug_dump($_REQUEST,1);
		break;

	default :
		if (defined('HOOKSDIR') && file_exists(HOOKSDIR.$www['cmd'].'.php'))
			$app['script_cmd'] = HOOKSDIR.$www['cmd'].'.php';

		elseif (defined('HTDOCDIR') && file_exists(HTDOCDIR.$www['cmd'].'.php'))
			$app['script_cmd'] = HTDOCDIR.$www['cmd'].'.php';

		elseif (file_exists('welcome.php'))
			$app['script_cmd'] = 'welcome.php';

		else
			$app['script_cmd'] = null;
}

if (DEBUG_ENABLED)
   debug_log('Ready to render page for command [%s,%s].',128,__FILE__,__LINE__,__METHOD__,$www['cmd'],$app['script_cmd']);

# Create page.
# Set the index so that we render the right menu tree.
$www['page'] = new page($app['server']->getIndex());

if ($app['script_cmd'])
	include $app['script_cmd'];

# Capture the output and put into the body of the page.
$www['body'] = new block();
$www['body']->SetBody(ob_get_contents());
$www['page']->block_add('body',$www['body']);
ob_end_clean();

if ($www['meth'] == 'ajax')
	$www['page']->show(get_request('frame','REQUEST',false,'BODY'),true);
else
	$www['page']->display();
?>
