(bug #4491) fix weird code in search scripts
[koha.git] / C4 / VirtualShelves.pm
index 3a9efd0..1d0e4ab 100644 (file)
@@ -252,7 +252,7 @@ from C4::Circulation.
 
 =cut
 
-sub GetShelfContents ($$;$$) {
+sub GetShelfContents ($;$$$) {
     my ($shelfnumber, $row_count, $offset, $sortfield) = @_;
     my $dbh=C4::Context->dbh();
        my $sth1 = $dbh->prepare("SELECT count(*) FROM virtualshelfcontents WHERE shelfnumber = ?");
@@ -264,8 +264,8 @@ sub GetShelfContents ($$;$$) {
                ($sortfield) = $sth2->fetchrow_array;
        }
     my $query =
-       " SELECT vc.biblionumber, vc.shelfnumber, vc.dateadded,
-                               biblio.*, biblioitems.itemtype, itemtypes.*
+       " SELECT vc.biblionumber, vc.shelfnumber, vc.dateadded, itemtypes.*,
+                               biblio.*, biblioitems.itemtype, biblioitems.publicationyear
          FROM   virtualshelfcontents vc
                 LEFT JOIN biblio      ON      vc.biblionumber =      biblio.biblionumber
                 LEFT JOIN biblioitems ON  biblio.biblionumber = biblioitems.biblionumber
@@ -277,9 +277,11 @@ sub GetShelfContents ($$;$$) {
                $query .= " DESC " if ($sortfield eq 'copyrightdate');
                push (@params, $sortfield);
        }
-       $query .= " LIMIT ?, ? ";
-       push (@params, ($offset ? $offset : 0));
-       push (@params, $row_count);
+    if($row_count){
+          $query .= " LIMIT ?, ? ";
+          push (@params, ($offset ? $offset : 0));
+          push (@params, $row_count);
+    }
     my $sth3 = $dbh->prepare($query);
        $sth3->execute(@params);
        return ($sth3->fetchall_arrayref({}), $total);
@@ -471,6 +473,7 @@ sub ShelfPossibleAction {
     $sth->execute($shelfnumber);
     my ( $owner, $category ) = $sth->fetchrow;
        my $borrower = GetMemberDetails($user);
+       return 0 if not defined($user);
        return 1 if ( $category >= 3);                                                  # open list
     return 1 if (($category >= 2) and
                                defined($action) and $action eq 'view');        # public list, anybody can view