#!/usr/bin/perl

print "Content-Type: Text/HTML\n\n";

use CGI ':standard';
use Vpanel 1.00;
require $header;
require $accountinfo;
$domainnname = find_domain ($mainuser);

# Define the tab which appears to the front
$tab_section = $tabnum_email;

# Output the content associated with this tab
print "<body class=section-$tab_section>";

# display tabs
require $tabdisplay;

$user = param ('user');
$user = lc($user);
$address = param('address');
$address = lc($address);

print_header ("Creation of a new email address for $domainname");
	
if ( $address eq "" )
{	
	print "<BR>You seem to have forgotten to enter an email address. Please click on the 'Back' button and enter the email ";
	print "address you would like to create.<BR><BR>";
} else {
	$address = $address . "@" . $domainname;
	$address_addition_result = add_address($address, $user . "@" . $domainname);
	if ( $address_addition_result == 0 )
	{
		# Addition failed because the syntax is incorrect
		print "There was a problem with the email address you entered; its syntax is not correct.<BR><BR>";
		print_support_contact_information();
	} elsif ( $address_addition_result == 2 ) {
		# Addition failed because address exists
		print "<div class=\"text\">There was a problem with the email address you entered:
		<ul>
			<li><b>it is already added to your account</b> as a regular email address or email forwarding;<br />
			you have to delete it first</li>
		<p>or</p>
			<li><b>it is awaiting addition to your account</b>;<br />
			in this case wait 5&nbsp;minutes to see it on the list of addresses assigned to your account</li>
		</ul>
		</div>";
		print_support_contact_information();
	} else {
		print "Your new email address is summarised below:<BR>";
		print "Please keep this information in a safe place for future reference. <br><br>";
		print "User: <b>$user</b><BR>";
		print "Address: <b>$address</b>";
		show_time_to_change();
	}
}

require $footer;
