#!/usr/bin/perl ########################################################################### # S-Mart Shopping Cart Script v1.9.5 my $version = '1.9.5'; # 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 # This script is mailware. Please e-mail me if you use it. # # Selling the code for this program without prior written consent is # expressly forbidden. In other words, please ask first before you try and # make money off of my program. # # Obtain permission before redistributing this software over the Internet or # in any other medium. In all cases copyright and header must remain intact. ########################################################################### # Custimization portion - All Options are set in smart.cfg !! ########################################################################### # Measure CPU time usage; my $start = (times)[0]; # Unbuffer the output; $| = 1; # Read in user prefs require 'config.cfg'; ########################################################################### # Done. Make no changes below this line, unless you know what you are doing. ########################################################################### use vars qw($conver $debug $tmpdir $storename %shipping2 %shipping3 $trackurl $useverify $usertime $orderdir $usercurr $trackdb $numtolist); my($incoming, @pairs, %FORM); $incoming = $ENV{'QUERY_STRING'}; #$incoming = $ENV{'PATH_INFO'}; @pairs = split(/&/, $incoming); #@pairs = split(/\//, $incoming); foreach (@pairs) { my($name, $value) = split(/=/, $_); # 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; } # Debug stuff # Print version number if ($FORM{'command'} eq 'debug' && $debug == 1) { print "Content-type: text/plain\n\n"; print "S-Mart Shopping Cart v$version.\nConfig file $conver.\n"; my $path = `pwd`; print "Path: $path\n"; my $perl = `which perl`; print "Perl: $perl\n"; my $sendmail = `which sendmail`; print "Sendmail: $sendmail\n"; my $dir = `ls -al`; print "Dir: $dir\n"; exit; } if ($ARGV[0] eq '-v') { print "S-Mart Shopping Cart v$version.\nConfig file $conver.\n"; exit; } # Get command variables my $command = $FORM{'command'}; my $pos = $FORM{'pos'}; my $type = $FORM{'type'}; # Parse form input &parse_form; # Get the date &get_date; &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_items2; } # 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; } elsif ($command eq 'deleteitem') { &delete_item; } else { &show_store; } # Subroutines: # Generate page, based on database search sub gen_page { my($SIZE,$i); &print_header; # Table header, change this for table options! print "
\n"; print "
\n"; open (FILE,"$basepath$delim$resourcedb") || die "Content-type: text/html\n\nCan't Open $resourcedb(r): $!\n"; my(@LINES)=; close(FILE); $SIZE=@LINES; if ($type eq 'all') { my($max) = $pos + $numtolist; if ($max > $SIZE) { $max = $SIZE; } for ($i=$pos;$i<$max;$i++) { my(%ITEM); ($ITEM{'itemid'}, $ITEM{'name'}, $ITEM{'price'}, $ITEM{'descrip'}, $ITEM{'quantity'}, $ITEM{'image'}, $ITEM{'weight'}, $ITEM{'itemurl'}, $ITEM{'group'}) = split(/\|/,$LINES[$i]); &print_item(\%ITEM); } print "
\n"; if ($max < $SIZE) { print "
Next $numtolist items
\n"; } } elsif ($type eq 'search') { my($matches) = 0; my($i) = $pos; while (($matches < $numtolist) && ($i < $SIZE)) { if (index(lc $LINES[$i],lc $FORM{'search'}) >= 0) { $matches++; my(%ITEM); ($ITEM{'itemid'}, $ITEM{'name'}, $ITEM{'price'}, $ITEM{'descrip'}, $ITEM{'quantity'}, $ITEM{'image'}, $ITEM{'weight'}, $ITEM{'itemurl'}, $ITEM{'group'}) = split(/\|/,$LINES[$i]); &print_item(\%ITEM); } $i++; } print "\n"; if ($i < $SIZE) { print "
\n"; print "\n"; print "\n"; print "
\n"; } } elsif ($type eq 'group') { my($matches) = 0; my($i) = $pos; while (($matches < $numtolist) && ($i < $SIZE)) { $_=$LINES[$i]; my(%ITEM); ($ITEM{'itemid'}, $ITEM{'name'}, $ITEM{'price'}, $ITEM{'descrip'}, $ITEM{'quantity'}, $ITEM{'image'}, $ITEM{'weight'}, $ITEM{'itemurl'}, $ITEM{'group'}) = split(/\|/,$_); my(@groups) = split(/,/,$ITEM{'group'}); my(%is_group); undef %is_group; for (@groups) { $is_group{$_} = 1 } if ($is_group{$FORM{'group'}}) { $matches++; &print_item(\%ITEM); } $i++; } print "\n"; if ($i < $SIZE) { print "Continue Search\n"; } } &print_footer; # This is where you want to customize your generated pages!! # Basically the top part will write out the header, then the table header # Change the table header for options like spacing, borders, etc... sub print_item { local(*ITEM) = shift; print "
\n"; # Hide the weight for later use print "\n"; print "\n"; print "\n"; # For showing product images if ($ITEM{'image'}) { print "\n"; } else { print "\n"; } #if ($ITEM{'image'}) { # print "\n"; # } # else { # print "\n"; # } # If the item has a URL, make it a link print "\n"; if ($ITEM{'itemurl'}) { print "\n"; } else { print "\n"; } #if ($ITEM{'itemurl'}) { # print "\n"; # } # else { # print "\n"; # } print "\n"; # Print other info #Description print "\n"; #print "\n"; print "\n"; #Available print "\n"; print "\n"; #Price print "\n"; #print "\n"; print "\n"; #Add button print "
Product:$ITEM{'name'}$ITEM{'name'} $ITEM{'name'} $ITEM{'name'}
Description$ITEM{'descrip'}
$ITEM{'descrip'}
Number Available$ITEM{'quantity'}
Price\£ $ITEM{'price'} Number Available: $ITEM{'quantity'}
Price: \£ $ITEM{'price'}
\n"; } ## END print_item print "\n"; } ## END gen_page # Show front end of database store. sub show_store { &print_header; #print "
\n"; print "
Stretch your IT Budget further by buying 2nd user Hardware!
We have an active database of over 1000 traders worldwide. This enables us to buy at the best possible prices regardless of market conditions. We source form Brokers, Dealers and Buy Back contracts with companies across Europe and America. We deal with branded manufacturers products, our regular clients believe 2nd user does not mean second best but does give excellent value for money.

\n"; #\n"; print "Save money on 2nd user IT equipment

\n\n"; print "If you would like a quotation for any 2nd user or refurbished I.T. equipment please email us your requirements on the form below. You will be pleasantly surprised at the savings you can make.............stretching your IT budget even further!

\n"; #print "List all items in stock
\n #
\n # # # # #
Search for a particular item(s): #
#
\n"; #print " # #\n
List all: #
#
\n"; #print "
\n
"; if ($usetrack eq 1) { print "
Track an Order
\n"; } #print "\n"; &print_footer; } ## END show_store # Print the HTML header sub print_header { print "Content-type: text/html\n\n"; open (HEADER,"$basepath$delim$header") || print "Could not open $basepath$delim$header $! \n"; while (

) { print $_; } close(HEADER); } ## END print_header; #Print the HTML footer sub print_footer { open (FOOTER,"$basepath$delim$footer") || print "Could not open $basepath$delim$footer $! \n"; while (