<?php

/*
** SellaNMS
** $Id: sella_nms.php,v 2.24 2005/05/02 06:37:37 sella Exp $
** Copyright (c) 2001 Digital Genesis Software, LLC. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
*/

require_once('config/config.php');
require_once('libs/dgsutil/cgi.php');
require_once('libs/dgsutil/text.php');
require_once('libs/dgsutil/misc.php');
require_once('libs/dgsutil/debug.php');
require_once('libs/dgsutil/startup.php');
require_once('libs/dgsutil/filesystem.php');
require_once('modules/module.php');
require_once('libs/util.php');

/* Main - Start */
initSellaNMS(); 
 
$retVal = array();
$data = getFormData();
 
if ($data['debug']) {
	if (!remoteDebug($data['debug'], $data['option']))
		return;
}

$timer = getTime(); 

if ($config['debug'])
	printf("Debug: main() - Calling processConfig()<BR>\n");

$state = processConfig($data);
if ($state) {
	if (process($retVal, $data)) {
		$data['frames'] = $retVal;
		display($data);
	}
}

if ($config['debug'])
	printf("Debug: main() - Total Time: %.1f<BR>\n", getTime() - $timer);

exit(0);
/* Main - End */

function display($data) {
   global $config, $timer;
   $modules = $config['modules'];
   $installBase = $config['installBase'];
   $fileSeparator = $config['fileSeparator'];
 
   if ($config['debug'])
      printf(">Debug: display() - Time: %.1f<BR>\n", getTime() - $timer);

	if (isset($data['visible'])) {
		headerFrame($data);
	} else {
		hiddenFrame($data);
	}

	return true;
}

function process(&$retVal, $data) {
   global $config, $timer;
   $modules = $config['modules'];
   $installBase = $config['installBase'];
   $fileSeparator = $config['fileSeparator'];
 
   if ($config['debug'])
      printf(">Debug: process() - Time: %.1f<BR>\n", getTime() - $timer);
 
	/* Only the hidden frame should do this. */
	if (isset($data['visible'])) {
		return true;
	}

   reset($modules);
   while (list(, $module) = each($modules)) {
		$mod = new $module();
		$result = $mod->doit();
		unset($mod);
      if (is_string($result)) {
         printf("Error: Module '%s' had a fatal error. Details below:<BR>\n<BR>\n%s<BR>\n", $module, $result);
         return false;
      } else if (is_array($result) && count($result) > 0) {
			while(list(, $frame) = each($result)) {
   			if ($config['debug']) {
			      printf(">Debug: process() - Module '%s' requested reload of '%s'.<BR>\n", $module, $frame);
				}
				$retVal[] = $frame;
			}
		}
   }

   return true;
}

/*
** Local Variables:
** c-basic-offset: 3
** tab-width: 3
** End:
** vim600: fdm=marker
** vim: noet ts=3 sw=3
*/

?>
