\n";
if ($creg eq '1') {
print " ";
}
else {
print " ";
}
print "GO BACK | CONTINUE SHOPPING
";
}
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 add_tax3 {
$temptax = $tax;
&confirm;
}
sub remove_tax3 {
$temptax = '0';
&confirm;
}
sub list_items_final {
my($totalprice,$totalquant,$totalweight) = 0;
open (REFFILE,"$reffile") || die "Content-type: text/html\n\nCan't Open $reffile(r): $!\n";
my(@LINES)=;
close(REFFILE);
$SIZE=@LINES;
$rcitem=1;
if ($usership eq 'NULL') {
$usership='0';
}
print "\n";
if ($useimage eq '1') {
print " ";
}
if ($useid eq '1') {
print "ITEM ID ";
}
print " $mname
ITEM NAME QUANTITY PRICE AMOUNT ";
for ($i=1;$i<$SIZE;$i++) {
$_=$LINES[$i];
($itemname, $itemprice, $itemquant, $weight, $itemid, $return_url) = split(/\|/,$_);
$tmpprice = ($itemprice*$itemquant);
$tmpprice = int($tmpprice * (10 ** 2) + .5) / (10 ** 2);
$totalprice += $tmpprice;
$totalquant += $itemquant;
$totalweight = ($weight*$itemquant) + $totalweight;
print "";
if ($useimage eq '1') {
if ($FORM{'image'}) {
print " \n";
}
else {
print " ";
}
}
if ($useid eq '1') {
print "$itemid \n";
}
$tmpprice = &format_price($tmpprice);
#$_ = $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 "$itemname \$ $itemprice \$ $tmpprice \n";
print "$itemname $itemquant \$ $itemprice \$ $tmpprice \n";
########## INCLUDE REQUIRED FIELD NAMES ###########
print " \n";
print " \n";
print " \n";
print " \n";
print " \n\n";
print " \n";
print " \n\n";
print " \n";
print " \n\n";
### SUBTOTAL PASSBACKS ###
print " \n";
print " \n\n";
$rcitem=$rcitem+1;
}
### QUANTITY FIGURED ###
print " \n";
print "
\n\n";
print "
Subtotal: ";
if ($useimage eq '1') {
print " ";
}
if ($useid eq '1') {
print " ";
}
$totalprice = &format_price($totalprice);
#$_ = $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 "\$ $totalprice \n";
### FULL ORDER SUBTOTAL PASSBACKS ###
print " \n";
print " \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 "";
if ($tax eq '1') {print "$taxstate "};
print "Taxes: ";
if ($useimage eq '1') {
print " ";
}
if ($useid eq '1') {
print " ";
}
$taxtotal = &format_price($taxtotal);
#$_ = $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 "\$ $taxtotal \n";
### TAX PASSBACKS ###
print " \n";
print " \n\n";
##### TAX TAG #####
print " \n";
print " \n";
print " \n\n";
}
elsif ($tax eq '2') {
$taxtotal = $totalprice * $taxamt;
$taxtotal = int($taxtotal * (10 ** 2) + .5) / (10 ** 2);
$totalprice = $totalprice + $taxtotal;
print "";
if ($tax eq '1') {print "$taxstate "};
print "Taxes: ";
if ($useimage eq '1') {
print " ";
}
if ($useid eq '1') {
print " ";
}
$taxtotal = &format_price($taxtotal);
#$_ = $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 "\$ $taxtotal \n";
### TAX PASSBACKS ###
print " \n";
print " \n\n";
##### INCLUDE TAX TAGT #####
print " \n";
print " \n";
print " \n\n";
}
}
#$rcitem=$rcitem+1;
if ($multiship eq 1) {
print "$ship_name Shipping: ";
if ($useimage eq '1') {
print " ";
}
if ($useid eq '1') {
print " ";
}
print "";
print " \n";
print " \n";
print " \n\n";
print " \n";
print " \n";
print " \n";
print " \n\n";
print " \n\n";
print " \n\n";
print " \n\n";
print " \n\n";
print " \n\n";
if ($usership eq 'NULL') {
print "Calculate Shipping ";
}
else {
print "\$ $usership ";
$totalprice += $usership;
}
print " \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 "Shipping: ";
if ($useimage eq '1') {
print " ";
}
if ($useid eq '1') {
print " ";
}
$shipamt = &format_price($shipamt);
#$_ = $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 "\$ $shipamt \n";
##### INCLUDE SHIPPING TAG (BY NUMBER OF ITEMS ORDERED.) #####
print " \n";
print " \n";
print " \n\n";
print " \n";
print " \n";
print " \n\n";
print " \n\n";
print " \n\n";
print " \n\n";
print " \n\n";
print " \n\n";
}
elsif ($shipping eq '2') {
$totalprice += $shipamt;
print "Shipping: ";
if ($useimage eq '1') {
print " ";
}
if ($useid eq '1') {
print " ";
}
$shipamt = &format_price($shipamt);
#$_ = $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 "\$ $shipamt \n";
##### INCLUDE SHIPPING TAG (NON-VARIABLE) #####
print " \n";
print " \n";
print " \n\n";
print " \n";
print " \n";
print " \n\n";
print " \n\n";
print " \n\n";
print " \n\n";
print " \n\n";
print " \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 "Shipping: ";
if ($useimage eq '1') {
print " ";
}
if ($useid eq '1') {
print " ";
}
$shipamt = &format_price($shipamt);
#$_ = $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 "";
if ($totalquant > '0') { print "$totalweight lbs. "; }
print " \$ $shipamt \n";
##### INCLUDE SHIPPING TAG (BY WEIGHT) #####
print " \n";
print " \n";
print " \n\n";
print " \n";
print " \n";
print " \n\n";
print " \n\n";
print " \n\n";
print " \n\n";
print " \n\n";
print " \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 "Shipping: ";
if ($useimage eq '1') {
print " ";
}
if ($useid eq '1') {
print " ";
}
$shipamt = &format_price($shipamt);
#$_ = $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 "\$ $shipamt \n";
##### INCLUDE SHIPPING TAG (BY WEIGHT) #####
print "\n \n";
print " \n";
#print " \n\n";
print " \n\n";
print " \n";
print " \n";
print " \n\n";
print " \n\n";
print " \n\n";
print " \n\n";
print " \n\n";
print " \n\n";
}
}
$totalprice = int($totalprice * (10 ** 2) + .5) / (10 ** 2);
$totalprice = &format_price($totalprice);
#$_ = $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 "Total price: ";
if ($useimage eq '1') {
print " ";
}
if ($useid eq '1') {
print " ";
}
print "\$ $totalprice \n";
if ($multicurr eq 1) {
$totalprice *= $usercurr;
$totalprice = int($totalprice * (10 ** 2) + .5) / (10 ** 2);
$totalprice = &format_price($totalprice);
# $_ = $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 "Total price in selected currency: ";
if ($useimage eq '1') {
print " ";
}
if ($useid eq '1') {
print " ";
}
print "Exchange Rate: $usercurr \$ $totalprice \n";
}
print "
\n";
print " \n";
print " \n\n";
print " \n";
#print " \n\n";
if ($multiship = 0) {
print " \n\n";
}
if ($multiship = 1) {
print " \n\n";
}
#print " \n\n";
#print " \n";
#print " \n\n";
}
#######################################################################
# format_price #
#######################################################################
# format_price is used to format prices to two decimal
# places. It takes one argumnet, the price to be formatted
# and is called with the following syntax:
#
# $price =&format_price(xxx.yyyyy);
#
# Notice that the main calling routine must assign the
# returned formatted price to some variable for its own
# use.
#
# Also notice that this routine takes a value even if it
# is longer than two decimal places and formats it with
# rounding. Thus, you can utilize price calculations such
# as 12.99 * 7.985 (where 7.985 might be some tax value.
sub format_price
{
# The incoming price is set to a local variables and a few
# wroking local variables are defined.
local ($unformatted_price) = @_;
local ($formatted_price);
# The script then uses the rounding method in EXCEL. If
# the 3rd decimal place is > 4, then we round the 2nd
# decimal place up 1. Otherwise, we leave the number
# alone. Notice that we will use the substr function to
# pull off the last value in the three decimal place
# number and compare it using the EXCEL logic.
#
# Basically, the routine uses the rounding rules of
# sprintf.
# The unformatted_price is rounded to
# to two decimal places and returned to the calling
# routine.
$formatted_price = sprintf ("%.2f", $unformatted_price);
return $formatted_price;
}
sub OrdParse {
# Disable warnings as this code deliberately uses local and environment
# variables which are preset to undef (i.e., not explicitly initialized)
local ($perlwarn);
$perlwarn = $^W;
$^W = 0;
local (*in) = shift if @_; # CGI input
local (*incfn, # Client's filename (may not be provided)
*inct, # Client's content-type (may not be provided)
*insfn) = @_; # Server's filename (for spooled files)
local ($len, $type, $meth, $errflag, $cmdflag, $got, $name);
binmode(STDIN); # we need these for DOS-based systems
binmode(STDOUT); # and they shouldn't hurt anything else
binmode(STDERR);
# Get several useful env variables
$type = $ENV{'CONTENT_TYPE'};
$len = $ENV{'CONTENT_LENGTH'};
$meth = $ENV{'REQUEST_METHOD'};
if ($len > $cgi_lib'maxdata) { #'
&CgiDie("cgi-lib.pl: Request to receive too much data: $len bytes\n");
}
if (!defined $meth || $meth eq '' || $meth eq 'GET' ||
$meth eq 'HEAD' ||
$type eq 'application/x-www-form-urlencoded') {
local ($key, $val, $i);
# Read in text
if (!defined $meth || $meth eq '') {
$in = $ENV{'QUERY_STRING'};
$cmdflag = 1; # also use command-line options
} elsif($meth eq 'GET' || $meth eq 'HEAD') {
$in = $ENV{'QUERY_STRING'};
} elsif ($meth eq 'POST') {
if (($got = read(STDIN, $in, $len) != $len))
{$errflag="Short Read: wanted $len, got $got\n";};
} else {
&CgiDie("cgi-lib.pl: Unknown request method: $meth\n");
}
@in = split(/[&;]/,$in);
push(@in, @ARGV) if $cmdflag; # add command-line parameters
foreach $i (0 .. $#in) {
# Convert plus to space
$in[$i] =~ s/\+/ /g;
# Split into key and value.
($key, $val) = split(/=/,$in[$i],2); # splits on the first =.
# Convert %XX from hex numbers to alphanumeric
$key =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge;
$val =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge;
# Associate key and value
$in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator
$in{$key} .= $val;
}
} elsif ($ENV{'CONTENT_TYPE'} =~ m#^multipart/form-data#) {
# for efficiency, compile multipart code only if needed
$errflag = !(eval <<'END_MULTIPART');
local ($buf, $boundary, $head, @heads, $cd, $ct, $fname, $ctype, $blen);
local ($bpos, $lpos, $left, $amt, $fn, $ser);
local ($bufsize, $maxbound, $writefiles) =
($cgi_lib'bufsize, $cgi_lib'maxbound, $cgi_lib'writefiles);
# The following lines exist solely to eliminate spurious warning messages
$buf = '';
($boundary) = $type =~ /boundary="([^"]+)"/; #"; # find boundary
($boundary) = $type =~ /boundary=(\S+)/ unless $boundary;
&CgiDie ("Boundary not provided: probably a bug in your server")
unless $boundary;
$boundary = "--" . $boundary;
$blen = length ($boundary);
if ($ENV{'REQUEST_METHOD'} ne 'POST') {
&CgiDie("Invalid request method for multipart/form-data: $meth\n");
}
if ($writefiles) {
local($me);
stat ($writefiles);
$writefiles = "/tmp" unless -d _ && -w _;
# ($me) = $0 =~ m#([^/]*)$#;
$writefiles .= "/$cgi_lib'filepre";
}
# read in the data and split into parts:
# put headers in @in and data in %in
# General algorithm:
# There are two dividers: the border and the '\r\n\r\n' between
# header and body. Iterate between searching for these
# Retain a buffer of size(bufsize+maxbound); the latter part is
# to ensure that dividers don't get lost by wrapping between two bufs
# Look for a divider in the current batch. If not found, then
# save all of bufsize, move the maxbound extra buffer to the front of
# the buffer, and read in a new bufsize bytes. If a divider is found,
# save everything up to the divider. Then empty the buffer of everything
# up to the end of the divider. Refill buffer to bufsize+maxbound
# Note slightly odd organization. Code before BODY: really goes with
# code following HEAD:, but is put first to 'pre-fill' buffers. BODY:
# is placed before HEAD: because we first need to discard any 'preface,'
# which would be analagous to a body without a preceeding head.
$left = $len;
PART: # find each part of the multi-part while reading data
while (1) {
die $@ if $errflag;
$amt = ($left > $bufsize+$maxbound-length($buf)
? $bufsize+$maxbound-length($buf): $left);
$errflag = (($got = read(STDIN, $buf, $amt, length($buf))) != $amt);
die "Short Read: wanted $amt, got $got\n" if $errflag;
$left -= $amt;
$in{$name} .= "\0" if defined $in{$name};
$in{$name} .= $fn if $fn;
$name=~/([-\w]+)/; # This allows $insfn{$name} to be untainted
if (defined $1) {
$insfn{$1} .= "\0" if defined $insfn{$1};
$insfn{$1} .= $fn if $fn;
}
BODY:
while (($bpos = index($buf, $boundary)) == -1) {
if ($left == 0 && $buf eq '') {
foreach $value (values %insfn) {
unlink(split("\0",$value));
}
&CgiDie("cgi-lib.pl: reached end of input while seeking boundary " .
"of multipart. Format of CGI input is wrong.\n");
}
die $@ if $errflag;
if ($name) { # if no $name, then it's the prologue -- discard
if ($fn) { print FILE substr($buf, 0, $bufsize); }
else { $in{$name} .= substr($buf, 0, $bufsize); }
}
$buf = substr($buf, $bufsize);
$amt = ($left > $bufsize ? $bufsize : $left); #$maxbound==length($buf);
$errflag = (($got = read(STDIN, $buf, $amt, length($buf))) != $amt);
die "Short Read: wanted $amt, got $got\n" if $errflag;
$left -= $amt;
}
if (defined $name) { # if no $name, then it's the prologue -- discard
if ($fn) { print FILE substr($buf, 0, $bpos-2); }
else { $in {$name} .= substr($buf, 0, $bpos-2); } # kill last \r\n
}
close (FILE);
last PART if substr($buf, $bpos + $blen, 2) eq "--";
substr($buf, 0, $bpos+$blen+2) = '';
$amt = ($left > $bufsize+$maxbound-length($buf)
? $bufsize+$maxbound-length($buf) : $left);
$errflag = (($got = read(STDIN, $buf, $amt, length($buf))) != $amt);
die "Short Read: wanted $amt, got $got\n" if $errflag;
$left -= $amt;
undef $head; undef $fn;
HEAD:
while (($lpos = index($buf, "\r\n\r\n")) == -1) {
if ($left == 0 && $buf eq '') {
foreach $value (values %insfn) {
unlink(split("\0",$value));
}
&CgiDie("cgi-lib: reached end of input while seeking end of " .
"headers. Format of CGI input is wrong.\n$buf");
}
die $@ if $errflag;
$head .= substr($buf, 0, $bufsize);
$buf = substr($buf, $bufsize);
$amt = ($left > $bufsize ? $bufsize : $left); #$maxbound==length($buf);
$errflag = (($got = read(STDIN, $buf, $amt, length($buf))) != $amt);
die "Short Read: wanted $amt, got $got\n" if $errflag;
$left -= $amt;
}
$head .= substr($buf, 0, $lpos+2);
push (@in, $head);
@heads = split("\r\n", $head);
($cd) = grep (/^\s*Content-Disposition:/i, @heads);
($ct) = grep (/^\s*Content-Type:/i, @heads);
($name) = $cd =~ /\bname="([^"]+)"/i; #";
($name) = $cd =~ /\bname=([^\s:;]+)/i unless defined $name;
($fname) = $cd =~ /\bfilename="([^"]*)"/i; #"; # filename can be null-str
($fname) = $cd =~ /\bfilename=([^\s:;]+)/i unless defined $fname;
$incfn{$name} .= (defined $in{$name} ? "\0" : "") .
(defined $fname ? $fname : "");
($ctype) = $ct =~ /^\s*Content-type:\s*"([^"]+)"/i; #";
($ctype) = $ct =~ /^\s*Content-Type:\s*([^\s:;]+)/i unless defined $ctype;
$inct{$name} .= (defined $in{$name} ? "\0" : "") . $ctype;
if ($writefiles && defined $fname) {
$ser++;
$fn = $writefiles . ".$$.$ser";
open (FILE, ">$fn") || &CgiDie("Couldn't open $fn\n");
binmode (FILE); # write files accurately
}
substr($buf, 0, $lpos+4) = '';
undef $fname;
undef $ctype;
}
1;
END_MULTIPART
if ($errflag) {
local ($errmsg, $value);
$errmsg = $@ || $errflag;
foreach $value (values %insfn) {
unlink(split("\0",$value));
}
&CgiDie($errmsg);
} else {
# everything's ok.
}
} else {
&CgiDie("cgi-lib.pl: Unknown Content-type: $ENV{'CONTENT_TYPE'}\n");
}
# no-ops to avoid warnings
$insfn = $insfn;
$incfn = $incfn;
$inct = $inct;
$^W = $perlwarn;
return ($errflag ? undef : scalar(@in));
}
sub OrdParse_old {
local (*in) = @_ if @_;
local ($i, $key, $val);
if ( $ENV{'REQUEST_METHOD'} eq "GET" ) {
$in = $ENV{'QUERY_STRING'};
} elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
} else {
# Added for command line debugging
# Supply name/value form data as a command line argument
# Format: name1=value1\&name2=value2\&...
# (need to escape & for shell)
# Find the first argument that's not a switch (-)
$in = ( grep( !/^-/, @ARGV )) [0];
$in =~ s/\\&/&/g;
}
@in = split(/&/,$in);
foreach $i (0 .. $#in) {
# Convert plus's to spaces
$in[$i] =~ s/\+/ /g;
# Split into key and value.
($key, $val) = split(/=/,$in[$i],2); # splits on the first =.
# Convert %XX from hex numbers to alphanumeric
$key =~ s/%(..)/pack("c",hex($1))/ge;
$val =~ s/%(..)/pack("c",hex($1))/ge;
# Associate key and value. \0 is the multiple separator
$in{$key} .= "\0" if (exists($in{$key}));
$in{$key} .= $val;
}
return length($in);
}
sub number { $a <=> $b }
sub confirm {
if (($usership eq 'NULL') && ($multiship eq 1)) {
print "Location: $cgiurl\?command=calcship \n\n";
}
&print_header;
&print_header_images;
print "
First Name:
$FORM{'sfname'}
Last Name:
$FORM{'slname'}
Shipping Address:
$FORM{'saddr'}
City:
$FORM{'scity'}
State:
$FORM{'sstate'}
Zip:
$FORM{'szip'}
Country:
$FORM{'sctry'}
\n";
}
print " \n";
print " \n";
print " ";
print " ";
}
sub check_expiration {
opendir(TEMP, 'tmp');
@Allnames = readdir(TEMP);
foreach $Name (@Allnames) {
$flush = "$tmpdir/$Name";
if (-d $flush) { Next }
else {
open (CHECK,"$flush") || die "Can't Open $Name(r): $!\n";
@LINES=;
close(CHECK);
$SIZE=@LINES;
$line=$LINES[0];
($filetime, $filedate, $filehost, $usership, $ship_name) = split(/\|/,$line);
closedir(TEMP);
}
}
$expired_time = $current_time - $expire_seconds;
if ($expired_time >= $filetime) {
unlink($flush);
}
}
sub print_nav_options {
print " \n";
}
# END smart.cgi