Baker and Taylor OPAC integration, plus some logic for Tags

Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
Joe Atzberger 2008-04-21 16:22:33 -05:00 committed by Joshua Ferraro
parent caa8afd2cc
commit 31da55ea2d
4 changed files with 184 additions and 20 deletions

View File

@ -28,13 +28,23 @@
<div id="catalogue_detail_biblio">
<!-- TMPL_IF NAME="AmazonContent" -->
<div id="bookcover"> <!-- TMPL_IF NAME="isbn" -->
<div id="bookcover"><!-- TMPL_IF NAME="isbn" -->
<a href="http://www.amazon.com/gp/reader/<!-- TMPL_VAR NAME="amazonisbn" -->/ref=sib_dp_pt/002-7879865-0184864#reader-link">
<img border="0" src="http://images.amazon.com/images/P/<!-- TMPL_VAR NAME="amazonisbn" -->.01._PIdp-schmooS,TopRight,7,-26_SCMZZZZZZZ_.jpg" alt="Cover Image" />
</a><!-- TMPL_ELSE -->
<img border="0" src="http://g-images.amazon.com/images/G/01/x-site/icons/no-img-sm.gif" alt="Cover Image" />
<!-- /TMPL_IF --></div>
<!-- /TMPL_IF -->
<!-- TMPL_ELSE -->
<!-- TMPL_IF NAME="BakerTaylorEnabled" -->
<div id="bookcover">
<!-- TMPL_IF NAME="isbn" -->
<a href="https://<!-- TMPL_VAR name="BakerTaylorBookstoreURL" ESCAPE="HTML" --><!-- TMPL_VAR name="clean_isbn" -->">
<img alt="See Baker &amp; Taylor" src="<!-- TMPL_VAR name="BakerTaylorImageURL" ESCAPE="HTML" --><!-- TMPL_VAR name="clean_isbn" -->" />
</a>
<!-- TMPL_ELSE -->
<!-- /TMPL_IF --></div>
<!-- /TMPL_IF -->
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="XSLTDetailsDisplay" -->
<!-- TMPL_VAR NAME="XSLTBloc" -->
<!-- TMPL_ELSE -->
@ -154,6 +164,7 @@
<!-- /TMPL_LOOP --></ul>
<!-- /TMPL_IF -->
<!-- /TMPL_IF -->
</div>
<div id="bibliodescriptions" class="toptabs">
@ -481,6 +492,34 @@
<option value="utf8">MARC (Unicode/UTF-8)</option> </select><input type="hidden" name="op" value="export" /><input type="hidden" name="bib" value="<!-- TMPL_VAR NAME="biblionumber" -->" />
<input type="submit" name="save" value="Go" /></form></div>
<!-- TMPL_IF NAME="TagsShowOnDetail" -->
<div class="detailtagcell"><span class="tagtitle">Tags:</span>
<!-- TMPL_IF NAME="TagLoop" -->
<ul><!-- TMPL_LOOP NAME="TagLoop" -->
<li><a href="/cgi-bin/koha/opac-search.pl?tag=<!-- TMPL_VAR NAME="term" ESCAPE="URL" -->&amp;q=<!-- TMPL_VAR NAME="term" ESCAPE="URL" -->"><!-- TMPL_VAR NAME="term" ESCAPE="HTML" --></a> <span class="weight">(<!-- TMPL_VAR NAME="weight_total" -->)</span></li>
<!-- /TMPL_LOOP -->
</ul>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="TagsInputOnDetail" -->
<form name="tagform<!-- TMPL_VAR NAME="biblionumber" -->" method="post" action="/cgi-bin/koha/opac-tags.pl">
<label for="newtag<!-- TMPL_VAR NAME="biblionumber" -->">New tag:</label>
<input name="newtag<!-- TMPL_VAR NAME="biblionumber" -->" id="newtag<!-- TMPL_VAR NAME="biblionumber" -->" maxlength="100" />
<input name="tagbutton" class="tagbutton" type="submit" value="Add" />
</form>
<br />
<span id="tagstatus<!-- TMPL_VAR NAME="biblionumber" -->" class="tagstatus" style="display:none;">
Tag status here.
</span>
<!-- /TMPL_IF -->
</div>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="BakerTaylorContentURL" -->
<div id="bakertaylor" class="detailtagcell">
<a href="<!-- TMPL_VAR NAME="BakerTaylorContentURL" ESCAPE="HTML" -->">
More info from B&amp;T
</a>
</div>
<!-- /TMPL_IF -->
</div>
</div>

View File

