Bug 23091: Add tests for _RestoreOverdueForLostAndFound
[koha.git] / serials / routing.pl
blob6a237f6f6ea952b421f6080429cad03ad3bc7570
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 Modern::Perl;
29 use CGI qw ( -utf8 );
30 use C4::Koha;
31 use C4::Auth;
32 use C4::Output;
33 use C4::Acquisition;
34 use C4::Output;
35 use C4::Context;
37 use C4::Members;
38 use C4::Serials;
39 use Koha::Patrons;
41 use URI::Escape;
43 my $query = CGI->new;
44 my $subscriptionid = $query->param('subscriptionid');
45 my $serialseq = $query->param('serialseq');
46 my $routingid = $query->param('routingid');
47 my $borrowernumber = $query->param('borrowernumber');
48 my $notes = $query->param('notes');
49 my $op = $query->param('op') || q{};
50 my $date_selected = $query->param('date_selected');
51 $date_selected ||= q{};
52 my $dbh = C4::Context->dbh;
54 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
56 template_name => 'serials/routing.tt',
57 query => $query,
58 type => 'intranet',
59 flagsrequired => { serials => 'routing' },
63 my $subs = GetSubscription($subscriptionid);
65 output_and_exit( $query, $cookie, $template, 'unknown_subscription')
66 unless $subs;
68 if($op eq 'delete'){
69 delroutingmember($routingid,$subscriptionid);
72 if($op eq 'add'){
73 addroutingmember($borrowernumber,$subscriptionid);
75 if($op eq 'save'){
76 my $sth = $dbh->prepare('UPDATE serial SET routingnotes = ? WHERE subscriptionid = ?');
77 $sth->execute($notes,$subscriptionid);
78 my $urldate = URI::Escape::uri_escape_utf8($date_selected);
79 print $query->redirect("routing-preview.pl?subscriptionid=$subscriptionid&issue=$urldate");
82 my @routinglist = getroutinglist($subscriptionid);
84 my ($count,@serials) = GetSerials($subscriptionid);
85 my $serialdates = GetLatestSerials($subscriptionid,$count);
87 my $dates = [];
88 foreach my $dateseq (@{$serialdates}) {
89 my $d = {};
90 $d->{publisheddate} = $dateseq->{publisheddate};
91 $d->{serialseq} = $dateseq->{serialseq};
92 $d->{serialid} = $dateseq->{serialid};
93 if($date_selected eq $dateseq->{serialid}){
94 $d->{selected} = ' selected';
95 } else {
96 $d->{selected} = q{};
98 push @{$dates}, $d;
101 my $member_loop = [];
102 for my $routing ( @routinglist ) {
103 my $member = Koha::Patrons->find( $routing->{borrowernumber} )->unblessed;
104 $member->{location} = $member->{branchcode};
105 if ($member->{firstname} ) {
106 $member->{name} = $member->{firstname} . q| |;
108 else {
109 $member->{name} = q{};
111 if ($member->{surname} ) {
112 $member->{name} .= $member->{surname};
114 $member->{routingid}=$routing->{routingid} || q{};
115 $member->{ranking} = $routing->{ranking} || q{};
117 push(@{$member_loop}, $member);
120 $template->param(
121 title => $subs->{bibliotitle},
122 subscriptionid => $subscriptionid,
123 memberloop => $member_loop,
124 op => $op eq 'new',
125 dates => $dates,
126 routingnotes => $serials[0]->{'routingnotes'},
127 hasRouting => check_routing($subscriptionid),
128 (uc(C4::Context->preference("marcflavour"))) => 1
132 output_html_with_http_headers $query, $cookie, $template->output;