<?php
date_default_timezone_set('Europe/London');

define('APPLICATION_PATH', realpath(dirname(__FILE__) . '../system/'));
set_include_path(
    APPLICATION_PATH . '../library'
    . PATH_SEPARATOR . get_include_path()
);

require_once('Zend/Loader/Autoloader.php');
$autoloader = Zend_Loader_Autoloader::getInstance();

$autoloader->pushAutoloader(array('docxloader', 'getClass'), 'cCreate');

$autoloader->setFallbackAutoloader(true);
$autoloader->suppressNotFoundWarnings(false);//For development only


Zend_Loader::loadFile('FusionCharts_Gen.php',APPLICATION_PATH .'../library');
//Zend_Loader::loadFile('FusionCharts.php',APPLICATION_PATH .'../library');
try{
	//Starting the session
	Zend_Session::start();

	// load the application configuration
	//$config = new Zend_Config_Ini('../settings.ini', 'development');//for development
	$config = new Zend_Config_Ini('../settings.ini', 'live');//for live
	Zend_Registry::set('config', $config);

	// create the application logger
	$logger = new Zend_Log(new Zend_Log_Writer_Stream($config->logging->file));
	Zend_Registry::set('logger', $logger);

	// connect to the database
	$params = array('host' => $config->database->hostname,
					'port' => $config->database->port,
					'username' => $config->database->username,
					'password' => $config->database->password,
					'dbname' => $config->database->database);
	$db = Zend_Db::factory($config->database->type, $params);
	Zend_Registry::set('db', $db);

	// connect to the servicepactnew database
    $params = array('host' => $config->database->mofirst->hostname,
					'port' => $config->database->port,
                    'username' => $config->database->mofirst->username,
                    'password' => $config->database->mofirst->password,
                    'dbname' => $config->database->mofirst->database);
    $mofirstDb = Zend_Db::factory($config->database->mofirst->type, $params);
    Zend_Registry::set('mofirstDb', $mofirstDb);
    
    // Defining our application's namespace and setting the expiry to be 60 minutes
    $namespace = new Zend_Session_Namespace("zacontrolpanel");
    $namespace->setExpirationSeconds(3600);
    $namespace->application="ZAControlPanel";
    Zend_Registry::set('namespace',$namespace);

	// setup application authentication and point to correct session namespace
	$auth = Zend_Auth::getInstance();
	$auth->setStorage(new Zend_Auth_Storage_Session("zacontrolpanel"));

	// handle the user request
	$controller = Zend_Controller_Front::getInstance();
	$controller->setControllerDirectory($config->paths->base.'/system/controllers');

	$controller->registerPlugin(new CustomControllerAclManager($auth));

	/* setup the view renderer
	 * Telling Zend_Controller to Use Smarty Instead of its Default View Renderer
	 */
	$vr = new Zend_Controller_Action_Helper_ViewRenderer();
	$vr->setView(new Templater());
	//to indicate that templates finish with a file extension of .tpl.
	//By default, Zend_View will use the extension .phtml
	$vr->setViewSuffix('tpl');
	Zend_Controller_Action_HelperBroker::addHelper($vr);

    /* SETUP CUSTOM HELPERS
     * Include custom-made helpers
     */
    Zend_Controller_Action_HelperBroker::addPrefix('Custom_Helper');
}
catch (Exception $exception) {
	echo 'error';
	        echo '<br /><br />' . $exception->getMessage() . '<br />'
           . '<div align="left">Stack Trace:'
           . '<pre>' . $exception->getTraceAsString() . '</pre></div>';
}

$controller->dispatch();
?>
