bug: sticky due date isn't stick if there is a question about an issue
[koha_fer] / circ / view_holdsqueue.pl
index 74cf9b4..a52400b 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   => { circulation => 1 },
+        flagsrequired   => { circulate => 1 },
         debug           => 1,
     }
 );
@@ -64,7 +65,7 @@ if ( $run_report ) {
 my $branches = GetBranches;
 my $branch   = C4::Context->userenv->{"branchname"};
 my @branchloop;
-foreach my $thisbranch ( keys %$branches ) {
+foreach my $thisbranch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches ) {
     my $selected = 1 if $thisbranch eq $branch;
     my %row = (
         value      => $thisbranch,
@@ -92,10 +93,20 @@ $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
+                  FROM tmp_holdsqueue
+                  JOIN biblio USING (biblionumber)
+                  LEFT JOIN items USING (itemnumber)
+                /;
+    if ($branchlimit) {
+           $query .=" WHERE 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});