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

print_header ("Creation of a new user for $domainname");

# write this new user information to file for later processing

# first check the page hasn't been refreshed and the user is already awaiting insertion

$user_addition_result = add_user($flag, $user, $password, $domainname);

if ( $user_addition_result == 0 )
{
	print "The user $user wasn't added as it seems to exist already.<BR>";
} else {
	print<<INFO;

	Your new user information is summarised below.
	Please keep this information in a safe place for future reference. <br><br>
	User: <b>$user</b><BR>
	Password: <b>$password</b><BR>

INFO
	
	if ( $address ne "" )
	{	
		$address = $address . "@" . $domainname;
		$address_addition_result = add_address($address, $user. "@" . $domainname);
		if ( $address_addition_result == 0 )
		{
			# Addition failed because address exists
			print "The email address $address wasn't added as it seems to exist already.<BR>";
		} else {
			print "Email address: <b>$address</b><BR>";
			print "<BR>You can set up further email addresses by clicking on the 'Email' tab above.";
		}
	} else {
		print "<BR>You can set up email addresses for this user by clicking on the 'Email' tab above.";
	}

	show_time_to_change();

	print_email_confirmation($domainname);
}
require $footer;
