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

include_once("auth.php");
db_connect($db_host, $db_user, $db_pass);
## login prüfen
if (ereg("[^0-9A-Za-z]", $newlogin))
{
	$fehlertext = ltext("alpw2_error6");
	include("allgemein_pwaendern.php");
	exit();
}

if ((strlen($newlogin) > 27) || (strlen($newlogin) < 3))
{
	$fehlertext = ltext("alpw2_error7");
	include("allgemein_pwaendern.php");
	exit();
}

if($newlogin != $PHP_AUTH_USER)
{
	$user_exists = false;
	$id = db_query("SELECT COUNT(*) AS cnt FROM kunden WHERE kunde='$newlogin'");
	$res = db_fetch_array($id);
	if($res['cnt'])
	{
		$user_exists = true;	
	}
	
	if(!$user_exists)
	{
		$id = db_query("SELECT COUNT(*) AS cnt FROM anbieter WHERE anbieter='$newlogin'");
		$res = db_fetch_array($id);
		if($res['cnt'])
		{
			$user_exists = true;	
		}
	}
	
	if(!$user_exists)
	{
		$id = db_query("SELECT COUNT(*) AS cnt FROM pop3 WHERE account='$newlogin'");
		$res = db_fetch_array($id);
		if($res['cnt'])
		{
			$user_exists = true;	
		}
	}
	
	if($user_exists)
	{
		db_close();
		$fehlertext = ltext("alpw2_error?");
		include("allgemein_pwaendern.php");
		exit();
	}
	
}

if ((istleer($neupw1)) && (istleer($neupw2)))
{
	db_query("update admin set login = '$newlogin'");
	db_query("update kunden set pw='1'");
	db_query("update allgemein set webalizerpw='1'");
	$fehlertitel = ltext("alpw2_errortitle");
	$fehlertext = ltext("alpw2_error5");
	deleteSUser($PHP_AUTH_USER);
	addSUser($newlogin, '', USERTYPE_ADMIN);
	db_close();
	header("Location: ./allgemein_pwaendern.php?fehlertext=".urlencode($fehlertext)."&fehlertitel=".urlencode($fehlertitel));
	exit();
}

## passwort prüfungen
if(!checkAdminLogin($PHP_AUTH_USER, $altpw))
{
	db_close();
	$fehlertext = ltext("alpw2_error1");
	include("allgemein_pwaendern.php");
	exit();
}

if ($neupw1 != $neupw2)
{
	db_close();
	$fehlertext = ltext("alpw2_error3");
	include("allgemein_pwaendern.php");
	exit();
}

if (!valid_pw($neupw1))
{
	db_close();
	$fehlertext = ltext("alpw2_error4");
	include("allgemein_pwaendern.php");
	exit();
}
## // passwort prüfungen

$neupw = crypt_pw($neupw1);
db_query("update admin set longpw = '$neupw', login = '$newlogin'");
db_query("update kunden set pw='1'");
db_query("update allgemein set webalizerpw='1'");

$def_user = $user_prefix . '0';

$id = db_query("select statistik from kunden where kunde='$def_user'");
if(db_num_rows($id))
{
	$werte = db_fetch_array($id);
	$statistik = $werte["statistik"];
	
	if (($statistikpwaendern == "yes") || ($statistik != "1"))
	{
		db_query("update kunden set longpw = '$neupw', pw=1, statistiklongpw='$neupw' where kunde = '$def_user'");
	}
	else
	{
		db_query("update kunden set longpw = '$neupw', pw=1 where kunde = '$def_user'");
	}
	db_query("update allgemein set newpwd='1'");
	db_query("update anbieter set longpw = '$neupw' where anbieter = 'res0'");
}
$fehlertitel = ltext("alpw2_errortitle");
$fehlertext = ltext("alpw2_error5");
deleteSUser($PHP_AUTH_USER);
addSUser($newlogin, '', USERTYPE_ADMIN);
db_close();
header("Location: ./allgemein_pwaendern.php?fehlertext=".urlencode($fehlertext)."&fehlertitel=".urlencode($fehlertitel));
?>
