#!/usr/bin/perl # Name: Selena Sol's Electronic Outlet (Database Version) # # Version: 4.0 # # Last Modified: 07-31-96 # # Copyright Information: This application was written by Selena Sol # (selena@eff.org, http://www.eff.org/~erict) having been inspired by # countless other Perl authors. Feel free to copy, cite, reference, # sample, borrow, resell or plagiarize the contents. However, if you # don't mind, please let me know where it goes so that I can at least # watch and take part in the development of the memes. Information wants # to be free, support public domain freware. Donations are appreciated # and will be spent on further upgrades and other public domain scripts. ####################################################################### # Clear Buffer and Print HTTP Header. # ####################################################################### # First tell Perl to bypass the buffer so that information generated by # the CGI will be sent immediately to the browser. The line $! = 1; does # this. Then, print out the http header so that we will easily be able to # debug and so that the browser will not time us out. $! = 1; print "Content-type: text/html\n\n"; ####################################################################### # Require Libraries. # ####################################################################### # Now let's require some of the supporting files that this script will # take advantage of. web_store.setup defines many global variables # for this script relative to the local server. cgi-lib.pl is used to # parse incoming form data. cgi-lib.sol is used to manipulate the counter # file. And mail-lib.pl is used to send mail to the store administrator # when someone places an order. require "./web_store.CT.setup"; require "$cgi_lib_pl"; require "$cgi_lib_sol"; require "$mail_lib_pl"; ####################################################################### # Gather Form Data. # ####################################################################### # Use cgi-lib.pl to parse the incoming form data and tell cgi-lib to # prepare that information in the associative array %form_data &ReadParse(*form_data); ####################################################################### # Require Store Setup File # ####################################################################### # Now check to see which store (dataabse) the client has asked to access. # If the incoming form variable $form_data{'store'} has a value, that # means that the client is asking for us to use a setup file other than # the default one. Thus we wil require the client-requested setup file # and set the variable $store equal to the client defined value so that we # can pass this information throughout the pages generated by this script. if ($form_data{'store'} ne "") { require "$data_setup_directory/$form_data{'store'}"; $store = "$form_data{'store'}"; } # If the variable did not have a value, the script loads the default setup # file and sets the $store variable equal to the same. else { require "$data_setup_directory/$default_setup_file"; $store = "$default_setup_file"; } ####################################################################### # Pruce Cart Directory and Assign a Shopping Cart. # ####################################################################### # Next, let's clean up our carts directory. There is no need to keep # old carts around after the clients are long gone. So we will grab a # listing of all of the client created shoppping carts in the # Client_carts directory. We will first open the directory which has the # carts, then we will read that directories contents and use grep to grab # every file with the extension .cart. Then we will close the directory. opendir (USER_CARTS, "$cart_directory") || &CgiDie ("I am very sorry, but I was not able to open the directory $cart_directory. Please make sure that you have defined the path correctly in the setup file and that the permissions allow the web server to read, write and execute. Note: This error occurred in the Prune Cart routine"); @carts = grep(/\.cart/,readdir(USER_CARTS)); closedir (USER_CARTS); # Now, for every cart in the directory, delete it (unlink) if it is older # than half a day (-M filename > .5) foreach $cart (@carts) { if (-M "$cart_directory/$cart" > .5) { unlink("$cart_directory/$cart"); } } # Now that we have cleaned the Cart directory, we can add the new users # cart. # If we have not received a shopping cart id number as form data, it means # that the clieent has not yet received a unique shopping cart. # So, assign the client a unique shopping cart file that they will use # while they are browsing the store. First we'll generate a random # (srand + rand) 8 digit (100000000) integer (int) and then add to that # the current process id ($$). We will append the process id to the end of # the integer by using .= instead of = if ($form_data{'cart_id'} eq "") { srand (time|$$); $cart_id = int(rand(10000000)); $cart_id .= ".$$"; # Now create a new cart for the shopper. open (CART, ">$cart_directory/$cart_id.cart") || &CgiDie ("I am very sorry but I was not able to create the user's unique shopping cart. Would you please make sure that the cart_id number generating routine is working properly, that you have defined the correct path for the Cart directory, and that the permissions on the Cart Directory allow the web server to read, write and execute. Note: This error occurred in the routine which generates new carts and the value of the cart appears to be $cart_directory/$cart_id.cart"); } # If there was a shopping cart id number coming in as form data, let us # simply rename the variable to $cart_id so that we have a standardized # variable name. Note, that once the client has recieved their own cart, # that cart number MUST be passed from screen to screen as url encoded # information or as a hidden form variable so that the clkient does not # lose their cart. else { $cart_id = "$form_data{'cart_id'}"; } ####################################################################### # Output Frontpage. # ####################################################################### # Now that they have received a cart, it is time to display to them the # first page of the store. We will assume that the site administrator has # created a frontpage and set that locatioon equal to $frontpage_file in # the store specific setup file (or default). # There are two cases in which we would want to display the frontpage. # firstly, if the user has specifically asked to "return to the frontpage" # and secondly, if no category has been assigned. That is, the main # purpose of the frontpage is to query the client for which category they # are interested in browsing (like which aisle they want to go down). # The main purpose of the frontpage is to present all these options and to # create hyperlinks which will define the categories. if ($form_data{'Type'} eq "" || $form_data{'return_to_frontpage'} ne "") { # So, if we have been asked for the frontpage, let's open it up and # display it line by line. open (FRONTPAGE, "$frontpage_file") || &CgiDie ("I am sorry, but I was not able to open $frontpage_file. Would you check to make sure you have defined the correct path in the setup file and that the file has permissions which allow the web server to read it. Note: This error occurred in the Output Frontpage routine"); while () { # However, we are going to want to do a couple of things to the page. # Firstly, we are going to need to make sure that the clients unique cart # id gets passed from the frontpage to any successive pages. The way we # do this is by url encoding. We are going to have the user click on a # link that says . # There are two things of note in that line. Firstly, we will be defining # a category in those links...this is essential. Secondly, we will be # adding a half done variable, userid. This userid= is really just a tag # which this script will be looking for. Anytime (/g) it sees that, it # will substitute (s/) occurances of cart_id= with cart_id= the actual cart id # of the user. # # Since we do not know ahead of time what the cart id is going to be, we # cannot actually hard code it in to the HTML. Thus, we create the # cart_id= tag so that this script can finish off the job on the fly. # We'll also tag on the current store setup file since we are not passing # it as a hidden variable. s/cart_id=/cart_id=$cart_id&store=$store/g; # Now there is another thing that this script might have to do. Suppose # that the client has already been browsing the store and actually has a # cart already. We are going to need to give them the submit buttons # necesary to go right to their cart. To do this, we will need to create # some HTML form lines. So, as soon as this script reached the line #


