#!/usr/bin/perl # -I/usr/local/apache/virtual/o/www.obm.co.uk/bin/webdb use lib '../bin/webdb'; use lib '../bin/perl5/lib'; #$ENV{'PATH'}.=":/usr/local/apache/virtual/o/www.obm.co.uk/bin"; #$ENV{'PATH'}.=":../bin"; $ENV{'PATH'}="/bin:/usr/bin:../bin"; $VAT=17.5; # V.A.T. Amount $company="Leisuretec"; # Company name to appear on HTML output pages $bgcolor="#ffffff"; # Background color for HTML pages $poundsign="£"; # HTML Entity for Pound Sign (£) $titlebgcolor="whitesmoke"; # Background colour for titles # Program name if($0=~/\//) { ($ProgramDir=$0)=~s/^(.*)\/[^\/]*$/$1/; } else { $ProgramDir=$ENV{'CWD'}; } $ProgramName=$0; $ProgramName=~s/^.*\/([^\/]+)$/$1/; $ProgramName=~s/\.([^\.]+)$//; $ProgramDir="." if(!$ProgramDir); $SilentMode=0; # Silent operation mode off by default # HTML Output Directory #$htmlwwwhome="/usr/local/apache/virtual/o/www.obm.co.uk/docs"; # Home directory for WWW server $htmlwwwhome="../docs"; # Home directory for WWW server $htmloutput="${htmlwwwhome}/catalog"; $htmlext=".html"; $tocfilename="toc"; $bullet="/images/blt_blue.gif"; # Bullet image to use #$update_catalogue_cache_program="/usr/local/apache/virtual/o/www.obm.co.uk/bin/catalogue.pl -updatecache"; $update_catalogue_cache_program="../bin/catalogue.pl -updatecache"; # Shopping Basket Configuration $HREFbasket="/cgi-bin/basket"; # Shopping Basket URL location $IMGbasket="/images/basket1.gif"; # Bullet image to use $HREFprefixNeeded="YES"; # Set to YES if basket resides on another site $HREFprefix="http://www.obm.co.uk"; # Normal site prefix $HREFprefixBasket="https://www.obm.co.uk"; # Basket site prefix #$HREFprefixBasket="http://194.168.85.58"; # Basket site prefix $HREFSecureprefix="https://www.obm.co.uk"; # Secure site prefix if($HREFprefixNeeded eq "YES") { $HREFbasket=$HREFprefixBasket.$HREFbasket; } else { $HREFprefix = ""; } # Recommendation Configuration File $RecommendConfigFile="${htmloutput}/recommend.cnf"; $RecommendTitle="Recommendations"; $RecommendDataFile="${htmloutput}/recommend.dat"; $BasketItemsDataFile="${htmloutput}/basketitems.dat"; # Database Export File settings $input_filename="full_bin.txt"; $fielddelimchar="^"; # Field Delimited $fielddelim='\^'; # RegEx to match field delimited $fieldsexpected=19; # Record Selection #$ignore_manu_codes="(0|40|41|5|60)"; # Ignore these manufacturers #$ignore_manu_codes="(0|40|41|5|60|24|90)"; # Ignore these manufacturers $ignore_manu_codes="(0|40|41|5|60|24|90|10)"; # Ignore these manufacturers # Pricing codes $pricePOA="P.O.A."; # Price code = -2 # Determine Input Filename if(length($ARGV[0])>0) { $input_filename=$ARGV[0]; } # Setup output string arrays @monthstring=("January","February","March","April","May","June","July","August","September","October","November","December"); @daystring=("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"); # HTML Output $htmlheader="\n\n"; $htmlheader.="\n"; $htmlheader.="\n"; $htmlheader.="\n
LeisuretecPO Box 68 - Benfleet - SS7 2YX - England - +44 1702 551863
\n"; $htmlfooter="

