#! /usr/bin/perl

# #################################################################
#
# Web HylaFAX gateway 1.0		           December 1998
# Nic Tjirkalli (nic@uunet.co.za, http://duffus.iafrica.com/~nic)
#
# #################################################################


require("cgilib.pl");
require("fax-gw-config.pl");

# Set perl not to buffer ouptput
        $| = 1;


# Static variables
	$fileo = "/tmp/.fax.$$";
	$filestat = "/tmp/.fax.stat.$$";

# Initialise  variables 

# Extract variables
$Name = "";
$Company = "";
$FaxNumber = "";
$Document = "";
$File = "";
$From = "";
$regarding = "";

$error = "";


&ReadParse(*input);

$Name = $input{'Name'}; 
$Company = $input{'Company'}; 
$FaxNumber = $input{'FaxNumber'}; 
$Document = $input{'Document'}; 
$File = $input{'File'}; 
$From = $input{'From'}; 
$Regarding = $input{'Regarding'}; 

# No fax number - ERROR
if ($FaxNumber) {
$error = "";
}
else
{
$error = "NO FAX NUMBER ENTERED - REDO";
}


# Error Exit
if ($error) {
&pagetop;
&errmess;
&bottom;
exit();
}

$command = $prog." -P high -m -D -f \"$From\" -r \"$Regarding\" -x \"$Company\"  -d \"$Name\"\@$FaxNumber $fileo"; 

# A file has been specified - make it the same as Document
if ($File)
{
	$Document = $File;
}

open(OUTPUT, ">$fileo");
print OUTPUT $Document;
close(OUTPUT);

# Produce output
&pagetop;
&output;
system("$command 1>$filestat 2>$filestat");

open(RESULT, "$cat $filestat |");
while($line=<RESULT>) {
print $line
}
close(RESULT);
print "<CENTER>";

system("$rm $fileo $filestat 1>/dev/null 2>/dev/null");



&bottom;


###########################################
sub pagetop {
{ print <<EOF
Content-type: text/html


<HTML>
<HEAD>$title</HEAD>
<BODY BGCOLOR=#ffffff LINK=#0000ff VLINK=#ff0000 ALINK=#FF0000 TEXT=#000000>

<HR SIZE="2" NOSHADE>
<CENTER>
<TABLE BORDER="0" WIDTH="100%">
<TR>
<TD BGCOLOR="FF0000" ALIGN="CENTER">
<H1><FONT COLOR="FFFF00">&nbsp; <BR> Web HylaFAX gateway 1.0</FONT></H1>
</TD>
</TR>
</TABLE>
</CENTER>


<HR SIZE="2" NOSHADE>

EOF
}
}

############################################
sub output	{
{ print <<EOF
<H1>FAX Transmission Details</H1>
<BR><P>
<HR SIZE="2" NOSHADE>
<BR><P>
<PRE>
Sending To 		:- $Name
To Fax Number 		:- $FaxNumber
Company 		:- $Company
From 			:- $From
Running Command 	:- $command
</PRE>

<BR><P>
<DD><B><i>sendfax</B></I> command output :-
<BR> 
EOF
}
}


############################################
sub errmess      {
{ print <<EOF
<H1>FAX Details Entry Error</H1>
<BR><P>
<HR SIZE="2" NOSHADE>
<BR><P>
<CENTER>
$error
EOF
}
}