Designed By Design Tyme

Copyright © 1998. All Rights Reserved.

!; exit; } ####################################################################### # Modify Quantity of Items in the Cart # ####################################################################### # Once the client has typed in some quantity changes and submitted the # information, we can make the modifications to the database. if ($form_data{'submit_change_quantity'} ne "") { # First, we will gather the keys as we did for the frontpage generation # far above and we will check to make sure they entered a positive # integer. @incoming_data = keys (%form_data); foreach $key (@incoming_data) { if ($key =~ /[\d]/ && $form_data{$key} =~ /[\D]/) { &bad_order_note; } # Just as we did above, we will create an array (@modify_items) of valid # keys. unless ($key =~ /[\D]/ && $form_data{$key} =~ /[\D]/) { if ($form_data{$key} ne "") { push (@modify_items, $key); } } # End of unless ($key =~ /[\D]/... } # End of foreach $key (@incoming_data) # Now we will open up the client's cart and go through it as usual. open (CART, "$cart_directory/$form_data{'cart_id'}.cart") || &CgiDie ("I am sorry but I was unable to open the User's Cart in the Modify Quantity of Items in the Cart routine. Please make sure that the cart directory is readable, writable and executable. The value I have for the user's cart is $cart_directory/$form_data{'cart_id'}.cart"); while () { @database_row = split (/\|/, $_); $cart_row_number = pop (@database_row); $db_id_number = pop (@database_row); push (@database_row, $db_id_number); push (@database_row, $cart_row_number); chop $cart_row_number; $old_quantity = shift (@database_row); # Now, we need to see if the item number submitted as form data is equal # to the number of the current database row. foreach $item (@modify_items) { if ($item eq $cart_row_number) { # If so, we will create the $shopper_row variable and begin creating the # modified row...that is we will replace the old quantity with the # quantity submitted by the client ($form_data{$item}). Recall that # $old_quantity has already been shifted off the array. $shopper_row .= "$form_data{$item}\|"; # Now add the rest of the database row to $shopper_row and set two flag # variables. $quantity_modified will let us know that the current row has # had a quantity modification. $invalid_submission will tell us basically # the same thing but will be used by a differenmt routine below. foreach $field (@database_row) { $quantity_modified = "yes"; $invalid_submission = "no"; $shopper_row .= "$field\|"; } chop $shopper_row; # Get rid of last | } # End of if ($item eq $cart_row_number) } # End of foreach $item (@modify_items) # Now, if we get here and $quantity_modified has not been set to yes, we # know that the above routine was skipped because the item number # submitted from the form was not equal to the curent database id number. # So we know that the current row is not having its quantity changed and # can be added to $shopper_row as is. Remember, we want to add the old # rows as well as the new modified ones... if ($quantity_modified ne "yes") { $shopper_row .= $_; } $quantity_modified = ""; } # End of while () close (CART); # Next, check to make sure that at somewhere along the line we had a valid # submission. If not, send them to the bad_order_note subroutine. if ($invalid_submission ne "no") { &bad_order_note } # Now overwrite the old cart with the new information and send them back # to the view of their current cart. open (CART, ">$cart_directory/$form_data{'cart_id'}.cart") || &CgiDie ("I am sorry but I was unable to open the User's Cart in the Modify Quantity of Items in the Cart routine. Please make sure that the cart directory is readable, writable and executable. The value I have for the user's cart is $cart_directory/$form_data{'cart_id'}.cart"); print CART "$shopper_row"; close (CART); &display_cart_contents; exit; } ####################################################################### # Output Delete Item Form # ####################################################################### # Perhaps instead, the client asked to delete an item rather than modify # the quantity. if ($form_data{'delete_item'} ne "") { # Print out the usual page and table headers. &page_header("Delete Item"); # Note: We will use the qq! method of printing as discussed in the Output # Frontpage routine above. print qq!
!; foreach $field (@display_fields) { print qq!\n!; } print qq!\n\n\n!; # Open up the cart and this time, add a check box instead of a text box so # that the client can specify a delete. Just as we did for modify, assign # the NAME equal to the cart_row_number. open (CART, "$cart_directory/$form_data{'cart_id'}.cart") || &CgiDie ("I am sorry but I was not able to open the User's cart when executing the Output Delete Item Form subroutine. The value I have for the cart is $cart_directory/$form_data{'cart_id'}.cart. Would you please check that this is correct and that the permissions are set appropriately"); while () { @cart_fields = split (/\|/, $_); $cart_row_number = pop(@cart_fields); $db_number = pop(@cart_fields); push (@cart_fields, $db_number); push (@cart_fields, $cart_row_number); chop $cart_row_number; $quantity = shift(@cart_fields); print "\n"; # Display table rows... foreach $display_number (@display_numbers) { if ($cart_fields[$display_number] eq "") { $cart_fields[$display_number] = "
-
"; } # If the field to print is the "price" field we will add a dollar sign to # the front pf the price. if ($display_number eq "$price_number") { print qq!!; } elsif ($display_number eq "$Image_number") { print qq!!; } elsif ($display_number eq "$db_id_number") { print qq!!; } else { print qq!!; } } # End of foreach $display_number (@display_numbers) print qq!\n!; $unformatted_subtotal = ($quantity*$cart_fields[$price_number]); $subtotal = sprintf ("%.2f\n", $unformatted_subtotal); $unformatted_grand_total = $grand_total + $subtotal; $grand_total = sprintf ("%.2f\n", $unformatted_grand_total); print qq!\n!; print qq!\n!; } # End of while () close (CART); # Add footer... # # Note: We will use the qq! method of printing as discussed in the Output # Frontpage routine above. print qq!
Delete Item$fieldQuantitySubtotal
\n"; print "\$$cart_fields[$display_number]$cart_fields[$display_number]$quantity\$$subtotal

