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

include_once( "../include/class.SQLString.php" );
include_once("auth.php");

$timestamp = time();
## mysql verbindung aufbauen
db_connect($db_host, $db_user, $db_pass);
## /mysql verbindung aufbauen

$domain = strtolower($domain);

## Richtige Eingabe?
if (istleer($domain))
	{
	 $fehlertext = ltext("todoae2_error1");
	 db_close();
	 include("tools_domains_aendern.php");
	 exit();
	}

if ((ereg(" ", $domain)) || (ereg(" ", $pfad)))
	{
	 $fehlertext = ltext("todoae2_error2");
	 db_close();
	 include("tools_domains_aendern.php");
	 exit();
	}

if (istleer($pfad))
	{
	 $fehlertext = ltext("todoae2_error3");
	 db_close();
	 include("tools_domains_aendern.php");
	 exit();
	}
 
if ( ereg("[\n\t\r]", $pfad) )
	{
	 $fehlertext = ltext("todoae2_error4");
	 db_close();
	 include("tools_domains_aendern.php");
	 exit();
	}
		
if (((ereg("[.]{2}", $pfad)) || (ereg("[^_a-zA-Z0-9./~-]", $pfad))) && (!ereg("^http[s]?://", $pfad)))
	{
	 $fehlertext = ltext("todoae2_error4");
	 db_close();
	 include("tools_domains_aendern.php");
	 exit();
	}

if ((!ereg("^/", $pfad)) && (!ereg("^http[s]?://", $pfad)))
	{
	 $fehlertext = ltext("todoae2_error5");
	 db_close();
	 include("tools_domains_aendern.php");
	 exit();
	}

if (ereg("[\\]", $pfad))
	{
	 $fehlertext = ltext("todoae2_error6");
	 db_close();
	 include("tools_domains_aendern.php");
	 exit();
	}

$pfad2 = str_replace("http://", "", $pfad);
$pfad2 = str_replace("https://", "", $pfad2);
if (ereg("/$", $pfad2))
	{
	 $pfad2 = substr($pfad2, 0, -1);
	}
if ($domain == $pfad2)
	{
	 $fehlertext = ltext("todoae2_error7");
	 db_close();
	 include("tools_domains_aendern.php");
	 exit();
	}

# existiert die domain
$loUser = new SQLString( $PHP_AUTH_USER );
$loDomain = new SQLString( $domain );
$id = safe_query2( "SELECT domain FROM domains WHERE domain = ?  and kunde = ? ",  $loDomain, $loUser );
if (db_num_rows($id) < 1)
	{
	 $fehlertext = ltext("todoae2_error8",array($domain));
	 db_close();
	 include("tools_domains_aendern.php");
	 exit();
	}
# /existiert die domain?


#if fp then testen ob mindestens eine domain mit (pfad = '/')
$id = safe_query2( "SELECT domain FROM domains WHERE kunde = ?  and frontpage=1", $loUser );
if (db_num_rows($id) > 0) #dann hat kunde fp
	{
	 $id = safe_query2( "SELECT domain FROM domains WHERE kunde = ?  AND pfad='/' ".
											" AND (richtigedomain = 0 or richtigedomain =1 or richtigedomain=2)", $loUser );
	 if ((db_num_rows($id) < 1) && ($pfad != '/'))
		{
		 $fehlertext = ltext("todoae2_error9");
		 db_close();
		 include("tools_domains_aendern.php");
		 exit();
		}
	}
#/if fp then testen ob mindestens eine domain mit (pfad = '/')

if ((ereg("/$",$pfad)) && ($pfad != "/") && (ereg("^/", $pfad))) { $pfad = substr($pfad,0,-1); }

fpalias_aendern($domain, "loeschen", $PHP_AUTH_USER);
if (($ssl == 1) || ($ssl == 2)) $sslquery = ", cssl=$ssl";
safe_query2( "UPDATE domains SET pfad=?, lastchange=$timestamp $sslquery where kunde=? and domain=? and frontpage=0",
						 new SQLString($pfad), $loUser, $loDomain );
fpalias_aendern($domain, "anlegen", $PHP_AUTH_USER);
safe_query( "UPDATE allgemein set httpd=1", TRUE );

$pfad = ""; #reset, damit nicht auf tools_domains.php angezeigt wird

$fehlertext = ltext("todoae2_error10",array($domain));
$fehlertitel = ltext("todoae2_error11");
db_close();
include("tools_domains.php");

?>
