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

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

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



if ($ueberschreiben == "nein")

        {

         safe_query( "update anbieter set dnsspezial = ?  where anbieter = ? ", TRUE, new SQLString( $zusatz ), new SQLString( $anbieter ) );

        }

if ($ueberschreiben == "ja") {

	safe_query( "update anbieter set dnsspezial = ?  where anbieter = ? ", TRUE, new SQLString( $zusatz ), new SQLString( $anbieter ) );

	# extract all required data

	## ns
	$id       = safe_query( "select pns, sns from anbieter where anbieter = ? ", TRUE, new SQLString( $anbieter ) );
	$werte    = db_fetch_array($id);
	$pns      =  $werte["pns"];
	$sns      =  $werte["sns"];
	## /ns

	## ip
	$id       = safe_query( "select standardip from anbieter where anbieter = ? ", TRUE, new SQLString( $anbieter ) );
	$werte    = db_fetch_array($id);
	$standard_ip       =  $werte["standardip"];

	$kunde_ips = array();
	$id       = safe_query( "select kunde,ip from ipadressen where anbieter = ? ", TRUE, new SQLString( $anbieter ) );
	while ($werte    = db_fetch_array($id)) {
		$kunde_ips[$werte['kunde']] = $werte['ip'];
	}
	
	## /ip

	$pnsdom = substr ($pns,(strpos ($pns, ".")+1));
	$snsdom = substr ($sns,(strpos ($sns, ".")+1));

	$id       = safe_query( "select ip_pns,ip_sns from admin", TRUE );
	$werte    = db_fetch_array($id);
	$ip_pns   =  $werte["ip_pns"];
	$ip_sns   =  $werte["ip_sns"];

	$id = safe_query( "select domain, kunde, lastchange from dns where anbieter = ? ", TRUE, new SQLString( $anbieter ) );

	while ($werte = db_fetch_array($id)) 
	{
		$domain     = $werte["domain"];
		$kunde      = $werte["kunde"];
		$lastchange = $werte["lastchange"];

		## serial
		$sn_date = substr ($lastchange, 0, 8);
		if($sn_date != date("Ymd")) {
			$seriennummer = date("Ymd")."01";
		} else {
			$sn_id = substr ($lastchange, -2)+1;
			if(strlen($sn_id)==1) {
				$sn_id="0".$sn_id;
			}
			$seriennummer = date("Ymd").$sn_id;
		}
		## /serial

		## domain
		$zonefile = str_replace ("##domain##", $domain, $zusatz);
		## /domain
		
		$ip       =  $kunde_ips[$kunde] ? $kunde_ips[$kunde] : $standard_ip;

		$zonefile = str_replace ("##ip##", $ip, $zonefile);
		
		$zonefile = str_replace ("##ns1##", $pns, $zonefile);
		$zonefile = str_replace ("##ns2##", $sns, $zonefile);

		if($snsdom == $domain){
			$zonefile = $sns.".      86400  IN   A         ".$ip_sns."\n".$zonefile;
		}
		if($pnsdom == $domain){
			$zonefile = $pns.".      86400  IN   A         ".$ip_pns."\n".$zonefile;
		}
		## /glue record

		safe_query( "update dns set zonefile = ? , lastchange = ? , neu = '1' where domain = ? ", TRUE, new SQLString( $zonefile ), new SQLInteger( $seriennummer ), new SQLString( $domain ) );
	}

	safe_query( "update allgemein set dns='1'", TRUE );

}

db_close();



$fehlertitel = ltext("eihtanaesp_errortitle1");

$fehlertext = ltext("eihtanaesp_error1");


include("einstellungen_dnsspezial_anbieter_aendern.php");

?>
