Gossamer Forum
Home : General : Perl Programming :

How to make a cgi send mail??

Quote Reply
How to make a cgi send mail??
Hi
Very grateful if somone can solve my little problem.

I have a shoppingcart in this script. Currently, the orders is written to a file. I have tried to use FormMail, but when trying to write the @ character (edit the script, and so upload), the script crash. I use @ charachter to spesify the recipent. Is there another way to di that.

Basically; What do I substitute are@a4.no with ? Here is my file;


#!/usr/bin/perl
# ^^ The line above needs to point to the Perl intrepreter on your system.
# Ask your sys admin for the correct path, or type 'which perl' at the unix
# prompt. You need Perl 5 or higher. type 'perl -v' to get your version.
############################################################################

############################################################################
# iTransact, Inc. RediCart v2.52
# Copyright © 1997, iTransact, Inc. All rights reserved.
############################################################################
# This script contains code written and owned by iTransact, Inc. and has
# been modified to enable merchants to have credit card and check
# transactions authorized and guaranteed online in real-time using
# iTransact's Transaction Gateway. This script is provided free of charge.
#
# Please visit us at http://www.itransact.com
#
# iTransact Transaction Gateway, RediCharge, RediCheck, and RediCart are
# trademarks of iTransact, Inc. Other product and company names
# mentioned herein may be the trademarks of their respective owners.
#
# THIS SCRIPT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
# EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
# TECHNICAL SUPPORT FOR THIS SCRIPT WILL NOT BE PROVIDED BY ITRANSACT, INC.
############################################################################

############################################################################
# AUTHOR INFORMATION
############################################################################
# S-Mart Shopping Cart Script v1.9
# Shop smart. Shop S-Mart.
# Written by Barry Robison. (brobison@rcinet.com)
# This script uses code written by Matt Wright.
# Please visit his site at http://worldwidemart.com
# Selling the code for this program without prior written consent of the
# author(s) is expressly forbidden. Obtain permission before
# redistributing this software over the Internet or in any other medium.
# In all cases copyright and header must remain intact.
#
# All customization requests to be sent to brobinson@rcinet.com.
############################################################################

############################################################################
# MAKE NO CHANGES BELOW THIS LINE.
############################################################################

# Measure CPU time usage;
$start = (times)[0];

# Get rid of NULL;
$zero - '0';

require 'smart.cfg';

