Bug 19059: Remove CancelReserve
[koha.git] / serials / routing.pl
blobaf23b6cffd1526a98471c41536f2e9c2a0acab01
1 #!/usr/bin/perl
3 # This file is part of Koha
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19 =head1 Routing.pl
21 script used to create a routing list for a serial subscription
22 In this instance it is in fact a setting up of a list of reserves for the item
23 where the hierarchical order can be changed on the fly and a routing list can be
24 printed out
26 =cut
28 use strict;
29 use warnings;
30 use CGI qw ( -utf8 );
31 use C4::Koha;
32 use C4::Auth;
33 use C4::Output;
34 use C4::Acquisition;
35 use C4::Output;
36 use C4::Context;
38 use C4::Members;
39 use C4::Serials;
40 use Koha::Patrons;
42 use URI::Escape;
44 my $query = new CGI;
45 my $subscriptionid = $query->param('subscriptionid');
46 my $serialseq = $query->param('serialseq');
47 my $routingid = $query->param('routingid');
48 my $borrowernumber = $query->param('borrowernumber');
49 my $notes = $query->param('notes');
50 my $op = $query->param('op') || q{};
51 my $date_selected = $query->param('date_selected');
52 $date_selected ||= q{};
53 my $dbh = C4::Context->dbh;
55 if($op eq 'delete'){
56 delroutingmember($routingid,$subscriptionid);
59 if($op eq 'add'){
60 addroutingmember($borrowernumber,$subscriptionid);
62 if($op eq 'save'){
63 my $sth = $dbh->prepare('UPDATE serial SET routingnotes = ? WHERE subscriptionid = ?');
64 $sth->execute($notes,$subscriptionid);
65 my $urldate = URI::Escape::uri_escape_utf8($date_selected);
66 print $query->redirect("routing-preview.pl?subscriptionid=$subscriptionid&issue=$urldate");
69 my @routinglist = getroutinglist($subscriptionid);
70 my $subs = GetSubscription($subscriptionid);
71 my ($count,@serials) = GetSerials($subscriptionid);
72 my $serialdates = GetLatestSerials($subscriptionid,$count);
74 my $dates = [];
75 foreach my $dateseq (@{$serialdates}) {
76 my $d = {};
77 $d->{publisheddate} = $dateseq->{publisheddate};
78 $d->{serialseq} = $dateseq->{serialseq};
79 $d->{serialid} = $dateseq->{serialid};
80 if($date_selected eq $dateseq->{serialid}){
81 $d->{selected} = ' selected';
82 } else {
83 $d->{selected} = q{};
85 push @{$dates}, $d;
88 my ($template, $loggedinuser, $cookie)
89 = get_template_and_user({template_name => 'serials/routing.tt',
90 query => $query,
91 type => 'intranet',
92 authnotrequired => 0,
93 flagsrequired => {serials => 'routing'},
94 debug => 1,
95 });
97 my $member_loop = [];
98 for my $routing ( @routinglist ) {
99 my $member = Koha::Patrons->find( $routing->{borrowernumber} )->unblessed;
100 $member->{location} = $member->{branchcode};
101 if ($member->{firstname} ) {
102 $member->{name} = $member->{firstname} . q| |;
104 else {
105 $member->{name} = q{};
107 if ($member->{surname} ) {
108 $member->{name} .= $member->{surname};
110 $member->{routingid}=$routing->{routingid} || q{};
111 $member->{ranking} = $routing->{ranking} || q{};
113 push(@{$member_loop}, $member);
116 $template->param(
117 title => $subs->{bibliotitle},
118 subscriptionid => $subscriptionid,
119 memberloop => $member_loop,
120 op => $op eq 'new',
121 dates => $dates,
122 routingnotes => $serials[0]->{'routingnotes'},
123 hasRouting => check_routing($subscriptionid),
124 (uc(C4::Context->preference("marcflavour"))) => 1
128 output_html_with_http_headers $query, $cookie, $template->output;