<?php
/**
 * phpaga
 *
 * This is phpaga's internal configuration file. There should be no
 * need to modify anything in here. All local configuration settings
 * are done in config.local.php
 *
 * @author Florian Lanthaler <florian@phpaga.net>
 * @version $Id: config.php 753 2006-10-25 21:52:28Z florian $
 *
 * Copyright (c) 2002, 2003 Florian Lanthaler <florian@phpaga.net>
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *    * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *
 *    * Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in
 *      the documentation and/or other materials provided with the
 *      distribution.
 *
 *    * Neither the name of Florian Lanthaler nor the names of his
 *      contributors may be used to endorse or promote products derived
 *      from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/* Include local configuration settings */
include_once("config.local.php");

/* Compress output if the option is not disabled and the browser
 * supports gzip encoding */

if ((!defined('PHPAGA_COMPRESSOUT_DISABLED') || !PHPAGA_COMPRESSOUT_DISABLED) && strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
    ob_start("gzencode");
    header("Content-Encoding: gzip");
}

/* Include Pear packages */
require_once("PEAR.php");
require_once("DB.php");
require_once("Log.php");
require_once("Mail.php");

/* Set error reporting */
if (defined("PHPAGA_ERR_VERBOSE") && (PHPAGA_ERR_VERBOSE == true))
    error_reporting(E_ALL);

/* DSN */
define("PHPAGA_DSN", sprintf("%s://%s:%s@%s/%s",
                             PHPAGA_DB_SYSTEM,
                             PHPAGA_DB_LOGIN,
                             PHPAGA_DB_PASSWD,
                             PHPAGA_DB_HOST,
                             PHPAGA_DB_NAME));

/* Include local configuration settings */
include_once("languages.php");

/* Set include paths */
define("PHPAGA_ETCPATH", PHPAGA_BASEPATH."etc/");
define("PHPAGA_EXTPATH", PHPAGA_BASEPATH."ext/");
define("PHPAGA_DOCPATH", PHPAGA_BASEPATH."htdocs/");
define("PHPAGA_LIBPATH", PHPAGA_BASEPATH."lib/");
define("PHPAGA_LNGPATH", PHPAGA_BASEPATH."locale/");
define("PHPAGA_FILEPATH", PHPAGA_BASEPATH."files/");
define("PHPAGA_PICTUREPATH", PHPAGA_BASEPATH."pictures/");
define("PHPAGA_LOGOPATH", PHPAGA_BASEPATH."logos/");
define("PHPAGA_BMTPATH", PHPAGA_LIBPATH."bill/");
define("PHPAGA_BASETPLPATH", PHPAGA_BASEPATH."templates/");
define("PHPAGA_MAILTPLPATH", PHPAGA_BASEPATH."mailtemplates/");

/* Include internal primary libraries */
include_once(PHPAGA_LIBPATH."db.php");
include_once(PHPAGA_LIBPATH."config.php");
include_once(PHPAGA_ETCPATH."globals.php");
include_once(PHPAGA_LIBPATH."users.php");
include_once(PHPAGA_LIBPATH."misc.php");
include_once(PHPAGA_ETCPATH."errors.php");
include_once(PHPAGA_LIBPATH."persons.php");

/* Fill $_REQUEST if necessary ($_REQUEST works with php 4.1 and later) */

if (!isset($_REQUEST))
    $_REQUEST = $HTTP_POST_VARS + $HTTP_GET_VARS + $HTTP_COOKIE_VARS;

/* Remove slashes from request paramters if magic_quotes_gpc is On,
 * as PEAR::DB's quoting functions will take care of quoting values
 */

if (get_magic_quotes_gpc() == 1)
{
    $_REQUEST = phpaga_stripslashesArray($_REQUEST);
    $_GET = phpaga_stripslashesArray($_GET);
    $_POST = phpaga_stripslashesArray($_POST);
}

if (!defined("PHPAGA_INSTALL") || !PHPAGA_INSTALL) {
    /* check session and load user config settings */
    include_once(PHPAGA_LIBPATH."sessions.php");
} else {
    /* load default config settings */
    $result = phpaga_config_read();
}

