<?
########## Confixx(R) 3.0 Professional ############
####### Copyright SWsoft, Inc. 2004-2005 ##########
#### http://www.sw-soft.com - info@sw-soft.com ####

error_reporting(7);

if( !defined('CONFIXX_ADMIN') )
{
	define('CONFIXX_ADMIN', 1);
}

//session_name('SID');
//session_start();
//phpinfo();
//print_r($GLOBALS);
//exit();

if (!isset($umgesetzt)) {

        $umgesetzt = true;



        if (is_array($_GET)) {

                foreach($_GET as $key => $val) {

                        if (!is_array($val)) {
                                if (get_magic_quotes_gpc()) $val = StripSlashes($val);
                                //$val = AddSlashes(StripSlashes($val));
                        }

                        $$key = $val;

                }

        } elseif (is_array($HTTP_GET_VARS)) {

                foreach($HTTP_GET_VARS as $key => $val) {

                        if (!is_array($val)) {
                                if (get_magic_quotes_gpc()) $val = StripSlashes($val);
                                //$val = AddSlashes(StripSlashes($val));
                        }

                        $$key = $val;

                }

        }



        if (is_array($_POST)) {

                foreach($_POST as $key => $val) {

                        if (!is_array($val)) {
                                if (get_magic_quotes_gpc()) $val = StripSlashes($val);
                                //$val = AddSlashes(StripSlashes($val));
                        }

                        $$key = $val;

                }

        } elseif (is_array($HTTP_POST_VARS)) {

                foreach($HTTP_POST_VARS as $key => $val) {

                        if (!is_array($val)) {
                                if (get_magic_quotes_gpc()) $val = StripSlashes($val);
                                //$val = AddSlashes(StripSlashes($val));
                        }

                        $$key = $val;

                }

        }



        if (is_array($_SERVER)) {

                foreach($_SERVER as $key => $val) {

                        $$key = $val;

                }

        } elseif (is_array($HTTP_SERVER_VARS)) {

                foreach($HTTP_SERVER_VARS as $key => $val) {

                        $$key = $val;

                }

        }



        unset($key, $val);

}



if (isset($anbieter)) $anbieter = strtolower(trim($anbieter));
$PHP_AUTH_USER = $PHP_AUTH_PW = '';

include("../settings.inc.php");
include("../functions.inc.php");
include('../sessions.inc.php');

db_connect($db_host, $db_user, $db_pass);

sessao_start();

/*

if( $_POST['username'] && $_POST['password'] )
{
	
	$id = db_query("select longpw, login from admin");
	$werte = db_fetch_array($id);
	$pwd_cr = crypt($_POST['password'], $werte['longpw']);
	if($_POST['username'] == $werte['login'] && $pwd_cr == $werte['longpw']) 
	{
		session_register('_username', '_password', '_usertype');
		$_SESSION['_username'] = $_POST['username'];
		$_SESSION['_password'] = $_POST['password'];
		$_SESSION['_usertype'] = USERTYPE_ADMIN;
	}
	
}


if($_SESSION['_username'])
{
	$PHP_AUTH_USER = $_SESSION['_username'];
	$PHP_AUTH_PW = $_SESSION['_password'];
}
*/

$id = db_query("SELECT login FROM admin");
$res = db_fetch_array($id);
if(isSUserLogged($res['login']))
{
	$PHP_AUTH_USER = $res['login'];
}

if(!$PHP_AUTH_USER)
{
	db_close;
	include('../loginform.php');
	exit();
}


if(0)
{
	
if (!isset($PHP_AUTH_USER))
{
	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the past
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
	header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/1.1
	header("Pragma: no-cache");                          // HTTP/1.0
	header('WWW-Authenticate: Basic realm="Admin Login"');
	header('HTTP/1.0 401 Unauthorized');
	include("../settings.inc.php");
	include("../noaccess.inc.php");
	exit();
}
else
{
	include("../settings.inc.php");
	include("../functions.inc.php");
	db_connect($db_host, $db_user, $db_pass);
	$id = db_query("select longpw, login from admin");
	$werte = db_fetch_array($id);
	$passwort = $werte["longpw"];
	$login = $werte["login"];
	if (istleer($login))
	{
		$login = "Administrator";
	}
	$passwort2 = crypt($PHP_AUTH_PW, $passwort);
	if (($passwort2 != $passwort) || ($login != $PHP_AUTH_USER))
	{
		header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the past
		header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
		header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/1.1
		header("Pragma: no-cache");                          // HTTP/1.0
		header('WWW-Authenticate: Basic realm="Admin Login"');
		header('HTTP/1.0 401 Unauthorized');
		include("../noaccess.inc.php");
		db_close();
		exit();
	}
}

}

## set language

$id = db_query("select language, postconf, business, checkupdates from admin");

$werte = db_fetch_array($id);

$shortlang = $werte["language"];
$postconf = $werte["postconf"];
$cbusiness = $werte["business"];
$checkupdates = $werte["checkupdates"];

$miscf = $shortlang."/misc.inc.php";

$langf = $shortlang."/admin.inc.php";

include("../languages/$miscf");

include("../languages/$langf");

## //


$strSkinName="/skins/skin_1";
$confixx_interface_version = 'xp30';
$id = db_query("SELECT custom_skins.path AS path, custom_skins.version AS version FROM skins INNER JOIN custom_skins ON (skins.skin_id = custom_skins.id) WHERE skins.cuser='admin'");
if(db_num_rows($id))
{
	$werte = db_fetch_array($id);
	$confixx_interface_version = $werte['version'];
	$strSkinName = $werte['path'];
}

if($cbusiness)
{
	$id2 = db_query("select defaultserver from bdefault");
	$werte2 = db_fetch_array($id2);
	$server = $werte2["defaultserver"];
	if ($server != "0")
	{
		$id3 = db_query("select ip, cuser, cpassword, port from bmysql where KeyServer='$server'");
		$werte3 = db_fetch_array($id3);
		$db_host=$werte3["ip"];
		$db_user=$werte3["cuser"];
		$db_pass=$werte3["cpassword"];
		# $db_port=$werte["port"];
	}
	
	
	if (!@mysql_connect($db_host, $db_user, $db_pass))
	{
		include("../settings.inc.php");
		db_query("update bdefault set defaultserver=0");
	}
	else
	{
		mysql_select_db($db_db);
		$id2 = db_query("SELECT userprefix FROM admin");
		$werte2 = db_fetch_array($id2);
		$user_prefix = $werte2["userprefix"];
	}
}

//*
if($id = db_query("select hostname from admin", false))
{
	$werte = db_fetch_array($id);
	if($werte['hostname'])
	{
		$hostname = $werte['hostname'];
	}
}
//*/


if(!$postconf && !isset($PostConfPage))
{
    db_close();
    include("postconf.php");
    exit(0);
}

if($confixx_interface_version != 'classic20')
{
	include_once('gui/module.GuiXP.php');
	$gui = new tGuiXP($strSkinName); // trailing slash !!!
}

db_close();

?>
