#!/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);
$user = param ('user');
$address = param ('address');

# 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 ("Changing the recipient of your info\@$domainname email address");

if ( $user eq "none" )
{
	# info@ is being forwarded to another email address

	if ( check_email_address_syntax($address) )
	{
		print "<p span class=text>Sorry, the email address you entered does not have the correct syntax.<br><br>";
		show_option_to_go_back("?address=info\@$domainname");
	} else {
		# FIXME: this does not work
		$ret = php_request ("setChangeParent", "scope=email:info"."@".$domainname, "parent=forward:".$addressnname);
		if (!defined ($ret) || ref ($ret) ne "SCALAR") {
			print "There was a problem deploying this change.";
		}
		#return 0;
		print "Thank you for your request to redirect emails sent to info\@$domainname to $address.";
		show_time_to_change();

		#open (CHANGEINFO, ">>$changeinfofile");
		#print CHANGEINFO "$domainname,$address\n";
		#close CHANGEINFO;
	}
} else {
	$ret = php_request ("setChangeParent", "scope=email:info"."@".$domainname, "parent=user:".$user."@".$domainname);
	if (!defined ($ret) || ref ($ret) ne "SCALAR") {
		print "There was a problem deploying this change.";
	}
	print "Thank you for your request to redirect the email address info\@$domainname to $user.";
	show_time_to_change();

	#open (CHANGEINFO, ">>$changeinfofile");
	#print CHANGEINFO "$domainname,$user\n";
	#close CHANGEINFO;
}

require $footer;