\n"; $htmlfooter.="\n"; $htmlfooter.="\n"; $htmlfooter.="\n"; $htmlfooter.="\n"; $htmlfooter.="
\n"; $htmlfooter.="Please note that all models may change without notification.
\n"; $htmlfooter.="Please telephone for up-to-date information and details.\n"; $htmlfooter.="
\n"; #$htmlfooter.=&footeraddress($input_filename); sub footeraddress { local($input_filename)=$_[0]; local($string); $string="
\n"; $string.="
\n"; $string.="\n"; $string.="\n"; $string.="\n"; $string.="\n"; $string.="
\n"; $string.="\n"; $string.="Sales / sales\@obm.co.uk
\n"; $string.="
\n
\n\n"; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime((stat($input_filename))[9]); #$year=sprintf "%d$year",($year>95)?19:20; $year=$year+1900; $timestring=sprintf "%s %d %s %d %d:%.2d",$daystring[$wday],$mday,$monthstring[$mon],$year,$hour,$min; $string.="Last Modified: ${timestring}
\n"; #$string.="URL: http://www.leisuretec.mail.co.uk\n"; $string.="
\n"; $string.="
\n"; $string.="
\n"; return $string; } if(! -d "$htmloutput") { printf STDERR "Catalogue directory $htmloutput does not exist!\n"; exit -1; } if($ProgramName eq "recommend") { $SilentMode=0; &recommend; exit 0; } elsif($ProgramName eq "basket") { $SilentMode=1; &basket; exit 0; } else { } use WebDB; if(%Optics=&ReadDatabase($input_filename) != undef) { #if(open(OPTICS,"gunzip -c $input_filename |")) { # printf "Input taken from $input_filename\n"; # @Optics=; # close(OPTICS); # $loop=0; # while() { # last if($loop>2); # chop; # printf "Test: $_\n"; # @data=split(/${fielddelim}/,$_); # printf "Matched\n"; # printf "GOT: @_[0] - @_[1] - @_[2]\n"; # $loop++; # } # Move through the list of items and reorder the relevant fields $FieldTitles=shift(@Optics); # Store the field titles line undef @Data; while($_=shift(@Optics)) { chop; $_ =~ s/\234/${poundsign}/g; my ($Fmodel,$Fdesc,$Fmag,$Finfo,$Fprice,$Fmanucode,$Fmanudesc,$Frangcode,$Frangdesc,$Franginfo,$Fsectcode,$Fsectdesc,$Fsectinfo,$Flistord,$Fmagtitle,$Fotherinfotitle,$Fpricetitle,$Ftype,$Fcategory,$Frecommended)=split(/${fielddelim}/,$_); if($Fmanucode!~/^${ignore_manu_codes}$/) { push(@Data,join("${fielddelimchar}",$Fmanucode,$Frangcode,$Fsectcode,$Flistord,$Fmodel,$Fmanudesc,$Frangdesc,$Fsectdesc,$Fdesc,$Fmag,$Finfo,$Fprice,$Fmagtitle,$Fotherinfotitle,$Fpricetitle,$Ftype,$Fcategory,$Frecommended)); } } # shift(@Data); # Remove the line containing headings @Optics=sort sortbycode (@Data); undef @Data; $dbobject = WebDB->new("leisuretec"); # Load the recommended configuration information # This has been expanded and is being used to identify 'type' and # 'category' for each item. undef %TypeCategoryConfig; if(open(FILE,"${RecommendConfigFile}")) { while() { if(!/^#/ && /^([^=]+)=(.*)$/) { $TypeCategoryConfig{"$1"}=$2; } } } # End of Load # @Optics now holds all the sorted optics data printf "Outputing catalogue data to the directory $htmloutput\n"; $lastmanudesc=""; $lastmanu=-1; $lastrang=-1; $lastsect=-1; $fileopen="false"; $count=0; $table=0; # Indicate whether table tag has been output undef @toc; undef @recommend; undef @basketitems; my %data_manu; while($_=shift(@Optics)) { ($Fmanucode,$Frangcode,$Fsectcode,$Flistord,$Fmodel,$Fmanudesc,$Frangdesc,$Fsectdesc,$Fdesc,$Fmag,$Finfo,$Fprice,$Fmagtitle,$Fotherinfotitle,$Fpricetitle,$Ftype,$Fcategory,$Frecommended)=split(/${fielddelim}/,$_); next if(length($Fmanucode)==0); # Add to recommendation list if relevant if($Frecommended=~/1/) { push(@recommend,$_); } # # Add to basket items if there is a model number if(length($Fmodel)>0 && $Fprice > 0) { my $d = $Fdesc; $d.=" - ".$Fmag if(length($Fmag)>0); $d.=" - ".$Finfo if(length($Finfo)>0); push(@basketitems,$Fmodel.$fielddelimchar.$Fmanudesc.$fielddelimchar.$d.$fielddelimchar.$Fprice); } # if($Fmanucode != $lastmanu) { # New manufacturer if($lastmanu!=-1) { printf "$count items for $lastmanudesc ($lastmanu)\n"; my %data; #printf "Count for Manu $Fmanucode added\n"; ${ $data_manu{$Fmanucode} }{'--COUNT--'} = $count; $count=0; } $lastmanudesc=$Fmanudesc; $lastmanu=$Fmanucode; if($table>0) { printf OUTPUT "\n"; $table=0; } #printf OUTPUT "\n\n\n"; printf OUTPUT "$htmlfooter\n"; printf OUTPUT &footeraddress($input_filename); printf OUTPUT "\n\n\n"; close(OUTPUT); $fileopen="false"; if(open(OUTPUT,"> $htmloutput/$Fmanucode$htmlext")) { $fileopen="true"; # Output the page header here printf OUTPUT "\n\n$company - $Fmanudesc\n\n\n"; #printf OUTPUT "\n"; printf OUTPUT "$htmlheader\n"; printf OUTPUT "

$Fmanudesc

\n"; printf OUTPUT "

Click to add items to your shopping basket. - View Basket

