Bug 16166: Improve L1 cache performance and safety
[koha.git] / serials / routing.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha
4 #
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.
9 #
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.
14 #
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>.
17
18
19 =head1 Routing.pl
20
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
25
26 =cut
27
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;
37
38 use C4::Members;
39 use C4::Serials;
40
41 use URI::Escape;
42
43 my $query = new CGI;
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;
53
54 if($op eq 'delete'){
55     delroutingmember($routingid,$subscriptionid);
56 }
57
58 if($op eq 'add'){
59     addroutingmember($borrowernumber,$subscriptionid);
60 }
61 if($op eq 'save'){
62     my $sth = $dbh->prepare('UPDATE serial SET routingnotes = ? WHERE subscriptionid = ?');
63     $sth->execute($notes,$subscriptionid);
64     my $urldate = URI::Escape::uri_escape_utf8($date_selected);
65     print $query->redirect("routing-preview.pl?subscriptionid=$subscriptionid&issue=$urldate");
66 }
67
68 my @routinglist = getroutinglist($subscriptionid);
69 my $subs = GetSubscription($subscriptionid);
70 my ($count,@serials) = GetSerials($subscriptionid);
71 my $serialdates = GetLatestSerials($subscriptionid,$count);
72
73 my $dates = [];
74 foreach my $dateseq (@{$serialdates}) {
75     my $d = {};
76     $d->{publisheddate} = $dateseq->{publisheddate};
77     $d->{serialseq} = $dateseq->{serialseq};
78     $d->{serialid} = $dateseq->{serialid};
79     if($date_selected eq $dateseq->{serialid}){
80         $d->{selected} = ' selected';
81     } else {
82         $d->{selected} = q{};
83     }
84     push @{$dates}, $d;
85 }
86
87 my ($template, $loggedinuser, $cookie)
88 = get_template_and_user({template_name => 'serials/routing.tt',
89                                 query => $query,
90                                 type => 'intranet',
91                                 authnotrequired => 0,
92                                 flagsrequired => {serials => 'routing'},
93                                 debug => 1,
94                                 });
95
96 my $member_loop = [];
97 for my $routing ( @routinglist ) {
98     my $member=GetMember('borrowernumber' => $routing->{borrowernumber});
99     $member->{location} = $member->{branchcode};
100     if ($member->{firstname} ) {
101         $member->{name} = $member->{firstname} . q| |;
102     }
103     else {
104         $member->{name} = q{};
105     }
106     if ($member->{surname} ) {
107         $member->{name} .= $member->{surname};
108     }
109     $member->{routingid}=$routing->{routingid} || q{};
110     $member->{ranking} = $routing->{ranking} || q{};
111
112     push(@{$member_loop}, $member);
113 }
114
115 $template->param(
116     title => $subs->{bibliotitle},
117     subscriptionid => $subscriptionid,
118     memberloop => $member_loop,
119     op => $op eq 'new',
120     dates => $dates,
121     routingnotes => $serials[0]->{'routingnotes'},
122     hasRouting => check_routing($subscriptionid),
123     (uc(C4::Context->preference("marcflavour"))) => 1
124
125     );
126
127 output_html_with_http_headers $query, $cookie, $template->output;