#! c:\perl\bin\perl ########################################################################### ########################################################################### # Custimization portion - All Options are set in smart.cfg !! ########################################################################### use Encode; use LWP::Simple qw(get); # Measure CPU time usage; $start = (times)[0]; # Unbuffer the output; $| = 1; # Read in user prefs require 'd:\xvrt\asturalba.com\html\smart.cfg'; ############################################################################## # Done. Make no changes below this line, unless you know what you are doing.## ############################################################################## use vars qw($tmpdir $storename %shipping2 %shipping3 $trackurl $useverify $usertime $orderdir $usercurr $trackdb); my($incoming, @pairs, %FORM); $incoming = $ENV{'QUERY_STRING'}; #$incoming = $ENV{'PATH_INFO'}; @pairs = split(/&/, $incoming); #@pairs = split(/\//, $incoming); foreach $pair (@pairs) { my($name, $value) = split(/=/, $pair); # 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_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; } 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++) { $_=$LINES[$i]; ($itemid, $name, $price, $descrip, $image, $weight, $itemurl, $group) = split(/\|/,$_); &print_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)) { $_=$LINES[$i]; if (index(lc $LINES[$i],lc $FORM{'search'}) >= 0) { $matches++; ($itemid, $name, $price, $descrip, $image, $weight, $itemurl, $group) = split(/\|/,$_); &print_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]; ($itemid, $name, $price, $descrip, $image, $weight, $itemurl, $group) = split(/\|/,$_); my(@groups) = split(/,/,$group); undef %is_group; for (@groups) { $is_group{$_} = 1 } if ($is_group{$FORM{'group'}}) { $matches++; &print_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 { print "
\n"; # Hide the weight for later use print "\n"; print "\n"; # For showing product images if ($image) { print "\n"; } else { print "\n"; } # If the item has a URL, make it a link if ($itemurl) { print "$name\n"; } else { print "$name\n"; } # Print other info #Price print "$price €\n"; #Quantity print "\n"; #Add button print "\n"; #Description print "$descrip\n"; # Close print "
\n"; } ## END print_item } ## END gen_page # Show front end of database store. sub show_store { &print_header; print "
\n"; print "
\n"; print "List all items available
\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 (