\n",&HTML::HTMLencodeURL("/catalog/$Fmanucode$htmlext"),&HTML::HTMLencodeURL("$Fmanudesc"); push(@toc,"$Fmanudesc$fielddelimchar$Fmanucode$htmlext"); #printf "Desc and column titles for Manu $Fmanucode added ($Fmanudesc)\n"; ${ $data_manu{$Fmanucode} }{'--DESC--'} = $Fmanudesc; ${ $data_manu{$Fmanucode} }{'--COL_TITLE_1--'} = $Fmagtitle; ${ $data_manu{$Fmanucode} }{'--COL_TITLE_2--'} = $Fotherinfotitle; ${ $data_manu{$Fmanucode} }{'--COL_TITLE_3--'} = $Fpricetitle; } else { printf STDERR "Can't open output file $htmloutput/$Fmanucode$htmlext: $!\n"; } $lastrang=-1; $lastsect=-1; } if($fileopen=="true") { if($table==0) { printf OUTPUT "\n"; $table=1; } if($lastrang!=$Frangcode) { printf OUTPUT "\n" if($count>0); if(length($Frangdesc)>0) { if($Frangdesc eq "BLANK") { $Frangdesc=""; } printf OUTPUT "\n"; printf OUTPUT "\n"; #printf "Desc for Range $Fmanucode/$Frangcode added ($Frangdesc)\n"; ${ ${ $data_manu{$Fmanucode} }{$Frangcode} }{'--DESC--'} = $Frangdesc; } $lastrang=$Frangcode; $lastsect=-1; } if($lastsect!=$Fsectcode) { printf OUTPUT "\n",($Fsectdesc eq "BLANK")?" ":"$Fsectdesc"; #printf "Desc for Section $Fmanucode/$Frangcode/$Fsectcode added ($Fsectdesc)\n"; ${ ${ ${ $data_manu{$Fmanucode} }{$Frangcode} }{$Fsectcode} }{'--DESC--'} = $Fsectdesc; $lastsect=$Fsectcode; } my %data_item; $data_item{'PRICE'} = $Fprice; if(length($Fprice)>0) { # Check price codes if($Fprice == -1) { $Fprice=""; } elsif($Fprice == -2) { $Fprice=$pricePOA; } else { $Fprice=sprintf "$poundsign%.2f",$Fprice; } } #printf OUTPUT "$Fmanudesc,$Fmanucode,$Frangdesc,$Frangcode,$Fsectdesc,$Fsectcode,$Flistord,$Fmodel,$Fdesc,$Fmag,$Finfo,$Fprice\n"; # Determine if the model exists in the DB undef $dbmodel; $model_with_dashes = $Fmodel; $model_with_dashes =~ s/\s/-/g; $model_with_dashes =~ tr/[A-Z]/[a-z]/; $data_item{'TYPE_CODE'} = $Ftype; $data_item{'CATEGORY_CODE'} = $Fcategory; $data_item{'RECOMMENDED'} = $Frecommended; $data_item{'MODEL'} = $Fmodel; $data_item{'DESC'} = $Fdesc; $data_item{'COL1'} = $Fmag; $data_item{'COL2'} = $Finfo; $data_item{'COL3'} = $Fprice; #printf "M:%s R:%s S:%s\n",$Fmanucode,$Frangcode,$Fsectcode; #printf "Item Data added in $Fmanucode/$Frangcode/$Fsectcode added ($Fmodel)\n"; push(@{ ${ ${ ${ $data_manu{$Fmanucode} }{$Frangcode} }{$Fsectcode} }{'ITEM_LIST'} },\%data_item); if($dbobject->Check_Record_Exists("PRODUCTS",$model_with_dashes)) { $dbmodel = $model_with_dashes; $dbobject->Set_Field("PRODUCTS",$model_with_dashes,"PRICE",$Fprice); $dbobject->Set_Field("PRODUCTS",$model_with_dashes,"MANUFACTURER",$Fmanudesc); $dbobject->Set_Field("PRODUCTS",$model_with_dashes,"MANUFACTURER_CODE",$Fmanucode); $dbobject->Set_Field("PRODUCTS",$model_with_dashes,"TYPE_CODE",$Ftype); $dbobject->Set_Field("PRODUCTS",$model_with_dashes,"CATEGORY_CODE",$Fcategory); $dbobject->Set_Field("PRODUCTS",$model_with_dashes,"RECOMMENDED",$Frecommended); $dbobject->Set_Field("PRODUCTS",$model_with_dashes,"TYPE",$TypeCategoryConfig{"Type.".$Ftype}); $dbobject->Set_Field("PRODUCTS",$model_with_dashes,"CATEGORY",$TypeCategoryConfig{"Type.".$Ftype.".Category.".$Fcategory}); } printf OUTPUT "\n",defined($dbmodel)?"":"",defined($dbmodel)?"":"",(length($Fmodel)>0 && length($Fprice)>0 && $Fprice=~/^${poundsign}[0-9.]+$/)?" ":""; } $count++; } if($table>0) { printf OUTPUT "

$Frangdesc
$Fmagtitle$Fotherinfotitle$Fpricetitle
%s
%s$Fmodel%s$Fdesc$Fmag$Finfo$Fprice%s
\n"; } #printf OUTPUT "\n"; printf OUTPUT "${htmlfooter}\n"; printf OUTPUT &footeraddress($input_filename); printf OUTPUT "\n\n"; close(OUTPUT); if($lastmanu!=-1) { printf "$count items for $lastmanudesc ($lastmanu)\n"; } foreach my $manu_code (keys %data_manu) { printf "Updating db with manufacturer '%s'\n",${ $data_manu{$manu_code} }{'--DESC--'}; $dbobject->Store_Record('catalogue',$manu_code,$data_manu{$manu_code}); } system("nohup","/bin/sh","-c","$update_catalogue_cache_program &"); # Now output the Table-of-Contents for the different manufacturers if(open(OUTPUT,"> $htmloutput/$tocfilename$htmlext")) { printf OUTPUT "\n\n$company - Binoculars & Telescopes Catalogue\n\n\n"; #printf OUTPUT "\n"; printf OUTPUT "$htmlheader\n"; # printf OUTPUT "

Binoculars & Telescopes Catalogue

\n"; printf OUTPUT "

\n\n\n
Binoculars & Telescopes Catalogue
\n"; printf OUTPUT "
View Basket
\n",&HTML::HTMLencodeURL("/catalog/"),&HTML::HTMLencodeURL("Binoculars & Telescopes Catalogue"); printf OUTPUT "
    \n"; @toc=sort(@toc); while($_=shift(@toc)) { ($name,$file)=split(/${fielddelim}/,$_); $file=~s/^${htmlwwwhome}//; # Remove server home dir printf OUTPUT "\"*\" $name
    \n"; } printf OUTPUT "