use vars qw($tmpdir $storename %shipping2 %shipping3 $trackurl $useverify $usertime $orderdir $usercurr $trackdb);
my($incoming, @pairs, %FORM);
$incoming = $ENV{'QUERY_STRING'};
@pairs = split(/&/, $incoming);
foreach $pair (@pairs) {
my($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}

# Get command variables
$command = $FORM{'command'};
$pos = $FORM{'pos'};
$type = $FORM{'type'};
$cmdlinegroup = $FORM{'group'};

# Parse form input
&parse_form;

# Get the date
&get_date;

# Get their hostname
#if ($usecookie eq '1') {
#require 'cookie.lib';
#&get_cookie;
#}
#else {

&get_host;

#}

# See if they have a cart already, if not, make one
&check_file;

# See what they want to do.

# Add an item to the cart.
if ($command eq 'add') {
&add_item;
}

# Change a quantity of an item in the cart, if at zero, delete it
elsif ($command eq 'change') {
&change_items;
}

# Show the order form. Get their name, phone number, CC info, etc..
elsif ($command eq 'buy1') {
&buy_items1;
}

# Process the order form info, mail out receipt, and order
elsif ($command eq 'buy2') {
&buy_items1;
}

# Show current cart
elsif ($command eq 'review') {
&review_items;
}

# List items, based on database call
elsif ($command eq 'listitems') {
&gen_page;
}

# Show a databae frontend.
elsif ($command eq 'showstore') {
&show_store;
}

# Delete a whole cart
elsif ($command eq 'delete') {
&delete_cart;
}
# Calculate shipping
elsif ($command eq 'calcship') {
&calc_shipping;
}
elsif ($command eq 'setship') {
&set_shipping;
}
elsif ($command eq 'removetax') {
&remove_tax;
}
elsif ($command eq 'addtax') {
&add_tax;
}
elsif ($command eq 'removetax2') {
&remove_tax2;
}
elsif ($command eq 'addtax2') {
&add_tax2;
}
elsif ($command eq 'retaddr') {
&ret_addr;
}

elsif ($command eq 'calccurr') {
&calc_currency;
}
elsif ($command eq 'setcurr') {
&set_currency;
}
else { &show_store; }

# Subroutines:

# Generate page, based on database search
sub gen_page {
my($SIZE,$max,$i,$itemid,$name,$price,$descrip,$image,$weight,$itemurl,$group);
&print_header;
# Table header, change this for table options!
print "<center><table cellpadding=5 border=1>\n";
print "<tr>\n";

open (FILE,"$resourcedb") &#0124; &#0124; die "Content-type: text/html\n\nCan't Open $resourcedb(r): $!\n";
my(@LINES)=<FILE>;
close(FILE);
$SIZE=@LINES;

if ($type eq 'all') {
$max = $pos + $numtolist;
if ($max > $SIZE) {
$max = $SIZE;
}
for ($i=$pos;$i<$max;$i++) {
$_=$LINES[$i];
($itemid, $name, $price, $descrip, $image, $weight, $itemurl, $group) = split(/\|/,$_);
&print_item;
}

print "</table>\n";
if ($max < $SIZE) {
print "<center><a href=\"$cgiurl\?command=listitems\&pos=$max&type=all\">Next $numtolist items</a></center>\n";
}
}

if ($type eq 'search') {
my($matches) = 0;
my($i) = $pos;
while (($matches < $numtolist) && ($i < $SIZE)) {
$_=$LINES[$i];
if (m/$FORM{'search'}/i) {
$matches++;
($itemid, $name, $price, $descrip, $image, $weight, $itemurl, $group) = split(/\|/,$_);
&print_item;
}
$i++;
}
print "</table>\n";
if ($i < $SIZE) {
print "<form method=post action=\"$cgiurl\?command=listitems\&pos=$i\&type=search\">\n";
print "<input type=hidden name=itemid value=\"$itemid\">\n";
print "<input type=hidden name=search value=\"$FORM{'search'}\">\n";
print "<center><input type=submit value=\"Continue Search\"></form>\n";
}
}

if ($type eq 'group') {
my($matches) = 0;
my($i) = $pos;
while (($matches < $numtolist) && ($i < $SIZE)) {
$_=$LINES[$i];
($itemid, $name, $price, $descrip, $image, $weight, $itemurl, $group) = split(/\|/,$_);
if ($group eq $FORM{'group'} &#0124; &#0124; $group eq $cmdlinegroup) {
$matches++;
&print_item;
}
$i++;
}
print "</table>\n";
if ($i < $SIZE) {
if ($cmdlinegroup) {
print "<a href=\"$cgiurl\?command=listitems\&pos=$i\&type=group\&group=$cmdlinegroup\">Continue Search</a>\n";
}
else {
print "<a href=\"$cgiurl\?command=listitems\&pos=$i\&type=group\&group=$FORM{'group'}\">Continue Search</a>\n";
}
}
}

&print_footer;

sub print_item {

print "<form method=post action=\"$cgiurl\?command=add\">\n";
# Hide the weight for later use
print "<input type=hidden name=weight value=\"$weight\">\n";
print "<input type=hidden name=itemid value=\"$itemid\">\n";
# If you want to redirect, keep this in!
if ($useredirect eq '1') {
print "<input type=hidden name=redirect value=\"referrer\">\n";
}

# For showing product images
if ($image) {
print "<td rowspan=2><img src=\"$imageurl/$image\"></td>\n";
}
else {
print "<td rowspan=2></td>\n";
}

# If the item has a URL, make it a link
if ($itemurl) {
print "<td><a href=\"$itemurl\">$name</a><input type=hidden name=itemname value=\"$name\"></td>\n";
}
else {
print "<td>$name<input type=hidden name=itemname value=\"$name\"></td>\n";
}

# Print other info

#Price
print "<td>\$ $price<input type=hidden name=itemprice value=\"$price\"></td>\n";

#Quantity
print "<td><input type=text size=2 name=itemquant value=1></td>\n";

#Add button
print "<td rowspan=2><input type=submit value=\"Buy Me!\"></td>\n";

#Description
print "</tr><tr><td colspan=3>$descrip</td>\n";

# Close
print "</form></tr><tr>\n";

}
## END print_item

}
## END gen_page


# Show front end of database store.
sub show_store {
&print_header;
print "<center>\n";
print "<table width=80%><td>\n";
print "<a href=\"$cgiurl\?command=listitems\&type=all\&pos=0\">List all items available</a><br>\n
<Br>\n
<table>
<td>Search for a particular item(s):</td>
<td>
<form method=post action=\"$cgiurl\?command=listitems\&pos=0\&type=search\">
<input type=text name=search size=30></td>
<td><input type=submit value=Search></form></tD>
</table>\n";
print "<table>
<td>List all:</td>
<td>
<form method=post action=\"$cgiurl/smart/smart.cgi\?command=listitems\&pos=0\&type=group\">
<select name=group><option selected>Select a Group</option>\n";

foreach $group (keys %groups){
print "<OPTION value=\"$group\"> $groups{$group} </option>\n";
}

print "</select></td><td>\n";

print "<center><input type=submit value=\"List\"</form></td>\n</table>\n<br>";

if ($usetrack eq 1) {
print "<br><a href=\"$trackurl\">Track an Order</a><br>\n";
}

print "</td></table>\n";
&print_footer;
}
## END show_store

# Print the HTML header
sub print_header {
print "Content-type: text/html\n\n";
open (HEADER,"$basepath/$header") &#0124; &#0124; print "Could not open $basepath/$header $! \n";
while (<HEADER> ) {
print $_;
}
close(HEADER);
}


#Print the HTML footer
sub print_footer {
open (FOOTER,"$basepath/$footer") &#0124; &#0124; print "Could not open $basepath/$footer $! \n";
while (<FOOTER> ) {
print $_;
}
close(FOOTER);
### Please do not delete this message.
print "<!br><!br>\n";
print "<hr width=50\%>\n";
print "<font size=-1>Portions copyright <a href='http://www.itransact.com'>iTransact Corporation</a> \& <a href=\"mailto:brobison\@rcinet.com\">Barry Robison</a>.<br>\n
This RediCart software is available <a href='http://www.itransact.com/redicart/index.html'>free of charge</a>.</font>";
}
## END print_footer

# List items in cart.
sub list_items {
my($totalprice,$totalquant,$totalweight) = 0;
open (REFFILE,"$reffile") &#0124; &#0124; die "Content-type: text/html\n\nCan't Open $reffile(r): $!\n";
my(@LINES)=<REFFILE>;
close(REFFILE);
$SIZE=@LINES;
$rcitem=1;

print "<form name=select1 method=POST action=\"$cgiurl?command=change\">\n";

##### INCLUDE REQUIRED ITRANSACT MERCHANT TAGS #####

#print "<FORM METHOD='POST' ACTION='SUBMIT'>\n";
#print "<INPUT type='hidden' name='recipient' value='webmastera4.no'>\n";
#print "<INPUT type='hidden' name='email_text' value='$etext'>\n";
#print "<INPUT type='hidden' name='lookup' value='first_name'>\n";
#print "<INPUT type='hidden' name='lookup' value='last_name'>\n";
#print "<INPUT type='hidden' name='lookup' value='address'>\n";
#print "<INPUT type='hidden' name='lookup' value='city'>\n";
#print "<INPUT type='hidden' name='lookup' value='state'>\n";
#print "<INPUT type='hidden' name='lookup' value='zip'>\n";
#print "<INPUT type='hidden' name='lookup' value='ctry'>\n";
#print "<INPUT type='hidden' name='lookup' value='phone'>\n";
#print "<INPUT type='hidden' name='lookup' value='email'>\n";

#print "<INPUT type='hidden' name='passback' value='good'>\n";
#print "<INPUT type='hidden' name='good' value='1'>\n";

##### INCLUDE SPLIT-FORM TAGS IF REQUIRED #####

if ($split eq '1') {
print "\n<INPUT type='hidden' name='mername' value='$mname'>\n";
print "<INPUT type='hidden' name='mertext' value='$mtext'>\n";
print "<INPUT type='hidden' name='acceptchecks' value='$checks'>\n";
print "<INPUT type='hidden' name='allowreg' value='$creg'>\n";
print "<INPUT type='hidden' name='checkguar' value='$cguar'>\n";
print "<INPUT type='hidden' name='acceptcards' value='$cards'>\n";
print "<INPUT type='hidden' name='altaddr' value='$creg'>\n";

}

print "\n";

print "<table border=1 cellpadding=5><tr>\n";

if ($useimage eq '1') {
print "<th></th>";
}

if ($useid eq '1') {
print "<th><font size=-1 color=blue>ITEM ID</font></th>";
}

print "<TR BGCOLOR='#000000'><TH COLSPAN=5 ALIGN=center><FONT SIZE=3 COLOR=white> <B>$mname</B> </FONT></TH></TR>
<th><font size=-1 color=blue>ITEM NAME</FONT></th><th><font size=-1 color=blue>QUANTITY</font></th><th><font size=-1 color=blue>PRICE</font></th><th><font size=-1 color=blue>AMOUNT</font></th></tr>";

for ($i=1;$i<$SIZE;$i++) {
$_=$LINES[$i];
($itemname, $itemprice, $itemquant, $weight, $itemid) = split(/\|/,$_);
$tmpprice = ($itemprice*$itemquant);
$tmpprice = int($tmpprice * (10 ** 2) + .5) / (10 ** 2);

$totalprice += $tmpprice;
$totalquant += $itemquant;
$totalweight = ($weight*$itemquant) + $totalweight;
print "<tr>";

if ($useimage eq '1') {
if ($FORM{'image'}) {
print "<td><img src=\"$imageurl/$FORM{'image'}\"></td>\n";
}
else {
print "<td></td>";
}
}

if ($useid eq '1') {
print "<td>$itemid <input type=hidden name=itemid value=\"$itemid\"></td>\n";
}

$_ = $tmpprice;

if (/\./) {
my($left,$right) = split(/\./,$tmpprice);
if (length($right) == 0) {
$tmpprice = $tmpprice . "00";
}
elsif (length($right) == 1) { $tmpprice = $tmpprice . "0"; }
}
else { $tmpprice = $tmpprice . ".00"; }


#print "<td>$itemname</td><td align=right>\$ $itemprice</td><td align=center><input type=number size=2 value=\"$itemquant\" name=item$i></td><td align=right>\$ $tmpprice</tr>\n";
print "<td>$itemname</td><td align=center><input type=number size=2 value=\"$itemquant\" name=item$i></td><td align=right>\$ $itemprice</td><td align=right>\$ $tmpprice</tr>\n";

########## INCLUDE REQUIRED FIELD NAMES ###########

print "<input type=hidden name='$rcitem-desc' value='$itemname'>\n";
print "<input type=hidden name='$rcitem-qty' value='$itemquant'>\n";
print "<input type=hidden name='$rcitem-cost' value='$itemprice'>\n\n";

$rcitem=$rcitem+1;

}
print "<tr><td><b>Subtotal:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}

$_ = $totalprice;
if (/\./) {
my($left,$right) = split(/\./,$totalprice);
if (length($right) == 0) {
$totalprice = $totalprice . "00";
}
elsif (length($right) == 1) { $totalprice = $totalprice . "0"; }
}
else { $totalprice = $totalprice . ".00"; }
print "<td></td><td></td><td align=right><b>\$ $totalprice</b></td></tr>\n";

if ($tax eq '2') {
$temptax=$tax }

if ($temptax <=> '0') {

if ($tax eq '0') {
# print nothing
}
elsif ($tax eq '1') {
$taxtotal = $totalprice * $taxper;
$taxtotal = int($taxtotal * (10 ** 2) + .5) / (10 ** 2);

$totalprice = $totalprice + $taxtotal;
print "<tr><td><b>Taxes:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}

$_ = $taxtotal;

if (/\./) {
my($left,$right) = split(/\./,$taxtotal);
if (length($right) == 0) {
$taxtotal = $taxtotal . "00";
}
elsif (length($right) == 1) { $taxtotal = $taxtotal . "0"; }
}
else { $taxtotal = $taxtotal . ".00"; }

print "<td></td><td></td><td align=right><b>\$ $taxtotal</center></b></td></tr>\n";

##### INCLUDE TAX TAG FOR ITRANSACT #####

print "<input type=hidden name='$rcitem-desc' value='Tax'>\n";
print "<input type=hidden name='$rcitem-qty' value='1'>\n";
print "<input type=hidden name='$rcitem-cost' value='$taxtotal'>\n\n";

}

elsif ($tax eq '2') {
$taxtotal = $totalprice * $taxamt;
$taxtotal = int($taxtotal * (10 ** 2) + .5) / (10 ** 2);

$totalprice = $totalprice + $taxtotal;
print "<tr><td><b>Taxes:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}

$_ = $taxtotal;

#$rcitem=$rcitem+1;

if (/\./) {
my($left,$right) = split(/\./,$taxtotal);
if (length($right) == 0) {
$taxtotal = $taxtotal . "00";
}
elsif (length($right) == 1) { $taxtotal = $taxtotal . "0"; }
}
else { $taxtotal = $taxtotal . ".00"; }
print "<td></td><td></td><td align=right><b>\$ $taxtotal</center></b></td></tr>\n";


##### INCLUDE TAX TAG FOR ITRANSACT #####

print "<input type=hidden name='$rcitem-desc' value='Tax'>\n";
print "<input type=hidden name='$rcitem-qty' value='1'>\n";
print "<input type=hidden name='$rcitem-cost' value='$taxtotal'>\n\n";

}

}


if ($multiship eq 1) {
print "<tr><td><b>Shipping:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}
print "<td></td><td></td><td align=right>";

if ($usership eq 'NULL') {
print "<a href=\"$cgiurl\?command=calcship\">Calculate<br>Shipping</a>";
}
else {
print "<b>\$ $usership</b>";
$totalprice += $usership;
}
print "</td></tr>\n";
}
else {
if ($shipping eq '0') {
# print nothing
}
elsif ($shipping eq '1') {
local($low,@prices,$price);
@prices = sort number keys %shipping;
$low = $prices[0];
foreach $price (@prices) {
if (($price > $low) && ($price <= $totalquant)) {$low = $price};
}
$shipamt = $shipping{$low};
$totalprice += $shipamt;
print "<tr><td><b>Shipping:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}


$_ = $shipamt;


if (/\./) {
my($left,$right) = split(/\./,$shipamt);
if (length($right) == 0) {
$shipamt = $shipamt . "00";
}
elsif (length($right) == 1) { $shipamt = $shipamt . "0"; }
}
else { $shipamt = $shipamt . ".00"; }
print "<td></td><td></td><td align=right><b>\$ $shipamt</b></td></tr>\n";


##### INCLUDE SHIPPING TAG FOR ITRANSACT (BY NUMBER OF ITEMS ORDERED.) #####

print "<input type=hidden name='$rcitem-desc' value='Shipping'>\n";
print "<input type=hidden name='$rcitem-qty' value='1'>\n";
print "<input type=hidden name='$rcitem-cost' value='$shipamt'>\n\n";

}
elsif ($shipping eq '2') {
$totalprice += $shipamt;
print "<tr><td><b>Shipping:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}


$_ = $shipamt;


if (/\./) {
my($left,$right) = split(/\./,$shipamt);
if (length($right) == 0) {
$shipamt = $shipamt . "00";
}
elsif (length($right) == 1) { $shipamt = $shipamt . "0"; }
}
else { $shipamt = $shipamt . ".00"; }
print "<td></td><td></td><td align=right><b>\$ $shipamt</b></td></tr>\n";


##### INCLUDE SHIPPING TAG FOR ITRANSACT (NON-VARIABLE) #####

print "<input type=hidden name='$rcitem-desc' value='Shipping'>\n";
print "<input type=hidden name='$rcitem-qty' value='1'>\n";
print "<input type=hidden name='$rcitem-cost' value='$shipamt'>\n\n";

}
elsif ($shipping eq '3') {
my($low,@weights,$weight);
@weights = sort number keys %shipping;
$low = $weights[0];
foreach $weight (@weights) {
if ($weight > $low && $weight <= $totalweight) {$low = $weight};
}
$shipamt = $shipping{$low};
$totalprice += $shipamt;
print "<tr><td><b>Shipping:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}


$_ = $shipamt;


if (/\./) {
my($left,$right) = split(/\./,$shipamt);
if (length($right) == 0) {
$shipamt = $shipamt . "00";
}
elsif (length($right) == 1) { $shipamt = $shipamt . "0"; }
}
else { $shipamt = $shipamt . ".00"; }

print "<td align=center>";

if ($totalquant > '0') { print "<B>$totalweight lbs.</B>"; }

print "</td><td></td><td align=right><b>\$ $shipamt</b></td></tr>\n";

# print "<td align=center><B>$totalweight lbs.</B></td><td></td><td align=right><b>\$ $shipamt</b></td></tr>\n";

##### INCLUDE SHIPPING TAG FOR ITRANSACT (BY WEIGHT) #####

print "<input type=hidden name='$rcitem-desc' value='Shipping'>\n";
print "<input type=hidden name='$rcitem-qty' value='1'>\n";
print "<input type=hidden name='$rcitem-cost' value='$shipamt'>\n\n";

}

elsif ($shipping eq '4') {
my($low,@prices);
@prices = sort number keys %shipping;
$low = $prices[0];
foreach $price (@prices) {
if ($price > $low && $price <= $totalprice) {$low = $price};
}
$shipamt = $shipping{$low};
$totalprice += $shipamt;
print "<tr><td><b>Shipping:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}


$_ = $shipamt;


if (/\./) {
my($left,$right) = split(/\./,$shipamt);
if (length($right) == 0) {
$shipamt = $shipamt . "00";
}
elsif (length($right) == 1) { $shipamt = $shipamt . "0"; }
}
else { $shipamt = $shipamt . ".00"; }
print "<td></td><td></td><td align=right><b>\$ $shipamt</b></td></tr>\n";


##### INCLUDE SHIPPING TAG FOR ITRANSACT (BY TOTAL) #####

print "\n<input type=hidden name='$rcitem-desc' value='Shipping'>\n";
print "<input type=hidden name='$rcitem-qty' value='1'>\n";
print "<input type=hidden name='$rcitem-cost' value='$usership'>\n\n";

}
}

$totalprice = int($totalprice * (10 ** 2) + .5) / (10 ** 2);
$_ = $totalprice;
if (/\./) {
my($left,$right) = split(/\./,$totalprice);
if (length($right) == 0) {
$totalprice = $totalprice . "00";
}
elsif (length($right) == 1) { $totalprice = $totalprice . "0"; }
}
else { $totalprice = $totalprice . ".00"; }

print "<tr><td><b>Total price:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}
print "<td></td><td></td><td align=right><b>\$ $totalprice</b></td></tr>\n";
if ($multicurr eq 1) {
$totalprice *= $usercurr;
$totalprice = int($totalprice * (10 ** 2) + .5) / (10 ** 2);
$_ = $totalprice;
if (/\./) {
my($left,$right) = split(/\./,$totalprice);
if (length($right) == 0) {
$totalprice = $totalprice . "00";
}
elsif (length($right) == 1) { $totalprice = $totalprice . "0"; }
}
else { $totalprice = $totalprice . ".00"; }
print "<tr><td><b>Total price in selected currency:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}
print "<td colspan=2>Exchange Rate: $usercurr</td><td align=right><b>\$ $totalprice</b></td></tr>\n";
}

print "</table><br>\n";

}

# Review all items in cart. Can modify quantities.
sub review_items {
if ( ($multicurr eq 1) && ($usercurr eq 'NULL') ) { print "Location: $cgiurl\?command=calccurr \n\n"; }
&print_header;
&list_items;
print "<center><input type=submit value=\"Re-Calculate\"></form>\n";
&print_footer;
}

# Add a item to the cart, show review page, unless they included a redirect variable.
sub add_item {
open (REFFILE,"$reffile") &#0124; &#0124; print "Content-type: text/html\n\n Can't Open $reffile(r): $!\n";
@LINES=<REFFILE>;
close(REFFILE);
$SIZE=@LINES;
open (REFFILE,">$reffile") &#0124; &#0124; print "Content-type: text/html\n\n Can't Open $reffile(r): $!\n";
print REFFILE "$date\| $ENV{'REMOTE_HOST'}\| $ENV{'HTTP_USER_AGENT'}\|$usercurr\|NULL\|\n";
for ($i=1;$i<$SIZE;$i++) {
$_=$LINES[$i];
my($itemname, $itemprice, $itemquant, $weight, $itemid) = split(/\|/,$_);
print REFFILE join "\|", $itemname,$itemprice,$itemquant,$weight,$itemid,"\|\n";
}
print REFFILE join "\|", $FORM{'itemname'},$FORM{'itemprice'},$FORM{'itemquant'},$FORM{'weight'},$FORM{'itemid'};
print REFFILE "\|\n";
close(REFFILE);
if ($useredirect eq '1') {
print "Content-type: text/html\n\n <html><body bgcolor=\#ffffff onload=\"history.back()\">Item added.<br>If your browser does not support Javascript, please press BACK now.\n";
}
if ($FORM{'redirect'}) {
print "Location: $FORM{'redirect'} \n\n";
}
else {
&review_items;
}
}

# Change quanities of items, delete zero quantity items.
sub change_items {
open (REFFILE,"$reffile") &#0124; &#0124; print "Content-type: text/html\n\n Can't Open $reffile(r): $!\n";
my(@LINES)=<REFFILE>;
close(REFFILE);
$SIZE=@LINES;

open (REFFILE,">$reffile") &#0124; &#0124; print "Content-type: text/html\n\n Can't Open $reffile(r): $!\n";
print REFFILE "$date\| $ENV{'REMOTE_HOST'}\| $ENV{'HTTP_USER_AGENT'}\|$usercurr\|NULL\|\n";
for ($i=1;$i<$SIZE;$i++) {
local($itemq) = "item$i";
$_=$LINES[$i];
my($itemname, $itemprice, $itemquant, $weight, $itemid) = split(/\|/,$_);
if ($FORM{$itemq} > 0) {
print REFFILE join "\|", $itemname,$itemprice,$FORM{$itemq},$weight,$itemid,"\|\n";
}
}
close(REFFILE);
print "Location: $cgiurl\?command=review\n\n";
}


# Show the order form
sub buy_items1 {

if (($usership eq 'NULL') && ($multiship eq 1)) {
print "Location: $cgiurl\?command=calcship \n\n";
}
&print_header;

print "<FORM METHOD='POST' ACTION='https://www.a4webhotell.com/cgi-bin/FormMail.cgi'>";

if ($tax eq '2') {
$temptax=$tax }

&list_items_final;

##### TAX INFO ON ORDER PAGE #####

if ($tax eq '1') {

if ($taxtotal > '0') {

print "<a href=\"$cgiurl\?command=removetax2\"><font size=-1><B>CLICK HERE</a> if you are not a $taxstate resident.</font><P>";
}

else {
print "<a href=\"$cgiurl\?command=addtax2\"><font size=-1><B>CLICK HERE</a></font> <B>if you are a $taxstate resident.</B><P>";
}
}
##### TAX INFO ENDS HERE #####


### THIS WHERE THE ORDER FORM IS DISPLAYED ###

if ($defaultform eq '1') {

&order_form;
}
else {

open (ORDER,"$basepath/$split_order") &#0124; &#0124; print "Could not open $basepath/$split_order $! \n";
while (<ORDER> ) {
print $_;
}
close(ORDER);
&print_footer;
}
}

# Process the order form
sub buy_items2 {
&OrdParse;

$in{good}=$good;

&print_header;

if( $in{good} eq "1")
{

print "You have successfully ordered the following:<br><br>\n";
&list_items;

}

print "<br><br>\n";
&print_footer;
unlink($reffile);
}

# parse form input
sub parse_form {
my(@pairs);
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
# Split the name-value pairs
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);
}
else {
&error('request_method');
}

