Bug 13418: Clean C4::VirtualShelves::Page a bit
[koha.git] / C4 / VirtualShelves / Page.pm
1 package C4::VirtualShelves::Page;
2
3 #
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 # perldoc at the end of the file, per convention.
22
23 use strict;
24 use warnings;
25
26 use CGI qw ( -utf8 );
27 use Exporter;
28 use Data::Dumper;
29
30 use C4::VirtualShelves qw/:DEFAULT ShelvesMax/;
31 use C4::Biblio;
32 use C4::Items;
33 use C4::Koha;
34 use C4::Auth qw/get_session/;
35 use C4::Members;
36 use C4::Output;
37 use C4::Dates qw/format_date/;
38 use C4::Tags qw(get_tags);
39 use C4::Csv;
40 use C4::XSLT;
41
42 use constant VIRTUALSHELVES_COUNT => 20;
43
44 use vars qw($debug @EXPORT @ISA $VERSION);
45
46 BEGIN {
47     $VERSION = 3.07.00.049;
48     @ISA     = qw(Exporter);
49     @EXPORT  = qw(&shelfpage);
50     $debug   = $ENV{DEBUG} || 0;
51 }
52
53 our %pages = (
54     intranet => { redirect => '/cgi-bin/koha/virtualshelves/shelves.pl', },
55     opac     => { redirect => '/cgi-bin/koha/opac-shelves.pl', },
56 );
57
58 sub shelfpage {
59     my ( $type, $query, $template, $loggedinuser, $cookie ) = @_;
60     ( $pages{$type} ) or $type = 'opac';
61     $query            or die "No query";
62     $template         or die "No template";
63     $template->param(
64     loggedinuser => $loggedinuser,
65     OpacAllowPublicListCreation => C4::Context->preference('OpacAllowPublicListCreation'),
66     );
67     my $edit;
68     my $shelves;
69     my @paramsloop;
70     my $totitems;
71     my $shelfoff    = ( $query->param('shelfoff') ? $query->param('shelfoff') : 1 );
72     $template->{VARS}->{'shelfoff'} = $shelfoff;
73     my $itemoff     = ( $query->param('itemoff')  ? $query->param('itemoff')  : 1 );
74     my $displaymode = ( $query->param('display')  ? $query->param('display')  : 'publicshelves' );
75     my ( $shelflimit, $shelfoffset, $shelveslimit, $shelvesoffset );
76     my $marcflavour = C4::Context->preference("marcflavour");
77
78     # get biblionumbers stored in the cart
79     my @cart_list;
80     my $cart_cookie = ( $type eq 'opac' ? "bib_list" : "intranet_bib_list" );
81     if($query->cookie($cart_cookie)){
82         my $cart_list = $query->cookie($cart_cookie);
83         @cart_list = split(/\//, $cart_list);
84     }
85
86     $shelflimit = ( $type eq 'opac' ? C4::Context->preference('OPACnumSearchResults') : C4::Context->preference('numSearchResults') );
87     $shelflimit = $shelflimit || ShelvesMax('MGRPAGE');
88     $shelfoffset   = ( $itemoff - 1 ) * $shelflimit;     # Sets the offset to begin retrieving items at
89     $shelveslimit  = $shelflimit;                        # Limits number of shelves returned for a given query (row_count)
90     $shelvesoffset = ( $shelfoff - 1 ) * $shelflimit;    # Sets the offset to begin retrieving shelves at (offset)
91                                                 # getting the Shelves list
92     my $category = ( ( $displaymode eq 'privateshelves' ) ? 1 : 2 );
93     my $shelflist = GetShelves( $category, $shelveslimit, $shelvesoffset, $loggedinuser );
94     my $totshelves = C4::VirtualShelves::GetShelfCount( $loggedinuser, $category );
95
96     #Get a list of private shelves for possible deletion. Only do this when we've defaulted to public shelves
97     my ( $privshelflist, $privtotshelves );
98     if ( $category == 2 ) {
99         ( $privshelflist, $privtotshelves ) = GetShelves( 1, $shelveslimit, $shelvesoffset, $loggedinuser );
100     }
101     my $op = $query->param('op');
102
103     # the format of this is unindented for ease of diff comparison to the old script
104     # Note: do not mistake the assignment statements below for comparisons!
105     if ( $query->param('modifyshelfcontents') ) {
106         my ( $shelfnumber, $barcode, $item, $biblio );
107         if ( $shelfnumber = $query->param('viewshelf') ) {
108             #add to shelf
109             if($barcode = $query->param('addbarcode') ) {
110                 if(ShelfPossibleAction( $loggedinuser, $shelfnumber, 'add')) {
111                     $item = GetItem( 0, $barcode);
112                     if (defined $item && $item->{'itemnumber'}) {
113                         $biblio = GetBiblioFromItemNumber( $item->{'itemnumber'} );
114                         AddToShelf( $biblio->{'biblionumber'}, $shelfnumber, $loggedinuser)
115                           or push @paramsloop, { duplicatebiblio => $barcode };
116                     }
117                     else {
118                         push @paramsloop, { failgetitem => $barcode };
119                     }
120                 }
121                 else {
122                     push @paramsloop, { nopermission => $shelfnumber };
123                 }
124             }
125             elsif(grep { /REM-(\d+)/ } $query->param) {
126             #remove item(s) from shelf
127                 if(ShelfPossibleAction($loggedinuser, $shelfnumber, 'delete')) {
128                 #This is just a general okay; DelFromShelf checks further
129                     my @bib;
130                     foreach($query->param) {
131                         /REM-(\d+)/ or next;
132                         push @bib, $1; #$1 is biblionumber
133                     }
134                     my $t= DelFromShelf(\@bib, $shelfnumber, $loggedinuser);
135                     if($t==0) {
136                         push @paramsloop, {nothingdeleted => $shelfnumber};
137                     }
138                     elsif($t<@bib) {
139                         push @paramsloop, {somedeleted => $shelfnumber};
140                     }
141                 }
142                 else {
143                     push @paramsloop, { nopermission => $shelfnumber };
144                 }
145             }
146         }
147         else {
148             push @paramsloop, { noshelfnumber => 1 };
149         }
150     }
151
152     my $showadd = 1;
153
154     # set the default tab, etc. (for OPAC)
155     my $shelf_type = ( $query->param('display') ? $query->param('display') : 'publicshelves' );
156     if ( defined $shelf_type ) {
157         if ( $shelf_type eq 'privateshelves' ) {
158             $template->param( showprivateshelves => 1 );
159         } elsif ( $shelf_type eq 'publicshelves' ) {
160             $template->param( showpublicshelves => 1 );
161             $showadd = 0;
162         } else {
163             $debug and warn "Invalid 'display' param ($shelf_type)";
164         }
165     } elsif ( $loggedinuser == -1 ) {
166         $template->param( showpublicshelves => 1 );
167     } else {
168         $template->param( showprivateshelves => 1 );
169     }
170
171     my ( $okmanage, $okview );
172     my $shelfnumber = $query->param('shelfnumber') || $query->param('viewshelf');
173     if ($shelfnumber) {
174         $okmanage = ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' );
175         $okview   = ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' );
176     }
177
178     my $delflag = 0;
179
180   SWITCH: {
181         if ($op) {
182         #Saving modified shelf
183             if ( $op eq 'modifsave' ) {
184                 unless ($okmanage) {
185                         push @paramsloop, { nopermission => $shelfnumber };
186                         last SWITCH;
187                 }
188                 my $shelf = {
189                     shelfname          => $query->param('shelfname'),
190                     sortfield          => $query->param('sortfield'),
191                     allow_add          => $query->param('allow_add'),
192                     allow_delete_own   => $query->param('allow_delete_own'),
193                     allow_delete_other => $query->param('allow_delete_other'),
194                 };
195                 if($query->param('category')) { #optional
196                     $shelf->{category}= $query->param('category');
197                 }
198                 unless(ModShelf($shelfnumber, $shelf )) {
199                   push @paramsloop, {modifyfailure => $shelf->{shelfname}};
200                   last SWITCH;
201                 }
202
203                 if($displaymode eq "viewshelf"){
204                     print $query->redirect( $pages{$type}->{redirect} . "?viewshelf=$shelfnumber" );
205                 } elsif($displaymode eq "publicshelves"){
206                     print $query->redirect( $pages{$type}->{redirect} );
207                 } else {
208                     print $query->redirect( $pages{$type}->{redirect} . "?display=privateshelves" );
209                 }
210                 exit;
211             }
212         #Editing a shelf
213         elsif ( $op eq 'modif' ) {
214                 my ( $shelfnumber2, $shelfname, $owner, $category, $sortfield, $allow_add, $allow_delete_own, $allow_delete_other) = GetShelf($shelfnumber);
215                 my $member = GetMember( 'borrowernumber' => $owner );
216                 my $ownername = defined($member) ? $member->{firstname} . " " . $member->{surname} : '';
217                 $edit = 1;
218                 $template->param(
219                     edit                => 1,
220                     display             => $displaymode,
221                     shelfnumber         => $shelfnumber2,
222                     shelfname           => $shelfname,
223                     owner               => $owner,
224                     ownername           => $ownername,
225                     "category$category" => 1,
226                     category            => $category,
227                     sortfield           => $sortfield,
228                     allow_add           => $allow_add,
229                     allow_delete_own    => $allow_delete_own,
230                     allow_delete_other  => $allow_delete_other,
231                 );
232             }
233             last SWITCH;
234         }
235
236         #View a shelf
237         if ( $shelfnumber = $query->param('viewshelf') ) {
238             # explicitly fetch this shelf
239             my ($shelfnumber2,$shelfname,$owner,$category,$sorton) = GetShelf($shelfnumber);
240
241             $template->param(
242                 'AllowOnShelfHolds'     => C4::Context->preference('AllowOnShelfHolds'),
243                 'DisplayMultiPlaceHold' => C4::Context->preference('DisplayMultiPlaceHold'),
244             );
245             if (C4::Context->preference('TagsEnabled')) {
246                 $template->param(TagsEnabled => 1);
247                     foreach (qw(TagsShowOnList TagsInputOnList)) {
248                     C4::Context->preference($_) and $template->param($_ => 1);
249                 }
250             }
251             #check that the user can view the shelf
252             if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) {
253                 my $items;
254                 my $tag_quantity;
255                 my $sortfield = ( $sorton ? $sorton : 'title' );
256                 $sortfield = $query->param('sort') || $sortfield; ## Passed in sorting overrides default sorting
257                 my $direction = $query->param('direction') || 'asc';
258                 $template->param(
259                     sort      => $sortfield,
260                     direction => $direction,
261                 );
262                 ( $items, $totitems ) = GetShelfContents( $shelfnumber, $shelflimit, $shelfoffset, $sortfield, $direction );
263                 for my $this_item (@$items) {
264                     my $biblionumber = $this_item->{'biblionumber'};
265                     my $record = GetMarcBiblio($biblionumber);
266                     if (C4::Context->preference("OPACXSLTResultsDisplay") && $type eq 'opac') {
267                         $this_item->{XSLTBloc} = XSLTParse4Display($biblionumber, $record, "OPACXSLTResultsDisplay");
268                     } elsif (C4::Context->preference("XSLTResultsDisplay") && $type eq 'intranet') {
269                         $this_item->{XSLTBloc} = XSLTParse4Display($biblionumber, $record, "XSLTResultsDisplay");
270                     }
271
272                     # the virtualshelfcontents table does not store these columns nor are they retrieved from the items
273                     # and itemtypes tables, so I'm commenting them out for now to quiet the log -crn
274                     #$this_item->{imageurl} = $imgdir."/".$itemtypes->{ $this_item->{itemtype}  }->{'imageurl'};
275                     #$this_item->{'description'} = $itemtypes->{ $this_item->{itemtype} }->{'description'};
276                     $this_item->{'dateadded'} = format_date( $this_item->{'dateadded'} );
277                     $this_item->{'imageurl'}  = getitemtypeinfo( $this_item->{'itemtype'}, $type )->{'imageurl'};
278                     $this_item->{'coins'}     = GetCOinSBiblio( $record );
279                     $this_item->{'subtitle'} = GetRecordValue('subtitle', $record, GetFrameworkCode($this_item->{'biblionumber'}));
280                     $this_item->{'normalized_upc'}  = GetNormalizedUPC(       $record,$marcflavour);
281                     $this_item->{'normalized_ean'}  = GetNormalizedEAN(       $record,$marcflavour);
282                     $this_item->{'normalized_oclc'} = GetNormalizedOCLCNumber($record,$marcflavour);
283                     $this_item->{'normalized_isbn'} = GetNormalizedISBN(undef,$record,$marcflavour);
284                     if(!defined($this_item->{'size'})) { $this_item->{'size'} = "" }; #TT has problems with size
285                     # Getting items infos for location display
286                     my @items_infos = &GetItemsLocationInfo( $this_item->{'biblionumber'});
287                     $this_item->{'itemsissued'} = CountItemsIssued( $this_item->{'biblionumber'} );
288                     $this_item->{'ITEM_RESULTS'} = \@items_infos;
289                     if ( grep {$_ eq $biblionumber} @cart_list) {
290                         $this_item->{'incart'} = 1;
291                     }
292
293                     if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnList')) {
294                         $this_item->{'TagLoop'} = get_tags({
295                             biblionumber=>$this_item->{'biblionumber'}, approved=>1, 'sort'=>'-weight',
296                             limit=>$tag_quantity
297                             });
298                     }
299
300                 }
301                 if($type eq 'intranet'){
302                     # Build drop-down list for 'Add To:' menu...
303                     my ($totalref, $pubshelves, $barshelves)=
304                     C4::VirtualShelves::GetSomeShelfNames($loggedinuser,'COMBO',1);
305                     $template->param(
306                         addbarshelves     => $totalref->{bartotal},
307                         addbarshelvesloop => $barshelves,
308                         addpubshelves     => $totalref->{pubtotal},
309                         addpubshelvesloop => $pubshelves,
310                     );
311                 }
312                 push @paramsloop, { display => 'privateshelves' } if $category == 1;
313                 $showadd = 1;
314                 my $i = 0;
315                 my $manageshelf = ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' );
316                 $template->param(
317                     shelfname           => $shelfname,
318                     shelfnumber         => $shelfnumber,
319                     viewshelf           => $shelfnumber,
320                     sortfield           => $sortfield,
321                     manageshelf         => $manageshelf,
322                     allowremovingitems  => ShelfPossibleAction( $loggedinuser, $shelfnumber, 'delete'),
323                     allowaddingitem     => ShelfPossibleAction( $loggedinuser, $shelfnumber, 'add'),
324                     "category$category" => 1,
325                     category            => $category,
326                     itemsloop           => $items,
327                     showprivateshelves  => $category==1,
328                 );
329             } else {
330                 push @paramsloop, { nopermission => $shelfnumber };
331             }
332             last SWITCH;
333         }
334
335         if ( $query->param('shelves') ) {
336             my $stay = 1;
337
338         #Add a shelf
339             if ( my $newshelf = $query->param('addshelf') ) {
340
341                 # note: a user can always add a new shelf (except database administrator account)
342                 my $shelfnumber = AddShelf( {
343                     shelfname => $newshelf,
344                     sortfield => $query->param('sortfield'),
345                     category => $query->param('category'),
346                     allow_add => $query->param('allow_add'),
347                     allow_delete_own => $query->param('allow_delete_own'),
348                     allow_delete_other => $query->param('allow_delete_other'),
349                     },
350                     $query->param('owner') );
351                 $stay = 1;
352                 if( !$shelfnumber ) {
353                     push @paramsloop, { addshelf_failed => 1 };
354                 } elsif ( $shelfnumber == -1 ) {    #shelf already exists.
355                     $showadd = 1;
356                     push @paramsloop, { already => $newshelf };
357                     $template->param( shelfnumber => $shelfnumber );
358                 } else {
359                     print $query->redirect( $pages{$type}->{redirect} . "?viewshelf=$shelfnumber" );
360                     exit;
361                 }
362             }
363
364         #Deleting a shelf (asking for confirmation if it has entries)
365             foreach ( $query->param() ) {
366                 /(DEL|REMSHR)-(\d+)/ or next;
367                 $delflag = 1;
368                 my $number = $2;
369                 unless ( defined $shelflist->{$number} || defined $privshelflist->{$number} ) {
370                     push( @paramsloop, { unrecognized => $number } );
371                     last;
372                 }
373                 #remove a share
374                 if(/REMSHR/) {
375                     RemoveShare($loggedinuser, $number);
376                     delete $shelflist->{$number} if exists $shelflist->{$number};
377                     delete $privshelflist->{$number} if exists $privshelflist->{$number};
378                     $stay=0;
379                     next;
380                 }
381                 #
382                 unless ( ShelfPossibleAction( $loggedinuser, $number, 'manage' ) ) {
383                     push( @paramsloop, { nopermission => $shelfnumber } );
384                     last;
385                 }
386                 my $contents;
387                 ( $contents, $totshelves ) = GetShelfContents( $number, $shelveslimit, $shelvesoffset );
388                 if ( $totshelves > 0 ) {
389                     unless ( scalar grep { /^CONFIRM-$number$/ } $query->param() ) {
390                         if ( defined $shelflist->{$number} ) {
391                             push( @paramsloop, { need_confirm => $shelflist->{$number}->{shelfname}, count => $totshelves, single => ($totshelves eq 1 ? 1:0) } );
392                             $shelflist->{$number}->{confirm} = $number;
393                         } else {
394                             push( @paramsloop, { need_confirm => $privshelflist->{$number}->{shelfname}, count => $totshelves } );
395                             $privshelflist->{$number}->{confirm} = $number;
396                         }
397                         $stay = 0;
398                         next;
399                     }
400                 }
401                 my $name;
402                 if ( defined $shelflist->{$number} ) {
403                     $name = $shelflist->{$number}->{'shelfname'};
404                     delete $shelflist->{$number};
405                 } else {
406                     $name = $privshelflist->{$number}->{'shelfname'};
407                     delete $privshelflist->{$number};
408                 }
409                 unless ( DelShelf($number) ) {
410                     push( @paramsloop, { delete_fail => $name } );
411                     last;
412                 }
413                 push( @paramsloop, { delete_ok => $name } );
414
415                 $stay = 0;
416             }
417             $showadd = 1;
418             if ($stay){
419                 $template->param( shelves => 1 );
420                 $shelves = 1;
421             }
422             last SWITCH;
423         }
424     } # end of SWITCH block
425
426     (@paramsloop) and $template->param( paramsloop => \@paramsloop );
427     $showadd      and $template->param( showadd    => 1 );
428     my @shelvesloop;
429     my @shelveslooppriv;
430     my $numberCanManage = 0;
431
432     # rebuild shelflist in case a shelf has been added
433     $shelflist = GetShelves( $category, $shelveslimit, $shelvesoffset, $loggedinuser ) unless $delflag;
434     $totshelves = C4::VirtualShelves::GetShelfCount( $loggedinuser, $category ) unless $delflag;
435     foreach my $element ( sort { lc( $shelflist->{$a}->{'shelfname'} ) cmp lc( $shelflist->{$b}->{'shelfname'} ) } keys %$shelflist ) {
436         my %line;
437         $shelflist->{$element}->{shelf} = $element;
438         my $category  = $shelflist->{$element}->{'category'};
439         my $owner     = $shelflist->{$element}->{'owner'}||0;
440         my $canmanage = ShelfPossibleAction( $loggedinuser, $element, 'manage' );
441         $shelflist->{$element}->{"viewcategory$category"} = 1;
442         $shelflist->{$element}->{manageshelf} = $canmanage;
443         if($canmanage || ($loggedinuser && $owner==$loggedinuser)) {
444             $shelflist->{$element}->{'mine'} = 1;
445         }
446         my $member = GetMember( 'borrowernumber' => $owner );
447         $shelflist->{$element}->{ownername} = defined($member) ? $member->{firstname} . " " . $member->{surname} : '';
448         $numberCanManage++ if $canmanage;    # possibly outmoded
449         if ( $shelflist->{$element}->{'category'} eq '1' ) {
450             $shelflist->{$element}->{shares} = IsSharedList($element);
451             push( @shelveslooppriv, $shelflist->{$element} );
452         } else {
453             push( @shelvesloop, $shelflist->{$element} );
454         }
455     }
456
457     my $url = $type eq 'opac' ? "/cgi-bin/koha/opac-shelves.pl" : "/cgi-bin/koha/virtualshelves/shelves.pl";
458     my %qhash = ();
459     foreach (qw(display viewshelf sortfield sort direction)) {
460         $qhash{$_} = $query->param($_) if $query->param($_);
461     }
462     ( scalar keys %qhash ) and $url .= '?' . join '&', map { "$_=$qhash{$_}" } keys %qhash;
463     if ( $shelfnumber && $totitems ) {
464         $template->param(  pagination_bar => pagination_bar( $url, ( int( $totitems / $shelflimit ) ) + ( ( $totitems % $shelflimit ) > 0 ? 1 : 0 ), $itemoff, "itemoff" )  );
465     } elsif ( $totshelves ) {
466         $template->param(
467              pagination_bar => pagination_bar( $url, ( int( $totshelves / $shelveslimit ) ) + ( ( $totshelves % $shelveslimit ) > 0 ? 1 : 0 ), $shelfoff, "shelfoff" )  );
468     }
469     $template->param(
470         shelveslooppriv                                                    => \@shelveslooppriv,
471         shelvesloop                                                        => \@shelvesloop,
472         shelvesloopall                                                     => [ ( @shelvesloop, @shelveslooppriv ) ],
473         numberCanManage                                                    => $numberCanManage,
474         "BiblioDefaultView" . C4::Context->preference("BiblioDefaultView") => 1,
475         csv_profiles                                                       => GetCsvProfilesLoop('marc')
476     );
477     if (   $shelfnumber
478         or $shelves
479         or $edit ) {
480         $template->param( vseflag => 1 );
481     }
482     if ($shelves or    # note: this part looks duplicative, but is intentional
483         $edit
484       ) {
485         $template->param( seflag => 1 );
486         #This hack is just another argument for refactoring this script one day
487         #At this point you are adding or editing a list; if you add, then you add a private list (by default) with permissions as below; if you edit, do not pass these permissions, they must come from the database
488         $template->param( allow_add => 0, allow_delete_own => 1, allow_delete_other => 0) unless $shelfnumber;
489     }
490
491 #Next call updates the shelves for the Lists button.
492 #May not always be needed (when nothing changed), but doesn't take much.
493     my ($total, $pubshelves, $barshelves) = C4::VirtualShelves::GetSomeShelfNames($loggedinuser, 'MASTHEAD');
494     $template->param(
495             barshelves     => $total->{bartotal},
496             barshelvesloop => $barshelves,
497             pubshelves     => $total->{pubtotal},
498             pubshelvesloop => $pubshelves,
499     );
500
501     output_html_with_http_headers $query, $cookie, $template->output;
502 }
503
504 1;
505 __END__
506
507 =head1 NAME
508
509 VirtualShelves/Page.pm
510
511 =head1 DESCRIPTION
512
513 Module used for both OPAC and intranet pages.
514
515 =head1 CGI PARAMETERS
516
517 =over 4
518
519 =item C<modifyshelfcontents>
520
521 If this script has to modify the shelf content.
522
523 =item C<shelfnumber>
524
525 To know on which shelf to work.
526
527 =item C<addbarcode>
528
529 =item C<op>
530
531  Op can be:
532     * modif: show the template allowing modification of the shelves;
533     * modifsave: save changes from modif mode.
534
535 =item C<viewshelf>
536
537 Load template with 'viewshelves param' displaying the shelf's information.
538
539 =item C<shelves>
540
541 If the param shelves == 1, then add or delete a shelf.
542
543 =item C<addshelf>
544
545 If the param shelves == 1, then addshelf is the name of the shelf to add.
546
547 =back
548
549 =cut