#!/usr/bin/perl -w ################################################################################ ################################################################################ ##### The code in this script is the property of Spark-IT Group ##### ##### All rights reserved. No unauthorized replication permitted. ##### ##### SIT PERL PayPal catalog script for WSDBI (C) 2009 ##### ##### Version 1.0.1 ##### ################################################################################ ################################################################################ # start user configuration ################################################################################ ################################################################################ $Feature_Name = "Online Billiard Supply Store"; $Feature_Short_Name = "Billiard Supply Store"; # the database table name and fields that this script will use for data source $item_data_table = "products"; $item_number_field = "Product_ID"; $item_active_field = "Active"; $item_category_field = "Category"; $item_name_field = "Product_Name"; $item_description_field = "Description"; $item_details_field = "Details"; $item_options_field = "Options"; $item_amount_field = "Reg_Price"; $item_sale_price_field = "Sale_Price"; $item_imgType_field = "File_Type"; $cart_type = "PayPal"; # see more configuration settings below #====================================================================== # optional PayPal user configurations #====================================================================== #load required perl modules or libraries before configuring paypal #my $dbh; my $db_params = "wsdbi_params.pm"; my $db_common = "admin/params.pl"; eval { #use strict; use DBI; require $db_params; require $db_common; }; #check for load errors if ($@) { &my_load_error_doc($@); exit(0); } #====================================================================== # optional PayPal user configurations #====================================================================== $selfURL = $ENV{SCRIPT_NAME}; #$selfURL = "/cgi-bin/store.pl"; # default background color for table data $bgcolor = "#ffffff"; #$PP_lc = Paypal language control: Set to param specified for your language. $PP_lc = "US"; # $image_url4_PayPal = Add Your Logo! # Customize the look of your PayPal payment pages by adding your logo. This # image, which must be 150 by 50 pixels in size, will appear in the upper left # hand corner of the page when your customer presses your Shopping Cart # button. Always use secure HTTPS URL protocol if possible. $image_url4_PayPal = "https://$op_info->{HTTP_Host}$my_Business_logo_URL "; # $return_url = Successful Payment URL # Enter the URL where you would like to send your customers after they have # completed payment. Once your customer has completed their payment, they will # see a payment confirmation page. From this page, they will press the # 'Continue' button and return to the Successful Payment URL you have # specified. If you do not enter a Successful Payment URL, customers who click # this link will be taken to a PayPal web page. $return_url = "http://$op_info->{HTTP_Host}$selfURL"; #$shopping_url = Continue Shopping (PayPal's "Return to Merchant" param) $shopping_url = "http://$op_info->{HTTP_Host}$selfURL"; #$cancel_return = URL where shopper is returned after Cancel Checkout at PayPal $cancel_return = "http://$op_info->{HTTP_Host}$selfURL"; # Enter the currency symbols PayPal uses to designate US dollars # or Euros or Pounds Sterlings. [Enter a backslash before the $ symbol!] # US: $ # Euros: € # Pounds Sterling: £ # Canadian Dollar (C$) # Japanese Yen (¥) $m_symbol = "\$"; # The currency of the payment is U.S.Dollars: USD # The currency of the payment is British Pounds Sterling: GBP # The currency of the payment is Euros: EUR # The currency of the payment is Canadian Dollar: CAD # The currency of the payment is Yen: JPY $currency_code = "CAD"; # End user configuration - DO NOT EDIT BELOW print "Content-type: text/html \n\n\r\n\r\n\r" unless ($content_type_printed); $content_type_printed++; ################################################################################ ################################################################################ use CGI::Carp qw(fatalsToBrowser); #comment out the above line unless developing and when done debugging the script ################################################################################ ################################################################################ ##### This code tells the browser what MIME type the content is. ##### ##### All content delivered by this script is HTML ##### ################################################################################ ################################################################################ #dont't buffer output $|++; # find out the OS if ( $^O eq 'MSWin32' || $ENV{'OS'} eq 'Windows_NT' ) { # this one for windows $windows = 'Yes'; $slash = '\\'; } else { $windows = 'No'; $slash = '/'; } # connect to DB, read CGI data, verify Login, ConnectToDB(); my_read_CGI_input(); ##### define time variables my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime(time); $mon = $mon + 1; $year = $year + 1900; $accessTime = "$hour:$min:$sec"; $AN = int( rand(10000) ); #init_cart_buttons if ( $cart_type eq "PayPal" ) { $view_cart_button = qq~
~; } else { $view_cart_button = qq~~; } ################################################################################# ################################################################################# if ( $data{cmd} eq "Sign-Off" ) { Log_Out(); } elsif ( $data{cmd} eq "PayPalOK" ) {Confirm_PayPal();} else { Main_HTML_Doc(); } DisConnectFromDB(); #End of main perl code, begin subroutines sub Main_HTML_Doc() { $top_right_link_content = qq~ ~; #Determine Page Content $left_content = Active_Product_Category_Links(); #Default Content $left_content = Dir_Help() if ( $data{cmd} eq "Help" ); $left_content = Dir_Thanks() if ( $data{cmd} eq "Thanks" ); $main_content = Default_Content(); #if($data{cmd} eq ""); #Default Content $main_content = Read_Inventory_DB() if ( ( $data{$item_category_field} ne "" ) || ( $data{cmd} eq "ShowItem" ) ); $main_content = Help_Html() if ( $data{cmd} eq "Help" ); $main_content = Thanks() if ( $data{cmd} eq "Thanks" ); my $page_title_text = "$data{$item_category_field} - " if ( defined $data{$item_category_field} ); if ( defined $item_name ) { my @item_keyword_list = split( " ", $item_name ); $item_keywords = join( ",", @item_keyword_list ); $item_keywords .= ","; $page_title_text = "$item_name - " if ( defined $data{Item} ); } print "Content-type: text/html \n\n\r\n\r\n\r" unless ($content_type_printed); $content_type_printed++; do "main_html_doc.pl"; } sub my_load_error_doc() { my ($item) = shift; my $server = ( $ENV{HTTP_HOST} ) ? $ENV{HTTP_HOST} : 'localhost'; my $REQUEST_URI = $ENV{'SCRIPT_NAME'} ? $ENV{'SCRIPT_NAME'} : $0; $item =~ s/\]/\]
|
Can't execute query:
$dbquery.
Reason: $DBI::errstr."; $sth->finish; DisConnectFromDB(); exit; } while ( my $sku_ref = $sth->fetchrow_hashref() ) { $entry_found = 0; foreach $this_category (@my_unique_categories) { if ( $this_category eq $sku_ref->{$item_category_field} ) { $entry_found = 1; } } if ( $entry_found == 0 ) { push( @my_unique_categories, $sku_ref->{$item_category_field} ); } } $sth->finish(); $i = 0; foreach $this_category (@my_unique_categories) { if ( ( $data{$item_category_field} ne "" ) && ( $data{$item_category_field} eq $this_category ) ) { $this_link = qq~
Reason:
Unknown DB table name: $dbtable"
);
&DisConnectFromDB;
exit(0);
}
my $sth = $dbh->prepare("DESC $dbtable");
if ( not $sth->execute() ) {
&show_my_error_doc("Can't execute query:
$dbquery.
Reason:
$DBI::errstr."
);
&DisConnectFromDB;
exit(0);
}
my $i = 0;
while ( my $row = $sth->fetchrow_hashref ) {
push( @fields, $row->{Field} );
$i++;
}
$sth->finish;
$DB_field_count = $i;
return @fields;
}
sub Dir_Help() {
my $help_content;
$help_content = Default_Content(); #Default Content
$help_content = Dir_Account() if ( $data{option} eq "AcctMngr" );
$help_content = Dir_Help() if ( $data{option} eq "Help" );
}
sub Dir_Thanks() {
my $html = qq~
Can't execute query:
$dbquery.
Reason: $DBI::errstr."; $sth->finish; DisConnectFromDB(); exit; } my $html = qq~
$view_cart_button |
$content_name
|
|
$item_name | ||
$item_number MSRP: $m_symbol$sku_ref->{$item_amount_field} $currency_code $item_sale_price $add_form_HTML |
$product_img_URL $sku_ref->{$item_description_field} | |
$item_details
Top |
||
Item |
Description |
|
$item_number MSRP: $m_symbol$sku_ref->{$item_amount_field} $currency_code $item_sale_price $add_form_HTML $detail_link |
$item_name $product_img_URL
$sku_ref->{$item_description_field}
|
|
||
$view_cart_button |
$content_name
|
|
To begin shopping, select a product category from the category list at left. |
||
$pay_methods | ||
$default_policy_content |
|
Reason:
$DBI::errstr."
);
&DisConnectFromDB;
exit(0);
}
unless ( $INV_recordRef = $sth->fetchrow_hashref() ) {
&show_error("Can't read Inventory record:
$db_query.
Reason:
Record not found."
);
&DisConnectFromDB;
exit(0);
}
$sth->finish();
}
sub ConnectToDB() {
if ( defined $sth ) { $sth->finish(); }
$dbh = DBI->connect( "DBI:mysql:$op_info->{WSDBI_DB_Name}:$op_info->{WSDBI_DB_Host}", $op_info->{WSDBI_DB_User}, $op_info->{WSDBI_DB_Pass} );
if ( not $dbh ) {
print "
Can't connect to server.
Reason: $DBI::errstr"; exit; } } sub DisConnectFromDB() { if ( defined $sth ) { $sth->finish(); } if ( defined $dbh ) { $dbh->disconnect or die "Can't disconnect from database. Reason: $DBI::errstr" and undef $dbh; } } __END__