foreach $pair (@pairs) {
my($name, $value) = split(/=/, $pair);

$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

# If they try to include server side includes, erase them, so they
# arent a security risk if the html gets returned. Another
# security hole plugged up.

$value =~ s/<!--(.|\n)*-->//g;

# Create two associative arrays here. One is a configuration array
# which includes all fields that this form recognizes. The other
# is for fields which the form does not recognize and will report
# back to the user in the html return page and the e-mail message.
# Also determine required fields.

if ($name eq 'bgcolor' &#0124; &#0124;
$name eq 'background' &#0124; &#0124;
$name eq 'link_color' &#0124; &#0124;
$name eq 'vlink_color' &#0124; &#0124;
$name eq 'text_color' &#0124; &#0124;
$name eq 'alink_color' &#0124; &#0124;
$name eq 'title' &#0124; &#0124;
$name eq 'sort' &#0124; &#0124;
$name eq 'print_config' &#0124; &#0124;
$name eq 'return_link_title' &#0124; &#0124;
$name eq 'return_link_url' && ($value)) {

$CONFIG{$name} = $value;
}
elsif ($name eq 'required') {
@required = split(/,/,$value);
}
elsif ($name eq 'exclude') {
@exclude = split(/,/,$value);
}
else {
if ($FORM{$name} && ($value)) {
$FORM{$name} = "$FORM{$name}, $value";
}
elsif ($value) {
$FORM{$name} = $value;
}
}
}
}