\n"; #printf OUTPUT "\n"; printf OUTPUT "${htmlfooter}\n"; printf OUTPUT &footeraddress($input_filename); printf OUTPUT "\n\n"; close(OUTPUT); printf "Table-of-Contents output to $htmloutput/$tocfilename$htmlext\n"; } # Output the recommendation data if(open(DATA,"> $RecommendDataFile")) { printf "Recommendation data output to $RecommendDataFile\n"; foreach(@recommend) { printf DATA "$_\n"; } close(DATA); } # Output the basket items data if(open(DATA,"> $BasketItemsDataFile")) { printf "Basket Items data output to $BasketItemsDataFile\n"; foreach(@basketitems) { printf DATA "$_\n"; } close(DATA); } } else { printf STDERR "Can't open $input_filename: $!\n"; } # Sort the items by codes sub sortbycode { my ($AFmanucode,$AFrangcode,$AFsectcode,$AFlistord,$AFmodel,$AFmanudesc,$AFrangdesc,$AFsectdesc,$AFdesc,$AFmag,$AFinfo,$AFprice,$AFmagtitle,$AFotherinfotitle,$AFpricetitle)=split(/${fielddelim}/,$a); my ($BFmanucode,$BFrangcode,$BFsectcode,$BFlistord,$BFmodel,$BFmanudesc,$BFrangdesc,$BFsectdesc,$BFdesc,$BFmag,$BFinfo,$BFprice,$BFmagtitle,$BFotherinfotitle,$BFpricetitle)=split(/${fielddelim}/,$b); return ( $AFmanucode <=> $BFmanucode || $AFrangcode <=> $BFrangcode || $AFsectcode <=> $BFsectcode || $AFlistord <=> $BFlistord || $AFmodel cmp $BFmodel ); } # Read the Optics database # First record will contain the fields in the database sub ReadDatabase { #local($input_filename)=$_[0]; $input_filename=$_[0]; local(%Optics); undef %Optics; print STDERR "InputFilename: $input_filename\n" if($SilentMode==0); $readprog="cat"; if(! -e $input_filename) { print STDERR " InputFilename didn't exist: $input_filename\n" if($SilentMode==0); foreach("gz:gunzip -c","Z:gunzip -c") { if(/^([^:]+):(.*)$/) { $fileext="$1"; $readprog="$2"; } else { $fileext="$_"; $readprog="cat"; } if(-e "${input_filename}.${fileext}") { $input_filename.=".${fileext}"; print STDERR " InputFilename found: $input_filename\n" if($SilentMode==0); last; } } } if(-e $input_filename && open(OPTICS,"${readprog} ${input_filename} |")) { printf STDERR "Input taken from $input_filename\n" if($SilentMode==0); @Optics=; close(OPTICS); #@Optics=~s/\r$//; foreach(@Optics) { s/\r$//; } return %Optics; } else { print STDERR "Problem opening input file $input_filename: $!\n" if($SilentMode==0); return undef; } } # Display the recommended items sub recommend { # Invoke the CGI parser require "${ProgramDir}/cgiparse.pl"; use WebDB; # Load the recommended configuration information undef %RecommendConfig; if(open(FILE,"${RecommendConfigFile}")) { while() { if(!/^#/ && /^([^=]+)=(.*)$/) { $RecommendConfig{"$1"}=$2; } } } printf "\n\n$company - ${RecommendTitle}\n\n\n\n"; #printf "$htmlheader\n"; printf "

${RecommendTitle}

\n"; print STDERR "RecommendDataFile: $RecommendDataFile\n" if($SilentMode==0); %Optics=&ReadDatabase($RecommendDataFile); print STDERR "Optics ref: ".\%Optics."\n" if($SilentMode==0); foreach(keys %FORM) { # printf "Key: $_\n"; if(/^Type\.(.*)$/) { if($FORM{'_RECOMMEND_TYPE_'}!~/$1/) { $FORM{'_RECOMMEND_TYPE_'}.="$1"; } } } foreach(keys %FORM) { # printf "Key: $_\n"; if(/^Type\.([^\.]+)\.Category\.([^\.]+)/) { if($FORM{'_RECOMMEND_CATEGORY_'}!~/$1$2/) { if(length($FORM{'_RECOMMEND_CATEGORY_'})>0) { $FORM{'_RECOMMEND_CATEGORY_'}.=","; } $FORM{'_RECOMMEND_CATEGORY_'}.="$1$2"; } } } if(length($FORM{'_RECOMMEND_TYPE_'})==0 && $FORM{'_TYPE_SELECTED_'}) { $FORM{'_RECOMMEND_TYPE_'}=$FORM{'_TYPE_SELECTED_'}; } if($#Optics < 0) { # No Optics database printf "

Sorry! An error was encountered and the recommendations could not be retreived.

\n"; } elsif($FORM{'_RECOMMEND_CATEGORY_'}) { # Category Recommendations requested $lasttype=""; $lastcategory=""; $tableopen=0; # Monitor whether a table is open or closed foreach(split(",",$FORM{'_RECOMMEND_CATEGORY_'})) { ($type,$category)=/^(.)(.)/; # Output a heading for the type if($lasttype ne $type) { if($tableopen==1) { printf "\n"; $tableopen=0; } printf "
%s
\n",&RecommendOutput('Type.'.${type},@RecommendConfig); $lasttype=$type; $lastcategory=""; } # Output the category heading if($lastcategory ne $category) { if($tableopen==1) { printf "\n"; $tableopen=0; } printf "
%s
\n",&RecommendOutput('Type.'.${type}.'.Category.'.${category},@RecommendConfig); } # Output the recommended items my $db = new WebDB("leisuretec"); foreach(@Optics) { ($Fmanucode,$Frangcode,$Fsectcode,$Flistord,$Fmodel,$Fmanudesc,$Frangdesc,$Fsectdesc,$Fdesc,$Fmag,$Finfo,$Fprice,$Fmagtitle,$Fotherinfotitle,$Fpricetitle,$Ftype,$Fcategory,$Frecommended)=split(/${fielddelim}/,$_); if($Ftype=~/${type}/ && $Fcategory=~/${category}/) { if($tableopen==0) { printf "\n"; $tableopen=1; } $model_with_dashes = $Fmodel; $model_with_dashes =~ s/\s/-/g; $model_with_dashes =~ tr/[A-Z]/[a-z]/; my $modellinked = $model_with_dashes; $modellinked = "".$model_with_dashes."" if($db->Check_Record_Exists("products",$Fmodel)); printf "\n",$modellinked,$Fdesc,$Fprice; } } # printf "Type: $type - Category $category\n"; } if($tableopen==1) { printf "
%s%s$poundsign%.2f
\n"; $tableopen=0; } printf "$htmlfooter"; } elsif($FORM{'_RECOMMEND_TYPE_'}) { # Recommendations requested printf "

