#!/usr/bin/perl
# Merchant OrderForm v1.53 - August 2000
# Cart Front End Collection and Preview
# Copyright © August 2000, All Rights Reserved
# Austin Contract Computing, Austin, Texas
# Russell Alexander - rga@io.com
# http://www.io.com/~rga/
# Written for Austin Contract Computing, Inc. All Rights Reserved 2000
# PLEASE NOTE_________________________________________________
# These programs are distributed as Trial Ware or Share Ware.
# You are Welcome to install and test all portions of the programs.
# The package is not limited in any way and code source is left readable.
# Please make arrangements for the fee if you continue operating it on a Web Site
# Feel free to contact me if you need special arrangements for use of MOF v1.53
# For personal web site use: $ 15.00
# For web development (3-10 sites): $ 45.00, includes limited support
# For web development (above 10 sites): $ 150.00, includes limited support
# Note: For Resale or hosting license please contact rga@io.com
# For payment arrangements: http://www.merchantorderform.com/payment.html
# IMPORTANT ____________________________________________
# Distribution of this file without owner consent is prohibited.
# Please contact the authors of this product for any use outside
# The original registration and user license
# COPYRIGHT NOTICE____________________________________________
# The contents of this file is protected under the United States
# copyright laws as an unpublished work, and is confidential and
# proprietary to Austin Contract Computing, Inc. Its use or disclosure
# in whole or in part without the expressed written permission of Austin
# Contract Computing, Inc. is prohibited.
# THIS IS THE FRONT END PROGRAM
# THIS IS THE FRONT END PROGRAM
# IMPORTANT: YOU SHOULD ONLY BE MODIFYING THE CONFIGURATION FILES
# IMPORTANT: YOU SHOULD ONLY BE MODIFYING THE CONFIGURATION FILES
# DO NOT CHANGE ANY OF THESE SETTINGS
# ===================================
require 5.001;
require 'mof15.conf';
require 'mof15_lib.pl';
# cookie names must be the same in both program files
# cookie names must be the same in both program files
$cookiename_OrderID = 'mof_v15_OrderID';
$cookiename_InfoID = 'mof_v15_InfoID';
# START PROGRAM FLOW
# START PROGRAM FLOW
&SetDateVariable;
# QUERY STRING INPUT
# QUERY STRING INPUT
if ($ENV{'QUERY_STRING'}) {
&CheckAllowedDomains if (scalar(@ALLOWED_DOMAINS));
&ProcessQueryString;
&CheckCookie;
if ($view) {
if ($cookieOrderID) {
$frm{'previouspage'} = $qry{'previouspage'};
&ReadDataFile($cookieOrderID);
$msg_function = "What's In Your Cart ?";
&AcceptOrder;
} else {
print "Location: $cookieredirect\n\n";
exit;
}
} else {
if ($cookieOrderID) {
&ReadDataFile($cookieOrderID);
&ProcessDataFile;
&WriteDataFile($cookieOrderID);
$msg_function = "Adding $msg_i New Item" if ($msg_i == 1);
$msg_function = "Adding $msg_i New Items" if ($msg_i != 1);
if ($msg_d) {
$msg_function = $msg_function . ", $msg_d Duplicate Item" if ($msg_d == 1);
$msg_function = $msg_function . ", $msg_d Duplicate Items" if ($msg_d != 1);
}
&AcceptOrder;
} else {
&GenerateOrderID;
&MakeCookie($cookiename_OrderID, $OrderID);
@orders = @NewOrder;
&WriteDataFile($OrderID);
$msg_function = "Adding $msg_i New Item" if ($msg_i == 1);
$msg_function = "Adding $msg_i New Items" if ($msg_i != 1);
&AcceptOrder;
}
}
# FORM POST INPUT
# FORM POST INPUT
} else {
&CheckAllowedDomains if (scalar(@ALLOWED_DOMAINS));
&ProcessForm;
# POSTMODE = SINGLEPOST-CHECKBOXES-QUANTITYBOXES
# POSTMODE = SINGLEPOST-CHECKBOXES-QUANTITYBOXES
if ($frm{'postmode'} eq "SINGLEPOST" || $frm{'postmode'} eq "CHECKBOXES" || $frm{'postmode'} eq "QUANTITYBOXES") {
&CheckCookie;
if ($cookieOrderID) {
&ReadDataFile($cookieOrderID);
&ProcessDataFile;
&WriteDataFile($cookieOrderID);
$msg_function = "Adding $msg_i New Item" if ($msg_i == 1);
$msg_function = "Adding $msg_i New Items" if ($msg_i != 1);
if ($msg_d) {
$msg_function = $msg_function . ", $msg_d Duplicate Item" if ($msg_d == 1);
$msg_function = $msg_function . ", $msg_d Duplicate Items" if ($msg_d != 1);
}
&AcceptOrder;
} else {
&GenerateOrderID;
&MakeCookie($cookiename_OrderID, $OrderID);
@orders = @NewOrder;
&WriteDataFile($OrderID);
$msg_function = "Adding $msg_i New Item" if ($msg_i == 1);
$msg_function = "Adding $msg_i New Items" if ($msg_i != 1);
&AcceptOrder;
}
# UPDATE CART
# UPDATE CART
} elsif ($frm{'postmode'} eq "UPDATE") {
&CheckCookie;
if ($cookieOrderID) {
$OrderID = $frm{'OrderID'};
@orders = @NewOrder;
&WriteDataFile($OrderID);
$msg_function = "Updated $msg_i Cart Item" if ($msg_i == 1);
$msg_function = "Updated $msg_i Cart Items" if ($msg_i != 1);
&AcceptOrder;
} else {
print "Location: $cookieredirect\n\n";
exit;
}
# DELETE CART
# DELETE CART
} elsif ($frm{'postmode'} eq "DELETE") {
$msg_i = $frm{'deleted_items'};
&CheckCookie;
if ($cookieOrderID) {
$OrderID = $frm{'OrderID'};
&WriteDataFile($OrderID);
$msg_function = "Deleted $msg_i Cart Item" if ($msg_i == 1);
$msg_function = "Deleted $msg_i Cart Items" if ($msg_i != 1);
&AcceptOrder;
} else {
print "Location: $cookieredirect\n\n";
exit;
}
# PREVIEW INVOICE
# PREVIEW INVOICE
} elsif ($frm{'postmode'} eq "PREVIEW") {
# setting up needed globals
# setting up needed globals
@UsingInfoFields = ();
@MasterInfoList = ();
%MissingInfoFields = ();
%Computations = ();
&CheckCookie;
$OrderID = $frm{'OrderID'};
$InfoID = $cookieInfoID if ($cookieInfoID);
$InfoID = $frm{'InfoID'} if $frm{'InfoID'};
@orders = @NewOrder;
# Begin Preview Decision Flow
# Begin Preview Decision Flow
if (&CheckFieldsNeeded) {
if ($cookieOrderID) {
if ($frm{'submit_preview_info'} eq "NEWSUBMIT") {
&ReadNewInfo;
&WriteInfoFile($InfoID);
$msg_function = "NEWSUBMIT";
} elsif ($frm{'submit_preview_info'} eq "EDITING") {
&ReadInfoFile($InfoID);
$msg_function = "EDITING";
} else {
if ($cookieInfoID) {
$InfoID = $cookieInfoID;
&ReadInfoFile($InfoID);
$msg_function = "FOUNDATA";
} else {
&GenerateInfoID;
&MakeNullList;
$msg_function = "NEWLIST";
}
}
} else {
print "Location: $cookieredirect\n\n";
exit;
}
} else {
if ($cookieOrderID) {
$msg_function = "Nothing Needed";
&MakeComputations;
&PreviewOrder;
exit;
} else {
print "Location: $cookieredirect\n\n";
exit;
}
}
# End Preview Decision Flow
# End Preview Decision Flow
&MakeCookie($cookiename_InfoID, $InfoID);
if (&CheckUsingInfoFields) {
&PreviewInformation;
} else {
if ($frm{'submit_preview_info'} eq "EDITING") {
&PreviewInformation;
} else {
&MakeComputations;
&PreviewOrder;
}
}
# CUSTOM MODE
# CUSTOM MODE
} elsif ($frm{'postmode'} eq "CUSTOM") {
$ErrMsg="Designer has set a Custom Input Mode ";
$ErrMsg=$ErrMsg . "Designer has set a Custom Input Mode ";
$ErrMsg=$ErrMsg . "Designer has set a Custom Input Mode ";
$ErrMsg=$ErrMsg . "Designer has set a Custom Input Mode";
&ErrorMessage($ErrMsg);
# MODE NOT FOUND
# MODE NOT FOUND
} else {
$ErrMsg="Unable to determine Input Mode ";
$ErrMsg=$ErrMsg . "postmode: $frm{'postmode'} ";
$ErrMsg=$ErrMsg . "Contact the Web Developer ";
$ErrMsg=$ErrMsg . "Referring URL: $ENV{'HTTP_REFERER'}";
&ErrorMessage($ErrMsg);
}
}
# ACCEPT ORDER
# ACCEPT ORDER
sub AcceptOrder {
@header = ();
@footer = ();
my ($i)=0;
my (@list) = ();
my ($nav_top, $nav_bottom) = (0,0);
my ($li, $lk, $lv, $msg_status, $msg_n);
my ($totalprice, $totalqnty, $temprice);
my ($line, $qty, $item, $desc, $price, $ship, $taxit);
if ($frm{'previouspage'}) {
$previouspage = $frm{'previouspage'};
} else {
$previouspage = $ENV{'HTTP_REFERER'};
}
$msg_n = scalar(@orders);
$msg_status = "Viewing $msg_n Items" if ($msg_n > 1);
$msg_status = "Viewing $msg_n Item" if ($msg_n == 1);
if ($msg_n == 0) {$msg_status = "Viewing No Items"}
&GetTemplateFile($accept_order_template,"Main Template File");
print "Content-Type: text/html\n\n";
print "@header \n\n";
$OrderID = $cookieOrderID if ($cookieOrderID);
$OrderID = $OrderID if ($OrderID);
# START PRINTING FROM HEADER
# START PRINTING FROM HEADER
# Insert MOF navigation at TOP
# Insert MOF navigation at TOP
$nav_top++ if ($menu_previous_top);
$nav_top++ if ($menu_help_top);
if ($nav_top) {
print "
\n\n";
}
# Update hidden POST AcceptOrder Quantities Form
# Update hidden POST AcceptOrder Quantities Form
print " \n";
print " \n";
print " \n";
print "$datetime_s Order ID: $OrderID $datetime_e \n";
print "$datetime_s $Date $ShortTime $datetime_e \n";
print "
\n";
print "
\n";
# printing orders in cart
# printing orders in cart
print " \n";
print " \n";
print "$fontheading Qty \n";
print "$fontheading Item Name \n";
print "$fontheading Description \n";
print "$fontheading Price \n";
# populate orders in table / store hidden input
# populate orders in table / store hidden input
foreach $line (@orders) {
($qty, $item, $desc, $price, $ship, $taxit) = split (/$delimit/, $line);
++$i;
print " \n";
print "$fontqnty \n\n";
print " \n";
print " \n";
print " \n\n";
print "$fontitem $item \n";
# Format User Input in Description
# Format User Input in Description
@list = split (/\|/, $desc);
$desc = shift (@list);
$desc =~ s/\[//g;
$desc = $fontdesc_s . $desc . $fontdesc_e;
foreach $li (@list) {
($lk, $lv) = split (/::/, $li);
if ($makelist) {
$desc = $desc . "$font_key_s$lk: $font_key_e$font_val_s$lv$font_val_e";
} else {
$desc = $desc . " - $font_key_s$lk: $font_key_e$font_val_s$lv$font_val_e";
}
}
print "$desc \n";
# Print row for single item or multiple to sub totals
# Print row for single item or multiple to sub totals
if ($qty > 1) {
print "$fontprice \ \; \n";
$sub_price = ($qty * $price);
$totalprice += $sub_price;
$totalqnty += $qty;
$sub_price = sprintf "%.2f", $sub_price;
$sub_price = CommifyMoney ($sub_price);
$price = CommifyMoney ($price);
$qty = CommifyNumbers ($qty);
print " \ \; \n";
print "$fontsubtext\n";
print "Sub Total $qty of $item at ";
print "$currency $price each \n";
print "$fontsub $currency $sub_price \n\n";
} else {
$totalprice += $price;
$totalqnty += $qty;
$price = CommifyMoney ($price);
print "$fontprice$currency $price \n\n";
}
}
print "
\n";
print "$returntofont \n";
# Print Summary Totals
# Print Summary Totals
if ($totalqnty > 1) {$pd = "Products"} else {$pd = "Product"}
$totalprice = sprintf "%.2f", $totalprice;
$totalprice = CommifyMoney ($totalprice);
$totalqnty = CommifyNumbers ($totalqnty);
print " \n";
print "$totaltext Subtotal \n";
print "$totalqnty $pd ----> \n";
print " ";
print "$totalcolor $currency $totalprice
\n";
# Bottom Navigation Menu
# Bottom Navigation Menu
print "
\n";
if ($menu_home_bottom) {
print "$menu_home_bottom \n";}
if ($menu_previous_bottom) {
print "$menu_previous_bottom \n";}
# Update FORM ends here, Can only start another FORM POST now
print "$menu_update_bottom \n";
if ($menu_delete_bottom && $msg_n) {
print "";
print " \n";
}
if ($menu_preview_bottom && $msg_n) {
print "";
print " \n";
}
if ($menu_help_bottom) {
print " \n";
print " \n";
print "$menu_help_bottom \n";}
print "
";
if ($msg_n) {
print "If you changed any quantities, please click ";
print "update quantity . ";
print " Click on Review Order button to check out and process your order. ";
} else {
print "You don't have any items in your cart ";
print "You can return to your ";
print "Previous Shopping Page ";
print "Or you can return to our ";
print "Site's Main Page ";
}
print "$returntofont\n";
print "@footer \n\n";
}
# PREVIEW INFORMATION
# PREVIEW INFORMATION
sub PreviewInformation {
my ($itm_n)=0;
my ($key, $val);
my (@InsuranceList) = ();
my (@MethodList) = ();
$msg_v;
@country_list = ();
@state_list = ();
($allow_shipping, $allow_tax) = (0,0);
# count how many items failed validation
$itm_m = scalar(keys(%MissingInfoFields));
# using shipping and/or tax flags
$allow_shipping++ if (scalar(@use_shipping));
$allow_shipping++ if (scalar(keys(%use_method)));
$allow_tax++ if (scalar(keys(%use_city_tax)));
$allow_tax++ if (scalar(keys(%use_zipcode_tax)));
$allow_tax++ if (scalar(keys(%use_state_tax)));
$allow_tax++ if (scalar(keys(%use_country_tax)));
@country_list = (&GetDropBoxList($use_country_list,'Ecom_ShipTo_Postal_CountryCode')) if ($use_country_list);
@state_list = (&GetDropBoxList($use_state_list,'Ecom_ShipTo_Postal_StateProv')) if ($use_state_list);
&GetTemplateFile($preview_info_template,"Preview Information File");
# you must call any sub routine that can ErrorMessage(ErrMsg)
# BEFORE you set up the print Content-Type header
# start HTML output
# start HTML output
print "Content-Type: text/html\n\n";
print "@header \n\n";
if ($itm_m == 1) {$fld = "Field is"}
else {$fld = "Fields are"}
if ($msg_function eq "FOUNDATA") {
print "We found previous information for you. $itm_m $fld incomplete. ";
print "Please complete all required information and continue by clicking the ";
print "review order function below.";
} elsif ($msg_function eq "EDITING") {
print "You can Edit any of this information. When finished Editing, then ";
print "click the review order function below to see your order summary. ";
} elsif ($msg_function eq "NEWSUBMIT") {
print "Some information for $itm_m $fld missing or incomplete. ";
print "Please complete all required information and continue by clicking the ";
print "review order function below.";
} elsif ($msg_function eq "NEWLIST") {
print "We are creating a new data file for you. $itm_m $fld required. ";
print "Please complete all required information and continue by clicking the ";
print "review order function below.";
}
print "