Followup 300bd572d3d21bbde1e91e8682611ad224992a7a
[koha.git] / serials / routing.pl
blob9580dca8d7de6922bcf0c4c5bc1419d73acb1d21
1 #!/usr/bin/perl
3 # This file is part of Koha
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.
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.
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
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;
31 use C4::Koha;
32 use C4::Auth;
33 use C4::Dates;
34 use C4::Output;
35 use C4::Acquisition;
36 use C4::Output;
37 use C4::Context;
39 use C4::Members;
40 use C4::Serials;
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 my $dbh = C4::Context->dbh;
54 if($op eq 'delete'){
55 delroutingmember($routingid,$subscriptionid);
58 if($op eq 'add'){
59 addroutingmember($borrowernumber,$subscriptionid);
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($date_selected);
65 print $query->redirect("routing-preview.pl?subscriptionid=$subscriptionid&issue=$urldate");
68 my ($routing, @routinglist) = getroutinglist($subscriptionid);
69 my $subs = GetSubscription($subscriptionid);
70 my ($count,@serials) = GetSerials($subscriptionid);
71 my ($serialdates) = GetLatestSerials($subscriptionid,$count);
73 my @dates;
74 my $i=0;
75 foreach my $dateseq (@$serialdates) {
76 $dates[$i]->{'planneddate'} = $dateseq->{'planneddate'};
77 $dates[$i]->{'serialseq'} = $dateseq->{'serialseq'};
78 $dates[$i]->{'serialid'} = $dateseq->{'serialid'};
79 if($date_selected eq $dateseq->{'serialid'}){
80 $dates[$i]->{'selected'} = ' selected';
81 } else {
82 $dates[$i]->{'selected'} = '';
84 $i++;
87 my ($template, $loggedinuser, $cookie)
88 = get_template_and_user({template_name => "serials/routing.tmpl",
89 query => $query,
90 type => "intranet",
91 authnotrequired => 0,
92 flagsrequired => {serials => 1},
93 debug => 1,
94 });
95 # my $date;
96 # if($serialseq){
97 # for(my $i = 0;$i<@serials; $i++){
98 # if($serials[$i]->{'serialseq'} eq $serialseq){
99 # $date = $serials[$i]->{'planneddate'}
102 # } else {
103 # $serialseq = $serials[0]->{'serialseq'};
104 # $date = $serials[0]->{'planneddate'};
107 # my $issue = "$serialseq ($date)";
109 my @results;
110 my $data;
111 for(my $i=0;$i<$routing;$i++){
112 $data=GetMember('borrowernumber' => $routinglist[$i]->{'borrowernumber'});
113 $data->{'location'}=$data->{'branchcode'};
114 if ($data->{firstname} ) {
115 $data->{name} = $data->{firstname} . q| |;
117 else {
118 $data->{name} = q{};
120 if ($data->{surname} ) {
121 $data->{name} .= $data->{surname};
123 $data->{'routingid'}=$routinglist[$i]->{'routingid'};
124 $data->{'subscriptionid'}=$subscriptionid;
125 if (! $routinglist[$i]->{routingid} ) {
126 $routinglist[$i]->{routingid} = q||;
128 my $rankingbox = '<select name="itemrank" onchange="reorder_item('
129 . $subscriptionid . ',' .$routinglist[$i]->{'routingid'} . ',this.options[this.selectedIndex].value)">';
130 for(my $j=1; $j <= $routing; $j++) {
131 $rankingbox .= "<option ";
132 if($routinglist[$i]->{ranking} && $routinglist[$i]->{ranking} == $j){
133 $rankingbox .= " selected=\"selected\"";
135 $rankingbox .= " value=\"$j\">$j</option>";
137 $rankingbox .= "</select>";
138 $data->{'routingbox'} = $rankingbox;
140 push(@results, $data);
143 # for adding routing list
144 my $new;
145 if ($op eq 'new') {
146 $new = 1;
147 } else {
148 # for modify routing list default
149 $new = 0;
152 $template->param(
153 title => $subs->{'bibliotitle'},
154 subscriptionid => $subscriptionid,
155 memberloop => \@results,
156 op => $new,
157 dates => \@dates,
158 routingnotes => $serials[0]->{'routingnotes'},
161 output_html_with_http_headers $query, $cookie, $template->output;