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


//
//  wws:debug
//
//apd_set_pprof_trace();
global $DEBUG;
$DEBUG = 0;
//
if ($DEBUG) echo "kunden_domain_upd.php<br>\n";
//
//

include_once("auth.php");
include_once("../include/module.Database.php");
include_once("../include/class.Cond.php");
include_once("../include/class.Data.php");
include_once("../include/class.Page.php");
include_once("../events.inc.php");
include_once("../include/event_functions.php");
include_once("../include/module.DNSTemplate.php");

$timestamp = time();

$datenausdbholen3 = "nein"; # damit die daten bei einem erneuten aufruf des vorherigen formulars nicht wieder aus der datenbank geholt werden.

if ( !is_array($domain) ){
  $fehlertext = ltext("kudoup_error0");
  include("kunden_neu4.php");
  exit();
}

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

$id = db_query("select standarddomain, idn from admin");
$werte = db_fetch_array($id);
$stddomain = $werte["standarddomain"];
$idn_support = $werte["idn"];

## überprüfen, ob kunde existiert und dem anbieter gehört

$loUser = new SQLString($PHP_AUTH_USER);
$loKunde = new SQLString($kunde);
$id = safe_query2( "SELECT kunde FROM kunden WHERE kunde=? AND anbieter=?", $loKunde, $loUser);
$zeilen = db_num_rows($id);
if ($zeilen <> 1) {
  $fehlertext = ltext("kudoup_error1");
  db_close();
  include("kunden_aendern.php");
  exit();
}
## /überprüfen, ob kunde existiert und dem anbieter gehört

$id = safe_query2( "SELECT frontpage, cssl FROM anbieter WHERE anbieter=?", $loUser);
$werte = db_fetch_array($id);
$skfrontpage = $werte["frontpage"];
$skssl = $werte["cssl"];

####### domains checken
## neue domains des kunden ermitteln


if ( $DEBUG ) {
	echo "domains:<br>\n";
	print_r($domain);
	echo "<hr>domdns:<br>\n";
	print_r($domdns);
	echo "<hr>domdnr:<br>\n";
	print_r($domdnr);
	echo "<hr>$old_ip -> $ip<br>\n";
}

# standardip holen
$id = safe_query2( "SELECT standardip FROM anbieter WHERE anbieter = ?", $loUser);
$werte = db_fetch_array($id);
$stdip = $werte["standardip"];
#/standardip holen

$new_ip = ( $ip == 'standard' )? $stdip: $ip;

if ( !$old_ip ){
	$id = safe_query2( "SELECT ip FROM kunden WHERE kunde=?", $loKunde);
	list($old_ip) = db_fetch_array($id);
	if( !$old_ip ){
		$old_ip = $stdip;
	}
}

include_once('module.Informer.php');
$domIndex = array();
$ga_WrongIdnDomains = array();

while ( list($key,$val) = each( $domain ) ) {
	$val = strtolower(trim($val));
	if ( $val ) {
		$ga_OriginalName[$key] = $val;
		// check if international and then translate
		$ls_DomainOrig = $val;
		include_once('class.InputDecode.php');
		$ls_DomainTranslated = InputDecode::decode($ls_DomainOrig);

		$hasNonAscii = preg_match('/[^\x00-\x7f]/',$ls_DomainOrig);

		if ( $hasNonAscii || $ls_DomainOrig != $ls_DomainTranslated ) {
			if ( $idn_support) {
			// has national characters
				include_once('idn_functions.php');
				$ls_Domain = translate_name_to_idn($ls_DomainTranslated); 
				$ga_NationalName[$key] = $ls_DomainTranslated;	// save the national name
			
			} else {
			// has national characters, but there are no IDN support
			// try to get name from database
				$res_idn = safe_query2( "SELECT d.domain FROM domains d, idn_aliases idn WHERE ".
														"idn.domain_id = d.id AND idn.idn_name = ?", new SQLString( $ls_DomainTranslated ) );
				if (db_num_rows($res_idn) > 0) {
					$row_idn = db_fetch_array($res_idn);
					$ls_Domain = $row_idn["domain"];
				} else {
					// the domain is not registered in db => new domain
					$ga_WrongIdnDomains[] = $ls_DomainOrig;
				}
				db_close($res_idn);
			}
		} else {
			$ls_Domain = $ls_DomainOrig;
		}
		// store ascii-translated name here
		$domIndex[$ls_Domain]=$key;
	}
}

$neuedomains=array_keys($domIndex);

