<?
########## 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");
include_once("class.EmailAddress.php");

#
# debug
#
global $DEBUG;
$DEBUG=0;
#
#
#

$ausdb = "nein";
db_connect($db_host, $db_user, $db_pass);

## email adresse für bestätigungsmeldung ermitteln
$id = safe_query( "select prefix, domain, pop3 from email where kunde = ?  and ident = ? ", TRUE, new SQLString( $PHP_AUTH_USER ), new SQLInteger( $ident ) );
$werte = db_fetch_array($id);
$emailadresse = $werte["prefix"]."@".$werte["domain"];
## //


$id = safe_query( "select pop3, prefix, domain from email where kunde = ? ", TRUE, new SQLString( $PHP_AUTH_USER ) );
while ($werte = db_fetch_array($id))
	{
	 $tmpmail = $werte["prefix"]."@".$werte["domain"];
	 $emailarray[$tmpmail] = $werte["pop3"];
	}

$lo_email = new EmailAddress();
	
## hauptemailadresse prüfen
if ($htyp == 1)	{ 

	$hpop3 = $lo_email->setEmail($hemail);  ## prepare email: first stage

	if ( ! istleer($emailarray[$hpop3]) ){  ## find dublicate
		 $fehlertext = ltext("emembe2_error1");
		 $pop3 = $hemail;
		 db_close();
		 include("email_email_bearbeiten.php");
		 exit();
	}

	if ( ! $lo_email->isEmailValid() ){  ## validate email
		 $fehlertext = ltext("emembe2_error2");
		 $pop3 = $hemail;
		 db_close();
		 include("email_email_bearbeiten.php");
		 exit();
	}
		
}elseif ($htyp == 0){
	$hpop3 = $hacc;
}

if (istleer($hpop3)){
	 $fehlertext = ltext("emembe2_error3");
	 db_close();
	 include("email_email_bearbeiten.php");
	 exit();
}
## //

$formatfehler = 0;

for ($i = 1; $i <= $max_emailrcpts; $i++){
	$typ = "typ".$i;
	$email = "email".$i;
	$acc = "acc".$i;

	if ($$typ == 1){
		
		$pop3 = $lo_email->setEmail( $$email ); ## prepare email: first stage

		if( $pop3 && !$lo_email->isEmailValid() )	{  ## validate email
			$formatfehler = 1;
			$pop3 = "";
		}
		if ( $pop3 && !istleer($emailarray[$pop3])){ ## find dublicate
			$pop3 = "";
			$topop = "ja";
		}
	}elseif ($$typ == 0){
		$pop3 = $$acc;
	}

	 if (!istleer($pop3))
		{
		 $schondrin = 0;
		 for ($xi = 0; $xi < count($pop3xa); $xi++)
			{
			 if ($pop3xa[$xi] == $pop3)
				{
				 $schondrin = 1;
				}
			}
		 if (($schondrin == 0) && ($pop3 != $hpop3))
			{
			 $pop3xa[] = $pop3;
			}
		}
	}
if (count($pop3xa) > 0)
	{
	 $pop3x = implode(':', $pop3xa);
	}

## E-Mail updaten
safe_query( "UPDATE email SET pop3 = ? , pop3x = ? , neu = '1' where kunde = ?  and ident = ? ", TRUE, new SQLString( $hpop3 ), new SQLString( $pop3x ), new SQLString( $PHP_AUTH_USER ), new SQLInteger( $ident ) );
safe_query( "update allgemein set aliases='1'", TRUE );


$fehlertitel = ltext("emembe2_error4");
if ($topop == "ja") { $fehlertext = ltext("emembe2_error5", array($emailadresse)); } else {
$fehlertext = ltext("emembe2_error6", array($emailadresse)); }
if ($formatfehler == 1)
	{
	 $fehlertext .= ltext("emembe2_error7");
	}
db_close();
include("email_email.php");
exit();
## //

?>