Please selection one or more categories of interest:

\n"; printf "
\n"; printf "\n",$FORM{'_RECOMMEND_TYPE_'}; foreach(split("",$FORM{'_RECOMMEND_TYPE_'})) { $type=$_; printf "

Recommendations for %s

\n",&RecommendOutput('Type.'.${type},@RecommendConfig); $categories=""; foreach(@Optics) { ($Fmanucode,$Frangcode,$Fsectcode,$Flistord,$Fmodel,$Fmanudesc,$Frangdesc,$Fsectdesc,$Fdesc,$Fmag,$Finfo,$Fprice,$Fmagtitle,$Fotherinfotitle,$Fpricetitle,$Ftype,$Fcategory,$Frecommended)=split(/${fielddelim}/,$_); if(${Ftype}=~/${type}/) { foreach(split("",$Fcategory)) { $categories.="$_" if($categories!~/$_/); } } } $output=""; foreach(split("",$categories)) { $output.=""; $output.=sprintf "%s\n",${type},${type},$_,${type},&RecommendOutput('Type.'.${type}.".Category.".$_,@RecommendConfig); $output.=sprintf "\n",${type},$_; $output.="\n"; } if(length($output)>0) { printf "
\n"; printf "$output"; printf "
\n"; } else { printf "

An error occured. No recommended categories could be read.

\n"; } } printf "

\n

"; printf "
\n"; } # elsif($FORM{'_REQUEST_METHOD_'}=~/empty|unknown/i) { else { # No selections made so far $types=""; foreach(@Optics) { ($Fmanucode,$Frangcode,$Fsectcode,$Flistord,$Fmodel,$Fmanudesc,$Frangdesc,$Fsectdesc,$Fdesc,$Fmag,$Finfo,$Fprice,$Fmagtitle,$Fotherinfotitle,$Fpricetitle,$Ftype,$Fcategory,$Frecommended)=split(/${fielddelim}/,$_); foreach(split("",$Ftype)) { $types.="$_" if($types!~/$_/); } } $output=""; foreach(split("",$types)) { $output.="\n"; $output.=sprintf "%s\n",$_,&RecommendOutput('Type.'.$_,@RecommendConfig); $output.=sprintf "\n",$_; $output.="\n"; } if(length($output)>0) { printf "

Please select the type of equipment you want recommendations on:

\n"; printf "
\n"; printf "
\n"; printf "$output"; printf "\n"; printf "
\n"; printf "
\n"; } else { printf "

An error occured. No recommended areas could be read.