## aktuelle domains des kunden ermitteln
$sql="SELECT d.id, d.domain, d.dns, d.dnr, dns.neu, not(dns.kunde IS NULL) AS dns_inserted, ".
	" maillist.id AS maillist_id, maillist.name AS maillist_name FROM domains d ".
	" LEFT JOIN dns ON dns.domain=d.domain AND dns.kunde=d.kunde ".
	" LEFT JOIN maillist ON maillist.domain_id=d.id AND maillist.neu <> 3 ".
	" WHERE d.richtigedomain = 1 AND d.kunde = ? AND d.anbieter=?";

$id = safe_query2($sql, $loKunde, $loUser);
$altedomains = array();
$registered = array();
$maillists = array();
$mlNames = array();
while($werte = db_fetch_array($id)){
  
  $curDomain=trim($werte["domain"]);

  if ( !in_array( $curDomain, $altedomains ) )
    $altedomains[] = $curDomain;

  if ( $werte["maillist_id"] ){
    $maillists[$curDomain][] = $werte["maillist_id"];
    $mlNames[$werte["maillist_id"]] = array($werte["maillist_name"], $curDomain);
  }

  if ( $ind = $domIndex[$curDomain] ) {
    $dns = $domdns[$ind] || 0;
    $dnr = $domdnr[$ind] || 0;

    if ( $werte["dnr"] )
      $registered[] = $ind;

    if ( $werte["neu"] == 2 ) {
//
// wird geloescht
//
      if ($dns || $dnr){
				$addDnsDomains[]=$curDomain;
      }      
    }elseif ( $dns ){
			$addDnsDomains[] = $curDomain;
    }elseif ( !$dns && $werte["dns_inserted"] ){
			$delDnsDomains[] = $curDomain;
    }
  }
}


## //

## ip muss bleiben, wenn kunde ssl benutzt
if ($exklusiv == 0)	{
  $id = safe_query2( "SELECT cssl FROM domains WHERE kunde=? AND anbieter=? and cssl=1", $loKunde, $loUser);
  if (db_num_rows($id) > 0)	{
    $fehlertext = ltext("kudoup_error2");
    db_close();
    include("kunden_neu4.php");
    exit();
  }
}
## //

## herausfinden welche domains neu hinzukommen
for ($i = 0;$i < count($neuedomains);$i++){
  $curDomain=$neuedomains[$i];
  if(!in_array($curDomain,$altedomains)){
    $domainsanlegen[] = $curDomain;
    if($ind=$domIndex[$curDomain]){
      $dns = $domdns[$ind]?$domdns[$ind]:0;
      $dnr = $domdnr[$ind]?$domdnr[$ind]:0;
      if ($dns || $dnr){
				$addDnsDomains[]=$curDomain;
      }
    }
  }
}


## herausfinden welche domains gelöscht werden
$domainsloeschen = array();
$delMaillists = array();
for ($i = 0;$i < count($altedomains);$i++){
  $curDomain=$altedomains[$i];
  $ind=$domIndex[$curDomain];
  if (!in_array($curDomain,$neuedomains) || $domdel[$ind]){

    $domainsloeschen[] = $curDomain;
    $delDnsDomains[]=$curDomain;
    if ( is_array($maillists[$curDomain]) )
      $delMaillists = array_merge ( $delMaillists, $maillists[$curDomain] );
  }
}

## prüfen, ob anbieter noch so viele domains hinzufügen darf
$anzahlneuedomains = count($domainsanlegen);
$anzahldeldomains = count($domainsloeschen);

$anzahlneuedomains -= $anzahldeldomains;

$idx = safe_query2( "SELECT maxdomains, maxdomainslimit, httpdspezial FROM anbieter ".
										"WHERE anbieter=?", $loUser);
$wertex = db_fetch_array($idx);
$maxdomains = $wertex["maxdomains"];
$maxdomainslimit = $wertex["maxdomainslimit"];
$httpdspezial = $wertex["httpdspezial"];

$idx = safe_query2( "SELECT COUNT(domain) AS anzahldomains FROM domains ".
										" WHERE anbieter=? AND richtigedomain=1", $loUser );
$wertex = db_fetch_array($idx);
$anzahldomains = $wertex["anzahldomains"];
$gesamtdomains = $anzahldomains + $anzahlneuedomains;

if (($gesamtdomains > $maxdomains) && ($maxdomainslimit == "1") && ($maxdomains <> "-1")){
  $fehlertext = ltext("kudoup_error3",array($maxdomains,$anzahldomains));
  db_close();
  include("kunden_neu4.php");
  exit();
}
## // prüfen, ob anbieter noch so viele domains hinzufügen darf

