#!/usr/bin/perl

####################################################################################################
## NetZone 10.0 
## index.cgi
##
## Author: Brian Walker, Webdirectionz Limited.
## Date: 30 October 2007
####################################################################################################
      
      
        use CGI qw/:standard/;
        use CGI::Carp qw(fatalsToBrowser carpout);
        
        use DBI;
        use Time::Local;
        use Image::Size;


####################################################################################################
# SPLIT QUERY STRING INTO VARIABLS AND VALUES
####################################################################################################
    
        require "cgi-lib.pl";
        &ReadParse(\%in,\%cgi_cfn);

####################################################################################################
# Query string variables
####################################################################################################


        $do		= $in{do};
	$agency		= $in{agency};
	$delivery	= $in{delivery};
	$email		= $in{email};
	$qty		= $in{qty};
	        
      
        print "Content-type: text/html\n\n";
        require "sysconfig.cgi";
	
	if ($do eq "order") {
		if ($agency eq "" || $delivery eq "" || $email eq "" || $qty eq "") {
			$message = "Please complete all fields.<br/><br/>";
			&display_order_form;
		}
		else {
			&submit_order;
		}
	}
	else { &display_order_form }
	
	
                
####################################################################################################
# Order form
####################################################################################################
sub display_order_form {
	
	print qq~
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Brochure Order</title>
	
	<style type="text/css">
	<!--
	html, body {background:transparent;font-family:'Arial',sans-serif;font-size:12px;}-->
	</style>

	</head>
	
	<body>Please complete the following order form:<br/><br/>
	<form action="brochure.cgi" method="post" style="margin:0px;">
	<span style="color:#FF0000; font-weight:bold;">$message</span>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	  <tr>
	    <td width="180" height="30" valign="top">Agency Name</td>
	    <td height="30" valign="top"><input name="agency" type="text" id="agency"  style="width:250px;" value="$agency" maxlength="150" /></td>
	  </tr>
	  <tr>
	    <td width="180" height="95" valign="top">Delivery address</td>
	    <td height="30" valign="top"><textarea name="delivery" id="delivery" style="width:250px; height:80px;">$delivery</textarea></td>
	  </tr>
	  <tr>
	    <td width="180" height="30" valign="top">Email address</td>
	    <td height="30" valign="top"><input name="email" type="text" id="email"  style="width:250px;" value="$email" maxlength="150" /></td>
	  </tr>
	  <tr>
	    <td width="180" height="30" valign="top">Quantity of brochures required</td>
	    <td height="30" valign="top"><input name="qty" type="text" id="qty"  style="width:50px;" value="$qty" maxlength="5" /></td>
	  </tr>
	  <tr>
	    <td width="180" height="30" valign="top"></td>
	    <td height="30" valign="top"><input name="submit" type="submit" id="submit" value="submit order"/></td>
	  </tr>
	</table>
	<input type="hidden" name="do" value="order">
	</form>
	</body>
	</html>
	
	
	~;
	exit;
	
}


####################################################################################################
# submit Order
####################################################################################################
sub submit_order {
	
	
	open( MAIL, "|$sendmail -t " ) || &display_error("can't open sendmail: $sendmail: $!\n");
	print MAIL "To: Feejee Experience Brochure Orders <enquiries\@feejeeexperience.com>\n";
	print MAIL "From: $agency <$email>\n";
	print MAIL "Subject: Feejee Experience Brochure Order\n";
	print MAIL "Mime-Version: 1.0\n";
	print MAIL "$contenttype";
	print MAIL <<ENDHTML;
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<title>FJX Brochure Order</title>
		<style type="text/css">
		<!--
		body, td {
			font-family: Arial, Verdana, Tahoma;
			font-size: 12px;
		}
		-->
		</style>
		</head>
		
		<body>
		<p>The following brochure order has been placed</p>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	  <tr>
	    <td width="180" height="30" valign="top">Agency Name</td>
	    <td height="30" valign="top">$agency</td>
	  </tr>
	  <tr>
	    <td width="180" height="95" valign="top">Delivery address</td>
	    <td height="30" valign="top">$delivery</td>
	  </tr>
	  <tr>
	    <td width="180" height="30" valign="top">Email address</td>
	    <td height="30" valign="top">$email</td>
	  </tr>
	  <tr>
	    <td width="180" height="30" valign="top">Quantity of brochures required</td>
	    <td height="30" valign="top">$qty</td>
	  </tr>

	</table>
	<p>&nbsp;</p>
	</body>
	</html>
		
	
ENDHTML
	close (MAIL);
	
	print qq~
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Brochure Order</title>
	
	<style type="text/css">
	<!--
	html, body {background:transparent;font-family:'Arial',sans-serif;font-size:12px;}-->
	</style>

	</head>
	
	<body>Thank you. Your brochure order has been submitted and we will let you know as soon as they've been despatched.

	</body>
	</html>
	
	
	~;
	exit;
}