<?php
require_once($CFG['site']['project_path'] . "common/functions.php");
require_once($CFG['site']['project_path'] . "common/functionsNew.php");
require_once($CFG['site']['project_path'] . "common/classes/smarty/libs/Smarty.class.php");
require_once($CFG['site']['project_path'] . "common/smartyFunctions.php");
$CFG['mods']['include_files'][] = "common/classes/class_AgCache.lib.php";
if (!empty($CFG['site']['is_module_page']) && !chkAllowedModule(array(
    $CFG['site']['is_module_page']
))) {
    Redirect2URL($CFG['redirect']['dsabled_module_url']);
}
foreach ($CFG['site']['modules_arr'] as $value) {
    if (chkAllowedModule(array(
        strtolower($value)
    ))) {
        if (is_file($CFG['site']['project_path'] . "common/configs/config_" . strtolower($value) . ".inc.php")) {
            require_once($CFG['site']['project_path'] . "common/configs/config_" . strtolower($value) . ".inc.php");
        }
        if (is_file($CFG['site']['project_path'] . "common/" . strtolower($value) . "_common_functions.php")) {
            require_once($CFG['site']['project_path'] . "common/" . strtolower($value) . "_common_functions.php");
        }
    }
}
chkIsSiteUnderMaintenance();
if (!$CFG['mods']['is_include_only']['html_header']) {
    set_magic_quotes_runtime(0);
    if (ini_get("register_globals")) {
        if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
            exit("GLOBALS overwrite attempt detected");
        }
        $noUnset = array(
            "GLOBALS",
            "_GET",
            "_POST",
            "_COOKIE",
            "_REQUEST",
            "_SERVER",
            "_ENV",
            "_FILES"
        );
        $input   = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
        foreach ($input as $k => $v) {
            if (!in_array($k, $noUnset) && isset($GLOBALS[$k])) {
                unset($GLOBALS[$k]);
            }
        }
    }
    if (get_magic_quotes_gpc()) {
        function stripslashes_deep($value) {
            $value = is_array($value) ? array_map("stripslashes_deep", $value) : stripslashes($value);
            return $value;
        }
        $_POST    = array_map("stripslashes_deep", $_POST);
        $_GET     = array_map("stripslashes_deep", $_GET);
        $_COOKIE  = array_map("stripslashes_deep", $_COOKIE);
        $_REQUEST = array_map("stripslashes_deep", $_REQUEST);
    }
    global $DEBUG_TRACE;
    if ($CFG['feature']['gzip']['is_use_gzip'] && extension_loaded("zlib") && "4" <= PHP_VERSION) {
        if (( integer ) ini_get("zlib.output_compression") < 1) {
            if ("4.0.4" <= PHP_VERSION) {
                ob_start("ob_gzhandler");
            }
        } else {
            ini_set("zlib.output_compression_level", $CFG['feature']['gzip']['level']);
        }
    }
    if ($CFG['debug']['is_custom_handler']) {
        require_once($CFG['site']['project_path'] . "common/classes/class_ErrorHandler.lib.php");
        $errHandler = new ErrorHandler();
        $errHandler->setErrorLevel($CFG['debug']['error_level']);
        $errHandler->setIsDebugMode($CFG['debug']['is_debug_mode']);
        $errHandler->setNumSourceToFetch($CFG['debug']['source_before_errline'], $CFG['debug']['source_after_errline']);
        $errHandler->setIsCatchFatalError($CFG['debug']['is_catch_fatal_error']);
        $errHandler->setErrorNotifyEmail($CFG['debug']['notify_email']);
        $errHandler->setDebugCSSURL($CFG['debug']['debug_css_url']);
    }
    if ($CFG['lang']['is_multi_lang_support']) {
        require_once($CFG['site']['project_path'] . "common/select_language.inc.php");
    }
    require_once($CFG['site']['project_path'] . "languages/" . $CFG['lang']['default'] . "/common/common.inc.php");
    require_once($CFG['site']['project_path'] . "languages/meta_details.php");
    foreach ($CFG['site']['modules_arr'] as $value) {
        if (chkAllowedModule(array(
            strtolower($value)
        ))) {
            if (is_file($CFG['site']['project_path'] . "languages/" . $CFG['lang']['default'] . "/" . strtolower($value) . "/common.inc.php")) {
                require_once($CFG['site']['project_path'] . "languages/" . $CFG['lang']['default'] . "/" . strtolower($value) . "/common.inc.php");
            }
            if (is_file($CFG['site']['project_path'] . "languages/" . strtolower($value) . "_meta_details.php")) {
                require_once($CFG['site']['project_path'] . "languages/" . strtolower($value) . "_meta_details.php");
            }
        }
    }
    require_once($CFG['site']['project_path'] . "languages/" . $CFG['lang']['default'] . "/common/help.inc.php");
    if (isset($CFG['lang']['include_files'])) {
        foreach ($CFG['lang']['include_files'] as $include_file) {
            require_once($CFG['site']['project_path'] . sprintf($include_file, $CFG['lang']['default']));
        }
    }
    if ($CFG['ssl']['is_use_ssl'] && (is_string($CFG['ssl']['secure_pages']) && $CFG['ssl']['secure_pages'] == "*" || is_array($CFG['ssl']['secure_pages']) && in_array($_SERVER['PHP_SELF'], $CFG['ssl']['secure_pages']))) {
        if (empty($_SERVER['HTTPS'])) {
            Redirect2URL("https://" . substr($CFG['site']['current_url'], strlen("http://")));
        }
    } else if (!empty($_SERVER['HTTPS'])) {
        Redirect2URL("http://" . substr($CFG['site']['current_url'], strlen("https://")));
    }
    if ($CFG['db']['is_use_db']) {
        require_once($CFG['site']['project_path'] . "common/classes/adodb_lite/adodb.inc.php");
        $db        = NewADOConnection($CFG['db']['abstraction'], "query");
        $db->debug = $CFG['debug']['is_db_debug_mode'];
        if ($CFG['debug']['is_db_debug_mode']) {
            global $SQL_QUERIES;
            define("ADODB_OUTP", "ExposeQuery");
        }
        if ($CFG['db']['hostname'] == "" || $CFG['db']['username'] == "" || $CFG['db']['name'] == "") {
            Redirect2URL("install.php");
        } else if ($CFG['site']['script_name'] != "siteInfo.php" && !mysql_connect($CFG['db']['hostname'], $CFG['db']['username'], $CFG['db']['password'])) {
            Redirect2URL("siteInfo.php?info=db");
        } else if ($CFG['site']['script_name'] != "install.php" && file_exists($CFG['site']['project_path'] . "install.php")) {
            Redirect2URL("siteInfo.php?info=install");
        }
        $db->Connect($CFG['db']['hostname'], $CFG['db']['username'], $CFG['db']['password'], $CFG['db']['name']);
        if (!$db) {
            trigger_error("DB Connection Error", E_USER_ERROR);
        }
    }
    if (isset($CFG['site']['set_default_charset_for_mysqlconnection']) && $CFG['site']['set_default_charset_for_mysqlconnection']) {
        $charset = isset($CFG['site']['charset']) ? $CFG['site']['charset'] : "utf-8";
        $sql     = "SET character_set_results = '{$charset}', character_set_client = '{$charset}', character_set_connection = '{$charset}', character_set_database = '{$charset}', character_set_server = '{$charset}'";
        $db->Execute($sql, array());
    }
    if ($CFG['http_headers']['is_default_http_headers']) {
        if ($CFG['session']['is_session']) {
            if (!empty($CFG['session']['cache_limiter'])) {
                session_cache_limiter($CFG['session']['cache_limiter']);
            }
            if ($CFG['session']['is_custom_handler'] && $CFG['db']['is_use_db']) {
                require_once($CFG['site']['project_path'] . "common/classes/class_CustomSession.lib.php");
            } else {
                session_start();
            }
        }
        require_once($CFG['site']['project_path'] . "common/http_headers.inc.php");
    }
    setUserConfigVariables();
    require_once($CFG['site']['project_path'] . "common/authentication/authenticate_user.inc.php");
    if ($CFG['html']['template']['is_template_support']) {
        require_once($CFG['site']['project_path'] . "common/select_template.inc.php");
    }
    if (isset($CFG['mods']['include_files'])) {
        foreach ($CFG['mods']['include_files'] as $include_file) {
            require_once($CFG['site']['project_path'] . sprintf($include_file, $CFG['lang']['default']));
        }
    }
}
if (!$CFG['mods']['is_include_only']['non_html_header_files'] && $CFG['html']['is_use_header']) {
    require_once($CFG['site']['project_path'] . "languages/" . $CFG['lang']['default'] . "/general/headerLanguage.php");
    if (!class_exists("FormHandler")) {
        require_once($CFG['site']['project_path'] . "common/classes/class_FormHandler.lib.php");
    }
    if (!class_exists("Widget")) {
        require_once($CFG['site']['project_path'] . "common/classes/class_Widget.lib.php");
    }
    require_once($CFG['site']['project_path'] . "common/classes/class_HeaderHandler.lib.php");
    require_once($CFG['site']['project_path'] . "languages/" . $CFG['lang']['default'] . "/lists_array/paging_list_array.inc.php");
    require_once($CFG['site']['project_path'] . sprintf($CFG['html']['header'], $CFG['lang']['default']));
}
require_once($CFG['site']['project_path'] . "languages/" . $CFG['lang']['default'] . "/general/headerLanguage.php");
?>