fix "Add Tag" button in MARC framework editor
[koha.git] / serials / routing.pl
blobd84076a49049c72dd8e96456ec87671b1ff116ad
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 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;
38 use C4::Members;
39 use C4::Serials;
41 my $query = new CGI;
42 my $subscriptionid = $query->param('subscriptionid');
43 my $serialseq = $query->param('serialseq');
44 my $routingid = $query->param('routingid');
45 my $borrowernumber = $query->param('borrowernumber');
46 my $notes = $query->param('notes');
47 my $op = $query->param('op');
48 my $date_selected = $query->param('date_selected');
49 my $dbh = C4::Context->dbh;
51 if($op eq 'delete'){
52 delroutingmember($routingid,$subscriptionid);
55 if($op eq 'add'){
56 addroutingmember($borrowernumber,$subscriptionid);
58 if($op eq 'save'){
59 my $sth = $dbh->prepare("UPDATE serial SET routingnotes = ? WHERE subscriptionid = ?");
60 $sth->execute($notes,$subscriptionid);
61 print $query->redirect("routing-preview.pl?subscriptionid=$subscriptionid&issue=$date_selected");
64 my ($routing, @routinglist) = getroutinglist($subscriptionid);
65 my $subs = GetSubscription($subscriptionid);
66 my ($count,@serials) = GetSerials($subscriptionid);
67 my ($serialdates) = GetLatestSerials($subscriptionid,$count);
69 my @dates;
70 my $i=0;
71 foreach my $dateseq (@$serialdates) {
72 $dates[$i]->{'planneddate'} = $dateseq->{'planneddate'};
73 $dates[$i]->{'serialseq'} = $dateseq->{'serialseq'};
74 $dates[$i]->{'serialid'} = $dateseq->{'serialid'};
75 if($date_selected eq $dateseq->{'serialid'}){
76 $dates[$i]->{'selected'} = ' selected';
77 } else {
78 $dates[$i]->{'selected'} = '';
80 $i++;
83 my ($template, $loggedinuser, $cookie)
84 = get_template_and_user({template_name => "serials/routing.tmpl",
85 query => $query,
86 type => "intranet",
87 authnotrequired => 0,
88 flagsrequired => {serials => 1},
89 debug => 1,
90 });
91 # my $date;
92 # if($serialseq){
93 # for(my $i = 0;$i<@serials; $i++){
94 # if($serials[$i]->{'serialseq'} eq $serialseq){
95 # $date = $serials[$i]->{'planneddate'}
96 # }
97 # }
98 # } else {
99 # $serialseq = $serials[0]->{'serialseq'};
100 # $date = $serials[0]->{'planneddate'};
103 # my $issue = "$serialseq ($date)";
105 my @results;
106 my $data;
107 for(my $i=0;$i<$routing;$i++){
108 $data=GetMember($routinglist[$i]->{'borrowernumber'},'borrowernumber');
109 $data->{'location'}=$data->{'streetaddress'};
110 $data->{'name'}="$data->{'firstname'} $data->{'surname'}";
111 $data->{'routingid'}=$routinglist[$i]->{'routingid'};
112 $data->{'subscriptionid'}=$subscriptionid;
113 my $rankingbox = '<select name="itemrank" onchange="reorder_item('.$subscriptionid.','.$routinglist[$i]->{'routingid'}.',this.options[this.selectedIndex].value)">';
114 for(my $j=1; $j <= $routing; $j++) {
115 $rankingbox .= "<option ";
116 if($routinglist[$i]->{'ranking'} == $j){
117 $rankingbox .= " selected=\"selected\"";
119 $rankingbox .= " value=\"$j\">$j</option>";
121 $rankingbox .= "</select>";
122 $data->{'routingbox'} = $rankingbox;
124 push(@results, $data);
127 # for adding routing list
128 my $new;
129 if ($op eq 'new') {
130 $new = 1;
131 } else {
132 # for modify routing list default
133 $new = 0;
136 $template->param(
137 title => $subs->{'bibliotitle'},
138 subscriptionid => $subscriptionid,
139 memberloop => \@results,
140 op => $new,
141 dates => \@dates,
142 routingnotes => $serials[0]->{'routingnotes'},
145 output_html_with_http_headers $query, $cookie, $template->output;