View | Details | Raw Unified | Return to bug 5551
Collapse All | Expand All

(-)a/C4/ShelfBrowser.pm (+235 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
package C4::ShelfBrowser;
4
5
# Copyright 2010 Catalyst IT
6
#
7
# This file is part of Koha.
8
#
9
# Koha is free software; you can redistribute it and/or modify it under the
10
# terms of the GNU General Public License as published by the Free Software
11
# Foundation; either version 2 of the License, or (at your option) any later
12
# version.
13
#
14
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License along
19
# with Koha; if not, write to the Free Software Foundation, Inc.,
20
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22
use strict;
23
use warnings;
24
25
use C4::Biblio;
26
use C4::Branch;
27
use C4::Context;
28
use C4::Koha;
29
30
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
31
32
BEGIN {
33
	$VERSION = 3.02;
34
	require Exporter;
35
	@ISA    = qw(Exporter);
36
	@EXPORT = qw(
37
	    &GetNearbyItems
38
    );
39
    @EXPORT_OK = qw(
40
    );
41
}
42
43
=head1 NAME
44
45
C4::ShelfBrowser - functions that deal with the shelf browser feature found in
46
the OPAC.
47
48
=head1 SYNOPSIS
49
50
  use C4::ShelfBrowser;
51
52
=head1 DESCRIPTION
53
54
This module provides functions to get items nearby to another item, for use
55
in the shelf browser function.
56
57
'Nearby' is controlled by a handful of system preferences that specify what
58
to take into account.
59
60
=head1 FUNCTIONS
61
62
=head2 GetNearbyItems($itemnumber, [$num_each_side])
63
64
  $nearby = GetNearbyItems($itemnumber, [$num_each_side]);
65
66
  @next = @{ $nearby->{next} };
67
  @prev = @{ $nearby->{prev} };
68
69
  foreach (@next) {
70
      # These won't format well like this, but here are the fields
71
  	  print $_->{title};
72
  	  print $_->{biblionumber};
73
  	  print $_->{itemnumber};
74
  	  print $_->{browser_normalized_upc};
75
  	  print $_->{browser_normalized_oclc};
76
  	  print $_->{browser_normalized_isbn};
77
  }
78
79
  # This is the information required to scroll the browser to the next left
80
  # or right set. Can be derived from next/prev, but it's here for convenience.
81
  print $nearby->{prev_itemnumber};
82
  print $nearby->{next_itemnumber};
83
  print $nearby->{prev_biblionumber};
84
  print $nearby->{next_biblionumber};
85
86
  # These will be undef if the values are not used to calculate the 
87
  # nearby items.
88
  print $nearby->{starting_homebranch}->{code};
89
  print $nearby->{starting_homebranch}->{description};
90
  print $nearby->{starting_location}->{code};
91
  print $nearby->{starting_location}->{description};
92
  print $nearby->{starting_ccode}->{code};
93
  print $nearby->{starting_ccode}->{description};
94
95
  print $nearby->{starting_itemnumber};
96
  
97
This finds the items that are nearby to the supplied item, and supplies
98
those previous and next, along with the other useful information for displaying
99
the shelf browser.
100
101
It automatically applies the following user preferences to work out how to
102
calculate things: C<ShelfBrowserUsesLocation>, C<ShelfBrowserUsesHomeBranch>, 
103
C<ShelfBrowserUsesCcode>.
104
105
The option C<$num_each_side> value determines how many items will be fetched
106
each side of the supplied item. Note that the item itself is the first entry
107
in the 'next' set, and counts towards this limit (this is to keep the
108
behaviour consistant with the code that this is a refactor of.) Default is
109
3.
110
111
This will throw an exception if something went wrong.
112
113
=cut
114
115
sub GetNearbyItems {
116
	my ($itemnumber, $num_each_side) = @_;
117
	$num_each_side ||= 3;
118
119
    my $dbh         = C4::Context->dbh;
120
    my $marcflavour = C4::Context->preference("marcflavour");
121
    my $branches = GetBranches();
122
123
    my $sth_get_item_details = $dbh->prepare("SELECT cn_sort,homebranch,location,ccode from items where itemnumber=?");
124
    $sth_get_item_details->execute($itemnumber);
125
    my $item_details_result = $sth_get_item_details->fetchrow_hashref();
126
    die "Unable to find item '$itemnumber' for shelf browser" if (!$sth_get_item_details);
127
    my $start_cn_sort = $item_details_result->{'cn_sort'};
128
129
    my ($start_homebranch, $start_location, $start_ccode);
130
    if (C4::Context->preference('ShelfBrowserUsesHomeBranch') && 
131
    	defined($item_details_result->{'homebranch'})) {
132
        $start_homebranch->{code} = $item_details_result->{'homebranch'};
133
        $start_homebranch->{description} = $branches->{$item_details_result->{'homebranch'}}{branchname};
134
    }
135
    if (C4::Context->preference('ShelfBrowserUsesLocation') && 
136
    	defined($item_details_result->{'location'})) {
137
        $start_location->{code} = $item_details_result->{'location'};
138
        $start_location->{description} = GetAuthorisedValueDesc('','',$item_details_result->{'location'},'','','LOC','opac');
139
    }
140
    if (C4::Context->preference('ShelfBrowserUsesCcode') && 
141
    	defined($item_details_result->{'ccode'})) {
142
        $start_ccode->{code} = $item_details_result->{'ccode'};
143
        $start_ccode->{description} = GetAuthorisedValueDesc('', '', $item_details_result->{'ccode'}, '', '', 'CCODE', 'opac');
144
    }
145
146
    # Build the query for previous and next items
147
    my $prev_query ='
148
        SELECT *
149
        FROM items
150
        WHERE
151
            ((cn_sort = ? AND itemnumber < ?) OR cn_sort < ?) ';
152
    my $next_query ='
153
        SELECT *
154
        FROM items
155
        WHERE
156
            ((cn_sort = ? AND itemnumber >= ?) OR cn_sort > ?) ';
157
    my @params;
158
    my $query_cond;
159
    push @params, ($start_cn_sort, $itemnumber, $start_cn_sort);
160
    if ($start_homebranch) {
161
    	$query_cond .= 'AND homebranch = ? ';
162
    	push @params, $start_homebranch->{code};
163
    }
164
    if ($start_location) {
165
    	$query_cond .= 'AND location = ? ';
166
    	push @params, $start_location->{code};
167
    }
168
    if ($start_ccode) {
169
    	$query_cond .= 'AND ccode = ? ';
170
    	push @params, $start_ccode->{code};
171
    }
172
173
    my $sth_prev_items = $dbh->prepare($prev_query . $query_cond . ' ORDER BY cn_sort DESC, itemnumber LIMIT ?');
174
    my $sth_next_items = $dbh->prepare($next_query . $query_cond . ' ORDER BY cn_sort, itemnumber LIMIT ?');
175
    push @params, $num_each_side;
176
    $sth_prev_items->execute(@params);
177
    $sth_next_items->execute(@params);
178
    
179
    # Now we have the query run, suck out the data like marrow
180
    my @prev_items = reverse GetShelfInfo($sth_prev_items, $marcflavour);
181
    my @next_items = GetShelfInfo($sth_next_items, $marcflavour);
182
183
    my $next_itemnumber = $next_items[-1]->{itemnumber} if @next_items;
184
    my $next_biblionumber = $next_items[-1]->{biblionumber} if @next_items;
185
186
    my $prev_itemnumber = $prev_items[0]->{itemnumber} if @prev_items;
187
    my $prev_biblionumber = $prev_items[0]->{biblionumber} if @prev_items;
188
189
    my %result = (
190
        next                => \@next_items,
191
        prev                => \@prev_items,
192
        next_itemnumber     => $next_itemnumber,
193
        next_biblionumber   => $next_biblionumber,
194
        prev_itemnumber     => $prev_itemnumber,
195
        prev_biblionumber   => $prev_biblionumber,   
196
        starting_itemnumber => $itemnumber,
197
    );
198
    $result{starting_homebranch} = $start_homebranch if $start_homebranch;
199
    $result{starting_location}   = $start_location   if $start_location;
200
    $result{starting_ccode}         = $start_ccode      if $start_ccode;
201
    return \%result;
202
}
203
204
# This runs through a statement handle and pulls out all the items in it, fills
205
# them up with additional info that shelves want, and returns those as a list.
206
# Not really intended to be exported.
207
sub GetShelfInfo {
208
    my ($sth, $marcflavour) = @_;
209
210
    my @items;
211
    while (my $this_item = $sth->fetchrow_hashref()) {
212
        my $this_biblio = GetBibData($this_item->{biblionumber});
213
        next if (!defined($this_biblio));
214
        $this_item->{'title'} = $this_biblio->{'title'};
215
        my $this_record = GetMarcBiblio($this_biblio->{'biblionumber'});
216
        $this_item->{'browser_normalized_upc'} = GetNormalizedUPC($this_record,$marcflavour);
217
        $this_item->{'browser_normalized_oclc'} = GetNormalizedOCLCNumber($this_record,$marcflavour);
218
        $this_item->{'browser_normalized_isbn'} = GetNormalizedISBN(undef,$this_record,$marcflavour);
219
        push @items, $this_item;
220
    }
221
    return @items;
222
}
223
224
# Fetches some basic biblio data needed by the shelf stuff
225
sub GetBibData {
226
	my ($bibnum) = @_;
227
228
    my $dbh         = C4::Context->dbh;
229
    my $sth = $dbh->prepare("SELECT biblionumber, title FROM biblio WHERE biblionumber=?");
230
    $sth->execute($bibnum);
231
    my $bib = $sth->fetchrow_hashref();
232
    return $bib;
233
}
234
235
1;
(-)a/installer/data/mysql/en/mandatory/sysprefs.sql (+3 lines)
Lines 279-281 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES Link Here
279
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ILS-DI:AuthorizedIPs','','.','Restricts usage of ILS-DI to some IPs','Free');
279
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ILS-DI:AuthorizedIPs','','.','Restricts usage of ILS-DI to some IPs','Free');
280
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OverduesBlockCirc','noblock','When checking out an item should overdues block checkout, generate a confirmation dialogue, or allow checkout','noblock|confirmation|block','Choice');
280
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OverduesBlockCirc','noblock','When checking out an item should overdues block checkout, generate a confirmation dialogue, or allow checkout','noblock|confirmation|block','Choice');
281
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('DisplayMultiPlaceHold','1','Display the ability to place multiple holds or not','','YesNo');
281
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('DisplayMultiPlaceHold','1','Display the ability to place multiple holds or not','','YesNo');
282
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('ShelfBrowserUsesLocation','1','Use the item location when finding items for the shelf browser.','1','YesNo');
283
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('ShelfBrowserUsesHomeBranch','1','Use the item home branch when finding items for the shelf browser.','1','YesNo');
284
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('ShelfBrowserUsesCcode','1','Use the item collection code when finding items for the shelf browser.','0','YesNo');
(-)a/installer/data/mysql/updatedatabase.pl (+9 lines)
Lines 3937-3942 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
3937
   SetVersion ($DBversion);
3937
   SetVersion ($DBversion);
3938
}
3938
}
3939
3939
3940
$DBversion = 'XXX';
3941
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3942
    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('ShelfBrowserUsesLocation','1','Use the item location when finding items for the shelf browser.','1','YesNo')");