if (defined("PHPAGA_INSTALL") && PHPAGA_INSTALL)
{
    if (!defined("PHPAGA_TEMPLATESET")) {
        define("PHPAGA_TEMPLATESET", "phpaga");
    }

    if (!defined("PHPAGA_DEFAULT_SKIN")) {
        define("PHPAGA_DEFAULT_SKIN", "phpaga");
    }
}

/* Uploads are enabled unless defined otherwise in config.local.php */

if (!defined("PHPAGA_UPLOADS_DISABLED"))
    define("PHPAGA_UPLOADS_DISABLED", false);

/* Include internal secondary libraries */

include_once(PHPAGA_LIBPATH."auth.php");
include_once(PHPAGA_LIBPATH."bills.php");
include_once(PHPAGA_LIBPATH."companies.php");
include_once(PHPAGA_LIBPATH."countries.php");
include_once(PHPAGA_LIBPATH."currencies.php");
include_once(PHPAGA_LIBPATH."expenses.php");
include_once(PHPAGA_LIBPATH."files.php");
include_once(PHPAGA_LIBPATH."finances.php");
include_once(PHPAGA_LIBPATH."mail.php");
include_once(PHPAGA_LIBPATH."materials.php");
include_once(PHPAGA_LIBPATH."operations.php");
include_once(PHPAGA_LIBPATH."products.php");
include_once(PHPAGA_LIBPATH."projects.php");
include_once(PHPAGA_LIBPATH."quotations.php");
include_once(PHPAGA_LIBPATH."language.php");
include_once(PHPAGA_ETCPATH."permissions.php");

define("PHPAGA_TPLPATH", PHPAGA_BASETPLPATH.PHPAGA_TEMPLATESET."/");

/* Configure and include Smarty */
if (!defined("SMARTY_DIR")) {
    define("SMARTY_DIR", PHPAGA_EXTPATH."smarty/libs/");
}

include_once(PHPAGA_LIBPATH."smarty.php");

/* Configure JpGraph */
if (!defined("JPGRAPH_DIR")) {
    define("JPGRAPH_DIR", PHPAGA_EXTPATH."jpgraph/src/");
}

/* Configure PDF class */
if (!defined("PDFCLASS_DIR")) {
    define("PDFCLASS_DIR", PHPAGA_EXTPATH."pdfclass/");
}


/* File thumbnails */

if (!defined("PHPAGA_FILES_PREVIEW"))
    define("PHPAGA_FILES_PREVIEW", true);

if (!defined("PHPAGA_BIN_CONVERT"))
    define("PHPAGA_BIN_CONVERT", "/usr/bin/convert");

/* Configure the mail backend */
if (!defined("PHPAGA_MAIL_BACKEND")) {
    define("PHPAGA_MAIL_BACKEND", "SENDMAIL");
}

if (!isset($phpaga_mail_sendmail_param)
    || !is_array($phpaga_mail_sendmail_param)) {

    $phpaga_mail_sendmail_param = array();
}

if (!isset($phpaga_mail_sendmail_param["sendmail_path"])
    || !strlen($phpaga_mail_sendmail_param["sendmail_path"])) {

    $phpaga_mail_sendmail_param["sendmail_path"] = "/usr/lib/sendmail";
}

if (!isset($phpaga_mail_sendmail_param["sendmail_args"])) {
    $phpaga_mail_sendmail_param["sendmail_args"] = "";
}

switch(strtoupper(PHPAGA_MAIL_BACKEND))
{

    case "SMTP":
        $phpaga_mail_param = $phpaga_mail_smtp_param;
        break;

    case "SENDMAIL":
        $phpaga_mail_param = $phpaga_mail_sendmail_param;
        break;

    case "MAIL":

    case "NONE":
        $phpaga_mail_param = array();
        break;

    default: phpaga_error(PHPAGA_ERR_INVALID_MAILBACKEND);
        break;
}

define("PHPAGA_SELF", basename($_SERVER["PHP_SELF"]));

?>