## herausfinden, ob die neu angelegten domains ok sind
## sind die neu angelegten domains schon vorhanden?
for ($i = 0;$i < count($domainsanlegen);$i++){
  $domainname = $domainsanlegen[$i];
  if (!istleer($domainname))	{
    $id = safe_query2( "SELECT domain FROM domains WHERE domain = ?", new SQLString($domainname) );
    if (db_num_rows($id) > 0){
      $domainschonda .= $domainname.", ";
    }
  }
}
if (!istleer($domainschonda)){
  $domainschonda = substr($domainschonda, 0, - 2);
  $fehlertext = ltext("kudoup_error4",array($domainschonda));
  db_close();
  include("kunden_neu4.php");
  exit();
}
## /sind die neu angelegten domains schon vorhanden?

## stimmt die syntax der neu angelegten domains?
for ($i = 0;$i < count($domainsanlegen);$i++){
  $domainname = trim($domainsanlegen[$i]);
  if ((!ereg("\.", $domainname)) || (ereg("([^a-z0-9.-])|([.]{2})", $domainname)) || 
      (ereg("^-", $domainname)) || (ereg("^www\.", $domainname))){
    $fehlerhaftedomains .= $domainname.", ";
  }
}

$fehlerhaftedomains = substr($fehlerhaftedomains, 0, - 2);

if (!istleer($fehlerhaftedomains) || sizeof($ga_WrongIdnDomains) > 0) {
	if (!istleer($fehlerhaftedomains)) {
		$fehlertext .= ltext("kune5_error19", array($fehlerhaftedomains));
	}
	if (sizeof($ga_WrongIdnDomains) > 0) {
		$fehlertext .= ltext('error_bad_domains__no_idn_support', array(implode(', ', $ga_WrongIdnDomains)));
	}
	db_close();
	include("kunden_neu4.php");
	exit();
}
	
$dname_regexp = "/${user_prefix}[0-9]+\." . str_replace('.', '\.', $stddomain) . "/i";
$badomains = array();
if(is_array($domainsanlegen)){
  foreach($domainsanlegen as $dname){
    $dname = trim($dname);
    if(preg_match($dname_regexp, $dname)){
      $badomains[] = $dname;
    }
  }
}

if(count($badomains)){
  $fehlertext = ltext("kune5_error23", array(implode(", ", $badomains), $user_prefix, $stddomain));
  db_close();
  include("kunden_neu4.php");
  exit();	
}
	
	
## /stimmt die syntax der neu angelegten domains?
## //

## subdomains ermitteln die gelöscht werden
for ($i = 0;$i < count($domainsloeschen);$i++){
  $suchdomain = trim($domainsloeschen[$i]);
  $id = safe_query2( "SELECT domain FROM domains WHERE kunde = ? and anbieter=? AND domain LIKE ?",
										 $loKunde, $loUser, new SQLString('%.$suchdomain') );
  while ($werte = db_fetch_array($id)){
    $subdomainsloeschen[] = $werte["domain"];
  }
}
##//



## emails ermitteln die gelöscht werden
$delAtDomains = array();
for ($i = 0;$i < count($domainsloeschen);$i++){
  $domain = trim($domainsloeschen[$i]);
	$loDomain = new SQLString( $domain );
  $id = safe_query2( "SELECT ident, prefix, domain FROM email WHERE kunde = ? AND domain = ? AND anbieter=?",
										 $loKunde, $loDomain, $loUser );
  while ($werte = db_fetch_array($id)){
    $emailsloeschenident[] = $werte["ident"];
    $emailsloeschenemail[] = $werte["prefix"]."@".$werte["domain"];
  }
  $id = safe_query2( "SELECT atdomains.id FROM domains, atdomains WHERE domains.domain=? ".
										 "AND domains.kunde=? AND domains.anbieter=? ".
										 "AND domains.id=atdomains.id_from", $loDomain, $loKunde, $loUser  );
  while ( $werte = db_fetch_array($id) )
    $delAtDomains[] = $werte["id"];
}

for ($i = 0;$i < count($subdomainsloeschen);$i++){
  $domain = trim($subdomainsloeschen[$i]);
  $id = safe_query2( "SELECT ident, prefix, domain FROM email WHERE kunde = ? AND domain = ? AND anbieter=?",
									$loKunde, new SQLString($domain), $loUser );
  while ($werte = db_fetch_array($id)){
    $emailsloeschenident[] = $werte["ident"];
    $emailsloeschenemail[] = $werte["prefix"]."@".$werte["domain"];
  }
}
## //