Pre-shipping Total = \$$grand_total


Designed By Design Tyme

Copyright © 1998. All Rights Reserved.

!; exit; } ####################################################################### # Delete Item From Cart # ####################################################################### # Once the client submits some items to delete, we come here. if ($form_data{'submit_deletion'} ne "") { # Again, check for valid entries..this time though we only need to make # sure that we filter out the extra form keys rather than make sure that # we have a positive integer value as well. @incoming_data = keys (%form_data); foreach $key (@incoming_data) { unless ($key =~ /[\D]/) { if ($form_data{$key} ne "") { push (@delete_items, $key); } } # End of unless ($key =~ /[\D]/... } # End of foreach $key (@incoming_data) # Open up the cart and get the $cart_row_number, $db_id_number, and # $old_quantity as we did for modification. open (CART, "$cart_directory/$form_data{'cart_id'}.cart") || &CgiDie ("I am sorry but I was not able to open the Users cart in the Delete item From Cart routine. The value I have for the cart is $cart_directory/$form_data{'cart_id'}.cart. Please check the path and the permissions."); while () { @database_row = split (/\|/, $_); $cart_row_number = pop (@database_row); $db_id_number = pop (@database_row); push (@database_row, $db_id_number); push (@database_row, $cart_row_number); chop $cart_row_number; $old_quantity = shift (@database_row); # Unlike modification, for deletion all we need to do is check to see if # the current database row matches a submitted item for deletion...if it # does not match add it to $shopper_row. If it is equal, do not...thus, # all the rows will be added except for the ones that should be deleted. $delete_item = ""; foreach $item (@delete_items) { if ($item eq $cart_row_number) { $delete_item = "yes"; } # End of if ($item eq $cart_row_number) } # End of foreach $item (@add_items) if ($delete_item ne "yes") { $shopper_row .= $_; } } # End of while () close (CART); # Overwrite the old cart with the new information and send them back to # the category page. open (CART, ">User_carts/$form_data{'cart_id'}.cart") || &CgiDie ("I am sorry but I was not able to open the Users cart in the Delete item From Cart routine. The value I have for the cart is $cart_directory/$form_data{'cart_id'}.cart. Please check the path and the permissions."); print CART "$shopper_row"; close (CART); &display_cart_contents; exit; } ####################################################################### # Output Order Form # ####################################################################### # Hopefully, the client will fill up there cart and head over to the cash # register. if ($form_data{'order_form'} ne "") { # First, let's print up an order form. To make this easier, I have # created a subdirectory which contains the order form and frontpage HTML # files...this way, it will be easier to modify them to your own needs. # This routine will simply output your predesigned order form, but as we # did for the frontpage, we will insert our hidden variables. # # Note: We will use the qq! method of printing as discussed in the Output # Frontpage routine above. open (ORDER_FORM, "$order_form") || &CgiDie ("I am sorry but I was unable to load the requested order form, $order_form when executing the Output Order form Routine. Please check that this variable is set correctly in the setup file and that it and the directory it is in have the correct permissions"); while () { if ($_ =~ /
!; # Print out the current cart contents. foreach $field (@display_fields) { print qq!\n!; } print qq!\n\n!; open (CART, "$cart_directory/$form_data{'cart_id'}.cart") || &CgiDie ("I am sorry, but I was not able to open the Users cart in the Output Order form routine. The value I have for the cart is $cart_directory/$form_data{'cart_id'}.cart. Would you please make sure this is correct and that the web server is allowed to manipulate this file."); while () { @cart_fields = split (/\|/, $_); $quantity = shift(@cart_fields); foreach $display_number (@display_numbers) { if ($cart_fields[$display_number] eq "") { $cart_fields[$display_number] = "
-
"; } # If the field to print is the "price" field we will add a dollar sign to # the front pf the price. if ($display_number eq "$price_number") { print qq!
!; } elsif ($display_number eq "$Image_number") { print qq!!; } elsif ($display_number eq "$db_id_number") { print qq!!; } else { print qq!!; } } # End of foreach $display_number (@display_numbers) print qq!!; $unformatted_subtotal = ($quantity*$cart_fields[$price_number]); $subtotal = sprintf ("%.2f\n", $unformatted_subtotal); $unformatted_grand_total = $grand_total + $subtotal; $grand_total = sprintf ("%.2f\n", $unformatted_grand_total); print qq!!; print qq!!; } # End of while () print qq!
$fieldQuantitySubtotal
\$$cart_fields[$display_number]$cart_fields[$display_number]$quantity\$$subtotal