# Get the hostname, for file reference
sub get_host {
$host = $ENV{'REMOTE_HOST'};
$reffile = "$tmpdir/$storename-$host";
}

sub check_file {
$exists = '1' if -e "$reffile";
if ($exists eq '1') {
&parse_file;
}
else {
&make_file;
}
}

# Parse the cart
sub parse_file {
open (REFFILE,"$reffile") &#0124; &#0124; die "Can't Open $reffile(r): $!\n";
@LINES=<REFFILE>;
close(REFFILE);
$SIZE=@LINES;
$_=$LINES[0];
($usertime, $userhost, $useragent, $usercurr, $usership) = split(/\|/,$_);
}

# If they don't have a cart, make them one.
sub make_file {
open(REFFILE,">$reffile");
print REFFILE "$date\| $ENV{'REMOTE_HOST'}\| $ENV{'HTTP_USER_AGENT'}\|";
if ($multicurr eq 1) { print REFFILE "NULL\|"; } else { print REFFILE "1\|"; }
print REFFILE "NULL\|\n";
close(REFFILE);
}

#Delete a cart
sub delete_cart {
unlink($reffile);
}

# Delete an item from the cart
sub delete_item {
open (REFFILE,"$reffile") &#0124; &#0124; print "Content-type: text/html\n\n Can't Open $reffile(r): $!\n";
@LINES=<REFFILE>;
close(REFFILE);
$SIZE=@LINES;

open (REFFILE,">$reffile") &#0124; &#0124; print "Content-type: text/html\n\n Can't Open $reffile(r): $!\n";
print REFFILE "$date\| $ENV{'REMOTE_HOST'}\| $ENV{'HTTP_USER_AGENT'}\|NULL\|NULL\|\n";
for ($i=1;$i<$SIZE;$i++) {
$_=$LINES[$i];
my($itemname, $itemprice, $itemquant, $weight, $itemid) = split(/\|/,$_);
if ($FORM{$itemname} eq $itemname) {
# Do nothing
}
else { print REFFILE $_; }
}
close(REFFILE);
print "Location: $cgiurl\?command=review\n\n";
}

