#!/usr/bin/perl use DBI; ##############Universally required subroutines############## require "universal_config_files/required_libs.txt"; ############################################################ #################Load Universal Config File################# require "universal_config_files/universal_cart_config.txt"; ############################################################ #Parse form now also run &clean_string on everything!!!!# &parse_form; #Parse http headers for form data #####Dynamically Configure Site Specific Config Files####### if ($ENV{'HTTP_HOST'} ne '' || $formdata{'HTTP_HOST'} ne '') { if ($ENV{'HTTP_HOST'} !~ '^www\.') { $ENV{'HTTP_HOST'} = 'www.' . $ENV{'HTTP_HOST'}; } if (-e 'site_files/' . $ENV{'HTTP_HOST'} . '/config_files/cart_config.txt') { $site = $ENV{'HTTP_HOST'}; } elsif (-e 'site_files/' . $formdata{'HTTP_HOST'} . '/config_files/cart_config.txt') { $site = $formdata{'HTTP_HOST'}; } else { &mime; print 'Fatal Error Encountered Running TVCart on: ' . $ENV{'HTTP_HOST'} . '. Please notify the administrator at tvadasz@americaninnovations.com, or call 845-371-3333.'; exit; } require 'site_files/' . $site. '/config_files/cart_config.txt'; #### Now, Merge Universal & Site Specific Config Files #### %look_and_feel_hash = merge_hashes (\%look_and_feel_hash, \%universal_look_and_feel_hash); %tax_hash = merge_hashes (\%tax_hash, \%universal_tax_hash); %shipping_charge_hash = merge_hashes (\%shipping_charge_hash, \%universal_shipping_charge_hash); %form_types_hash = merge_hashes (\%form_types_hash, \%universal_form_types_hash); %field_properties_hash = merge_hashes (\%field_properties_hash, \%universal_field_properties_hash); #### #### #### #### #### #### #### #### } else { &mime; print 'TVCart Has Encountered A Fatal Error: ENV[HTTP_HOST] Not Found.\n\nPlease Report This Error To tvadasz@americaninnovations.com or 845-371-3333 Immediately.'; exit; } #################################################################### #### Declare Variables , initialize them. #### my %cookie_information = &get_cookie_information(); #Retrieves cookie, creates it if necessary. my $user_type; my $form_complete = 'true'; my %form_completeness_hash; my %arguments; &mime; #Print Mime Info. ### Must always Verify Status before letting them do anything! ### if ($cookie_information{'just_initialized'} eq 'true') { $user_type = $cookie_information{'user_type'}; #Not really from cookie... returned from initialization. } else { $user_type = verify_status($cookie_information{'user_name'}, $cookie_information{'session_id'}); } ### ### ### ### if ($user_type eq 'invalid') { $arguments{'html_file_name'} = 'critical_error.html'; $arguments{'error_code'} = 'Invalid Session ID'; &parse_page_for_tags(\%arguments); exit; } ### ### Set Specific Info you want passed around ### ### $arguments{'session_id'} = $cookie_information{'session_id'}; $arguments{'user_name'} = $cookie_information{'user_name'}; $arguments{'user_type'} = $user_type; $arguments{'form_type'} = $formdata{'form_type'}; $arguments{'action'} = $formdata{'action'}; ### ### ### ### ### ### ### #-------------------------------------------------------------------------------------------------# #---------------------------------------User Tracking Info----------------------------------------# my $cart_file_location = '/usr/home/ctxspy12/usr/local/etc/httpd/cgi-bin/tvcart/site_files/' . $site . '/customer_shopping_lists/' .$cookie_information{'user_name'} . $cookie_information{'session_id'}; my @LINES = &load_file_into_array($cart_file_location); my $tmp_ln_counter = 0; foreach my $LINE (@LINES) { if ($LINE =~ /TRACKING_INFO_ENDS_HERE/) { $LINES[$tmp_ln_counter] = $formdata{'page'} . "\t" . '  ' . "$formdata{'action'}\nTRACKING_INFO_ENDS_HERE\n"; } $tmp_ln_counter++; } #--------------More user tracking-------------# open (CART_FILE, ">$cart_file_location"); flock (CART_FILE,2); foreach my $LINE (@LINES) { print CART_FILE $LINE; } close (CART_FILE); flock (CART_FILE,8); #---------------------------------------------# #-------------------------------------------------------------------------------------------------# ######################################Perform Desired Actions########################################### if ($formdata{'action'} eq 'set_shipping_type') { $arguments{'shipping_type'} = $formdata{'shipping_type'}; &modify_cart_contents(\%arguments); } if ($formdata{'action'} eq 'set_form_type') { &modify_cart_contents(\%arguments); } if ($formdata{'action'} eq 'set_destination_type') { $arguments{'destination_type'} = $formdata{'destination_type'}; &modify_cart_contents(\%arguments); } if ($formdata{'action'} eq 'complete_order' && $arguments{'user_type'} eq 'guest') { #This block exists because of customers who incorrectly enter their info, and need to go back & correct it. my %arguments = %arguments; $arguments{'action'} = 'set_customer_info'; &modify_cart_contents(\%arguments); } #----------------We set the zipcode when people explicitly ask, and when checking out------------------# if ($formdata{'action'} eq 'set_zipcode' || $formdata{'action'} eq 'complete_order') { my %arguments = %arguments; $arguments{'zipcode'} = $formdata{'zipcode'}; $arguments{'action'} = 'set_zipcode'; if ($formdata{'action'} eq 'complete_order') { $arguments{'state_update'} = 'false'; } &modify_cart_contents(\%arguments); } #------------------------------------------------------------------------------------------------------# if ($formdata{'action'} eq 'add_items' || $formdata{'action'} eq 'recalculate') { foreach my $key (keys %formdata) { if ($key =~ "quantity_of_item_") { my $index_number = $key; $index_number =~s /quantity_of_item_//; #Strip it to get index_num $arguments{'items'}{$index_number}{'quantity'} = $formdata{$key}; } if ($key =~ "catalog_number_of_item_") { my $index_number = $key; $index_number =~s /catalog_number_of_item_//; #Strip it to get index_num $arguments{'items'}{$index_number}{'catalog_number'} = $formdata{$key}; } } ## "Normalize" the hash.. I think the error stems in that there are 'hole's in the index numbers## #my %tmp_hash; #my $tmp_counter = 1; #foreach my $item (keys %{$arguments{'items'}}) #{ # %{$tmp_hash{$tmp_counter}} = %{$arguments{'items'}{$item}}; # $tmp_counter++; #} #%{$arguments{'items'}} = %tmp_hash; ## ## ## ## ## ## ## ## ## ## ## ## ## &modify_cart_contents(\%arguments); } if ($formdata{'action'} eq 'remove_items') { foreach my $key (keys %formdata) { if ($key =~ 'remove_item_') { my $index_number = $key; $index_number =~ s/remove_item_//; $arguments{'items'}{$index_number} = '1'; } } &modify_cart_contents(\%arguments); } if ($formdata{'action'} eq 'set_item_style') { if ($formdata{'item'} =~ '^[0-9]+$' && $formdata{'item_style'} =~ '^[0-9]+$') { $arguments{'items'}{$formdata{'item'}} = $formdata{'item_style'}; &modify_cart_contents(\%arguments); } } if ($formdata{'action'} eq 'complete_order') { # my %cart_contents = &get_cart_info(\%arguments); #ERASE IF WE SEE NO PROBLEMS my $form_complete = 'true'; my %can_complete = &meets_purchase_requirements(\%arguments); #if ($cart_contents{'empty'} eq 'false' && $can_complete eq 'true')#ERASE IF WE SEE NO PROBLEMS if ($can_complete{'value'} eq 'true') { my %form_data; ###### ##### CHANGE THIS TO GET_FORM_TYPE# *REMOVE SOON UNLESS WE SEE PROBLEMS* ###### # ###Set Form Type### # if (exists($formdata{'form_type'}) && $formdata{'form_type'} ne '') #Check Form First! # { # #If form type is not set in customer_cart file, we use this..; # #$arguments{'form_type'} = $arguments{'form_type'}; # $form_data{'form_type'} = $formdata{'form_type'}; # } # elsif (exists($cart_contents{'form_type'})) #Check File Second! # { # ($form_data{'form_type'}, $form_data{'form_sub_type'}) = split (/:/,&clean_string($cart_contents{'form_type'})); # } # ### ### ### ##### ##### Done below... the above section can be removed ##### my %form_data = &get_form_type(\%arguments); #--------------Double Check & Make sure that all form date is clean---------------# foreach my $key (keys %field_properties_hash) { if (exists $formdata{$key}) { $form_data{$key} = &clean_string($formdata{$key}); } } #---------------------------------------------------------------------------------# $form_data{'user_type'} = $user_type; %form_completeness_hash = &check_form_completeness(\%form_data); foreach my $key (keys %form_completeness_hash) { if ($form_completeness_hash{$key}{'complete'} ne 'true') { $form_complete = 'false'; } } if ($form_complete eq 'true') { my %arguments = %arguments; my %customer_info = &get_customer_info($arguments{'user_name'}, $arguments{'session_id'}); my %form_info = &get_form_type(\%arguments); %{$arguments{'form_data'}} = %form_data; ### ### #When you send out the e-mail, if the user modifies any of his info ### ### ### ### #at checkout time, make a note of it in the email. ### ### $arguments{'email_data'}{'to'} = $form_data{'email'}; $arguments{'email_data'}{'from'} = $order_receipt_from_address; $arguments{'email_data'}{'subject'} = "Order Confirmation"; $arguments{'email_data'}{'file_name'} = "$user_email_page{$user_type}{$form_info{'form_sub_type'}}"; &send_email(\%arguments); $arguments{'email_data'}{'to'} = $main_order_recipient; $arguments{'email_data'}{'cc'} = 'sales@americaninnovations.com'; #Checked by grant's computer. $arguments{'email_data'}{'bcc'} = 'info@aisecurecheckout.com'; #Checked by my computer. $arguments{'email_data'}{'from'} = $order_receipt_from_address; $arguments{'email_data'}{'reply_to'} = $form_data{'email'}; $arguments{'email_data'}{'subject'} = "$site - $form_info{'form_sub_type'}"; $arguments{'email_data'}{'file_name'} = $order_email_page; &send_email(\%arguments); } else { $arguments{'html_file_name'} = 'critical_error.html'; $arguments{'error_code'} = 'The following fields were empty or in an improper format: