Bug 17843: [QA Follow-up] Some polishing
[koha.git] / virtualshelves / shelves.pl
index 3e03e6d..86b7852 100755 (executable)
@@ -29,9 +29,12 @@ use C4::XSLT;
 
 use Koha::Biblios;
 use Koha::Biblioitems;
+use Koha::ItemTypes;
 use Koha::CsvProfiles;
 use Koha::Virtualshelves;
 
+use constant ANYONE => 2;
+
 my $query = new CGI;
 
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
@@ -49,7 +52,8 @@ my $category = $query->param('category') || 1;
 my ( $shelf, $shelfnumber, @messages );
 
 if ( $op eq 'add_form' ) {
-    # Nothing to do
+    # Only pass default
+    $shelf = { allow_change_from_owner => 1 };
 } elsif ( $op eq 'edit_form' ) {
     $shelfnumber = $query->param('shelfnumber');
     $shelf       = Koha::Virtualshelves->find($shelfnumber);
@@ -66,14 +70,14 @@ if ( $op eq 'add_form' ) {
         push @messages, { type => 'alert', code => 'does_not_exist' };
     }
 } elsif ( $op eq 'add' ) {
+    my $allow_changes_from = $query->param('allow_changes_from');
     eval {
         $shelf = Koha::Virtualshelf->new(
             {   shelfname          => scalar $query->param('shelfname'),
                 sortfield          => scalar $query->param('sortfield'),
                 category           => scalar $query->param('category'),
-                allow_add          => scalar $query->param('allow_add'),
-                allow_delete_own   => scalar $query->param('allow_delete_own'),
-                allow_delete_other => scalar $query->param('allow_delete_other'),
+                allow_change_from_owner => $allow_changes_from > 0,
+                allow_change_from_others => $allow_changes_from == ANYONE,
                 owner              => scalar $query->param('owner'),
             }
         );
@@ -100,9 +104,9 @@ if ( $op eq 'add_form' ) {
         if ( $shelf->can_be_managed( $loggedinuser ) ) {
             $shelf->shelfname( scalar $query->param('shelfname') );
             $shelf->sortfield( $sortfield );
-            $shelf->allow_add( scalar $query->param('allow_add') );
-            $shelf->allow_delete_own( scalar $query->param('allow_delete_own') );
-            $shelf->allow_delete_other( scalar $query->param('allow_delete_other') );
+            my $allow_changes_from = $query->param('allow_changes_from');
+            $shelf->allow_change_from_owner( $allow_changes_from > 0 );
+            $shelf->allow_change_from_others( $allow_changes_from == ANYONE );
             $shelf->category( scalar $query->param('category') );
             eval { $shelf->store };
 
@@ -145,23 +149,24 @@ if ( $op eq 'add_form' ) {
                 my @barcodes = split /\n/, $barcodes; # Entries are effectively passed in as a <cr> separated list
                 foreach my $barcode (@barcodes){
                     $barcode =~ s/\r$//; # strip any naughty return chars
+                    next if $barcode eq '';
                     my $item = GetItem( 0, $barcode);
                     if (defined $item && $item->{itemnumber}) {
                         my $biblio = GetBiblioFromItemNumber( $item->{itemnumber} );
                         my $added = eval { $shelf->add_biblio( $biblio->{biblionumber}, $loggedinuser ); };
                         if ($@) {
-                            push @messages, { item_barcode => $barcode, type => 'error', code => ref($@), msg => $@ };
+                            push @messages, { item_barcode => $barcode, type => 'alert', code => ref($@), msg => $@ };
                         } elsif ( $added ) {
                             push @messages, { item_barcode => $barcode, type => 'message', code => 'success_on_add_biblio' };
                         } else {
                             push @messages, { item_barcode => $barcode, type => 'message', code => 'error_on_add_biblio' };
                         }
                     } else {
-                        push @messages, { item_barcode => $barcode, type => 'error', code => 'item_does_not_exist' };
+                        push @messages, { item_barcode => $barcode, type => 'alert', code => 'item_does_not_exist' };
                     }
                 }
             } else {
-                push @messages, { type => 'error', code => 'unauthorized_on_add_biblio' };
+                push @messages, { type => 'alert', code => 'unauthorized_on_add_biblio' };
             }
         }
     } else {
@@ -243,14 +248,14 @@ if ( $op eq 'view' ) {
 
                 my $marcflavour = C4::Context->preference("marcflavour");
                 my $itemtype = Koha::Biblioitems->search({ biblionumber => $content->biblionumber })->next->itemtype;
-                my $itemtypeinfo = getitemtypeinfo( $itemtype, 'intranet' );
+                $itemtype = Koha::ItemTypes->find( $itemtype );
                 my $biblio = Koha::Biblios->find( $content->biblionumber );
                 $this_item->{title}             = $biblio->title;
                 $this_item->{author}            = $biblio->author;
                 $this_item->{dateadded}         = $content->dateadded;
-                $this_item->{imageurl}          = $itemtypeinfo->{imageurl};
-                $this_item->{description}       = $itemtypeinfo->{description};
-                $this_item->{notforloan}        = $itemtypeinfo->{notforloan};
+                $this_item->{imageurl}          = $itemtype ? C4::Koha::getitemtypeimagelocation( 'intranet', $itemtype->imageurl ) : q{};
+                $this_item->{description}       = $itemtype ? $itemtype->description : q{}; #FIXME Should this be translated_description ?
+                $this_item->{notforloan}        = $itemtype->notforloan if $itemtype;
                 $this_item->{'coins'}           = GetCOinSBiblio($record);
                 $this_item->{'subtitle'}        = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $biblionumber ) );
                 $this_item->{'normalized_upc'}  = GetNormalizedUPC( $record, $marcflavour );
@@ -323,7 +328,7 @@ $template->param(
     messages => \@messages,
     category => $category,
     print    => scalar $query->param('print') || 0,
-    csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ],
+    csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc', used_for => 'export_records' }) ],
 );
 
 output_html_with_http_headers $query, $cookie, $template->output;