#!/usr/bin/perl -T
##
## Agora.cgi 4.0
$versions{'agora.cgi'} = "4.0" . $ENV{"AGORAWRAP"};
$versions{'perl'} = "$]";
$versions{'OSNAME'} = "$^O";
$versions{'server'} = $ENV{'SERVER_SOFTWARE'} if $ENV{'SERVER_SOFTWARE'};
#$versions{'cookie'} = $ENV{'HTTP_COOKIE'} if $ENV{'HTTP_COOKIE'};
#print "Content-type: text/html;\n\n";
##
## Version history is available at...
## http://www.agoracgi.com/
##
## Agora.cgi is based on Selena Sol's freeware 'Web Store'
## available at http://www.extropia.com with many modifications
## made independently by Carey Internet Services before splitting
## off and becoming this package known as agora.cgi. The package
## distributed here is Copyright 1999-2000 by Steven P. Kneizys of
## Agoracgi.com and is distributed free of charge consistent with
## the GNU General Public License Version 2 dated June 1991.
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## Version 2 as published by the Free Software Foundation.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
##
## There are several add-on modest-cost modules planned, see the
## http://www.agoracgi.com web site for more details. Licensing
## for these add-on modules will be different than for this program.
##
$| = 1;
$ENV{"PATH"} = "/bin:/usr/bin";
$test=`whoami`;
$versions{'whoami'} = $test if $test;
$versions{'id'} = `id`;
if ((-f "./wrap_agc.o") && (!($ARGV[0] =~ /nowrap/i))) { # use wrapper
$ENV{"AGORAWRAP"}="*";
print `./wrap_agc.o`;
&call_exit;
}
$time = time;
$main_program_running = "yes";
push(@INC,"./library/additions");
&require_supporting_libraries (__FILE__, __LINE__,
"./admin_files/agora_user_lib.pl",
"./library/cgi-lib.pl");
&read_and_parse_form_data;
&require_supporting_libraries (__FILE__, __LINE__,
"./library/agora.setup.db");
&codehook("after_loading_setup_db");
&require_supporting_libraries (__FILE__, __LINE__,
"./admin_files/$sc_gateway_name-user_lib.pl",
"$sc_html_setup_file_path",
"$sc_cookie_lib");
$sc_loading_primary_gateway = "yes";
&require_supporting_libraries(__FILE__,__LINE__,"$sc_process_order_lib_path");
$sc_loading_primary_gateway = "no";
&codehook("before_loading_custom_libs");
opendir (USER_LIBS, "./custom") || &codehook("cannot-open-custom-dir");
@mylibs = sort(readdir(USER_LIBS));
closedir (USER_LIBS);
foreach $zlib (@mylibs) {
$lib = $zlib;
$lib =~ /([\w\-\=\+]+)(\.pl)/i;
$zfile = "$1$2";
$zlib =~ /([^\n|;]+)/;
$lib = $1;
if ((-f "./custom/$lib") && ($lib eq $zfile)) {
&require_supporting_libraries(__FILE__, __LINE__,"./custom/$lib");
}
}
&codehook("after_loading_custom_libs");
&get_cookie;
&alias_and_override;
&error_check_form_data;
$cart_id = $form_data{'cart_id'};
if ($cookie{'cart_id'} eq "" && $form_data{'cart_id'} eq "") {
&delete_old_carts;
&assign_a_unique_shopping_cart_id;
$cart_id_history .= "set new cart value "; #for debugging of course
&codehook("got_a_new_cart");
} else {
if ($form_data{'cart_id'} eq "") {
$cart_id = $cookie{'cart_id'};
$cart_id_history .= "from cookie "; #for debugging of course
&set_sc_cart_path;
} else {
$cart_id = $form_data{'cart_id'};
$cart_id_history .= "set from form data "; #for debugging of course
&set_sc_cart_path;
}
}
&codehook("pre_header_navigation");
print $sc_browser_header;
$sc_header_printed = 1;
#print "cart_id: $cart_id $cart_id_for_html $cart_id_history
\n";# debugging
$are_any_query_fields_filled_in = "no";
&codehook("open_for_business");
foreach $query_field (@sc_db_query_criteria)
{
@criteria = split(/\|/, $query_field);
if ($form_data{$criteria[0]} ne "")
{
$are_any_query_fields_filled_in = "yes";
}
}
if (($search_request ne "") && ($are_any_query_fields_filled_in eq "no")) {
$page = "searchpage.html";
$search_request = "";
if (!(-f "$sc_html_product_directory_path/$page")){
$page = "";
$form_data{'product'} = "."; # show everything
$are_any_query_fields_filled_in = "yes";
} else {
$form_data{'page'} = $page;
}
}
&codehook("special_navigation");
if (&form_check('display_cart'))
{
&load_order_lib;
&display_cart_contents;
&call_exit;
}
if (&form_check('add_to_cart_button'))
{
&load_order_lib;
&add_to_the_cart;
&call_exit;
}
elsif (&form_check('modify_cart_button'))
{
&load_order_lib;
&display_cart_contents;
&call_exit;
}
elsif (&form_check('change_quantity_button'))
{
&load_order_lib;
&output_modify_quantity_form;
&call_exit;
}
elsif (&form_check('submit_change_quantity_button'))
{
&load_order_lib;
&modify_quantity_of_items_in_cart;
&call_exit;
}
elsif (&form_check('delete_item_button'))
{
&load_order_lib;
&output_delete_item_form;
&call_exit;
}
elsif (&form_check('submit_deletion_button'))
{
&load_order_lib;
&delete_from_cart;
&call_exit;
}
elsif (&form_check('order_form_button'))
{
&load_order_lib;
&display_order_form;
&call_exit;
}
elsif (&form_check('clear_order_form_button'))
{
&load_order_lib;
&clear_verify_file;
&codehook("display_cleared_order_form");
&display_order_form;
&call_exit;
}
elsif (&form_check('submit_order_form_button'))
{
&load_order_lib;
if ($sc_test_repeat) {
&display_order_form;
} else {
&process_order_form;
}
&call_exit;
}
elsif (($page ne "" || $search_request ne ""
|| &form_check('continue_shopping_button')
|| $are_any_query_fields_filled_in =~ /yes/i) &&
($form_data{'return_to_frontpage_button'} eq ""))
{
&display_products_for_sale;
&call_exit;
}
$sc_processing_order="yes"; # assume unless we fall through
&codehook("gateway_response");
$sc_processing_order="no";
# If we got here, then just output the front page
&output_frontpage;
&call_exit;
#########################################################################
# load the order library #
#########################################################################
sub load_order_lib{
&require_supporting_libraries (
__FILE__,
__LINE__,
"$sc_order_lib_path");
}
#########################################################################
# check if a form_data button has been selected #
#########################################################################
sub form_check {
if ($SUB_form_check eq '') {
$ZCODE=q`
$SUB_form_check = '1';
sub SUB_form_check {
local ($name) = @_;
local ($name2) = $name . ".x";
if (($form_data{$name} ne "") || ($form_data{$name2} ne "")) {
return 1;
} else {
return "";
}
}
`;eval($ZCODE);if ($@ ne ''){&zcode_error($ZCODE,$@,__FILE__,__LINE__);}
}
&SUB_form_check;
}
#######################################################################
# Require Supporting Libraries. #
#######################################################################
# require_supporting_libraries is used to read in some of
# the supporting files that this script will take
# advantage of.
#
# require_supporting_libraries takes a list of arguments
# beginning with the current filename, the current line
# number and continuing with the list of files which must
# be required using the following syntax:
#
# &require_supporting_libraries (__FILE__, __LINE__,
# "file1", "file2",
# "file3"...);
#
# Note: __FILE__ and __LINE__ are special Perl variables
# which contain the current filename and line number
# respectively. We'll continually use these two variables
# throughout the rest of this script in order to generate
# useful error messages.
sub require_supporting_libraries
{
# The libraries are required by us,so exit if loading error
local ($file, $line, @require_files) = @_;
local ($require_file);
&request_supporting_libraries("warn exit",$file, $line, @require_files);
}
sub request_supporting_libraries
{
# The incoming file and line arguments are split into
# the local variables $file and $line while the file list
# is assigned to the local list array @require_files.
#
# $require_file which will just be a temporary holder
# variable for our foreach processing is also defined as a
# local variable.
local ($what_to_do_on_error, $file, $line, @require_files) = @_;
local ($require_file);
# Next, the script checks to see if every file in the
# @require_files list array exists (-e) and is readable by
# it (-r). If so, the script goes ahead and requires it.
foreach $require_file (@require_files)
{
if (-e "$require_file" && -r "$require_file")
{ # file is there, now try to require it
$result = eval('require "$require_file"'); # require it in a not-fatal way
if ($@ ne "") {
if($what_to_do_on_error =~ /warn/i) {
if ($error_header_done ne "yes") {
$error_header_done = "yes";
print "Content-type: text/html\n\n";
}
print "
| \n";
print "Error loading library $require_file: \n $@\n"; print " Please contact the site administrator to ", "fix the error. \($ENV{'SERVER_ADMIN'}\) \n"; print " |
#
#
# Note: using the http:// format is less efficient
# converted to taint-mode sub 2/5/2000
sub serve_picture {
if ($SUB_serve_picture eq '') {
$ZCODE=q`
$SUB_serve_picture = '1';
sub SUB_serve_picture {
local ($qstr,$sc_path_of_images_directory) = @_;
local ($test, $test2, $my_path_to_image);
$qstr =~ /([\w\-\=\+\/\.\:]+)/;
$qstr = "$1";
$my_path_to_image = $sc_path_of_images_directory . $qstr ;
$test = substr($my_path_to_image,0,6);
$test2 = substr($my_path_to_image,(length($my_path_to_image)-3),3);
if ($test2=~ /jpg/i || $test2 =~ /gif/i || $test2 =~ /png/i) {
# file is ok to display
if ($test2=~ /jpg/i) {# .jpg is jpeg file
$test2 = "jpeg";
}
if ($test=~ /http:\//i || $test =~ /https:/i) {
# need to GET the info .. no implemented here in agora
# use LWP::Simple;
# print "Content-type: image/$test2\n\n";
# print get($my_path_to_image);
} else { # is a filename we can load up directly
print "Content-type: image/$test2\n\n";
if (!(-f $my_path_to_image)) {# try adding another slash!
$my_path_to_image = $sc_path_of_images_directory ."/" . $qstr ;
}
open (MYPIC,$my_path_to_image);
$size = 250000;
while ($size > 0) {
$size = read(MYPIC,$the_picture,$size);
print "$the_picture";
}
close(MYPIC);
}
}
}
`;eval($ZCODE);if ($@ ne ''){&zcode_error($ZCODE,$@,__FILE__,__LINE__);}
}
&SUB_serve_picture;
}
#######################################################################
# Alias and Override
#
# This routine allows the use of aliases for switches, such as
# using xm= instead of exact_match=
#
# Also, override certain setup variables under certain conditions
#
#######################################################################
sub alias_and_override {
local ($junk,$raw_text)="";
local (@mylibs,$lib);
local ($testval,$testval2,$found_response);
&codehook("alias_and_override_top");
if (defined($form_data{'versions'})) {
print "Content-type: text/html\n\n";
print "\n| $junk | $versions{$junk} |
| $junk | $versions{$junk} |