Bug 13669: Catch the errors to have them to the logs
[koha.git] / opac / opac-shelves.pl
index 8b66274..6e5052d 100755 (executable)
@@ -72,13 +72,13 @@ if ( $op eq 'add_form' ) {
     if ( $loggedinuser ) {
         eval {
             $shelf = Koha::Virtualshelf->new(
-                {   shelfname          => $query->param('shelfname'),
-                    sortfield          => $query->param('sortfield'),
-                    category           => $query->param('category') || 1,
-                    allow_add          => $query->param('allow_add'),
-                    allow_delete_own   => $query->param('allow_delete_own'),
-                    allow_delete_other => $query->param('allow_delete_other'),
-                    owner              => $loggedinuser,
+                {   shelfname          => scalar $query->param('shelfname'),
+                    sortfield          => scalar $query->param('sortfield'),
+                    category           => scalar $query->param('category') || 1,
+                    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'),
+                    owner              => scalar $loggedinuser,
                 }
             );
             $shelf->store;
@@ -188,7 +188,7 @@ if ( $op eq 'add_form' ) {
 } elsif ( $op eq 'remove_biblios' ) {
     $shelfnumber = $query->param('shelfnumber');
     $shelf = Koha::Virtualshelves->find($shelfnumber);
-    my @biblionumber = $query->param('biblionumber');
+    my @biblionumber = $query->multi_param('biblionumber');
     if ($shelf) {
         if ( $shelf->can_biblios_be_removed( $loggedinuser ) ) {
             my $number_of_biblios_removed = eval {
@@ -223,6 +223,7 @@ if ( $op eq 'view' ) {
             $category = $shelf->category;
             my $sortfield = $query->param('sortfield') || $shelf->sortfield;    # Passed in sorting overrides default sorting
             my $direction = $query->param('direction') || 'asc';
+            $direction = 'asc' if $direction ne 'asc' and $direction ne 'desc';
             my ( $page, $rows );
             unless ( $query->param('print') or $query->param('rss') ) {
                 $rows = C4::Context->preference('OPACnumSearchResults') || 20;
@@ -235,7 +236,7 @@ if ( $op eq 'view' ) {
                     prefetch => [ { 'biblionumber' => { 'biblioitems' => 'items' } } ],
                     page     => $page,
                     rows     => $rows,
-                    order_by => "$order_by $direction",
+                    order_by => { "-$direction" => $order_by },
                 }
             );
 
@@ -247,18 +248,23 @@ if ( $op eq 'view' ) {
 
             my $borrower = GetMember( borrowernumber => $loggedinuser );
 
+            my $xslfile = C4::Context->preference('OPACXSLTResultsDisplay');
+            my $lang   = $xslfile ? C4::Languages::getlanguage()  : undef;
+            my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef;
+
             my @items;
             while ( my $content = $contents->next ) {
-                my $this_item;
                 my $biblionumber = $content->biblionumber->biblionumber;
+                my $this_item    = GetBiblioData($biblionumber);
                 my $record       = GetMarcBiblio($biblionumber);
 
-                if ( C4::Context->preference("OPACXSLTResultsDisplay") ) {
-                    $this_item->{XSLTBloc} = XSLTParse4Display( $biblionumber, $record, "OPACXSLTResultsDisplay" );
+                if ( $xslfile ) {
+                    $this_item->{XSLTBloc} = XSLTParse4Display( $biblionumber, $record, "OPACXSLTResultsDisplay",
+                                                                1, undef, $sysxml, $xslfile, $lang);
                 }
 
                 my $marcflavour = C4::Context->preference("marcflavour");
-                my $itemtypeinfo = getitemtypeinfo( $content->biblionumber->biblioitems->first->itemtype, 'intranet' );
+                my $itemtypeinfo = getitemtypeinfo( $content->biblionumber->biblioitems->first->itemtype, 'opac' );
                 $this_item->{imageurl}          = $itemtypeinfo->{imageurl};
                 $this_item->{description}       = $itemtypeinfo->{description};
                 $this_item->{notforloan}        = $itemtypeinfo->{notforloan};
@@ -354,7 +360,7 @@ $template->param(
     shelf    => $shelf,
     messages => \@messages,
     category => $category,
-    print    => $query->param('print') || 0,
+    print    => scalar $query->param('print') || 0,
     listsview => 1,
 );