for ($i = 0;$i < count($domainsanlegen);$i++){
  if (!istleer(trim($domainsanlegen[$i]))){
    $domainsanlegen2[] = trim($domainsanlegen[$i]);
  }
}

for ($i = 0;$i < count($domainsloeschen);$i++){
  if (!istleer(trim($domainsloeschen[$i]))){
    $domainsloeschen2[] = trim($domainsloeschen[$i]);
  }
}

if (($action == "jetzt") || ((count($domainsloeschen2) == 0) && (count($domainsanlegen2) == 0))) { 
## update ausführen


## ip adresse anlegen bzw. löschen
  if ($ip != "standard"){
		$loIP = new SQLString( $ip );
    $id = safe_query2( "SELECT ip FROM ipadressen WHERE anbieter=? AND ip=? AND (kunde='' OR kunde=?)",
											 $loUser, $loIP, $loKunde);
    if (db_num_rows($id) < 1){
      $fehlertext = ltext("kudoup_error6");
      db_close();
      include("kunden_neu4.php");
      exit();		
    } else {
      if ($exklusiv == 1){
        $id = safe_query2( "SELECT ip FROM kunden WHERE ip = ? AND kunde != ?", $loIP, $loKunde );
        if (db_num_rows($id) > 0){
          $fehlertext = ltext("kudoup_error7");
          db_close();
					include("kunden_neu4.php");
					exit();		
        }
        safe_query2( "UPDATE ipadressen SET kunde = '' WHERE kunde = ? AND anbieter=?", $loKunde, $loUser );
        safe_query2( "UPDATE ipadressen SET kunde = ? WHERE ip = ? AND anbieter=? AND kunde=''", $loKunde, $loIP, $loUser);
      } else {
        safe_query2( "UPDATE ipadressen SET kunde = '' WHERE kunde = ?", $loKunde );
      }
    }
  } else {
    $ip = $stdip;
		$loIP = new SQLString( $ip );
    safe_query2( "UPDATE ipadressen SET kunde = '' WHERE kunde = ?", $loKunde );
  }


## /ip adresse anlegen bzw. löschen

## domains löschen & emails löschen


  for ($i=0;$i<count($domainsloeschen);$i++){
    $domain = $domainsloeschen[$i];
		$loDomain = new SQLString( $domain );

    db_query( "UPDATE allgemein SET dns=1" );
    domain_aendern($domain, "loeschen", $kunde);
    fpalias_aendern($domain, "loeschen", $kunde);
	
    $res = safe_query2( "SELECT id FROM domains WHERE domain = ? and kunde = ? and anbieter=?", $loDomain, $loKunde, $loUser);
		$row = db_fetch_array($res);
		$domain_id = $row['id'];
		db_close($res);

		safe_query2( "DELETE FROM idn_aliases WHERE domain_id=$domain_id");
    safe_query2( "DELETE FROM domains WHERE domain = ? AND kunde = ? AND anbieter=?", $loDomain, $loKunde, $loUser);
    $timestamp = time();
  
    $eID = safe_query2( "SELECT prefix, domain, ident, neu FROM email WHERE domain = ? ".
											 " AND kunde = ? AND anbieter=? AND neu = 0", $loDomain, $loKunde, $loUser );
    while ($eWERTE = db_fetch_array($eID)){
			$eident = $eWERTE["ident"];
      if ( $eWERTE["neu"]==0 ){
        $eaccount = $eWERTE["prefix"];
        $epfad = $eWERTE["domain"];
        safe_query2( "INSERT INTO delaccs (account, type, kunde, pfad) VALUES (?, 'alias', ?, ?)",
										 new SQLString( $eaccount ), $loKunde, new SQLString( $epfad ) );
      }
      safe_query2( "DELETE FROM autoresponder WHERE ident = ? AND kunde = ?",
								new SQLString($eident), $loKunde );
    }
    
    safe_query2("delete FROM email WHERE domain = ? AND kunde = ? AND anbieter=?", $loDomain, $loKunde, $loUser);
    
  }

  if ( count($delAtDomains) )
    safe_query2( "DELETE FROM atdomains WHERE id IN ( " . implode( ",", $delAtDomains ) . " )" );


  for ($i=0;$i<count($delDnsDomains);$i++){
    $domain=$delDnsDomains[$i];
    safe_query2( "UPDATE dns SET neu=2 WHERE domain=? AND kunde=? AND anbieter=?",
								 new SQLString($domain), $loKunde, $loUser );
  }
	db_query("UPDATE allgemein SET dns=1");

  for ($i=0;$i<count($subdomainsloeschen);$i++){

    $domain = $subdomainsloeschen[$i];
		$loDomain = new SQLString( $domain );

    domain_aendern($domain, "loeschen", $kunde);
    fpalias_aendern($domain, "loeschen", $kunde);
	
    $res = safe_query2( "SELECT id FROM domains WHERE domain = ? AND kunde = ? AND anbieter=?",
												$loDomain, $loKunde, $loUser);
		$row = db_fetch_array($res);
		$subdomain_id = $row['id'];
		db_close($res);
	
		db_query("DELETE FROM idn_aliases WHERE domain_id=$subdomain_id");
    safe_query2( "DELETE FROM domains WHERE domain = ? AND kunde = ? AND anbieter=?", $loDomain, $loKunde, $loUser );
    
    $eID = safe_query2( "SELECT prefix, domain, ident FROM email WHERE domain = ? ".
												" AND kunde = ? AND anbieter=? AND neu = 0", $loDomain, $loKunde, $loUser );
    
    safe_query2( "DELETE FROM email WHERE domain = ? AND kunde = ? AND anbieter=?", $loDomain, $loKunde, $loUser );

    while ($eWERTE = db_fetch_array($eID)){
      $eaccount = $eWERTE["prefix"];
      $epfad = $eWERTE["domain"];
    
      safe_query2( "INSERT INTO delaccs (account, type, kunde, pfad) VALUES (?, 'alias', ?, ? )",
									 new SQLString($eaccount), $loKunde, new SQLString($epfad));
    }
  }
## domains anlegen

  for ( $i=0; $i<count($domainsanlegen); $i++ ) {
    $domain = $domainsanlegen[$i];
		$loDomain = new SQLString( $domain );
		$loHttpdSpec = new SQLString($httpdspezial);

    if (!istleer($domain)){
      $index = $domIndex[$domain];
			$nat_name = $ga_NationalName[$index];
	  
      $dns=$domdns[$index]?$domdns[$index]:0;
      $dnr=$domdnr[$index]?$domdnr[$index]:0;
     
      
      $sql = "INSERT INTO domains (domain, kunde, anbieter, richtigedomain, pfad, lastchange, zusatz, dns, dnr)".
				" VALUES (?, ?, ?, 1, '/', $timestamp, ?, $dns, $dnr )";

      $res1 = safe_query2( $sql, $loDomain, $loKunde, $loUser, $loHttpdSpec);
      global $db_type;
      if($db_type=='mysql'){
				$id1  = db_insert_id($res1);
      }else{
				$id1  = db_insert_id('domains','id');
      }
      db_close($res1);
	  
      domain_aendern($domain, "anlegen", $kunde);
      fpalias_aendern($domain, "anlegen", $kunde);


      $sql = "INSERT INTO domains (domain, kunde, anbieter, richtigedomain, pfad, lastchange, zusatz, dns, dnr)".
				" VALUES ( ?, ?, ?, 2, '/', '$timestamp', ?, 0, 0)";

      $res2 = safe_query2($sql,new SQLString('www.'.$domain), $loKunde, $loUser, $loHttpdSpec);
      if($db_type=='mysql'){
				$id2  = db_insert_id($res2);
      }else{
				$id2  = db_insert_id('domains','id');
      }
      db_close($res2);
      domain_aendern("www.".$domain, "anlegen", $kunde);
      fpalias_aendern("www.".$domain, "anlegen", $kunde);

			if ($nat_name) {
				include_once('idn_functions.php');
				save_idn_alias($id1, $nat_name, false);
				save_idn_alias($id2, "www.$nat_name", false);
			}
    }
  }

	if( file_exists("../dnr.php") ) {
		include_once("../dnr.php");
		$dnrGo = 1;

	} else {
		$dnrGo = 0;
	}

#	global $dnr_c_firstname,$dnr_c_gender,$dnr_c_plz,$dnr_c_land,$dnr_c_name,$dnr_c_firma,
#		$dnr_c_anschrift,$dnr_c_ort,$dnr_c_telefon,$dnr_c_telefax,$dnr_c_emailadresse,
#		$dnr_d_domain,$dnr_d_pns,$dnr_d_sns;
#
#	global $dnr_a_firstname,$dnr_a_gender,$dnr_a_plz,$dnr_a_land,$dnr_a_name,$dnr_a_firma,
#		$dnr_a_anschrift,$dnr_a_ort,$dnr_a_telefon,$dnr_a_telefax,$dnr_a_emailadresse;
	
	if ( $DEBUG ) {
		echo "addDnsDomains:<br>\n";
		print_r($addDnsDomains);
		echo "<hr>\n";
	}

  for($i=0;$i<count($addDnsDomains);$i++){

		$domain=$addDnsDomains[$i];
		$ind=$domIndex[$domain];


		if ($ind){
			$dns=$domdns[$ind]?$domdns[$ind]:0;
			$dnr=$domdnr[$ind]?$domdnr[$ind]:0;
      
                 ## dns eintrag erstellen
			if ($dns == 1 || $dnr == 1 || $dnr == 2) {

				list( $zonefile, $seriennummer ) = ff_ProcessTemplate ( $PHP_AUTH_USER, $domain, $ip,
																																NULL, $dnstemplate, $pns,	$sns );

//
// pruefen gibt's shon oder nein
//
// field "domain" is primary key
//
				$sql = "SELECT zonefile,neu FROM dns WHERE domain=?";
				$id = safe_query( $sql, TRUE, $loDomain);
	
				$loZone = new SQLString($zonefile);

				if ( db_num_rows($id) > 0 ) {
					$werte = db_fetch_array($id);
					if ( $DEBUG ) {
						echo "$old_ip == $new_ip<br>\n";
					}
					if ( $werte[0] && ( $old_ip == $new_ip ) ) {
						$new = $werte[1]? 1: 0;
						$sql="UPDATE dns SET neu=$new, kunde=?, anbieter= ? WHERE domain=?";
						safe_query2( $sql, $loKunde, $loUser, $loDomain);
					}else{
						$sql="UPDATE dns SET zonefile=?, lastchange='$seriennummer', neu=1, kunde=?, anbieter=? WHERE domain=?";
						safe_query2( $sql, $loZone, $loKunde, $loUser, $loDomain );
					}
				}else{		
					$sql="INSERT INTO dns (domain,zonefile,lastchange,neu,anbieter,kunde)".
						" VALUES (?,?,'$seriennummer',1, ?, ? )";
					safe_query2( $sql, $loDomain, $loZone, $loUser, $loKunde );

				}

	
        db_query("UPDATE allgemein SET dns=1");

      
                 ## /dns eintrag erstellen
                 ## dnr ausführen
				if( $dnrGo && $dnr && !in_array($ind,$registered) ){
                    ## kundenvariablen:

					safe_query2( "UPDATE domains SET dnr=1 WHERE domain=? AND kunde=? AND anbieter=?",
											 $loDomain, $loKunde, $loUser );

					$id = safe_query2( "SELECT gender,plz,firstname,land,name,firma,anschrift,plzort,".
														"telefon,fax,emailadresse FROM kunden WHERE kunde = ?", $loKunde);

					$werte = db_fetch_array($id);

					$dnr_c_firstname    = $werte["firstname"];
					$dnr_c_gender       = $werte["gender"];
					$dnr_c_plz          = $werte["plz"];
					$dnr_c_land         = $werte["land"];
					$dnr_c_name         = $werte["name"];
					$dnr_c_firma        = $werte["firma"];
					$dnr_c_anschrift    = $werte["anschrift"];
					$dnr_c_ort          = $werte["plzort"];
					$dnr_c_telefon      = $werte["telefon"];
					$dnr_c_telefax      = $werte["fax"];
					$dnr_c_emailadresse = $werte["emailadresse"];
					## domaindaten:
					$dnr_d_domain       = $domain;
					$dnr_d_pns          = $pns;
					$dnr_d_sns          = $sns;
                    ## adminvariablen:

					$id = safe_query2( "SELECT gender,plz,firstname,land,name,firma,anschrift,plzort,".
														 "telefon,fax,emailadresse FROM anbieter WHERE anbieter = ?", $loUser );

					$werte = db_fetch_array($id);

					$dnr_a_firstname    = $werte["firstname"];
					$dnr_a_gender       = $werte["gender"];
					$dnr_a_plz          = $werte["plz"];
					$dnr_a_land         = $werte["land"];
					$dnr_a_name         = $werte["name"];
					$dnr_a_firma        = $werte["firma"];
					$dnr_a_anschrift    = $werte["anschrift"];
					$dnr_a_ort          = $werte["plzort"];
					$dnr_a_telefon      = $werte["telefon"];
					$dnr_a_telefax      = $werte["fax"];
					$dnr_a_emailadresse = $werte["emailadresse"];
					## dnr ausführen

					sendDnr();

				}//dnr.php
			}//$dns
		}//$ind
	}//$addDns





  /* -------------------- delete mail lists -------------------- */
  MailListPage::deleteLists ($delMaillists);
  /* -------------------- end delete mail lists -------------------- */





//
// loeschen Domainen
//
	if( count($delDnsDomain) ) {
		for($i=0;$i<count($delDnsDomain);$i++){
			$curDomain=$delDnsDomains[$i];

			safe_query2( "UPDATE dns SET neu=2 WHERE domain=? AND kunde=? AND anbieter=?",
									 new SQLString($curDomain), $loKunde, $loUser );
			
		}
		db_query("UPDATE allgemein SET dns=1");
	}

## //
  set_countdomains($kunde);
## //

  safe_query2( "UPDATE kunden SET changedomains = 1 WHERE kunde = ? and anbieter = ?", $loKunde, $loUser);
  $id = db_query( "SELECT neukundenreload FROM admin");
  $werte = db_fetch_array($id);
  $neukundenreload = $werte["neukundenreload"];

  if ($neukundenreload == 1){
    db_query( "UPDATE allgemein SET httpd=1, httpdupdate=0");
  } else{
    db_query( "UPDATE allgemein SET httpd=1");
  }

  safe_query2( "UPDATE kunden SET ip = ? WHERE kunde = ? AND anbieter = ?", $loIP, $loKunde, $loUser );
## update fertig! bestätigung ausgeben
  $fehlertitel = ltext("errtype_notice");
  $fehlertext = ltext("msg_saved_data");
  db_close();
  include("kunden_aendern.php");

  exit();

} ## /update ausführen
else { ## bestätigung holen

  db_close();
?>

<HTML>
<HEAD>
<META content="text/html; charset=<? echo $lang_html_charset; ?>" http-equiv=Content-Type>
<LINK href="<?=$strSkinName?>/style.css" rel=stylesheet type=text/css>
</HEAD>

<BODY bgColor=#ffffff bottomMargin=0 leftMargin=0 topMargin=0 MARGINHEIGHT="0" MARGINWIDTH="0">
<br><? include("../fehler.inc.php"); ?>
<script>
function doChange()
{
document.forms[0].submit();
}
</script>
<table class="tblbgcolor" align="left" border="1" cellpadding="3" cellspacing="0" bordercolorlight="#CCCCCC" bordercolordark="#FFFFFF">
<tr>

<script>
<?
echo js_f_call_help('kudoup_title1', 'kudoup_descr1');
?>
</script>
    <TD valign="top"> 
      <form action="kunden_domain_upd.php" method="post">
<?
  if (count($domainsanlegen) > 0) { 
?>
        <p>
       <b>
          <? echo ltext("kudoup_title2"); ?>
          </b> </p>
        <p>
<? 
    for ($i=0;$i<count($domainsanlegen);$i++)	{
		$dom_name = $domainsanlegen[$i];
		$key = $domIndex[$dom_name];
		include_once('class.InputDecode.php');
		$idn_str = InputDecode::utf8ToUnicodeEntities($ga_NationalName[$key]);
		
   		if ($idn_str) {
			$show_str = "$idn_str ($dom_name)";
		 } else {
			$show_str = $dom_name;
		 }
   if (!istleer($domainsanlegen[$i])) {
        echo $show_str."<br>";
      }
    }
?>
          </p>
<? 
  }
  if (count($domainsloeschen) > 0) { 
?>
        <p>
       <b>
          <? echo ltext("kudoup_title3"); ?>
          </b> </p>
        <p>
<? 
    for ($i=0;$i<count($domainsloeschen);$i++)	{
		$dom_name = $domainsloeschen[$i];
		include_once('idn_functions.php');
		$idn_str = get_html_idn_name($dom_name);
		
		if ($idn_str) {
			$show_str = "$idn_str ($dom_name)";
		 } else {
			$show_str = $dom_name;
		 }
      if (!istleer($domainsloeschen[$i])) {
			echo $show_str."<br>";
      }
    }
?>
          </p>
<? 
  }
  if (count($subdomainsloeschen) > 0) { 
?>
        <p><b>
<? 
    echo ltext("kudoup_title4"); 
?>
          </b></p>
        <p>
<? 
    for ($i=0;$i<count($subdomainsloeschen);$i++)	{
   		$dom_name = $subdomainsloeschen[$i];
		include_once('idn_functions.php');
		$idn_str = get_html_idn_name($dom_name);
		
		if ($idn_str) {
			$show_str = "$idn_str ($dom_name)";
		 } else {
			$show_str = $dom_name;
		 }
  		 echo $show_str."<br>";
    }
?>
          </p>
<? 
  }
  if (count($emailsloeschenident) > 0) { 
?>
        <p><b>
<? 
    echo ltext("kudoup_title5"); 
?>
          </b></p>
        <p>
<? 
    for ($i=0;$i<count($emailsloeschenemail);$i++) {
      echo $emailsloeschenemail[$i]."<br>";
    }
?>
         </p>
<? 
  }
  if(count($delMaillists)) {
?>
        <p><b>
<? 
    echo ltext("kudoup_title6"); 
?>
          </b></p>
        <p>
<? 
    for ($i=0;$i<count($delMaillists);$i++) {
    	
      $mlname = $mlNames[$delMaillists[$i]][0] . '@' . $mlNames[$delMaillists[$i]][1];
      echo $mlname . '<br>';
      
    }
?>
         </p>
<?
	
  }

?>
        <br>
	
	<table cellpadding="0" cellspacing="0" border="0">
	<tr>
	<td><input type=image border=0 src="<?=$strSkinName?>/pics/buttons/bt_img_left.gif"></td>
	<td background="<?=$strSkinName?>/pics/buttons/bt_img_middle.jpg"><a href="javascript:doChange()"  class="button-1"><? echo ltext("kudoup_button1"); ?></a></td>
	<td><input type=image border=0 src="<?=$strSkinName?>/pics/buttons/bt_changepass.gif"></td>
	</tr>
	</table></a>

<!--
 wws:

      <input type="hidden" name="domains" value="<? echo $domains; ?>">
	<input type="hidden" name="dns" value="<? echo $dns; ?>">
      <input type="hidden" name="dnr" value="<? echo $dnr; ?>">
-->

<?

//
// uebergeben argumenten
//
  if($DEBUG){
    echo "\n<br>domainsloeschen:<br>\n";
    print_r($domainsloeschen);
    echo "\n<br>altedomains:<br>\n";
    print_r($altedomains);
    echo "\n<br>domainsanlegen:<br>\n";
    print_r($domainsanlegen);
  }

  $j=0;  
  for($i=0;$i<count($domainsloeschen);$i++){
    $curDomain=$domainsloeschen[$i];
	if (!empty($ga_OriginalName[$domIndex[$curDomain]])) {
		$curDomain = $ga_OriginalName[$domIndex[$curDomain]];
	}
    if ($curDomain){
      $j++;
      echo "\n<input type=\"hidden\" name=\"domain[$j]\" value=\"$curDomain\">\n";
      echo "<input type=\"hidden\" name=\"domdel[$j]\" value=\"1\">\n";
    }
  }  

  for ($i=0;$i<count($altedomains);$i++)	{
    $curDomain=$altedomains[$i];
    if ($curDomain && !in_array($curDomain,$domainsloeschen)){
      $ind=$domIndex[$curDomain];
      $dns=$domdns[$ind]?$domdns[$ind]:0;
      $dnr=$domdnr[$ind]?$domdnr[$ind]:0;
	  if (!empty($ga_OriginalName[$ind])) {
		$curDomain = $ga_OriginalName[$ind];
	  }
      $j++;
      echo "\n<input type=\"hidden\" name=\"domain[$j]\" value=\"$curDomain\">\n";
      if ($dns) echo "<input type=\"hidden\" name=\"domdns[$j]\" value=\"$dns\">\n";
      if ($dnr) echo "<input type=\"hidden\" name=\"domdnr[$j]\" value=\"$dnr\">\n";
    }
  }

  for($i=0;$i<count($domainsanlegen);$i++){
    $curDomain=$domainsanlegen[$i];
    if ($curDomain){
      $ind=$domIndex[$curDomain];
      $dns=$domdns[$ind]?$domdns[$ind]:0;
      $dnr=$domdnr[$ind]?$domdnr[$ind]:0;
	  if (!empty($ga_OriginalName[$ind])) {
		$curDomain = $ga_OriginalName[$ind];
	  }
      $j++;
      echo "\n<input type=\"hidden\" name=\"domain[$j]\" value=\"$curDomain\">\n";
      if ($dns) echo "<input type=\"hidden\" name=\"domdns[$j]\" value=\"$dns\">\n";
      if ($dnr) echo "<input type=\"hidden\" name=\"domdnr[$j]\" value=\"$dnr\">\n";
    }
  }  


//
// stop-domain
//
  $j++;
  echo "\n<input type=\"hidden\" name=\"domain[$j]\" value=\"\">\n";

?>

        <input type="hidden" name="kunde" value="<? echo $kunde; ?>">
        <input type="hidden" name="exklusiv" value="<? echo $exklusiv; ?>">
        <input type="hidden" name="ip" value="<? echo $ip; ?>">
        <input type="hidden" name="action" value="jetzt">
      </form>
    </TD>
  </TR>
  </TBODY> 
</TABLE>
</BODY>
</HTML>
<? 
} ## / bestätigung holen
?>
