(Bug 3402) Serials issue name not escaped when passed forward to routing slip
[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 under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
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 CGI;
30 use C4::Koha;
31 use C4::Auth;
32 use C4::Dates;
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');
50 my $date_selected = $query->param('date_selected');
51 my $dbh = C4::Context->dbh;
52
53 if($op eq 'delete'){
54     delroutingmember($routingid,$subscriptionid);
55 }
56
57 if($op eq 'add'){
58     addroutingmember($borrowernumber,$subscriptionid);
59 }
60 if($op eq 'save'){
61     my $sth = $dbh->prepare("UPDATE serial SET routingnotes = ? WHERE subscriptionid = ?");
62     $sth->execute($notes,$subscriptionid);
63     my $urldate = URI::Escape::uri_escape($date_selected);
64     print $query->redirect("routing-preview.pl?subscriptionid=$subscriptionid&issue=$urldate");
65 }
66     
67 my ($routing, @routinglist) = getroutinglist($subscriptionid);
68 my $subs = GetSubscription($subscriptionid);
69 my ($count,@serials) = GetSerials($subscriptionid);
70 my ($serialdates) = GetLatestSerials($subscriptionid,$count);
71
72 my @dates;
73 my $i=0;
74 foreach my $dateseq (@$serialdates) {
75         $dates[$i]->{'planneddate'} = $dateseq->{'planneddate'};
76         $dates[$i]->{'serialseq'} = $dateseq->{'serialseq'};
77         $dates[$i]->{'serialid'} = $dateseq->{'serialid'};
78         if($date_selected eq $dateseq->{'serialid'}){
79             $dates[$i]->{'selected'} = ' selected';
80         } else {
81             $dates[$i]->{'selected'} = '';
82         }
83         $i++;
84 }
85
86 my ($template, $loggedinuser, $cookie)
87 = get_template_and_user({template_name => "serials/routing.tmpl",
88                                 query => $query,
89                                 type => "intranet",
90                                 authnotrequired => 0,
91                                 flagsrequired => {serials => 1},
92                                 debug => 1,
93                                 });
94 # my $date;
95 # if($serialseq){
96 #    for(my $i = 0;$i<@serials; $i++){
97 #       if($serials[$i]->{'serialseq'} eq $serialseq){
98 #           $date = $serials[$i]->{'planneddate'}
99 #       }
100 #    }
101 # } else {
102 #    $serialseq = $serials[0]->{'serialseq'};
103 #    $date = $serials[0]->{'planneddate'};
104 # }
105
106 # my $issue = "$serialseq ($date)";
107   
108 my @results;
109 my $data;
110 for(my $i=0;$i<$routing;$i++){
111     $data=GetMember($routinglist[$i]->{'borrowernumber'},'borrowernumber');
112     $data->{'location'}=$data->{'branchcode'};
113     $data->{'name'}="$data->{'firstname'} $data->{'surname'}";
114     $data->{'routingid'}=$routinglist[$i]->{'routingid'};
115     $data->{'subscriptionid'}=$subscriptionid;
116     my $rankingbox = '<select name="itemrank" onchange="reorder_item('.$subscriptionid.','.$routinglist[$i]->{'routingid'}.',this.options[this.selectedIndex].value)">';
117     for(my $j=1; $j <= $routing; $j++) {
118         $rankingbox .= "<option ";
119         if($routinglist[$i]->{'ranking'} == $j){
120             $rankingbox .= " selected=\"selected\"";
121         }
122         $rankingbox .= " value=\"$j\">$j</option>";
123     }
124     $rankingbox .= "</select>";
125     $data->{'routingbox'} = $rankingbox;
126     
127     push(@results, $data);
128 }
129
130 # for adding routing list
131 my $new;
132 if ($op eq 'new') {
133     $new = 1;
134 } else {
135 # for modify routing list default
136     $new = 0;
137 }
138
139 $template->param(
140     title => $subs->{'bibliotitle'},
141     subscriptionid => $subscriptionid,
142     memberloop => \@results,    
143     op => $new,
144     dates => \@dates,
145     routingnotes => $serials[0]->{'routingnotes'},
146     );
147
148         output_html_with_http_headers $query, $cookie, $template->output;