<?
########## 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");

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

$id = safe_query( "select frontpage from anbieter where anbieter = ? ", TRUE, new SQLString( $PHP_AUTH_USER ) );
$werte = db_fetch_array($id);
$skfrontpage = $werte["frontpage"];

if ($skfrontpage < 1)
	{
	 $fehlertext = ltext("kufrup_error1");
	 db_close();
	 include("kunden_start.php");
	 exit();
	}

if ($rmpwht == "nein") 
	{
	 $fehlertext = ltext("kufrup_error2");
	 $fehlertitel = ltext("kufrup_errortitle1");
	 db_close();
	 include("kunden_frontpage.php");
	 exit();
	}

$id = safe_query( "select frontpage, domain from domains where kunde = ?  and richtigedomain='3' and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
$werte = db_fetch_array($id);
$frontpage = $werte["frontpage"];
$domain = $werte["domain"];

if (db_num_rows($id) < 1)
	{
	 echo db_num_rows($id);
	 echo $kunde;
	 echo $PHP_AUTH_USER;
	 echo $frontpage;
	 $fehlertext = ltext("kufrup_error3");
	 db_close();
	 include("kunden_frontpage.php");
	 exit();
	}

$id = safe_query( "select kunde from kunden where kunde = ?  and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
if (db_num_rows($id) < 1)
	{
	 db_close();
	 $fehlertext = ltext("kufrup_error4");
	 include("kunden_frontpage.php");
	 exit();
	}

$id = safe_query( "select pwschutz, fehlerseiten from kunden where kunde = ?  and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
$werte = db_fetch_array($id);
$pwschutz = $werte["pwschutz"];
$fehlerseiten = $werte["fehlerseiten"];

if (($frontpage == 0) && (($pwschutz == 1) || ($fehlerseiten == 1)))
	{
	if ($rmpwht == "ja") ##wenn fehlerseiten und pwschutz automatisch gelöscht werden sollen
		{
		 $delid = safe_query( "select pfad from fehlermeldungen where kunde = ?  and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
		 while ($delwerte = db_fetch_array($delid))
			{
			 $iid = safe_query( "select * from htaccess where pfad = ?  and kunde = ? ", TRUE, new SQLString( $pfad ), new SQLString( $kunde ) );
			 if (db_num_rows($iid) < 1)
				{
				 safe_query( "insert into htaccess (pfad, kunde) VALUES (  ? ,  ?  )", TRUE, new SQLString( $pfad ), new SQLString( $PHP_AUTH_USER ) );
				}
			}

 		 $delid = safe_query( "select pfad from pwschutz where kunde = ?  and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
		 while ($delwerte = db_fetch_array($delid))
			{
			 $iid = safe_query( "select * from htaccess where pfad = ?  and kunde = ? ", TRUE, new SQLString( $pfad ), new SQLString( $kunde ) );
			 if (db_num_rows($iid) < 1)
				{
				 safe_query( "insert into htaccess (pfad, kunde) VALUES (  ? ,  ?  )", TRUE, new SQLString( $pfad ), new SQLString( $PHP_AUTH_USER ) );
				}
			}
		 safe_query( "delete from pwschutz where kunde = ?  and anbieter = ? ", TRUE, new SQLString($kunde), new SQLString($PHP_AUTH_USER) );
		 safe_query( "delete from fehlermeldungen where kunde = ?  and anbieter = ? ", TRUE, new SQLString($kunde), new SQLString($PHP_AUTH_USER) );
		 safe_query( "update allgemein set htaccess='1'", TRUE );
		 safe_query( "update kunden set pwschutz='0', fehlerseiten='0' where kunde = ?  and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
		}
	else
		{
		 db_close();
		 $fehlertext = ltext("kufrup_error5", array($kunde));
		 include("kunden_frontpage.php");
		 exit();
		}
	}

$id = safe_query( "select domain from domains where kunde = ?  and anbieter = ?  and pfad='/' and (richtigedomain='0' or richtigedomain='1' or richtigedomain='2')", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
if (db_num_rows($id) < 1)
	{
	 db_close();
	 $fehlertext = ltext("kufrup_error6");
	 include("kunden_frontpage.php");
	 exit();
	}

if ($frontpage == 1)
	{
	 $id = safe_query( "select neu from frontpage where kunde = ? ", TRUE, new SQLString( $kunde ) );
	 $werte = db_fetch_array($id);
	 $fpneu = $werte["neu"];
 	 $id = safe_query( "select domain from domains where kunde = ?  and pfad = '/'", TRUE, new SQLString( $kunde ) );
	 while ($werte = db_fetch_array($id))
		{
		 $domain2 = $werte["domain"];
		 fpalias_aendern($domain2, "loeschen", $kunde);
		}

	 safe_query( "update domains set frontpage='0' where kunde = ?  and richtigedomain='3' and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
	 safe_query( "update kunden set frontpage='0' where kunde = ?  and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
	 if ($fpneu == 1)
		{
		 safe_query( "delete from frontpage where kunde = ? ", TRUE, new SQLString($kunde) );
		}
	 else
		{
		 safe_query( "update frontpage set loeschen='1', neu='0' where kunde = ? ", TRUE, new SQLString( $kunde ) );
		 safe_query( "update allgemein set frontpagedel='1', httpd='1'", TRUE );
		}
	 $fehlertext = ltext("kufrup_error7", array($kunde));
	}
else
	{
	 safe_query( "update domains set frontpage = '1' where kunde = ?  and richtigedomain='3' and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
	 safe_query( "update kunden set frontpage='1' where kunde = ?  and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
	 $id = safe_query( "select domain from domains where kunde = ?  and pfad = '/'", TRUE, new SQLString( $kunde ) );
	 while ($werte = db_fetch_array($id))
		{
		 $domain2 = $werte["domain"];
		 fpalias_aendern($domain2, "anlegen", $kunde);
		}
	 $pwclear = mkpasswd(8);
	 $fpid = safe_query( "select kunde from frontpage where kunde = ? ", TRUE, new SQLString( $kunde ) );
	 if (db_num_rows($fpid) > 0)
		{
		 safe_query( "update frontpage set loeschen='0' where kunde = ?  and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
		}
	 else
		{
		 safe_query( "insert into frontpage (kunde, benutzer, passwort, domain, neu, loeschen, anbieter) VALUES (  ? ,  'frontpage',  ? ,  ? ,  '1',  '0',  ?  )", TRUE, new SQLString( $kunde ), new SQLString( $pwclear ), new SQLString( $domain ), new SQLString( $PHP_AUTH_USER ) );
		 safe_query( "update allgemein set frontpageadd='1', httpd='1'", TRUE );
		}
	 $fehlertext = ltext("kufrup_error8",array($kunde,$domain,$pwclear));
	}

db_close();
$fehlertitel = ltext("kufrup_errortitle1");
include("kunden_frontpage.php");
?>
