<?php

include_once (dirname(__FILE__) . "/../config/config.inc.php"); //here you can change the database IP
include_once (dirname(__FILE__) . "/../config/version.php"); // Version information of Phonalisa
# Check if mod_rewrite is enabled
if (function_exists('apache_get_modules')) {
    $modules = apache_get_modules();
    $mod_rewrite = in_array('mod_rewrite', $modules);
} else {
    $mod_rewrite = getenv('HTTP_MOD_REWRITE') == 'On' ? true : false;
}

if ($cacheServer != null) {
    $cache = array(
        'class' => 'CMemCache',
        'servers' => array(
            array(
                'host' => $cacheServer,
                'port' => 11211,
                'weight' => 60,
            )
        ),
    );
} else {
    $cache = array(
        'class' => 'CDummyCache'
    );
}
// FIXME see components controller there was some bug with urlManager or rewrite rules ... 
//$helpBaseUrl = "https://docs.phonalisa.de/index.php";
$helpBaseUrl = "https://docs.phonalisa.de";
$licenseApi = "https://license.phonalisa.de/api";

function isProvisioningRequest()
{
    if (isset($_GET['r']) && $_GET['r'] == 'provisioningGeneral' && isset($_GET['mac'])) {
        return true;
    }
    return false;
}
$path = dirname(__FILE__) . "/../components/ModuleManager.php";
include_once($path);

// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
Yii::setPathOfAlias('bootstrap', dirname(__FILE__) . '/../extensions/bootstrap');

$main = array(
    'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
    'name' => 'Phonalisa 6 Next Generation IP Telecommunications System', //FIXME: Get from config
    "runtimePath"=>isset($runtimePath) ? $runtimePath : dirname(__FILE__) . DIRECTORY_SEPARATOR . '../runtime',
    // preloading 'log' component
    'preload' => array(
        'log',
        //'bootstrap',
        'less', // preload the component to allow for automatic compilation
    ),
    // autoloading model and component classes
    'import' => array(
        'ext.select2.Select2',
        'application.models.*',
        'application.components.*',
        'application.components.callforwarding.*',
        'application.components.parsedown.*',
        'application.modules.adminSipAccounts.models.*',
        'application.modules.adminGroups.models.*',
        'application.modules.routingGateways.models.*',
        'application.modules.faxInbox.models.*',
        'application.modules.addressBookGeneral.models.*'
    ),
    //FIXME: build this from SiteController may using the group module(s)
    //FIXME: Add depends key into module definitions!
    // modules can be found now in "/components/ModuleManager.php"
    // application components
    'components' => array(
        'detectMobileBrowser' => array(
            'class' => 'ext.yii-detectmobilebrowser.XDetectMobileBrowser',
        ),
        'assetManager'=>array(
            'basePath'=>isset($assetsPath) ? $assetsPath : dirname(__FILE__) . DIRECTORY_SEPARATOR . '../../assets',
        ),
        'session' => array(
            'autoStart' => false,
            'sessionName' => 'JSESSIONID',
        ),
        'user' => array(
            // enable cookie-based authentication
            'allowAutoLogin' => true,
            'class' => 'WebUser',
        ),
        'accessManager' => array(
            'class' => 'AccessManager',
        ),
        'cache' => $cache,
        'bootstrap' => array(
            'class' => 'bootstrap.components.Bootstrap',
        ),
        'less' => array(
            'class' => 'ext.less.components.LessCompiler',
            //'forceCompile'=> false, // indicates whether to force compiling
            'paths' => array(
                'less/main.less' => 'css/style.css',
            ),
        ),
        'request' => array(
            'class' => 'application.components.HttpRequest',
            'enableCookieValidation' => true,
            'enableCsrfValidation' => false, // FIXME
        ),
        'urlManager' => array(),
        //FIXME: May use the Configuration Module to get this Path!
        'db' => array(
            'connectionString' => 'sqlite:' . dirname(__FILE__) . '/../data/phonalisa.db',
            'enableProfiling' => true,
            'enableParamLogging' => true,
        ),
        //FIXME: Have to check if production state->user config module
        'errorHandler' => array(
            'class'=>'PhonalisaErrorHandler',
            // use 'site/error' action to display errors
            'errorAction' => 'site/error',
        ),
    ),
    // application-level parameters that can be accessed
    // using Yii::app()->params['paramName']
    'params' => array(
        // this is used in contact page
        'adminEmail' => 'webmaster@example.com',
        'languages' => array(
            'de_de' => 'Deutsch',
            'en_us' => 'English',
            'fr_fr' => 'Francais',
	    'nl_nl' => 'Nederlands'
        /* 'no'=>'Norway', 'ru'=>'Русский' */
        ), //FIXME Get selected languages from Config
        'themes' => array(
            'default' => 'Default',
            'green' => 'Aqua Thunder',
            'red' => 'Bloody Thunder',
            'glass' => 'Blueberry Soda',
            "blue"=>"Ocean",
            "tequila"=>"Sunrise", 
            "sky" => "Red Universe",
            "sky_blue" => "Blue Universe",
            "kitty" => "Pink Smile",
            "sky_two" => "Colored Universe",
            "digital" => "Bloody Rain",
            "digital_green" => "Green Rain",
            "snake" => "Jungle",
            "phantom" => "Phantom",
            "earth" => "Earth Colors"
            
        ),
        'databaseServer' => $databaseServer, //the database IP
        'multidomain' => $multidomain, //the SIP-Registrat IP
        'domains' => $domains, //the SIP-Registrat IP
        'logServer' => $logServer,
        'logServerPort' => $logServerPort,
        'devMode' => isset($devMode) ? $devMode : false,
        'helpBaseUrl' => isset($helpBaseUrl) ? $helpBaseUrl : null,
        'licenseApi' => $licenseApi,
        'phonalisaVersion' => isset($phonalisaVersion) ? $phonalisaVersion : null,
        'phonalisaEdition' => isset($phonalisaEdition) ? $phonalisaEdition : null,
        'phonalisaReleaseDate' => isset($releaseDate) ? $releaseDate : null,
        'phonalisaReleaseBranch' => isset($releaseBranch) ? $releaseBranch : null,
        'phonalisaReleaseCommitId' => isset($releaseCommitId) ? $releaseCommitId : null,
        'systemVersion' => isset($systemVersion) ? $systemVersion : null,
        'defaultPageSize' => 20,
        'enableErgophoneProvisioning' => false,
        'ergophoneConfigRootPath' => __DIR__ . "/../data",
        'testBaseUrl' => isset($testBaseUrl) ? $testBaseUrl : null,
        'globalConfigDefault' => isset($globalConfigDefault) ? $globalConfigDefault : null,
        'applianceMode' => isset($applianceMode) ? $applianceMode : false,
        'applianceModel' => isset($applianceModel) ? $applianceModel : false,
        'tellowsApiName' => isset($tellowsApiName) ? $tellowsApiName : 'phonalisa',
    ),
    'sourceLanguage' => '00',
    'language' => 'en_us', // overwritten in components/Controller.php
);

if ($main["params"]["devMode"] === true)
{
    
    $applicationLog = array(
        'class' => 'CLogRouter',
        'routes' => array(
        array(
                'class' => 'CFileLogRoute',
                'levels' => 'error, warning, notice',
            ),
        ),
    );
    $main['components']["log"] = $applicationLog;
}

$main['modules'] = ModuleManager::getDeclaredModules();     

return $main;