Pre-shipping Total = \$$grand_total

!; close (CART); } # End of if ($_ =~ /) close (ORDER_FORM); exit; } ####################################################################### # Send In Order # ####################################################################### # Finally, we need to send the order to whoever handles order filling. if ($form_data{'send_in_order'} ne "") { # Begin by sending out the header and sorting the incoming form variables. # The reason that we do this is because the keys function will not give us # the form varioables in any speciic order due to hash routines. Thus, by # encoding each form variable in our HTML document with a preceding number # like 01-name or 05-city we give ourselves the ability to sort them in # the order we want them at this point. Take a look at the distribution # HTML. You will see that all of the NAME values are ordered this way. # The number corresponds to its order when all the variables are printed # out. The sort funtion will take all of the unsorted variables in # @variable_names, sort them and then add them to @sorted_variable_names &page_header("Your Order Has Been Sent"); @variable_names = keys (%form_data); @sorted_variable_names = sort (@variable_names); # Now remind the client of what she entered onm the order form...and begin # creating the body of the email message that we wills end to the store # administrator (using $email_body). $email_body .= "Personal Information\n\n"; print qq!

You submitted the following information

!; # Basically print out the form variable and its associated value for every # form field the client submitted...but don't bother printing out # administrative hidden variables used byu this scipt since the user # doesn't care. If you add other hidden variables make sure to escape # them here. We'll also add the list to the $email_body variable. foreach $variable (@sorted_variable_names) { if ($form_data{$variable} ne "" && $variable ne "cart_id" && $variable ne "Type" && $variable ne "send_in_order" && $variable ne "store") { print qq!\n!; print qq!\n!; $email_body .= " $order_form_array{$variable} = $form_data{$variable}\n"; } } # End of foreach $variable (@sorted_variable_names) print qq!
$order_form_array{$variable}$form_data{$variable}
!; # Now output the current cart contents as ordered. No surprises here, we # have done this over and over again above. print qq!