3943
    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('ShelfBrowserUsesHomeBranch','1','Use the item home branch when finding items for the shelf browser.','1','YesNo')");
3944
    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('ShelfBrowserUsesCcode','0','Use the item collection code when finding items for the shelf browser.','1','YesNo')");
3945
    print "Upgrade to $DBversion done (Add flexible shelf browser constraints)\n";
3946
    SetVersion ($DBversion);
3947
}
3948
3940
=head1 FUNCTIONS
3949
=head1 FUNCTIONS
3941
3950
3942
=head2 DropAllForeignKeys($table)
3951
=head2 DropAllForeignKeys($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref (-6 / +28 lines)
Lines 202-213 OPAC: Link Here
202
                  no: "Don't allow"
202
                  no: "Don't allow"
203
            - patrons to see what books they have checked out in the past.
203
            - patrons to see what books they have checked out in the past.
204
        -
204
        -
205
            - pref: OPACShelfBrowser
206
              choices:
207
                  yes: Show
208
                  no: "Don't show"
209
            - "a shelf browser on item details pages, allowing patrons to see what's near that item on the shelf. Note that this uses up a fairly large amount of resources on your server, and should be avoided if your collection has a large number of items."
210
        -
211
            - pref: OpacTopissue
205
            - pref: OpacTopissue
212
              choices:
206
              choices:
213
                  yes: Allow
207
                  yes: Allow
Lines 294-296 OPAC: Link Here
294
                  yes: Keep
288
                  yes: Keep
295
                  no: "Don't keep"
289
                  no: "Don't keep"
296
            - patron search history in the OPAC.
290
            - patron search history in the OPAC.
291
    Shelf Browser:
292
        -
293
            - pref: OPACShelfBrowser
294
              choices:
295
                  yes: Show
296
                  no: "Don't show"
297
            - "a shelf browser on item details pages, allowing patrons to see what's near that item on the shelf. Note that this uses up a fairly large amount of resources on your server, and should be avoided if your collection has a large number of items."
298
        -
299
            - pref: ShelfBrowserUsesLocation
300
              default: 1
301
              choices:
302
                  yes: Use
303
                  no: "Don't use"
304
            - "the item location when finding items for the shelf browser."
305
        -
306
            - pref: ShelfBrowserUsesHomeBranch
307
              default: 1
308
              choices:
309
                  yes: Use
310
                  no: "Don't use"
311
            - "the item home branch when finding items for the shelf browser."      
312
        -
313
            - pref: ShelfBrowserUsesCcode
314
              default: 0
315
              choices:
316
                  yes: Use
317
                  no: "Don't use"
318
            - "the item collection code when finding items for the shelf browser."      
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl (-1 / +1 lines)
Lines 422-428 YAHOO.util.Event.onContentReady("furtherm", function () { Link Here
422
422
423
<!-- TMPL_IF NAME="OpenOPACShelfBrowser" -->
423
<!-- TMPL_IF NAME="OpenOPACShelfBrowser" -->
424
<div id="shelfbrowser">
424
<div id="shelfbrowser">
425
<h5 style="text-align: center;"><!-- TMPL_IF NAME="starting_homebranch" -->Browsing <!-- TMPL_VAR NAME="starting_homebranch" --> Shelves<!-- /TMPL_IF --><!-- TMPL_IF NAME="starting_location" -->, Shelving Location:</span><!-- TMPL_VAR NAME="starting_location" --> <!-- /TMPL_IF --> <a style="font-size: 75%;" href="/cgi-bin/koha/opac-detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->">Close Shelf Browser</a></h5>
425
<h5 style="text-align: center;"><!-- TMPL_IF NAME="starting_homebranch" -->Browsing <!-- TMPL_VAR NAME="starting_homebranch" --> Shelves<!-- /TMPL_IF --><!-- TMPL_IF NAME="starting_location" -->, Shelving Location: <!-- TMPL_VAR NAME="starting_location" --><!-- /TMPL_IF --><!-- TMPL_IF name="starting_ccode" -->, Collection Code: <!-- TMPL_VAR name="starting_ccode" --><!-- /TMPL_IF --> <a style="font-size: 75%;" href="/cgi-bin/koha/opac-detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->">Close Shelf Browser</a></h5>
426
426
427
        
427
        
428
        <table><tr>
428
        <table><tr>
(-)a/opac/opac-detail.pl (-107 / +17 lines)
Lines 39-44 use C4::Review; Link Here
39
use C4::Members;
39
use C4::Members;
40
use C4::VirtualShelves;
40
use C4::VirtualShelves;
41
use C4::XSLT;
41
use C4::XSLT;
42
use C4::ShelfBrowser;
42
43
43
BEGIN {
44
BEGIN {
44
	if (C4::Context->preference('BakerTaylorEnabled')) {
45
	if (C4::Context->preference('BakerTaylorEnabled')) {
Lines 197-203 for my $itm (@items) { Link Here
197
my $dbh              = C4::Context->dbh;
198
my $dbh              = C4::Context->dbh;
198
my $marcflavour      = C4::Context->preference("marcflavour");
199
my $marcflavour      = C4::Context->preference("marcflavour");
199
my $marcnotesarray   = GetMarcNotes   ($record,$marcflavour);
200
my $marcnotesarray   = GetMarcNotes   ($record,$marcflavour);
200
my $marcisbnsarray   = GetMarcISBN   ($record,$marcflavour);
201
my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
201
my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
202
my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
202
my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
203
my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
203
my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
Lines 210-216 my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($bib Link Here
210
                     MARCAUTHORS             => $marcauthorsarray,
210
                     MARCAUTHORS             => $marcauthorsarray,
211
                     MARCSERIES              => $marcseriesarray,
211
                     MARCSERIES              => $marcseriesarray,
212
                     MARCURLS                => $marcurlsarray,
212
                     MARCURLS                => $marcurlsarray,
213
                     MARCISBNS               => $marcisbnsarray,
214
                     norequests              => $norequests,
213
                     norequests              => $norequests,
215
                     RequestOnOpac           => C4::Context->preference("RequestOnOpac"),
214
                     RequestOnOpac           => C4::Context->preference("RequestOnOpac"),
216
                     itemdata_ccode          => $itemfields{ccode},
215
                     itemdata_ccode          => $itemfields{ccode},
Lines 446-556 if ( C4::Context->preference("Babeltheque") ) { Link Here
446
if (C4::Context->preference("OPACShelfBrowser")) {
445
if (C4::Context->preference("OPACShelfBrowser")) {
447
    # pick the first itemnumber unless one was selected by the user
446
    # pick the first itemnumber unless one was selected by the user
448
    my $starting_itemnumber = $query->param('shelfbrowse_itemnumber'); # || $items[0]->{itemnumber};
447
    my $starting_itemnumber = $query->param('shelfbrowse_itemnumber'); # || $items[0]->{itemnumber};
449
    $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
448
    if (defined($starting_itemnumber)) {
450
    # find the right cn_sort value for this item
449
        $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
451
    my ($starting_cn_sort, $starting_homebranch, $starting_location);
450
        my $nearby = GetNearbyItems($starting_itemnumber,3);
452
    my $sth_get_cn_sort = $dbh->prepare("SELECT cn_sort,homebranch,location from items where itemnumber=?");
451
453
    $sth_get_cn_sort->execute($starting_itemnumber);
452
        $template->param(
454
    while (my $result = $sth_get_cn_sort->fetchrow_hashref()) {
453
            starting_homebranch => $nearby->{starting_homebranch}->{description},
455
        $starting_cn_sort = $result->{'cn_sort'};
454
            starting_location => $nearby->{starting_location}->{description},
456
        $starting_homebranch->{code} = $result->{'homebranch'};
455
            starting_ccode => $nearby->{starting_ccode}->{description},
457
        $starting_homebranch->{description} = $branches->{$result->{'homebranch'}}{branchname};
456
            starting_itemnumber => $nearby->{starting_itemnumber},
458
        $starting_location->{code} = $result->{'location'};
457
            shelfbrowser_prev_itemnumber => $nearby->{prev_itemnumber},
459
        $starting_location->{description} = GetAuthorisedValueDesc('','',   $result->{'location'} ,'','','LOC', 'opac');
458
            shelfbrowser_next_itemnumber => $nearby->{next_itemnumber},
460
    
459
            shelfbrowser_prev_biblionumber => $nearby->{prev_biblionumber},
461
    }
460
            shelfbrowser_next_biblionumber => $nearby->{next_biblionumber},
462
    
461
            PREVIOUS_SHELF_BROWSE => $nearby->{prev},
463
    ## List of Previous Items
462
            NEXT_SHELF_BROWSE => $nearby->{next},
464
    # order by cn_sort, which should include everything we need for ordering purposes (though not
463
        );
465
    # for limits, those need to be handled separately
466
    my $sth_shelfbrowse_previous;
467
    if (defined $starting_location->{code}) {
468
      $sth_shelfbrowse_previous = $dbh->prepare("
469
        SELECT *
470
        FROM items
471
        WHERE
472
            ((cn_sort = ? AND itemnumber < ?) OR cn_sort < ?) AND
473
            homebranch = ? AND location = ?
474
        ORDER BY cn_sort DESC, itemnumber LIMIT 3
475
        ");
476
      $sth_shelfbrowse_previous->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}, $starting_location->{code});
477
    } else {
478
      $sth_shelfbrowse_previous = $dbh->prepare("
479
        SELECT *
480
        FROM items
481
        WHERE
482
            ((cn_sort = ? AND itemnumber < ?) OR cn_sort < ?) AND
483
            homebranch = ?
484
        ORDER BY cn_sort DESC, itemnumber LIMIT 3
485
        ");
486
      $sth_shelfbrowse_previous->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code});
487
    }
488
    my @previous_items;
489
    while (my $this_item = $sth_shelfbrowse_previous->fetchrow_hashref()) {
490
        my $sth_get_biblio = $dbh->prepare("SELECT biblio.*,biblioitems.isbn AS isbn FROM biblio LEFT JOIN biblioitems ON biblio.biblionumber=biblioitems.biblionumber WHERE biblio.biblionumber=?");
491
        $sth_get_biblio->execute($this_item->{biblionumber});
492
        while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
493
			$this_item->{'title'} = $this_biblio->{'title'};
494
			my $this_record = GetMarcBiblio($this_biblio->{'biblionumber'});
495
			$this_item->{'browser_normalized_upc'} = GetNormalizedUPC($this_record,$marcflavour);
496
			$this_item->{'browser_normalized_oclc'} = GetNormalizedOCLCNumber($this_record,$marcflavour);
497
			$this_item->{'browser_normalized_isbn'} = GetNormalizedISBN(undef,$this_record,$marcflavour);
498
        }
499
        unshift @previous_items, $this_item;
500
    }
501
    
502
    ## List of Next Items; this also intentionally catches the current item
503
    my $sth_shelfbrowse_next;
504
    if (defined $starting_location->{code}) {
505
      $sth_shelfbrowse_next = $dbh->prepare("
506
        SELECT *
507
        FROM items
508
        WHERE
509
            ((cn_sort = ? AND itemnumber >= ?) OR cn_sort > ?) AND
510
            homebranch = ? AND location = ?
511
        ORDER BY cn_sort, itemnumber LIMIT 3
512
        ");
513
      $sth_shelfbrowse_next->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}, $starting_location->{code});
514
    } else {
515
      $sth_shelfbrowse_next = $dbh->prepare("
516
        SELECT *
517
        FROM items
518
        WHERE
519
            ((cn_sort = ? AND itemnumber >= ?) OR cn_sort > ?) AND
520
            homebranch = ?
521
        ORDER BY cn_sort, itemnumber LIMIT 3
522
        ");
523
      $sth_shelfbrowse_next->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code});
524
    }
525
    my @next_items;
526
    while (my $this_item = $sth_shelfbrowse_next->fetchrow_hashref()) {
527
        my $sth_get_biblio = $dbh->prepare("SELECT biblio.*,biblioitems.isbn AS isbn FROM biblio LEFT JOIN biblioitems ON biblio.biblionumber=biblioitems.biblionumber WHERE biblio.biblionumber=?");
528
        $sth_get_biblio->execute($this_item->{biblionumber});
529
        while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
530
            $this_item->{'title'} = $this_biblio->{'title'};
531
			my $this_record = GetMarcBiblio($this_biblio->{'biblionumber'});
532
            $this_item->{'browser_normalized_upc'} = GetNormalizedUPC($this_record,$marcflavour);
533
            $this_item->{'browser_normalized_oclc'} = GetNormalizedOCLCNumber($this_record,$marcflavour);
534
            $this_item->{'browser_normalized_isbn'} = GetNormalizedISBN(undef,$this_record,$marcflavour);
535
        }
536
        push @next_items, $this_item;
537
    }
464
    }
538
    
539
    # alas, these won't auto-vivify, see http://www.perlmonks.org/?node_id=508481
540
    my $shelfbrowser_next_itemnumber = $next_items[-1]->{itemnumber} if @next_items;
541
    my $shelfbrowser_next_biblionumber = $next_items[-1]->{biblionumber} if @next_items;
542
    
543
    $template->param(
544
        starting_homebranch => $starting_homebranch->{description},
545
        starting_location => $starting_location->{description},
546
        starting_itemnumber => $starting_itemnumber,
547
        shelfbrowser_prev_itemnumber => (@previous_items ? $previous_items[0]->{itemnumber} : 0),
548
        shelfbrowser_next_itemnumber => $shelfbrowser_next_itemnumber,
549
        shelfbrowser_prev_biblionumber => (@previous_items ? $previous_items[0]->{biblionumber} : 0),
550
        shelfbrowser_next_biblionumber => $shelfbrowser_next_biblionumber,
551
        PREVIOUS_SHELF_BROWSE => \@previous_items,
552
        NEXT_SHELF_BROWSE => \@next_items,
553
    );
554
}
465
}
555
466
556
if (C4::Context->preference("BakerTaylorEnabled")) {
467
if (C4::Context->preference("BakerTaylorEnabled")) {
557
- 

Return to bug 5551