Add multiple items to virt shelf, and bugvix virtual shelf adds.
[srvgit] / opac / opac-addbybiblionumber.pl
index 88930c0..2a8c788 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 
-#script to provide bookshelf management
+#script to provide virtualshelf management
 # WARNING: This file uses 4-character tabs!
 #
 # $Header$
 use strict;
 use C4::Biblio;
 use CGI;
-use C4::BookShelves;
+use C4::VirtualShelves;
 use C4::Circulation;
 use C4::Auth;
 use C4::Output;
 
 my $query        = new CGI;
-my $biblionumber = $query->param('biblionumber');
+my @biblionumber = $query->param('biblionumber');
 my $shelfnumber  = $query->param('shelfnumber');
-my $newbookshelf = $query->param('newbookshelf');
+my $newvirtualshelf = $query->param('newvirtualshelf');
 my $category     = $query->param('category');
 
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
-        template_name   => "opac-addbookbybiblionumber.tmpl",
+        template_name   => "opac-addbybiblionumber.tmpl",
         query           => $query,
         type            => "opac",
         authnotrequired => 1,
     }
 );
 
-$shelfnumber = AddShelf( '', $newbookshelf, $loggedinuser, $category ) if $newbookshelf;
+$shelfnumber = AddShelf(  $newvirtualshelf, $loggedinuser, $category ) if $newvirtualshelf;
 
-# to know if we had to add more than one biblio.
-my $multiple = 0;
-$multiple = 1 if $biblionumber =~ /^(\d*\/)*$/;
-
-
-if ($shelfnumber) {
+# multiple bibs might come in as '/' delimited string (from where, i don't see), or  as array.
 
-    if ($multiple){
-        foreach (split /\//,$biblionumber){
-            &AddToShelfFromBiblio($_,$shelfnumber);
+my $multiple = 0;
+my @bibs;
+if (scalar(@biblionumber) == 1) {
+       @biblionumber =  (split /\//,$biblionumber[0]);
+}
+if ($shelfnumber && ($shelfnumber != -1)) {
+        for my $bib (@biblionumber){
+            &AddToShelfFromBiblio($bib,$shelfnumber);
         }
-    }
-    else {
-        &AddToShelfFromBiblio( $biblionumber, $shelfnumber );
-    }
     print $query->header;
     print "<html><body onload=\"window.close();\"></body></html>";
     exit;
@@ -75,9 +71,9 @@ else {
             $shelvesloop{$element} = $shelflist->{$element}->{'shelfname'};
     }
 
-    my $CGIbookshelves;
+    my $CGIvirtualshelves;
     if ( @shelvesloop > 0 ) {
-        $CGIbookshelves = CGI::scrolling_list (
+        $CGIvirtualshelves = CGI::scrolling_list (
             -name     => 'shelfnumber',
             -values   => \@shelvesloop,
             -labels   => \%shelvesloop,
@@ -87,30 +83,23 @@ else {
         );
     }
 
-    if ( $multiple ) {
         my @biblios;
-        foreach (split /\//,$biblionumber){
-            my $data = GetBiblioData($_);
-            push @biblios,$data;
-        }
+        for my $bib (@biblionumber) {
+                       my $data = GetBiblioData( $bib );
+                       push(@biblios, 
+               { biblionumber => $bib,
+               title        => $data->{'title'},
+               author       => $data->{'author'},
+               } );
+       }
         $template->param (
-            multiple => 1,
-            biblionumber => $biblionumber,
+            multiple => (scalar(@biblios) > 1),
             total    => scalar @biblios,
             biblios  => \@biblios,
         );
-    }
-    else { # just one to add.
-        my $data = GetBiblioData( $biblionumber );
-        $template->param (
-            biblionumber => $biblionumber,
-            title        => $data->{'title'},
-            author       => $data->{'author'},
-        );
-    }
 
     $template->param (
-        CGIbookshelves       => $CGIbookshelves,
+        CGIvirtualshelves       => $CGIvirtualshelves,
     );
 
     output_html_with_http_headers $query, $cookie, $template->output;