@ -192,7 +192,18 @@ $(document).ready(function(){
<!-- TMPL_IF name="imageurl" -->
<img src="<!-- TMPL_VAR name="imageurl" -->" title="<!-- TMPL_VAR name="description" -->" />
<!-- TMPL_ELSE -->
<!-- TMPL_VAR name="description" -->
<!-- TMPL_IF NAME="BakerTaylorEnabled" -->
<!-- TMPL_IF NAME="clean_isbn" --><a href="https://<!-- TMPL_VAR name="BakerTaylorBookstoreURL" ESCAPE="HTML" --><!-- TMPL_VAR name="clean_isbn" -->">
<img alt="See Baker &amp; Taylor" src="<!-- TMPL_VAR name="BakerTaylorImageURL" ESCAPE="HTML" --><!-- TMPL_VAR name="clean_isbn" -->" />
</a>
<!-- TMPL_ELSE -->
(No clean ISBN.)
<!-- /TMPL_IF -->
<!-- TMPL_ELSE -->
<!-- TMPL_IF name="imageurl" --><img src="<!-- TMPL_VAR name="imageurl" -->" title="<!-- TMPL_VAR name="description" -->" />
<!-- TMPL_ELSE --><!-- TMPL_VAR name="description" -->
<!-- /TMPL_IF -->
<!-- /TMPL_IF -->
<!-- /TMPL_IF -->
<!-- /TMPL_UNLESS -->
</td>
@ -240,20 +251,31 @@ $(document).ready(function(){
<p><!-- TMPL_IF name="RequestOnOpac" --><!-- TMPL_UNLESS NAME="norequests" --><!-- TMPL_IF NAME="opacuserlogin" --><a class="reserve" href="/cgi-bin/koha/opac-reserve.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->">Place Hold</a><!-- /TMPL_IF --><!-- /TMPL_UNLESS --> <!-- /TMPL_IF -->
<!--TMPL_IF EXPR="opacbookbag || virtualshelves" --><input type="checkbox" id="bib<!-- TMPL_VAR NAME="biblionumber" -->" name="biblionumber" value="<!-- TMPL_VAR NAME="biblionumber" -->" title="Click to add to cart" /> <label for="bib<!-- TMPL_VAR NAME="biblionumber" -->"><!-- /TMPL_IF --><!--TMPL_IF EXPR="opacbookbag || virtualshelves" --></label><!-- /TMPL_IF --> </p>
</td>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="TaggingOnList" -->
<!-- /TMPL_IF --> <!-- this is possibly an extra from merge -->
<!-- TMPL_IF NAME="TagsEnabled" -->
<!-- TMPL_IF NAME="TagsShowOnList" -->
<td><div class="tagcell">
<!-- TMPL_IF NAME="TagLoop" -->
<span class="tagtitle">Tags:</span>
<ul><!-- TMPL_LOOP NAME="TagLoop" --><li><!-- TMPL_VAR NAME="tag" --></li>
<ul><!-- TMPL_LOOP NAME="TagLoop" --><li><a href="/cgi-bin/koha/opac-search.pl?tag=<!-- TMPL_VAR NAME="term" ESCAPE="URL" -->&amp;q=<!-- TMPL_VAR NAME="term" ESCAPE="URL" -->"><!-- TMPL_VAR NAME="term" --></a> <span class="weight">(<!-- TMPL_VAR NAME="weight_total" -->)</span></li>
<!-- /TMPL_LOOP -->
</ul>
<!-- TMPL_ELSE -->
<!-- /TMPL_IF -->
<a href="#">Add new tag</a>
<!-- TMPL_IF NAME="TagsInputOnList" -->
<form name="tagform<!-- TMPL_VAR NAME="biblionumber" -->" method="post" action="/cgi-bin/koha/opac-tags.pl">
<label for="newtag<!-- TMPL_VAR NAME="biblionumber" -->">New tag:</label>
<input name="newtag<!-- TMPL_VAR NAME="biblionumber" -->" id="newtag<!-- TMPL_VAR NAME="biblionumber" -->" maxlength="100" />
<input name="tagbutton" class="tagbutton" type="submit" value="Add" />
</form>
<br />
<span id="tagstatus<!-- TMPL_VAR NAME="biblionumber" -->" class="tagstatus" style="display:none;">
Tag status here.
</span>
<!-- /TMPL_IF -->
</div>
</td>
<!-- /TMPL_IF -->
<!-- /TMPL_IF -->
</tr>
<!-- /TMPL_LOOP -->
</table>

View File

@ -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;

View File

@ -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) {