#!/usr/bin/perl

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

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

$from_address = param('from');
$from_address = $from_address . "\@" . $domainname;
$from_address = lc($from_address);

$to_adress = param('to');
$to_adress = lc ($to_adress);


# 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;

print_header("Creation of an email address to be forwarded to another email address for $domainname");

$address_addition_result = add_forward($from_address, $to_adress);

if ( $address_addition_result == 0 )
{
	# Addition failed because the syntax is incorrect
		print "There was a problem with one of the email addresses 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 forwarding is summarised below.";
		print "Please keep this information in a safe place for future reference. <br><br>";
		print "Address: <b>$from_address</b><BR>";
		print "Being forwarded to: <b>$to_adress</b>";
		show_time_to_change();
}


require $footer;