You ordered the following items

!; foreach $field (@display_fields) { print qq!\n!; } print qq!\n\n!; # Now we are going to do something a litle bit diferent when it comes to # mailing the store administrator. First open the cart again and begin # reading it line by line. $email_body .= "\nOrder Information\n\n"; open (CART, "$cart_directory/$form_data{'cart_id'}.cart") || &CgiDie ("I am sorry, but I was not able to open the user cart in the Send in Order routine. The value I have for the cart is $cart_directory/$form_data{'cart_id'}.cart. Would you please check the path and permissions."); while () { @cart_fields = split (/\|/, $_); $quantity = shift(@cart_fields); $cart_quantity = $cart_quantity + $quantity; # The thing is, the store admin doe snot need to have every single # database row included with orders...that would be a pain to read and # would be horrid on formatting...so we are going to aonly include some # essential fields... Firstly, we need to note the quantity of every item. $email_body .= " $quantity"; # Then, for every item that we have set to display in our setup file... foreach $display_number (@display_numbers) { # print the whole row for the client on the web... print qq!\n!; # But for the store admin, we are going to get another list from the setup # file, @email_numbers. @email_numbers is a sub list of @display_numbers # which includes only those fields that the store admin needs to see. For # example, whereas the client may want to see descirtions, name, price, # item number, size, and a picture...the admin may only want to see item # number, name and quantity. Thus, we will only send the store admin # those fields which shehas set the setup file to give her. BTW, the four # spaces before $cart_fields[$display_number] are just for # formatting...you'll see when you get one of the emails. foreach $display_field (@email_numbers) { if ($display_number eq $display_field) { if ($display_number eq "$price_number") { $email_body .= " \$$cart_fields[$display_number]"; } else { $email_body .= " $cart_fields[$display_number]"; } } } } # End of foreach $display_number (@display_numbers) # Add a new line for every cart item. $email_body .= "\n"; # Include the footer information for the client on the web and calculate # costs. print qq!!; $unformatted_subtotal = ($quantity*$cart_fields[$price_number]); $subtotal = sprintf ("%.2f\n", $unformatted_subtotal); $unformatted_grand_total = $grand_total + $subtotal; $grand_total = sprintf ("%.2f\n", $unformatted_grand_total); print qq!\n!; print qq!\n!; } # End of while () #################### # Specific cost calculations for my exammple...not necessary for you. if ($cart_quantity eq "1") { $unformatted_shipping_cost = 2.50; } if ($cart_quantity eq "2") { $unformatted_shipping_cost = 3.50; } if ($cart_quantity ne "2") { $cart_quantity = $cart_quantity - 2; $unformatted_shipping_cost = 3.50 + $cart_quantity; } $shipping_cost = ("%.2f\n", $unformatted_shipping_cost); ########################## $unformatted_final_total = $grand_total + $shipping_cost; $final_total = ("%.2f\n", $unformatted_final_total); # Print up the footer for both the client and admin including total price. print qq!
$fieldQuantitySubtotal
$cart_fields[$display_number]$quantity\$$subtotal

