<?php

/**
 * Umgebung definieren
 */
$environment = getenv('ENVIRONMENT');
if ($environment === false)
{
	$tmpPath = __DIR__;
	$found = false;
	while ($tmpPath != '/')
	{
		$htFile = $tmpPath . '/.htaccess';
		if (is_file($htFile) && is_readable($htFile))
		{
			$htContent = file($htFile);
			foreach ($htContent as $line => $text)
			{
				if (strpos($text, 'SetEnv') !== false && strpos($text, 'ENVIRONMENT') !== false)
				{
					$found = true;
					$environment = trim(str_replace(array('SetEnv', 'ENVIRONMENT'), '', $text));
					break;
				}
			}
		}
		if ($found)
		{
			break;
		}
		$tmpPath = dirname($tmpPath);
	}
}

define('ENVIRONMENT', $environment);

if (isset($_SERVER['HTTPS']))
{
	define('SCHEME', 'https');
}
else
{
	define('SCHEME', 'http');
}

if (ENVIRONMENT === 'local')
{
	define('HOST_URL', SCHEME . '://192.168.178.66/svj/');
	define('PATH_PREFIX', '/svj');
}
elseif (ENVIRONMENT === 'testing')
{
	define('HOST_URL', SCHEME . '://');
}
elseif (ENVIRONMENT === 'production')
{
	define('HOST_URL', SCHEME . '://www.svj-fussball.de/');
	define('PATH_PREFIX', '');
}
else
{
	die('Umgebungsvariable ist nicht gesetzt!');
}
define('ADMIN_URL', HOST_URL . 'administrator');

/**
 * Pfade definieren
 */
define('PATH_ROOT', dirname(__DIR__) . '/');
define('PATH_SITE', PATH_PREFIX . '/administrator');
define('PATH_ACT', PATH_ROOT . '.actions/');
define('PATH_CLS', PATH_ROOT . '.classes/');
define('PATH_CNF', PATH_ROOT . '.config/');
define('PATH_FNC', PATH_ROOT . '.functions/');
define('PATH_INC', PATH_ROOT . '.includes/');
define('PATH_LANG', PATH_ROOT . '.lang/');
define('WEBSERVICE_MED', PATH_ROOT . 'media/');


/**
 * Relative URLs für die Templates definieren
 */
define('HTML_IMG', PATH_PREFIX . '/images/');
define('HTML_CSS', PATH_PREFIX . '/css/');
define('PATH_CSS', PATH_SITE . '/css/');
define('PATH_IMG', PATH_SITE . '/images/');
define('PATH_JS', PATH_SITE . '/js/');
define('PATH_MED', PATH_PREFIX . '/media/');

define('PATH_PORTAL_TPL', PATH_ROOT . 'administrator/templates/');
define('PATH_WEBSITE_TPL', PATH_ROOT . 'templates/');


/**
 * Datenbank konfigurieren
 */
define('DB_TYPE', 'mysqli');
define('DB_HOST', 'localhost');
define('DB_NAME', 'c9svj');
define('DB_USER', 'c9svj');
define('DB_PASS', 'rXzmeEM@3');


/**
 * Tabellennamen definieren
 */
define('TBL_NAVI', 'navi');
define('TBL_CONTENT', 'content');
define('TBL_HEAD', 'content_headline');
define('TBL_IMAGE', 'content_image');
define('TBL_TEXT', 'content_text');
define('TBL_TEXTIMAGE', 'content_textimage');

define('TBL_LOG', 'portal_log');
define('TBL_RIGHTS', 'portal_rights');
define('TBL_USER', 'portal_user');


/**
 * Mimetypes
 */
$vC['mimetypes'] = array
(
	'jpg' => 'image/jpeg',
	'png' => 'image/png',
	'gif' => 'image/gif'
);

/**
 * Weitere Includes
 */
include_once(PATH_CNF . 'config_version.php');
include_once(PATH_INC . 'global_header.php');