From 31da55ea2d1f121a08dff692841082472e8319f8 Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Mon, 21 Apr 2008 16:22:33 -0500 Subject: [PATCH] Baker and Taylor OPAC integration, plus some logic for Tags Signed-off-by: Joshua Ferraro --- .../prog/en/modules/opac-detail.tmpl | 43 ++++++++++++- .../prog/en/modules/opac-results.tmpl | 34 ++++++++-- opac/opac-detail.pl | 63 ++++++++++++++++-- opac/opac-search.pl | 64 +++++++++++++++++-- 4 files changed, 184 insertions(+), 20 deletions(-) diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl index 744dccc09c..e1ea077025 100755 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl @@ -28,13 +28,23 @@
-
@@ -481,6 +492,34 @@ " />
+ +
Tags: + + + + +
" method="post" action="/cgi-bin/koha/opac-tags.pl"> + + " id="newtag" maxlength="100" /> + +
+
+ " class="tagstatus" style="display:none;"> + Tag status here. + + +
+ + + +
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl index 6b99247f80..5910988e74 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl @@ -192,7 +192,18 @@ $(document).ready(function(){ " title="" /> - + + "> + See Baker & Taylor" /> + + + (No clean ISBN.) + + + " title="" /> + + + @@ -240,20 +251,31 @@ $(document).ready(function(){

">Place Hold " name="biblionumber" value="" title="Click to add to cart" />

- - + + +
Tags: -
  • + - - Add new tag + +
    " method="post" action="/cgi-bin/koha/opac-tags.pl"> + + " id="newtag" maxlength="100" /> + +
    +
    + " class="tagstatus" style="display:none;"> + Tag status here. + +
+ diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index e9394e901d..91aa87d9d8 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -28,6 +28,7 @@ use C4::Serials; #uses getsubscriptionfrom biblionumber use C4::Output; use C4::Biblio; use C4::Items; +use C4::Tags qw(get_tags); use C4::Dates qw/format_date/; use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn get_biblio_from_xisbn); use C4::Amazon; @@ -36,6 +37,13 @@ use C4::Serials; use C4::Members; use C4::XSLT; +BEGIN { + if (C4::Context->preference('BakerTaylorEnabled')) { + require C4::External::BakerTaylor; + import C4::External::BakerTaylor qw(&image_url &link_url); + } +} + my $query = new CGI; my ( $template, $borrowernumber, $cookie ) = get_template_and_user( { @@ -137,11 +145,11 @@ for my $itm (@items) { my $dbh = C4::Context->dbh; my $marcflavour = C4::Context->preference("marcflavour"); my $record = GetMarcBiblio($biblionumber); - my $marcnotesarray = GetMarcNotes( $record, $marcflavour ); - my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); - my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); - my $marcseriesarray = GetMarcSeries($record,$marcflavour); - my $marcurlsarray = GetMarcUrls($record,$marcflavour); + my $marcnotesarray = GetMarcNotes ($record,$marcflavour); + my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour); + my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour); + my $marcseriesarray = GetMarcSeries ($record,$marcflavour); + my $marcurlsarray = GetMarcUrls ($record,$marcflavour); $template->param( MARCNOTES => $marcnotesarray, @@ -202,7 +210,19 @@ $template->param( # XISBN Stuff my $xisbn=$dat->{'isbn'}; $xisbn =~ /(\d*[X]*)/; -$template->param(amazonisbn => $1); +$template->param(amazonisbn => $1); # FIXME: so it is OK if the ISBN = 'XXXXX' ? +my ($clean, $amazonisbn); +$amazonisbn = $1; +# these might be overkill, but they are better than the regexp above. +if ( + $amazonisbn =~ /\b(\d{13})\b/ or + $amazonisbn =~ /\b(\d{10})\b/ or + $amazonisbn =~ /\b(\d{9}X)\b/i +) { + $clean = $1; + $template->param(clean_isbn => $1); +} + if (C4::Context->preference("OPACFRBRizeEditions")==1) { eval { $template->param( @@ -302,4 +322,35 @@ $template->param( ); } +if (C4::Context->preference("BakerTaylorEnabled")) { + $template->param( + BakerTaylorEnabled => 1, + BakerTaylorImageURL => &image_url(), + BakerTaylorLinkURL => &link_url(), + BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'), + ); + my ($bt_user, $bt_pass); + if ($clean and + $bt_user = C4::Context->preference('BakerTaylorUsername') and + $bt_pass = C4::Context->preference('BakerTaylorPassword') ) + { + $template->param( + BakerTaylorContentURL => + sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y", + $bt_user,$bt_pass,$clean) + ); + } +} + +my $tag_quantity; +if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) { + $template->param( + TagsEnabled => 1, + TagsShowOnDetail => $tag_quantity, + TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail') + ); + $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, + 'sort'=>'-weight', limit=>$tag_quantity})); +} + output_html_with_http_headers $query, $cookie, $template->output; diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 40dcb4724b..8e4fc55c32 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -11,7 +11,9 @@ use C4::Context; use C4::Output; use C4::Auth; use C4::Search; +use C4::Biblio; # GetBiblioData use C4::Koha; +use C4::Tags qw(get_tags); use POSIX qw(ceil floor); use C4::Branch; # GetBranches @@ -20,6 +22,13 @@ use C4::Branch; # GetBranches use CGI qw('-no_undef_params'); my $cgi = new CGI; +BEGIN { + if (C4::Context->preference('BakerTaylorEnabled')) { + require C4::External::BakerTaylor; + import C4::External::BakerTaylor qw(&image_url &link_url); + } +} + my ($template,$borrowernumber,$cookie); # decide which template to use @@ -50,8 +59,19 @@ if (C4::Context->preference("marcflavour") eq "UNIMARC" ) { $template->param('UNIMARC' => 1); } -foreach (qw(TaggingOnList TaggingOnDetail)) { - C4::Context->preference($_) and $template->param($_ => 1); +if (C4::Context->preference('BakerTaylorEnabled')) { + $template->param( + BakerTaylorEnabled => 1, + BakerTaylorImageURL => &image_url(), + BakerTaylorLinkURL => &link_url(), + BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'), + ); +} +if (C4::Context->preference('TagsEnabled')) { + $template->param(TagsEnabled => 1); + foreach (qw(TagsShowOnList TagsInputOnList)) { + C4::Context->preference($_) and $template->param($_ => 1); + } } ## URI Re-Writing @@ -178,6 +198,8 @@ if ( $template_type eq 'advsearch' ) { # * we can edit the values by changing the key # * multivalued CGI paramaters are returned as a packaged string separated by "\0" (null) my $params = $cgi->Vars; +my $tag; +$tag = $params->{tag} if $params->{tag}; # Params that can have more than one value # sort by is used to sort the query @@ -277,9 +299,7 @@ sub _input_cgi_parse ($) { for my $this_cgi ( split('&',shift) ) { next unless $this_cgi; $this_cgi =~ /(.*)=(.*)/; - my $input_name = $1; - my $input_value = $2; - push @elements, { input_name => $input_name, input_value => $input_value }; + push @elements, { input_name => $1, input_value => $2 }; } return @elements; } @@ -310,7 +330,17 @@ my $facets; # this object stores the faceted results that display on the left-ha my @results_array; my $results_hashref; -if (C4::Context->preference('NoZebra')) { +if ($tag) { + my $taglist = get_tags({term=>$tag}); + $results_hashref->{biblioserver}->{hits} = scalar (@$taglist); + my @biblist = (map {GetBiblioData($_->{biblionumber})} @$taglist); + my @marclist = (map {$_->{marc}} @biblist ); + $DEBUG and printf STDERR "taglist (%s biblionumber)\nmarclist (%s records)\n", scalar(@$taglist), scalar(@marclist); + $results_hashref->{biblioserver}->{RECORDS} = \@marclist; + # FIXME: tag search and standard search should work together, not exclusively + # FIXME: No facets for tags search. +} +elsif (C4::Context->preference('NoZebra')) { eval { ($error, $results_hashref, $facets) = NZgetRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan); }; @@ -323,6 +353,8 @@ if (C4::Context->preference('NoZebra')) { ($error, $results_hashref, $facets) = getRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan); }; } +use Data::Dumper; +print STDERR "-" x 25, "\n", Dumper($results_hashref); if ($@ || $error) { $template->param(query_error => $error.$@); output_html_with_http_headers $cgi, $cookie, $template->output; @@ -350,6 +382,26 @@ for (my $i=0;$i<=@servers;$i++) { } else { @newresults = searchResults( $query_desc,$hits,$results_per_page,$offset,@{$results_hashref->{$server}->{"RECORDS"}}); } + my $tag_quantity; + if (C4::Context->preference('TagsEnabled') and + $tag_quantity = C4::Context->preference('TagsShowOnList')) { + foreach (@newresults) { + my $bibnum = $_->{biblionumber} or next; + $_ ->{'TagLoop'} = get_tags({biblionumber=>$bibnum, 'sort'=>'-weight', + limit=>$tag_quantity }); + } + } + foreach (@newresults) { + my $clean = $_->{isbn} or next; + unless ( + $clean =~ /\b(\d{13})\b/ or + $clean =~ /\b(\d{10})\b/ or + $clean =~ /\b(\d{9}X)\b/i + ) { + next; + } + $_ ->{'clean_isbn'} = $1; + } $total = $total + $results_hashref->{$server}->{"hits"}; ## If there's just one result, redirect to the detail page if ($total == 1) { -- 2.39.5