# Get the date.
sub get_date {
@days =
('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
@months = ('January','February','March','April','May','June','July',
'August','September','October','November','December');

($sec,$min,$hour,$mday,$mon,$year,$wday) =
localtime(time);
if ($hour < 10) { $hour = "0$hour"; }
if ($min < 10) { $min = "0$min"; }
if ($sec < 10) { $sec = "0$sec"; }

$date = "$days[$wday], $months[$mon] $mday, 19$year at $hour\:$min\:$sec";

}

# Did they fill out all necessary info?
sub check_required {

foreach $require (@required) {
if ($require eq 'bgcolor' &#0124; &#0124;
$require eq 'background' &#0124; &#0124;
$require eq 'link_color' &#0124; &#0124;
$require eq 'vlink_color' &#0124; &#0124;
$require eq 'alink_color' &#0124; &#0124;
$require eq 'text_color' &#0124; &#0124;
$require eq 'sort' &#0124; &#0124;
$require eq 'title' &#0124; &#0124;
$require eq 'print_config' &#0124; &#0124;
$require eq 'return_link_title' &#0124; &#0124;
$require eq 'return_link_url') {

if (!($CONFIG{$require}) &#0124; &#0124; $CONFIG{$require} eq ' ') {
push(@ERROR,$require);
}
}
elsif (!($FORM{$require}) &#0124; &#0124; $FORM{$require} eq ' ') {
push(@ERROR,$require);
}
}

if (@ERROR) {
&error('missing_fields', @ERROR);
}

}

# Warning Warning.
sub error {
&print_header;
($error,@error_fields) = @_;

if ($error eq 'missing_fields') {


print " <h1>Error: Blank Fields</h1>\n\n";
print "The following fields were left blank in your submission form:<p>\n";

# Print Out Missing Fields in a List.
print "<ul>\n";
foreach $missing_field (@error_fields) {
print "<li>$missing_field\n";
}
print "</ul>\n";

# Provide Explanation for Error and Offer Link Back to Form.
print "<p><hr size=7 width=75\%><p>\n";
print "These fields must be filled out before you can successfully submit\n";
print "the form. Please return to the <a href=\"$ENV{'HTTP_REFERER'}\">Fill Out Form</a> and try again.\n";
}
elsif ($error eq 'noship') {
print "<h2>Error: Shipping not Set!</h2><br> Please go back and calcualte shipping!\n";
}
&print_footer;
exit;
}

sub print_script {
print <<"JAVA";
<SCRIPT LANGUAGE="JavaScript">
<!--
function MakeArray()
{
this.length = MakeArray.arguments.length
for (var i = 0; i < this.length; i++)
this[i+1] = MakeArray.arguments
}

function jumpPage1(form)
{
i = document.select1.SelectMenu.selectedIndex;
form.ship.value = url1[i+1];
form.total.value = url1[i+1]+total;
}
JAVA

print "url1 = new MakeArray($shipping1{$low}, $shipping2{$low}, $shipping3{$low});\n";
print "total = $totalprice \- $shipping1{$low};\n";

print <<"JAVA";

// -->
</script>
JAVA

}

sub calc_shipping {
&print_header;

local ($totalprice,$totalquant,$totalweight) = 0;
open (REFFILE,"$reffile") &#0124; &#0124; die "Content-type: text/html\n\nCan't Open $reffile(r): $!\n";
@LINES=<REFFILE>;
close(REFFILE);
$SIZE=@LINES;

print "<form method=POST name=select1 action=\"$cgiurl?command=setship\">\n";
print "<table border=1 cellpadding=5><tr>\n";

if ($useimage eq '1') {
print "<th></th>";
}

if ($useid eq '1') {
print "<th><font size=-1 color=blue>ITEM ID</font></th>";
}

print "<TR BGCOLOR='#000000'><TH COLSPAN=5 ALIGN=center><FONT SIZE=3 COLOR=white> <B>$mname</B> </FONT></TH></TR>
<th><font size=-1 color=blue>ITEM NAME</FONT></th><th><font size=-1 color=blue>QUANTITY</font></th><th><font size=-1 color=blue>PRICE</font></th><th><font size=-1 color=blue>AMOUNT</font></th></tr>";

for ($i=1;$i<$SIZE;$i++) {
$_=$LINES[$i];
($itemname, $itemprice, $itemquant, $weight, $itemid) = split(/\|/,$_);
$tmpprice = $itemprice*$itemquant;
$tmpprice = int($tmpprice * (10 ** 2) + .5) / (10 ** 2);

$totalprice=$totalprice + $tmpprice;
$totalquant=$totalquant + $itemquant;
$totalweight = ($weight*$itemquant) + $totalweight;
print "<tr>";

if ($useimage eq '1') {
if ($FORM{'image'}) {
print "<td><img src=\"$imageurl/$FORM{'image'}\"></td>\n";
}
else {
print "<td></td>";
}
}

if ($useid eq '1') {
print "<td>$itemid <input type=hidden name=itemid value=\"$itemid\"></td>\n";
}

$_ = $tmpprice;

if (/\./) {
my($left,$right) = split(/\./,$tmpprice);
if (length($right) == 0) {
$tmpprice = $tmpprice . "00";
}
elsif (length($right) == 1) { $tmpprice = $tmpprice . "0"; }
}
else { $tmpprice = $tmpprice . ".00"; }

print "<td>$itemname</td><td align=center>$itemquant</td><td align=right>\$ $itemprice</td><td align=right>\$ $tmpprice</tr>\n";
}
print "<tr><td><b>Subtotal:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}

$_ = $totalprice;
if (/\./) {
my($left,$right) = split(/\./,$totalprice);
if (length($right) == 0) {
$totalprice = $totalprice . "00";
}
elsif (length($right) == 1) { $totalprice = $totalprice . "0"; }
}
else { $totalprice = $totalprice . ".00"; }
print "<td></td><td></td><td align=right><b>\$ $totalprice</b></td></tr>\n";

if ($tax eq '0') {
# print nothing
}
elsif ($tax eq '1') {
$taxtotal = $totalprice * $taxper;
$taxtotal = int($taxtotal * (10 ** 2) + .5) / (10 ** 2);

$totalprice = $totalprice + $taxtotal;

#print "<tr><td><b>Taxes:</b></td>";
#if ($useimage eq '1') {
# print "<td></td>";
# }
#if ($useid eq '1') {
# print "<td></td>";
# }
#
#$_ = $taxtotal;
#
#if (/\./) {
# my($left,$right) = split(/\./,$taxtotal);
# if (length($right) == 0) {
# $taxtotal = $taxtotal . "00";
# }
# elsif (length($right) == 1) { $taxtotal = $taxtotal . "0"; }
# }
# else { $taxtotal = $taxtotal . ".00"; }
#print "<td></td><td></td><td align=right><b>\$ $taxtotal</center></b></td></tr>\n";

##### INCLUDE TAX TAG FOR ITRANSACT #####

#print "<input type=hidden name='$rcitem-desc' value='Tax'>\n";
#print "<input type=hidden name='$rcitem-qty' value='1'>\n";
#print "<input type=hidden name='$rcitem-cost' value='$taxtotal'>\n\n";

}

elsif ($tax eq '2') {
$taxtotal = $totalprice * $taxamt;
$taxtotal = int($taxtotal * (10 ** 2) + .5) / (10 ** 2);
$totalprice += $taxtotal;
print "<tr><td><b>Taxes:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}

$_ = $taxtotal;

if (/\./) {
my($left,$right) = split(/\./,$taxtotal);
if (length($right) == 0) {
$taxtotal = $taxtotal . "00";
}
elsif (length($right) == 1) { $taxtotal = $taxtotal . "0"; }
}
else { $taxtotal = $taxtotal . ".00"; }

print "<td></td><td></td><td align=right><b>\$ $taxtotal</center></b></td></tr>\n";

}

if ($shipping eq '0') {
# print nothing
}
elsif ($shipping eq '1') {
local(@prices,$price);
@prices = sort number keys %shipping;
$low = $prices[0];
foreach $price (@prices) {
if ($price < $low && $price >= $totalquant) {$low = $price};
}
$shipamt = $shipping{$low};
$totalprice += $shipamt;
}
elsif ($shipping eq '2') {
$totalprice += $shipamt;
}
elsif ($shipping eq '3') {
my(@weights,$weight);
@weights = sort number keys %shipping;
$low = $weights[0];
foreach $weight (@weights) {
if ($weight > $low && $weight <= $totalweight) {$low = $weight};
}
$shipamt = $shipping{$low};
$totalprice += $shipamt;
}
elsif ($shipping eq '4') {
my(@prices);
@prices = sort number keys %shipping1;
$low = $prices[0];
foreach $price (@prices) {
if ($price > $low && $price <= $totalprice) {$low = $price};
}
$shipamt = $shipping1{$low};
$totalprice += $shipamt;
}

print "<tr><td><b>Shipping:</b></td>";
$totalprice = int($totalprice * (10 ** 2) + .5) / (10 ** 2);
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}
print "<td>";

&print_script;

$_ = $shipamt;


if (/\./) {
my($left,$right) = split(/\./,$shipamt);
if (length($right) == 0) {
$shipamt = $shipamt . "00";
}
elsif (length($right) == 1) { $shipamt = $shipamt . "0"; }
}
else { $shipamt = $shipamt . ".00"; }
# print "<td></td><td></td><td align=right><b>\$ $shipamt</b></td></tr>\n";

print "</td><td>
<select name=\"SelectMenu\" onChange=\"jumpPage1(this.form)\">
<option>Standard</option>
<option>2nd Day</option>
<option>Next Day</option>

</select></td><td align=right><b>\$ <input type=text name=ship size=8 maxlength=0 value=\"$shipamt\" onFocus=\"form.ship.blur()\" onSelect=\"form.ship.blur()\"></b></td></tr>\n";


$totalprice = int($totalprice * (10 ** 2) + .5) / (10 ** 2);
$_ = $totalprice;
if (/\./) {
($left,$right) = split(/\./,$totalprice);
if (length($right) == 0) {
$totalprice = $totalprice . "00";
}
elsif (length($right) == 1) { $totalprice = $totalprice . "0"; }
}
else { $totalprice = $totalprice . ".00"; }

print "<tr><td><b>Total price:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}
print "<td></td><td></td><td align=right><b>\$ <input type=text name=total size=8 maxlength=0 value=\"$totalprice\" onFocus=\"form.total.blur()\" onSelect=\"form.total.blur()\"></b></td></tr>\n";
print "</table><br>\n";

print "<center><input type=submit value=\"Set Shipping\"></form>\n";
&print_footer;
}


sub set_shipping {
open (REFFILE,"$reffile") &#0124; &#0124; print "Content-type: text/html\n\n Can't Open $reffile(r): $!\n";
my(@LINES)=<REFFILE>;
close(REFFILE);
$SIZE=@LINES;

open (REFFILE,">$reffile") &#0124; &#0124; print "Content-type: text/html\n\n Can't Open $reffile(r): $!\n";
print REFFILE "$date\| $ENV{'REMOTE_HOST'}\| $ENV{'HTTP_USER_AGENT'}\|$usercurr\|$FORM{'ship'}\|\n";
for ($i=1;$i<$SIZE;$i++) {
$_=$LINES[$i];
my($itemname, $itemprice, $itemquant, $weight, $itemid) = split(/\|/,$_);
print REFFILE join "\|", $itemname,$itemprice,$itemquant,$weight,$itemid,"\|\n";
}
print "Location: $cgiurl\?command=review\n\n";

}

sub calc_currency {

sub print_curr_script {
print <<"JAVA";
<SCRIPT LANGUAGE="JavaScript">
<!--
function MakeArray()
{
this.length = MakeArray.arguments.length
for (var i = 0; i < this.length; i++)
this[i+1] = MakeArray.arguments
}

function jumpPage1(form)
{
i = document.select1.SelectMenu.selectedIndex;
form.exchange.value = url1[i+1];
}
JAVA

print "url1 = new MakeArray(";
my(@currs) = sort number keys %currency;
foreach $curr (@currs) { print "$currency{$curr},"; }
print "1);\n";

print <<"JAVA";


// -->
</script>
JAVA

}

&print_header;
print "<form method=POST name=select1 action=\"$cgiurl?command=setcurr\">\n";
print "<table border=1><tr>";
print "<th></th><th>Currency</th><th>Exchange Rate</th></tr><tr><td>\n";

&print_curr_script;

print "</td><td><select name=\"SelectMenu\" onChange=\"jumpPage1(this.form)\">";
@currs = sort number keys %currency;
foreach $curr (@currs) { print "<option> $curr </option>\n"; }
print "<option selected>Pick a Currency</option></select></td><td>\n";
print "<input type=text name=exchange size=8 maxlength=0 value=\"1\" onFocus=\"form.total.blur()\" onSelect=\"form.total.blur()\">";
print "</td></tr></table>\n";
print "<center><input type=submit value=\"Set Currency\"></form>\n";
&print_footer;
}

sub set_currency {
open (REFFILE,"$reffile") &#0124; &#0124; print "Content-type: text/html\n\n Can't Open $reffile(r): $!\n";
my(@LINES)=<REFFILE>;
close(REFFILE);
$SIZE=@LINES;

open (REFFILE,">$reffile") &#0124; &#0124; print "Content-type: text/html\n\n Can't Open $reffile(r): $!\n";
print REFFILE "$date\| $ENV{'REMOTE_HOST'}\| $ENV{'HTTP_USER_AGENT'}\|$FORM{'exchange'}\|$usership\|\n";
for ($i=1;$i<$SIZE;$i++) {
$_=$LINES[$i];
my($itemname, $itemprice, $itemquant, $weight, $itemid) = split(/\|/,$_);
print REFFILE join "\|", $itemname,$itemprice,$itemquant,$weight,$itemid,"\|\n";
}
print "Location: $cgiurl\?command=review\n\n";

}

sub track_order {

$orderid = time() . "-" . $$;

open (TRACK, ">>$trackdb");
print TRACK $orderid . "\|";
foreach $key (%FORM) {
print TRACK "$key\=$FORM{$key}\&";
}
print TRACK "\|pending\|NONE\|\n";
close(TRACK);
}