\n"; } } #printf &footeraddress($RecommendDataFile); printf "\n\n"; } sub RecommendOutput { local($variable)=shift(@_); local($RecommendConfig)=@_; if($RecommendConfig{$variable}) { return $RecommendConfig{$variable}; } else { $variable=~s/^.*\.(.+)/$1/; return $variable; } } # ----------------------------------------------------------------------------- # Shopping Basket # # $BASKETidformvar="LEISURETEC_BASKET_ID"; $BASKETidcookie="LEISURETEC_BASKET_ID"; # Actions: ADD REMOVE DISPLAY sub basket { use HTML; use WebDB; use Template; # Redirect to Secure server if necessary # This won't work with POST forms, so make sure # we redirect at the beginning before forms are in use. # if($ENV{'HTTPS'} !~ /ON/i) { # my $q = $ENV{'QUERY_STRING'}; # $q = "?".$q if(length($q)>0); # Use_Secure_Server($HREFSecureprefix.$ENV{'SCRIPT_NAME'}.$q); # exit 0; # } my $cookie_expiry_time = 60*60*24*30*3; # 3months my $cookies = HTML->HTMLcookie; my $db = WebDB->new("leisuretec"); if(!defined($db)) { printf STDERR "Can't open database!\n"; my $html = Template->new; $html->compile_template_data("sorry_no_basket"); return; } my $basketid = undef; my $send_basketid = "NO"; if(defined($$cookies{'basketid'}) && $db->Check_Record_Exists("basket",$$cookies{'basketid'})) { # If there is a basketid and it still exists in our database... $basketid=$$cookies{'basketid'}; } else { # Otherwise we issue a new basketid... my $timenow = time; my $i = 0; $send_basketid = "YES"; $basketid=sprintf("%s-%s-%s",$timenow,$ENV{'REMOTE_ADDR'},$i); while($db->Check_Record_Exists("basket",$$cookies{'basketid'})) { # Increment $i until a new basket is found. if($i==1000) { $basketid=undef; my $send_basketid = "NO"; last; } $i++; $basketid=sprintf("%s-%s-%s",$timenow,$ENV{'REMOTE_ADDR'},$i); } $db->Set_Field("basket",$basketid,"BASKET_ID",$basketid); } if(!defined($basketid)) { printf STDERR "Can't allocate a new basket!\n"; my $html = Template->new; $html->compile_template_data("sorry_no_basket"); return; } if($send_basketid eq "YES") { my $expiry_time = time+$cookie_expiry_time; my $basket_cookie = sprintf("basketid=%s; expires=%s; path=/",$basketid,&StringTime($expiry_time)); $db->Set_Field("basket",$basketid,"EXPIRY_TIME",$expiry_time); HTML->CGI_Header("text/html",$basket_cookie); } else { HTML->CGI_Header("text/html"); } my %formdata = HTML->HTMLinput; my($return_link)=$formdata{'RETURN_LINK'}; my($return_desc)=$formdata{'RETURN_DESC'}; my $output; if($formdata{'ACTION'} eq "ADD") { if(length($formdata{'ITEM'})>0) { my(@itemvalues) = &Get_Item_Details($formdata{'ITEM'}); if(@itemvalues && $#itemvalues==3-1) { my($model)=$formdata{'ITEM'}; my($manu,$desc,$price)=@itemvalues; my $itemsdata = $db->Get_Field("basket",$basketid,"ITEMS"); my @items = split(/;/,$itemsdata); my $additem = "YES"; foreach(@items) { if(/^([^:]+):(\d+)$/) { my($m,$q) = ($1,$2); if($m eq $model) { $q++; $_=sprintf("%s:%d",$m,$q); $additem = "NO"; } } } push(@items,$model.":1") if($additem eq "YES"); $itemsdata = join(";",@items); $db->Set_Field("basket",$basketid,"ITEMS",$itemsdata); } } $output.=&Display_Basket($basketid,$db,$return_link,$return_desc,$formdata{'INFO_MSG'}); } elsif($formdata{'ACTION'} =~ /EMPTY BASKET/i) { $db->Set_Field("basket",$basketid,"ITEMS",""); $output.=&Display_Basket($basketid,$db,$return_link,$return_desc,$formdata{'INFO_MSG'}); } elsif($formdata{'ACTION'} =~ /(SUBMIT|PLACE) ORDER/i) { if(length($db->Get_Field("basket",$basketid,"ITEMS"))==0) { $output.=&Display_Basket($basketid,$db,$return_link,$return_desc,$formdata{'INFO_MSG'}); } elsif($formdata{'SUBACTION'} eq "PAYMENT_DETAILS") { # User has supplied payment details and verified order # Now we need to check the payment details $output.=&Process_Order($basketid,$db,\%formdata,$return_link,$return_desc); } else { $output.=&Get_Payment_Details($basketid,$db,$return_link,$return_desc); } } elsif($formdata{'ACTION'} =~ /RECALCULATE/i) { # User has changed the quantity settings, so check through # items and compare quantities, then update db basket record. &Check_Quantities($basketid,$db,\%formdata); $output.=&Display_Basket($basketid,$db,$return_link,$return_desc,$formdata{'INFO_MSG'}); } else { $output.=&Display_Basket($basketid,$db,$return_link,$return_desc,$formdata{'INFO_MSG'}); } printf $output; return; } # Redirect to Secure server if necessary sub Use_Secure_Server { my $url = shift; if($ENV{'HTTPS'} !~ /ON/i) { # Https is not currently in use, redirect to correct place. #printf "HTTP/1.0 302\n"; print "Location: ".$url."\n"; print "Content-type: text/html\n"; printf "\n"; } } sub Get_Payment_Details { my($basketid,$db,$return_link,$return_desc) = @_; my $output = ""; $output.=&Basket_Page_Header("Online Order Processing"); my $items = $db->Get_Field("basket",$basketid,"ITEMS"); $output.=sprintf("
\n",$ProgramName); $output.="\n"; $output.=sprintf("\n",$HREFbasket,&HTML::HTMLencodeURL($return_link),&HTML::HTMLencodeURL($return_desc),$return_link,$return_desc); $output.="\n"; $output.="\n"; $output.=sprintf("\n"); $output.=sprintf < HTMLEOF $output.="\n"; $output.=sprintf("\n",(length($return_link)>0 && length($return_desc)>0)?"Return to $return_desc by using the other window":""); $output.="
Please check your order items are correctly listed below.
If not, return to your Shopping Basket and add or remove items.
Alternatively you can continue browsing at your last location %s.
\n"; $output.="\n"; $output.="\n"; my $total = 0; my $count = 0; my $count_items = 0; my $item; foreach $item (split(/;/,$items)) { $item =~ /^(.*):(\d*)$/; $count++; my($model,$quantity) = ($1,$2); my @itemdata = &Get_Item_Details($model); if(@itemdata && $#itemdata==3-1) { my($manu,$desc,$price) = @itemdata; $total=$total+($price*$quantity); $count_items=$count_items+$quantity; $output.=sprintf("\n",$model,$manu,$desc,$poundsign,$price,$quantity,$poundsign,$quantity*$price); } else { $output.=sprintf("\n",$model,"This product is currently unavailable","0"); } } $output.="\n"; $output.=sprintf("\n"); #$output.=sprintf("\n",$poundsign,$total-($total/1.175)); $output.=sprintf("\n",$poundsign,$total); $output.="\n"; $output.="
ItemDescriptionUnit PriceQtyCost

%s%s
%s
%s%.2f%d%s%.2f
%s%s%d

Postage & PackagingTBA
V.A.T.%s%.2f
Total%s%.2f
Postage and packaging will be notified with order confirmation.
\n"; $output.="
\n"; $output.="
The prices listed here are for guidance only. Whilst we make every effort to keep this on-line price list up-to-date, we can not be held responsible for any changes in the pricing or products which may occur. Although we offer a method for online ordering, your order will be validated off-line. Although rather seldom, any price different between the online pricing shown here and the actual verified pricing will be notified to you. Orders which result is a price difference will need to be authorised by you before the transaction takes place. Postage & packaging will also vary based upon the items and your location.
Please complete the payment details.
Please note that we can only accept orders for delivery to the card holders address.
Card Holder Details
Full Name:
This must match the card holders name.
*
Address:
This must match the card holders address,
and will also be used for delivery.
*
Town / City:*
County / State:*
Postal Code / ZIP Code:*
Country:*
Daytime Telephone:*
Evening Telephone:
Email Address:*

