<?php
/**
 * nfc-bootloader.php
 * 
 * Setup the basic env minus the Front Controller (nfc = no front controller)
 *
 * @author Brad Kowalczyk <brad@staff.atmail.com>
 */

// define the namespaces in use
define('ATMAIL_ADMIN_NAMESPACE', 'atmail6_admin');
define('ATMAIL_NAMESPACE', 'atmail6');

$path = dirname(dirname(__FILE__));
$path1 = "$path/library:$path/library/Pear:$path/application/models:$path";
$path = dirname(dirname(__FILE__)) . "/webmail";
$path2 = "$path/library:$path/library/Pear:$path/application/models:$path";
ini_set('include_path', "$path1:$path2");

date_default_timezone_set('UTC');

//Error reporting
error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);

// Lets give the script some ram!
ini_set('memory_limit', -1);

// remove php time limit
set_time_limit(0);

mb_internal_encoding('UTF-8');
iconv_set_encoding("internal_encoding", "UTF-8");//setting gave grief at some point, i suspect it was surrounding Lucene, but needed for ZF mime header decoding. this doesnt work, possible because conflicts with php.ini setting
iconv_set_encoding("input_encoding", "BASE-64");
iconv_set_encoding("output_encoding", "UTF-8");

//Site application root and paths
//all references to directories have / appended to eliminate posibility of direcory reference composition resulting in '/....' as in root 
//i.e. when composing a directory string, all components dont/cant/wont start with a / eliminating the possibility if a resulting string referring to OS root
define('APP_ROOT', dirname(dirname(__FILE__)) . '' . DIRECTORY_SEPARATOR);

require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
//$loader->registerNamespace('App_'); //for model namespacing
$loader->setFallbackAutoloader(true);
$loader->suppressNotFoundWarnings(false);
Zend_Loader::loadFile('Atmail/General.php', null, true);
Zend_Loader::loadFile('Atmail/Exception.php', null, true);

$siteBaseUrl = substr($_SERVER["SCRIPT_NAME"],0,strpos($_SERVER["SCRIPT_NAME"],'index.php'));

Zend_Registry::set( 'siteBaseUrl', $siteBaseUrl );

// Get database configuration    
$dbConfig = new Zend_Config_Ini('config/dbconfig.ini', 'production');
Zend_Registry::set('dbConfig', $dbConfig);
$dbAdapter = dbAdapterFactory($dbConfig);
Zend_Db_Table::setDefaultAdapter($dbAdapter);
Zend_Registry::set('dbAdapter', $dbAdapter); 

//Get main configuration from database
$config = new Atmail_Config_Mysql($dbConfig, true);

//$config->global['cacheEnabled'] = false;
$config->global['allowLocalPop3'] = true; //for testing/debugging
$config->global['allowLocalImap'] = true; //for testing/debugging 
Zend_Registry::set('config', $config);

$locale = new Zend_Locale();
Zend_Registry::set('Zend_Locale', $locale);

$log = new Atmail_Log();
$log->addPriority('atmail', 10); 
$log->addPriority('sysadmin', 20); 
$log->addPriority('imap', 30); 
$log->addPriority('firebug', 40); 

$logBasePath = APP_ROOT . 'log' . DIRECTORY_SEPARATOR;
Zend_Registry::set('log', $log);

unset($config);
unset($settings);
