bug 3120: tweak splitting of Dewey call number
[koha.git] / circ / view_holdsqueue.pl
index 3abe39e..920f852 100755 (executable)
@@ -23,6 +23,7 @@ This script displays items in the tmp_holdsqueue table
 =cut
 
 use strict;
+use warnings;
 use CGI;
 use C4::Auth;
 use C4::Output;
@@ -39,7 +40,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
         query           => $query,
         type            => "intranet",
         authnotrequired => 0,
-        flagsrequired   => { circulate => 1 },
+        flagsrequired   => { circulate => "circulate_remaining_permissions" },
         debug           => 1,
     }
 );
@@ -92,10 +93,21 @@ $template->param( branchloop     => \@branchloop,
 sub GetHoldsQueueItems {
        my ($branchlimit,$itemtypelimit) = @_;
        my $dbh = C4::Context->dbh;
-       my $query = "SELECT * FROM tmp_holdsqueue";
-       $query.=" WHERE holdingbranch = \"$branchlimit\"" if $branchlimit;
+
+    my @bind_params = ();
+       my $query = q/SELECT tmp_holdsqueue.*, biblio.author, items.ccode, items.location, items.enumchron, items.cn_sort, biblioitems.publishercode,biblio.copyrightdate,biblioitems.publicationyear,biblioitems.pages,biblioitems.size,biblioitems.publicationyear,biblioitems.isbn
+                  FROM tmp_holdsqueue
+                  JOIN biblio USING (biblionumber)
+                                 LEFT JOIN biblioitems USING (biblionumber)
+                  LEFT JOIN items USING (itemnumber)
+                /;
+    if ($branchlimit) {
+           $query .=" WHERE tmp_holdsqueue.holdingbranch = ?";
+        push @bind_params, $branchlimit;
+    }
+    $query .= " ORDER BY ccode, location, cn_sort, author, title, pickbranch, reservedate";
        my $sth = $dbh->prepare($query);
-       $sth->execute();
+       $sth->execute(@bind_params);
        my $items = [];
     while ( my $row = $sth->fetchrow_hashref ){
                $row->{reservedate} = format_date($row->{reservedate});