Item Total = \$$grand_total

Shipping and Handling: \$$shipping_cost

Final Total: \$$final_total

!; close (CART); $email_body .= "\nGrand Total = \$$final_total\n"; print "$_"; close (ORDER_FORM); # Use the send_mail routine in mail-lib.pl to send the email to the store # admin including the clients ordering information then get the heck outa # Dodge. &send_mail("$admin_email","$admin_email", "$email_subject", "$email_body"); exit; } ####################################################################### # Display items for Sale Basd on Given Category # ####################################################################### # If we have gotten through all of the if tests above, it means that the # client simply wanted to see a category display...so let's display the # current items within the category selected by the client. We will use # the display_items_for_sale subroutine below else { &display_items_for_sale; exit; } ####################################################################### # display_items_for_sale # ####################################################################### sub display_items_for_sale { # Firstly, we need to make sure that the category the user has asked to # see is indeed a category and not a category of categories! For # instance, we may have a category called peripherals which coulld include # printers, hard drives, memory, cabling, etc...it might not make sense to # dump them all in one category...thus, we will want to have printers, # storage, etc in their own categories...but suppose that we already have # ten top level categories and do not want to display the 5 extra # peripheral categories. The way around this is to use the # @root_category_list array in the store specific setup file. This array # shouild contain all of the category names that are actually categories # of categories. Each item in the list should correspond to an html file # in the Html directory. For instance, we may have "Peripherals" as an # array element. This script will look for Peripherals.html in the Html # directory....This HTML file should just present the client with the # types of sub categories within Peripherals....okay, enough setup...we'll # go through the routine. foreach $root_category (@root_category_list) { # Go through the elements in @root_category_list one at a time. If it so # happens that the category coming in as form data is equal to one of # those elements, we will output the associated HTML document as we did # for the frontpage and order form above. if ($root_category eq "$form_data{'Type'}") { open (ROOT_CATEGORY_PAGE, "$html_directory/$root_category.html") || &CgiDie ("I am sorry, but I was not able to open the root category page in the display_items_for_sale subroutine. The path I have is $html_directory/$root_category.html. Would you please check the path and permissions."); while () { s/cart_id=/cart_id=$cart_id&store=$store/g; if ($_ =~ / !; } elsif ($_ =~ /<\/BODY/) { print qq!
$_!; } else { print "$_"; } } # End of while () exit; } # End of if ($root_category eq "$form_data{'Type'}") } # End of foreach $root_category (@root_category_list) # If it passed through that test, it means that we have found a category # which has only items and no subcategories. BTW, you may not have a # category with both items and subcategories...only one or the other. # So, display the items that fit this category. This is the exact same # routine as we have used above time and again. &page_header("$form_data{'Type'}"); print qq!
!; #Quantity Desired open (DATABASE, "$data_file") || &CgiDie ("I am sorry, but I was unable to open the Data file in the display_items_for_sale subroutine. the value I have is $data_file. Would you please check the path and permissions."); # foreach $field (@display_fields) # { #print qq!\n!; #$field #} #print qq!!; while () { @database_row = split (/\|/, $_); if ($database_row[$category_field_number] eq $form_data{'Type'}) { #print qq!!; @database_row = split (/\|/, $_); $db_number = pop(@database_row); push (@database_row, $db_number); chop $db_number; #print qq!\n!; #print qq!\n!; #foreach $row (@database_row) # { #@display_numbers = split (/\|/, $row); # Make sure to only output the rows that the admin has set to be # displayed. #foreach $display_number (@display_numbers) #{ #if ($display_number eq "$price_number") # { #print qq!\$$database_row[$display_number]\n!; # } #if ($display_number eq "$Image_number") #{ # print qq! # \n!; # } # else #{ #print qq!$database_row[$display_number]\n!; #} print qq!
$database_row[2]
$database_row[4]
\$$database_row[5] ID: $database_row[0] Quantity:
<$hr> \n!; # } # End of foreach $display_number (@display_numbers) #print qq!!; } # End of if ($_ =~ /^$form_data{'Type'}/i) } # End of while () # Print out the footer... print qq!