Card Type: *
Card Number:*
Card Expiry Date:*
Issue Number:
If Applicable
Issue Date:
If Applicable
Security Code: Last three digits found on the signature strip of your card.

Comments:
* denotes the compulsory fields
Please verify that your above order and payment details are correct, then hit the submit order button below.
\n"; $output.="\n"; $output.="\n"; $output.="\n"; $output.="
\n"; $output.=&Basket_Page_Footer; return $output; } sub Process_Order { my($basketid,$db,$formdata,$return_link,$return_desc) = @_; my $output = ""; $output.=&Basket_Page_Header("Online Order Submission"); $valid = "YES"; # Check for the required fields my $field; foreach $field ("CUSTOMER_NAME","ADDRESS_1","TOWN","COUNTY","POSTCODE","COUNTRY","EMAIL","CARD_NUMBER","CARD_EXPIRY_DATE") { $valid = "NO" if(length($$formdata{$field})==0); } if(length($$formdata{"TELEPHONE_DAYTIME"})==0 && length($$formdata{"TELEPHONE_EVENING"})==0) { $valid="NO"; } if(length($$formdata{"CARD_TYPE"})==0 || $$formdata{"CARD_TYPE"} =~ /^\*\*/) { $valid="NO"; } if($valid eq "YES") { $output.=&Store_Order($basketid,$db,$formdata); } else { $output.="

There were items missing which are required to complete your order. Please use the back button on your browser and complete the contact and card details.

\n"; } $output.=&Basket_Page_Footer; return $output; } sub Store_Order { my($basketid,$db,$formdata) = @_; my $items = $db->Get_Field("basket",$basketid,"ITEMS"); my %data; #foreach my $field ("CUSTOMER_NAME","ADDRESS_1","ADDRESS_2","TOWN","COUNTY","POSTCODE","COUNTRY","TELEPHONE_DAYTIME","TELEPHONE_EVENING","EMAIL","CARD_TYPE","CARD_NUMBER","CARD_EXPIRY_DATE","CARD_ISSUE_NUMBER","CARD_ISSUE_DATE") { # $data{$field} = $$formdata{$field}; #} my @item_array = split(/;/,$items); my $item; foreach $item (@item_array) { $item =~ /^(.*):(\d*)$/; my($model,$quantity) = ($1,$2); my @itemdata = &Get_Item_Details($model); my($manu,$desc,$price); if(@itemdata && $#itemdata==3-1) { ($manu,$desc,$price) = @itemdata; } $item = join(":",$model,$quantity,$manu,$desc,$price); } my $stored_okay = "YES"; my %order_data; #$stored_okay = "NO" if($db->Set_Field("orders",$basketid,"BASKET_ID",$basketid)!=0); #$stored_okay = "NO" if($db->Set_Field("orders",$basketid,"ITEMS",join(";",@item_array))!=0); $order_data{"BASKET_ID"}=$basketid; $order_data{"ITEMS"}=join(";",@item_array); my $field; foreach $field ("CUSTOMER_NAME","ADDRESS_1","ADDRESS_2","TOWN","COUNTY","POSTCODE","COUNTRY","TELEPHONE_DAYTIME","TELEPHONE_EVENING","EMAIL","CARD_TYPE","CARD_NUMBER","CARD_EXPIRY_DATE","CARD_ISSUE_NUMBER","CARD_ISSUE_DATE","CARD_SECURITY_CODE","COMMENTS") { #$stored_okay = "NO" if($db->Set_Field("orders",$basketid,$field,$$formdata{$field})!=0); $order_data{$field}=$$formdata{$field}; } my $order_ref = $basketid; $order_ref =~ s/\.//g; #$db->Set_Field("orders",$basketid,"ORDER_REF",$order_ref); $order_data{"ORDER_REF"}=$order_ref; $stored_okay="NO" if($db->Store_Record("orders",$basketid,\%order_data) == 1); # Now that we've stored the order, remove the basket ID #$db->Set_Field("basket",$basketid,"REMOVE_RECORD_AFTER",time); $db->Delete_Record("basket",$basketid) if($stored_okay eq "YES"); my $output = ""; $output.="Thank you for your order. You will receive a confirmation of the order and an order number shortly.

In the mean time, if you need to contact us regarding this order, please quote the order reference number '".$order_ref."' in all correspondence.\n

Thank you for using our on-line ordering system.

Return to the OBM Home Page by closing this window and using your original window to continue browsing.