sub order_form {

print "<strong><center><HR width=590><font size=-1 color=blue><B>GENERAL INFORMATION</b></FONT><HR width=590></strong></center></TD>
<TABLE width=590>
<input type=hidden name='recipient' value='are/@a4.no'>
<TR>
<TD ALIGN='right'><B>First Name: </B> </TD>
<TD><INPUT NAME='first_name' SIZE=15> <B>Last Name: </B>
<INPUT NAME='last_name' SIZE=15> <BR> </TD>
</TR>

<TR>
<TD ALIGN='right'><B>Address: </B> </TD>
<TD><INPUT NAME='address' SIZE=30><BR></TD>
</TR>

<TR>
<TD ALIGN='right'><B>City: </B> </TD>
<TD><INPUT NAME='city' SIZE=15> <B> State: </B>
<INPUT NAME='state' SIZE=3 MAXLENGTH=2> <B> Zip: </B>
<INPUT NAME='zip' SIZE=10><BR></TD>
</TR>

<TR>
<TD ALIGN='right'><B>Country: </B> </TD>
<TD><INPUT NAME='country' SIZE=45 value='USA'><BR></TD>
</TR>

<TR>
<TD ALIGN='right'><B>Phone Number: </B> </TD>
<TD><strong><INPUT NAME='phone' SIZE=15><BR></TD>
</TR>

<TR>
<TD ALIGN='right'><B>E-Mail Address: </B> </TD>
<TD><INPUT NAME='email' SIZE=30></TD>
</TR>

</TABLE>
<TD><HR width=590></TD>
<TR><TD>

</CENTER>


</B></font>
<!--<!BR><font size=-1><B>TO COMPLETE YOUR ORDER, PRESS CONTINUE AND YOU WILL BE TAKEN TO A SECURE SERVER.--><BR>
<INPUT TYPE='submit' VALUE='PROCEED TO SECURE SERVER.'>

</form>"

}


sub remove_tax {
$temptax = '0';
&review_items;
}

sub add_tax {
$temptax = $tax;
&review_items;
}


sub remove_tax2 {
$temptax = '0';
&buy_items1;
}

sub add_tax2 {
$temptax = $tax;
&buy_items1;
}



sub list_items_final {
my($totalprice,$totalquant,$totalweight) = 0;
open (REFFILE,"$reffile") &#0124; &#0124; die "Content-type: text/html\n\nCan't Open $reffile(r): $!\n";
my(@LINES)=<REFFILE>;
close(REFFILE);
$SIZE=@LINES;
$rcitem=1;

if ($usership eq 'NULL') {
$usership='0';
}

#print "<form name=select1 method=POST action=\"$cgiurl?command=change\">\n";

##### INCLUDE REQUIRED ITRANSACT MERCHANT TAGS #####

#print "<FORM METHOD='POST' ACTION='https://secure.redi-check.com/cgi-bin/rc3preord/chkord.cgi'>\n";

print "\n";


print "<INPUT type='hidden' name='vendor_id' value='$mid'>\n";
print "<INPUT type='hidden' name='home_page' value='$hp'>\n";
print "<INPUT type='hidden' name='ret_addr' value='$retaddr'>\n";
print "<INPUT type='hidden' name='email_text' value='$etext'>\n";

#print "<INPUT type='hidden' name='ret_mode' value='$ret_mode'>\n";

print "<INPUT type='hidden' name='lookup' value='first_name'>\n";
print "<INPUT type='hidden' name='lookup' value='last_name'>\n";
print "<INPUT type='hidden' name='lookup' value='address'>\n";
print "<INPUT type='hidden' name='lookup' value='city'>\n";
print "<INPUT type='hidden' name='lookup' value='state'>\n";
print "<INPUT type='hidden' name='lookup' value='zip'>\n";
print "<INPUT type='hidden' name='lookup' value='ctry'>\n";
print "<INPUT type='hidden' name='lookup' value='phone'>\n";
print "<INPUT type='hidden' name='lookup' value='email'>\n";

#print "<INPUT type='hidden' name='passback' value='good'>\n";
#print "<INPUT type='hidden' name='good' value='1'>\n";

#print "<INPUT type='hidden' name='passback' value='desc1'>\n";
#print "<INPUT type='hidden' name='desc1' value='$itemname'>\n";

##### INCLUDE SPLIT-FORM TAGS IF REQUIRED #####

if ($split eq '1') {
print "\n<INPUT type='hidden' name='mername' value='$mname'>\n";
print "<INPUT type='hidden' name='mertext' value='$mtext'>\n";
print "<INPUT type='hidden' name='acceptchecks' value='$checks'>\n";
print "<INPUT type='hidden' name='allowreg' value='$creg'>\n";
print "<INPUT type='hidden' name='checkguar' value='$cguar'>\n";
print "<INPUT type='hidden' name='acceptcards' value='$cards'>\n";
print "<INPUT type='hidden' name='altaddr' value='$creg'>\n";

}

print "\n";

print "<table border=1 cellpadding=5><tr>\n";

if ($useimage eq '1') {
print "<th></th>";
}

if ($useid eq '1') {
print "<th><font size=-1 color=blue>ITEM ID</font></th>";
}

print "<TR BGCOLOR='#000000'><TH COLSPAN=5 ALIGN=center><FONT SIZE=3 COLOR=white> <B>$mname</B> </FONT></TH></TR>
<th><font size=-1 color=blue>ITEM NAME</FONT></th><th><font size=-1 color=blue>QUANTITY</font></th><th><font size=-1 color=blue>PRICE</font></th><th><font size=-1 color=blue>AMOUNT</font></th></tr>";

for ($i=1;$i<$SIZE;$i++) {
$_=$LINES[$i];
($itemname, $itemprice, $itemquant, $weight, $itemid) = split(/\|/,$_);
$tmpprice = ($itemprice*$itemquant);
$tmpprice = int($tmpprice * (10 ** 2) + .5) / (10 ** 2);

$totalprice += $tmpprice;
$totalquant += $itemquant;
$totalweight = ($weight*$itemquant) + $totalweight;
print "<tr>";


if ($useimage eq '1') {
if ($FORM{'image'}) {
print "<td><img src=\"$imageurl/$FORM{'image'}\"></td>\n";
}
else {
print "<td></td>";
}
}

if ($useid eq '1') {
print "<td>$itemid <input type=hidden name=itemid value=\"$itemid\"></td>\n";
}



$_ = $tmpprice;

if (/\./) {
my($left,$right) = split(/\./,$tmpprice);
if (length($right) == 0) {
$tmpprice = $tmpprice . "00";
}
elsif (length($right) == 1) { $tmpprice = $tmpprice . "0"; }
}
else { $tmpprice = $tmpprice . ".00"; }


#print "<td>$itemname</td><td align=right>\$ $itemprice</td><td align=center><input type=number size=2 value=\"$itemquant\" name=item$i></td><td align=right>\$ $tmpprice</tr>\n";
print "<td>$itemname</td><td align=center>$itemquant</td><td align=right>\$ $itemprice</td><td align=right>\$ $tmpprice</tr>\n";

########## INCLUDE REQUIRED FIELD NAMES ###########

print "<input type=hidden name='$rcitem-desc' value='$itemname'>\n";
print "<input type=hidden name='$rcitem-qty' value='$itemquant'>\n";
print "<input type=hidden name='$rcitem-cost' value='$itemprice'>\n";

print "<INPUT type='hidden' name='passback' value='desc$rcitem'>\n";
print "<INPUT type='hidden' name='desc$rcitem' value='$itemname'>\n\n";

print "<INPUT type='hidden' name='passback' value='qty$rcitem'>\n";
print "<INPUT type='hidden' name='qty$rcitem' value='$itemquant'>\n\n";

print "<INPUT type='hidden' name='passback' value='cost$rcitem'>\n";
print "<INPUT type='hidden' name='cost$rcitem' value='$itemprice'>\n\n";

### SUBTOTAL PASSBACKS ###

print "<INPUT type='hidden' name='passback' value='sub$rcitem'>\n";
print "<INPUT type='hidden' name='sub$rcitem' value='$tmpprice'>\n\n";

$rcitem=$rcitem+1;

}

### QUANTITY FIGURED ###

print "<P><INPUT type='hidden' name='passback' value='finalquant'><BR>\n";
print "<INPUT type='hidden' name='finalquant' value='$rcitem'><P>\n\n";


print "<tr><td><b>Subtotal:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}

$_ = $totalprice;
if (/\./) {
my($left,$right) = split(/\./,$totalprice);
if (length($right) == 0) {
$totalprice = $totalprice . "00";
}
elsif (length($right) == 1) { $totalprice = $totalprice . "0"; }
}
else { $totalprice = $totalprice . ".00"; }
print "<td></td><td></td><td align=right><b>\$ $totalprice</b></td></tr>\n";

### FULL ORDER SUBTOTAL PASSBACKS ###

print "<INPUT type='hidden' name='passback' value='subtotal'>\n";
print "<INPUT type='hidden' name='subtotal' value='$totalprice'>\n\n";

if ($temptax <=> '0') {

if ($tax eq '0') {
# print nothing
}
elsif ($tax eq '1') {
$taxtotal = $totalprice * $taxper;

$taxtotal = int($taxtotal * (10 ** 2) + .5) / (10 ** 2);


$totalprice = $totalprice + $taxtotal;
print "<tr><td><b>";

if ($tax eq '1') {print "$taxstate "};

print "Taxes:</b></td>";

if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}




$_ = $taxtotal;

if (/\./) {
my($left,$right) = split(/\./,$taxtotal);
if (length($right) == 0) {
$taxtotal = $taxtotal . "00";
}
elsif (length($right) == 1) { $taxtotal = $taxtotal . "0"; }
}
else { $taxtotal = $taxtotal . ".00"; }
print "<td></td><td></td><td align=right><b>\$ $taxtotal</center></b></td></tr>\n";



### TAX PASSBACKS ###

print "<INPUT type='hidden' name='passback' value='taxes'>\n";
print "<INPUT type='hidden' name='taxes' value='$taxtotal'>\n\n";

##### TAX TAG #####

print "<input type=hidden name='$rcitem-desc' value='Tax'>\n";
print "<input type=hidden name='$rcitem-qty' value='1'>\n";
print "<input type=hidden name='$rcitem-cost' value='$taxtotal'>\n\n";

}

elsif ($tax eq '2') {

$taxtotal = $totalprice * $taxamt;
$taxtotal = int($taxtotal * (10 ** 2) + .5) / (10 ** 2);

$totalprice = $totalprice + $taxtotal;

print "<tr><td><b>";

if ($tax eq '1') {print "$taxstate "};

print "Taxes:</b></td>";

if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}

$_ = $taxtotal;

if (/\./) {
my($left,$right) = split(/\./,$taxtotal);
if (length($right) == 0) {
$taxtotal = $taxtotal . "00";
}
elsif (length($right) == 1) { $taxtotal = $taxtotal . "0"; }
}
else { $taxtotal = $taxtotal . ".00"; }
print "<td></td><td></td><td align=right><b>\$ $taxtotal</center></b></td></tr>\n";


### TAX PASSBACKS ###

print "<INPUT type='hidden' name='passback' value='taxes'>\n";
print "<INPUT type='hidden' name='taxes' value='$taxtotal'>\n\n";

##### INCLUDE TAX TAGT #####

print "<input type=hidden name='$rcitem-desc' value='Tax'>\n";
print "<input type=hidden name='$rcitem-qty' value='1'>\n";
print "<input type=hidden name='$rcitem-cost' value='$taxtotal'>\n\n";

}

}