Designed By Design Tyme

Copyright © 1998. All Rights Reserved.

!; close (DATABASE); } # End of sub display_items_for_sale # bad_order_note is a subroutine that we will use in case the client has # inputted a bad character in one of the input fields. sub bad_order_note { &page_header("Wooopsy"); print qq!

Wooopsy

I'm sorry, it appears that you did not enter a valid numeric quantity (whole numbers greater than zero) for one or more of the items you ordered and I am not allowed to modify your cart unless you do so. Would you try again? Thanks


Designed By Design Tyme

Copyright © 1998. All Rights Reserved.

!; exit; } # page_header just prints out the basic header tags. We pass the routine # one argumnet which should be printed out differentiating pages which use # this routine. sub page_header { local($type_of_page) = @_; &generic_header("$global_page_title - $type_of_page"); print qq!
!; } sub display_cart_contents { # First use the page_header subrtoutine at the end of this script to # output an HTML header passing it one parameter relating to how the page # title should be modified. &page_header("View/Modify Cart"); # Now begin to create a table to display the current cart contents. print qq!
!; # Next create the table headers. For every item in our special list of # database items to be displayed, lets create a header cell. foreach $field (@display_fields) { print qq!\n!; } # Now add on a cell for Quanity and one for Subtotal since the client's # cart has those "extra" fields. print qq!\n\n\n!; # Then open the client's cart again and go through it one line at a time. open (CART, "$cart_directory/$form_data{'cart_id'}.cart") || &CgiDie ("I am sorry, but I was unable to open the client cart in the display_cart_contents subroutine. The value I have is $cart_directory/$form_data{'cart_id'}.cart. Would you check the path and permissions."); while () { @cart_fields = split (/\|/, $_); $cart_id_number = pop (@cart_fields); $quantity = shift(@cart_fields); # Now, we need to fill in the table row for every cart database row. # @display_numbers defined in the dataabse specific setup file will give # us the array numbers associated with the fields that we want displayed # on this table. Then we will get the value of that number from the # cart_fileds array. foreach $display_number (@display_numbers) { if ($cart_fields[$display_number] eq "") { $cart_fields[$display_number] = "
-
"; } if ($display_number eq "$price_number") { print qq!
\n!; } elsif ($display_number eq "$Image_number") { print qq!!; } elsif ($display_number eq "$db_id_number") { print qq!!; } else { print qq!\n!; } } # End of foreach $display_number (@display_numbers) # Then we will need to use the quantity value we shifted earlier to fill # the next table cell, and then, after using another database specific # setup variable, calculate the subtotal for that database row and fill # the final cell and close out the table row and the cart file (once we # have gone all the way through it. print qq!!; $unformatted_subtotal = ($quantity*$cart_fields[$price_number]); $subtotal = sprintf ("%.2f\n", $unformatted_subtotal); $unformatted_grand_total = $grand_total + $subtotal; $grand_total = sprintf ("%.2f\n", $unformatted_grand_total); print qq!!; print qq!!; } # End of while () close (CART); # Finally, print out the footer. print qq!
$fieldQuantitySubtotal
\$$cart_fields[$display_number]$cart_fields[$display_number]$quantity\$$subtotal

