#!/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);
$emailbody = param ('emailbody');
$fromaddress = param ('fromaddress');
$fromaddress = lc($fromaddress);
$vacationuser = param ('vacationuser');
$subject = param ('subject');
$full_address = "$fromaddress\@$domainname";

# 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 'Out of Office' reply for $domainname");

if ( $vacationuser eq "" || $emailbody eq "" || $fromaddress eq "" || $subject eq "" )
{
	print "Sorry, but you seem to have left out some required information.";
	show_option_to_go_back("?fromaddress=$fromaddress&subject=$subject&emailbody=$emailbody");	
} else {
	# all details have been entered; write details to files for processing
	if ( check_email_address_syntax($full_address) )
	{
		# syntax is wrong
		print qq!
		Sorry, but the syntax of the email address you supplied [ <i>$full_address</i> ] doesn't
		seem to be correct.
		!;
		show_option_to_go_back("?fromaddress=$fromaddress&subject=$subject&emailbody=$emailbody");
	} else {
		
	$ret = php_request ("setVacation", "scope=user:$vacationuser\@$domainname", "vacationStatus=Yes", "vacationText=$emailbody");
	#return 1 if (defined ($ret) && ref ($ret) ne "SCALAR");
	#return 0;
	#open (VACFILE, ">$userresponsefile.$vacationuser");
	#print VACFILE "From: $full_address\n";
	#print VACFILE "Subject : $subject\n";
	#print VACFILE "Delivered-By-The-Graces-Of: The Vacation Program\n\n";
	#print VACFILE $emailbody;
	#print "\n\n";
	#close VACFILE;

	#open (VACUSERS, ">>$uservacationfile");
	#print VACUSERS $vacationuser, ",", $domainname, "\n";
	#close VACUSERS;
	
	#print "Thank you. You have elected to create an 'Out of Office' automated reply for the user $vacationuser.";
	show_time_to_change();
	}
}
require $footer;
