<?php
/**
 * Main endpoint
 *
 * @category 	Atmail
 * @package 	Application
 * @subpackage	Main endpoint
 * @copyright 	Copyright (c) 2009-2011 ATMAIL. All rights reserved
 * @license 	See http://atmail.com/license.php for license agreement
 * @author		Atmail (http://atmail.com)
 */
 
// check session.auto_start status
//
// Hot fix for suPHP
// Since there is no function apache_request_headers(), just added a quick implementation here.
// 
if( !function_exists('apache_request_headers') ) { 
	function apache_request_headers() { 
		$arh = array(); 
		$rx_http = '/\AHTTP_/';
		foreach($_SERVER as $key => $val) { 
			if( preg_match($rx_http, $key) ) { 
				$arh_key = preg_replace($rx_http, '', $key); 
				$rx_matches = array(); 
				// do some nasty string manipulations to restore the original letter case 
				// this should work in most cases 
				$rx_matches = explode('_', $arh_key); 
				if( count($rx_matches) > 0 and strlen($arh_key) > 2 ) { 
					foreach($rx_matches as $ak_key => $ak_val) $rx_matches[$ak_key] = ucfirst($ak_val); 
					$arh_key = implode('-', $rx_matches); 
				} 
				$arh[$arh_key] = $val; 
			} 
		} 
		return( $arh ); 
	} 
} 

if(ini_get("session.auto_start"))
{
	ini_set('session.auto_start', "0");
	session_write_close();
}

include_once('bootloader.php');

    // todo:dtb: temp logging
//    foreach($_SERVER as $key => $val)
//    {
//        Zend_Registry::get('log')->debug("SERVER key: $key          val: $val");
//    }
//
//    foreach($_POST as $key => $val)
//    {
//        Zend_Registry::get('log')->debug("POST key: $key          val: $val");
//    }


if(isset($frontController) && $frontController)
{
	$frontController->dispatch();
    	Zend_Session::writeClose();
	Zend_Registry::get('log')->debug('Hit closing down. Hit time: ' . round( ( microtime(true) - DEBUG_START_MT ),3 ) . ' seconds. ' . session_id());
}

