Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 181 lines (163 sloc) 5.362 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
#!/usr/bin/env perl

# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA


=head1 view_holdsqueue

This script displays items in the tmp_holdsqueue and hold_fill_targets tables

=cut

use strict;
use warnings;
use CGI;
use C4::Auth;
use C4::Output;
#use C4::Items;
#use C4::Koha; # GetItemTypes
use C4::Branch;
use C4::Reserves;

my $query = new CGI;
my $run_report = $query->param('run_report');
my $run_pass = $query->param('run_pass');
my $branchlimit = $query->param('branchlimit') // '';
#my $limit = $query->param('limit') // 20;
my $limit = 0;
my $currPage = $query->param('currPage') // 1;
my $orderby = $query->param('orderby') // 'tmp_holdsqueue.title';
#my $offset = ($currPage -1)*$limit;
my $offset = 0;
my $total = 0;
my $qitems = [];

my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
    {
        template_name => 'circ/view_holdsqueue.tmpl',
        query => $query,
        type => "intranet",
        authnotrequired => 0,
        flagsrequired => { circulate => "circulate_remaining_permissions" },
        debug => 1,
    }
);
$template->param(
   currPage => $currPage,
   limit => $limit,
);

if ($run_pass) {
   ($total,$qitems) = C4::Reserves::GetHoldsQueueItems(
      branch => $branchlimit,
      offset => $offset,
      limit => $limit,
      orderby => $orderby,
   );
   my $c = 0;
   my @qbranches = C4::Reserves::getBranchesQueueWeight();
   foreach my $item(@$qitems) {
      my $action = $query->param("action_$c") // '';
      my @actions = qw(pass trace);
      if ($action ~~ @actions) {
         my $res = C4::Reserves::GetReserve($$item{reservenumber});
         if ($action eq 'pass') { C4::Reserves::ModReservePass($res,@qbranches) }
         elsif ($action eq 'trace') { C4::Reserves::ModReserveTrace($res)}
      }
      $c++;
   }
   $run_report = 1;
}

if ($run_report) {
   $total = 0;
   $qitems = [];
    ($total,$qitems) = C4::Reserves::GetHoldsQueueItems(
      branch => $branchlimit,
      limit => $limit,
      offset => $offset,
      orderby=> $orderby,
    );
    my $c = 0;
    foreach my $item(@$qitems) {
       $$item{action_cnt} = $c;
       my @qbranches = split(/\,/,$$item{queue_sofar});
       @qbranches = reverse @qbranches;
       $qbranches[0] = "<i><b>$qbranches[0]</b></i>";
       $$item{branches_sentto} = join("<br>\n",@qbranches);
       $c++;
    }

    $template->param(
        itemsloop => $qitems,
        run_report => $run_report,
        action_cnts=> $c,
        dateformat => C4::Context->preference("dateformat"),
    );
}

if ($run_report || $run_pass) {
   $template->param(
      total => $total,
      from => ($offset+1),
      to => ($total< ($offset+$limit))? $total: ($offset+$limit),
      pager => _pager(),
      branch => $branchlimit || '',
      branchlimit => $branchlimit || '',
      branchname => $branchlimit? C4::Branch::GetBranchName($branchlimit) : 'ALL',
      orderby => $orderby,
   );
}
$template->param(
   branchloop => GetBranchesLoop(C4::Context->userenv->{'branch'}),
);

# writing the template
output_html_with_http_headers $query, $cookie, $template->output;
exit;

sub _pager
{
   my $out = '';
   return '' unless ($limit && $total);
   my $totalPages = $total%$limit? int($total/$limit)+1 : $total/$limit;
   return $out if $totalPages == 1;
   if ($currPage==1) {
      $out .= ' <b>1</b>';
   }
   else {
      my $prev = $currPage -1;
      $out = qq|<a href="javascript:;" onclick="pager(1)">&lt;&lt;</a>
<a href="javascript:;" onclick="pager($prev)">&lt;</a>
<a href="javascript:;" onclick="pager(1)">1</a>|;
   }
   if ($currPage-2 >2) {
      $out .= ' ... ';
   }

   my $lastI = 0;
   for my $i($currPage-2..$currPage+2) {
      next if $i<2;
      if ($i==$currPage) {
         $out .= " <b>$i</b>";
      }
      else {
         $out .= qq| <a href="javascript:;" onclick="pager($i)">$i</a>|;
      }
      $lastI = $i;
      last if $i+1 >=$totalPages;
   }
   if ($currPage+3 < $totalPages) {
      $out .= ' ... ';
   }

   if ($currPage != $totalPages) {
      my $next = $currPage +1;
      $out .= qq| <a href="javascript:;" onclick="pager($totalPages);">$totalPages</a>|
      if $lastI != $totalPages;
      $out .= qq| <a href="javascript:;" onclick="pager($next);">&gt;</a>
<a href="javascript:;" onclick="pager($totalPages);">&gt;&gt;</a>|;
   }
   else {
      $out .= " <b>$totalPages</b>" if $lastI != $totalPages;
   }

   return qq|<div style="font-size:10pt;">$out</div><br>|;
}

__END__
Something went wrong with that request. Please try again.