Pre-shipping Total = \$$grand_total


Designed By Design Tyme

Copyright © 1998. All Rights Reserved.

!; exit; } sub get_short_date { # The subroutine begins by defining some local working # variables local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,$date); local (@days, @months); @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday', 'Friday','Saturday'); @months = ('January','February','March','April','May','June','July', 'August','September','October','November','December'); # Next, it uses the localtime command to get the current # time, from the value returned by the time # command, splitting it into variables. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # Then the script formats the variables and assign them to # the final $date variable. Note that $sc_current_century # is defined in web_store.setup. Since the 20th centruy # is really 1900-1999, we'll need to subtract 1 from this # value in order to format the year correctly. if ($hour < 10) { $hour = "0$hour"; } if ($min < 10) { $min = "0$min"; } if ($sec < 10) { $sec = "0$sec"; } $mon++; if ($year < 99) { $year += 2000; } else { $year += 1900; } $date = "$mon/$mday/$year at $hour\:$min\:$sec"; $short_date = "$mon/$mday/$year"; return $short_date; } sub get_date { # The subroutine begins by defining some local working # variables local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,$date); local (@days, @months); @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday', 'Friday','Saturday'); @months = ('January','February','March','April','May','June','July', 'August','September','October','November','December'); # Next, it uses the localtime command to get the current # time, from the value returned by the time # command, splitting it into variables. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # Then the script formats the variables and assign them to # the final $date variable. Note that $sc_current_century # is defined in web_store.setup. Since the 20th centruy # is really 1900-1999, we'll need to subtract 1 from this # value in order to format the year correctly. if ($hour < 10) { $hour = "0$hour"; } if ($min < 10) { $min = "0$min"; } if ($sec < 10) { $sec = "0$sec"; } $mon++; #$year = ($current_century-1) . "$year"; if ($year < 99) { $year += 2000; } else { $year += 1900; } $date = "$mon/$mday/$year at $hour\:$min\:$sec"; return $date; } sub get_count { open (COUNTER_FILE, "<$location_of_counter_file") || &file_open_error ("$location_of_counter_file", "Submit Addition", __FILE__, __LINE__); while () { $current_counter = $_; } close (COUNTER_FILE); $current_counter++; $new_counter = $current_counter; return $new_counter; }