"; return $output; } sub Check_Quantities { my $basketid = shift; my $db = shift; my $formdata = shift; my $items = $db->Get_Field("basket",$basketid,"ITEMS"); my %item_quantity; my @item_number; my $i = 0; my $item; foreach $item (split(/;/,$items)) { $i++; $item =~ /^(.*):(\d*)$/; $item_number[$i] = $1; $item_quantity{$1} = $2; } my $update_db = "NO"; my $name; foreach $name (keys %{$formdata}) { if($name =~ /^ITEM_(\d+)_QUANTITY$/) { my $number = $1; # If non-numerical data is found then leave as is next if($$formdata{$name}!~/^\d+$/); if($$formdata{$name} ne $item_quantity{$item_number[$number]}) { # Item quantities differ, so update... $item_quantity{$item_number[$number]}=$$formdata{$name}; #printf STDERR "Checking Quantity: $number $name $$formdata{$name}\n"; $update_db = "YES"; } } } if($update_db eq "YES") { my @it; for(my $i=1; $i<=$#item_number; $i++) { #printf STDERR "Checking $i %s=%s\n",$item_number[$i],$item_quantity{$item_number[$i]}; if($item_quantity{$item_number[$i]}>0) { push(@it,$item_number[$i].":".$item_quantity{$item_number[$i]}); } } #printf STDERR "Setting DB: %s\n",join(";",@it); $db->Set_Field("basket",$basketid,"ITEMS",join(";",@it)); } } sub Display_Basket { my($basketid,$db,$return_link,$return_desc,$info_msg) = @_; if(!defined($basketid)) { printf STDERR "No basketid passed to Display_Basket!\n"; my $html = Template->new; $html->compile_template_data("sorry_no_basket"); return; } if(!defined($db)) { printf STDERR "No database object passed to Display_Basket!\n"; my $html = Template->new; $html->compile_template_data("sorry_no_basket"); return; } if(!defined($return_link)) { $return_link = "/catalog/"; $return_desc = "Binoculars & Telescopes Catalogue"; } my $output ; $output.=&Basket_Page_Header("Shopping Basket",$info_msg); my $items = $db->Get_Field("basket",$basketid,"ITEMS"); $output.=sprintf("
\n",$ProgramName); $output.="\n"; $output.="\n"; $output.="\n"; $output.="\n"; $output.="\n"; my $total = 0; my $count = 0; my $item; foreach $item (split(/;/,$items)) { $item =~ /^(.*):(\d*)$/; $count++; my($model,$quantity) = ($1,$2); my @itemdata = &Get_Item_Details($model); if(@itemdata && $#itemdata==3-1) { my($manu,$desc,$price) = @itemdata; $total=$total+($price*$quantity); $output.=sprintf("\n",$model,$manu,$desc,$poundsign,$price,$count,$quantity,$poundsign,$quantity*$price); } else { $output.=sprintf("\n",$model,"This product is currently unavailable",$count,"0"); } } $output.="\n"; $output.=sprintf("\n"); #$output.=sprintf("\n",$poundsign,$total-($total/1.175)); $output.=sprintf("\n",$poundsign,$total); #$output.=sprintf("\n",$poundsign,$total); $output.=sprintf("\n",(length($return_link)>0 && length($return_desc)>0)?"Return to $return_desc by using the other window":""); $output.=sprintf("\n",$VAT); $output.="
This is a secure page -- If you would prefer, you may order directly with us by telephone.
You can check the page security by looking for the padlock symbol at the bottom of this window, or right-click and select Properties/View Page Info.
A separate window (this window) has been opened in addition to the OBM site to allow you to access your basket securely. This provides a view into your secure basket whilst still offering you responsive browsing (in the other window) of our range of products. You may switch between the windows as you wish and you can close this window if you no longer wish to see it at this time. Your basket contents will be maintained and will be available next time you add to or view your secure basket.
ItemDescriptionUnit PriceQuantityCost

%s%s
%s
%s%.2f%s%.2f
%s%s

Modify your quantity required and then select 'Recalculate'.
Specify a quantity of 0 to remove an item from your basket.
Postage & PackagingTBA
Modify your quantity required and then select 'Recalculate'.
Specify a quantity of 0 to remove an item from your basket.
V.A.T.%s%.2f
Total%s%.2f
Total%s%.2f
%s
Prices include UK V.A.T which can be deducted for residence outside the UK and EU countries. This is currently set at %.2f\%
\n"; $output.="\n"; $output.="\n"; $output.="
\n"; $output.=&Basket_Page_Footer; } sub Get_Item_Details { my $model = shift; %Optics=&ReadDatabase($BasketItemsDataFile); if(defined(@Optics)) { my @results = grep(/^$model$fielddelim/,@Optics); if($#results==-1) { # Nothing was returned, relax to case-insensitive search @results = grep(/^$model$fielddelim/i,@Optics); } if($#results==0) { my($item_model,$item_manu,$item_desc,$item_price) = split(/$fielddelim/,$results[0]); $item_price =~ s/[^\d\.]//; return($item_manu,$item_desc,$item_price); } else { return undef; } } else { return undef; } } sub Basket_Page_Footer { return <

Please note that all models may change without notification.
Every effort is made to ensure that the details listed here are as up-to-date as possible, however, we can not be held responsible for any changes which may occur or be held responsible for any loss or damage incurred as a result of accessing or using this site. All pricing and models on this website are provided as a guide. Availability and pricing will be confirmed upon order placement. By accessing this site, you agree to these terms and conditions and understand that all information on this web site is provided as guidance only. We can not provide goods on a sales and return basis.
Please telephone for up-to-date information and details.

Sales / sales\@obm.co.uk
HTML } sub Basket_Page_Header { my $title = shift; my $info = shift; my $infostr = ""; if(length($info)>0) { $infostr .= "\n"; $infostr .= "\n"; $infostr .= "
${info}
\n"; } return < Leisuretec - $title
Leisuretec PO Box 68 - Benfleet - SS7 2YX - England - +44 1702 551863

$title
$infostr HTML } sub StringTime { my $expirestime = shift; my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($expirestime); my $stringtime = sprintf("%s, %.d-%.3s-%.4d %.2d:%.2d:%.2d GMT",$HTML::daysfull[$wday+1],$mday,$HTML::months[$mon+1],$year+1900,$hour,$min,$sec); #printf "Retrieved cookies: %s
\n",join(" ",keys(%{HTML->HTMLcookie})); return $stringtime;; }