$rcitem=$rcitem+1;

if ($multiship eq 1) {
print "<tr><td><b>Shipping:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}
print "<td></td><td></td><td align=right>";

print "<input type=hidden name='$rcitem-desc' value='Shipping'>\n";
print "<input type=hidden name='$rcitem-qty' value='1'>\n";
print "<input type=hidden name='$rcitem-cost' value='$usership'>\n\n";

if ($usership eq 'NULL') {
print "<a href=\"$cgiurl\?command=calcship\">Calculate<br>Shipping</a>";
}
else {
print "<b>\$ $usership</b>";
$totalprice += $usership;
}
print "</td></tr>\n";
}
else {
if ($shipping eq '0') {
# print nothing
}
elsif ($shipping eq '1') {
local($low,@prices,$price);
@prices = sort number keys %shipping;
$low = $prices[0];
foreach $price (@prices) {
if (($price > $low) && ($price <= $totalquant)) {$low = $price};
}
$shipamt = $shipping{$low};
$totalprice += $shipamt;
print "<tr><td><b>Shipping:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}



$_ = $shipamt;


if (/\./) {
my($left,$right) = split(/\./,$shipamt);
if (length($right) == 0) {
$shipamt = $shipamt . "00";
}
elsif (length($right) == 1) { $shipamt = $shipamt . "0"; }
}
else { $shipamt = $shipamt . ".00"; }
print "<td></td><td></td><td align=right><b>\$ $shipamt</b></td></tr>\n";


##### INCLUDE SHIPPING TAG FOR ITRANSACT (BY NUMBER OF ITEMS ORDERED.) #####

print "<input type=hidden name='$rcitem-desc' value='Shipping'>\n";
print "<input type=hidden name='$rcitem-qty' value='1'>\n";
print "<input type=hidden name='$rcitem-cost' value='$shipamt'>\n\n";

}
elsif ($shipping eq '2') {
$totalprice += $shipamt;
print "<tr><td><b>Shipping:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}


$_ = $shipamt;


if (/\./) {
my($left,$right) = split(/\./,$shipamt);
if (length($right) == 0) {
$shipamt = $shipamt . "00";
}
elsif (length($right) == 1) { $shipamt = $shipamt . "0"; }
}
else { $shipamt = $shipamt . ".00"; }
print "<td></td><td></td><td align=right><b>\$ $shipamt</b></td></tr>\n";


##### INCLUDE SHIPPING TAG FOR ITRANSACT (NON-VARIABLE) #####

print "<input type=hidden name='$rcitem-desc' value='Shipping'>\n";
print "<input type=hidden name='$rcitem-qty' value='1'>\n";
print "<input type=hidden name='$rcitem-cost' value='$shipamt'>\n\n";

}
elsif ($shipping eq '3') {
my($low,@weights,$weight);
@weights = sort number keys %shipping;
$low = $weights[0];
foreach $weight (@weights) {
if ($weight > $low && $weight <= $totalweight) {$low = $weight};
}
$shipamt = $shipping{$low};
$totalprice += $shipamt;
print "<tr><td><b>Shipping:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}


$_ = $shipamt;


if (/\./) {
my($left,$right) = split(/\./,$shipamt);
if (length($right) == 0) {
$shipamt = $shipamt . "00";
}
elsif (length($right) == 1) { $shipamt = $shipamt . "0"; }
}
else { $shipamt = $shipamt . ".00"; }

print "<td align=center>";

if ($totalquant > '0') { print "<B>$totalweight lbs.</B>"; }

print "</td><td></td><td align=right><b>\$ $shipamt</b></td></tr>\n";


##### INCLUDE SHIPPING TAG FOR ITRANSACT (BY WEIGHT) #####

print "<input type=hidden name='$rcitem-desc' value='Shipping'>\n";
print "<input type=hidden name='$rcitem-qty' value='1'>\n";
print "<input type=hidden name='$rcitem-cost' value='$shipamt'>\n\n";
$passship=$shipamt;
}

elsif ($shipping eq '4') {
my($low,@prices);
@prices = sort number keys %shipping;
$low = $prices[0];
foreach $price (@prices) {
if ($price > $low && $price <= $totalprice) {$low = $price};
}
$shipamt = $shipping{$low};
$totalprice += $shipamt;
print "<tr><td><b>Shipping:</b></td>";
if ($useimage eq '1') {
print "<td></td>";
}
if ($useid eq '1') {
print "<td></td>";
}


$_ = $shipamt;


if (/\./) {
my($left,$right) = split(/\./,$shipamt);
if (length($right) == 0) {
$shipamt = $shipamt . "00";
}
elsif (length($right) == 1) { $shipamt = $shipamt . "0"; }
}
else { $shipamt = $shipamt . ".00"; }
print "
Quote Reply
Re: How to make a cgi send mail?? In reply to
Please dont post huge files of code, but rahter link to them off of your server.
Quote Reply
Re: How to make a cgi send mail?? In reply to
Hi:

You escaped @ with /. It should be escaped with \ - e.g., 'are\@a4.no'

Dan Smile
Quote Reply
Re: How to make a cgi send mail?? In reply to
Thanks!

it worked!