3 # Copyright 2008 BibLibre, Olivier SAURY
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
28 this script modify the status of a subscription to ACCEPTED or to REJECTED
37 * aorr_confirm : to confirm accept or reject
38 * accepted : to display only accepted.
39 * rejected : to display only rejected.
47 ###################################################################################
53 use C4::Auth; # get_template_and_user
56 use C4::Koha; # GetAuthorisedValue
57 use C4::Dates qw/format_date format_date_in_iso/;
61 ###################################################################################
65 my $bookfundgroupnumber = $input->param('bookfundgroupnumber');
66 my $op = $input->param('op') || "aorr_confirm";
69 my $bookfundgroupname;
72 my $dbh = C4::Context->dbh;
74 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
76 template_name => "suggestion/acceptorrejectpd.tmpl",
80 flagsrequired => { catalogue => 1 },
87 ###################################################################################
88 ###################################################################################
89 ## modify suggestions'status. Choose a list of suggestions
90 ###################################################################################
91 ###################################################################################
94 if ( $op eq "aorr_confirm" ) {
96 ## modify suggestions'status
97 ###################################################################################
99 my @suggestionlist = $input->param("aorr");
101 foreach my $suggestion (@suggestionlist) {
102 if ( $suggestion =~ /(A|R)(.*)/ ) {
104 my ( $newstatus, $ordernumber ) = ( $1, $2 );
105 $newstatus = "REJECTED" if $newstatus eq "R";
106 $newstatus = "ACCEPTED" if $newstatus eq "A";
107 my $reason = $input->param( "reason" . $ordernumber );
108 if ( $reason eq "other" ) {
109 $reason = $input->param( "other-reason" . $ordernumber );
112 my $bookfundnumber = $input->param( "bookfunds_loop".$ordernumber);
113 my $step = $input->param( "step".$ordernumber);
119 $bookfundgroupnumber,
129 $suggestion_loop0 = &SearchSuggestion("", "", "", "", 'ASKED', "","",2,$bookfundgroupnumber);
133 if ( $op eq "accepted" ) {
135 ## accepted suggestions
136 ###################################################################################
138 $suggestion_loop0 = &GetSuggestionByStatus('ACCEPTED',3,$bookfundgroupnumber);
139 $template->param(done => 1);
143 if ( $op eq "rejected" ) {
145 ## rejected suggestions
146 ###################################################################################
148 $suggestion_loop0 = &GetSuggestionByStatus('REJECTED',3,$bookfundgroupnumber);
149 $template->param(done => 1);
153 ## book fund group name
154 #########################################################################################
155 my $dbh = C4::Context->dbh;
156 my $sth = $dbh->prepare("
157 SELECT bookfundgroupname
158 FROM aq2bookfundgroups
159 WHERE bookfundgroupnumber=?
161 $sth->execute($bookfundgroupnumber);
162 my $data = $sth->fetchrow_hashref;
163 $bookfundgroupname = $data->{'bookfundgroupname'};
168 foreach my $suggestion (@$suggestion_loop0) {
170 ###################################################################################
171 ###################################################################################
172 ## get more information about suggestions
173 ###################################################################################
174 ###################################################################################
178 $suggestion->{'reasonsloop'} = GetAuthorisedValues("SUGGEST");
181 $suggestion->{'suggestioncreatedon'} = format_date($suggestion->{'suggestioncreatedon'});
182 $suggestion->{'suggestionmanagedingpdon'} = format_date($suggestion->{'suggestionmanagedingpdon'});
183 $suggestion->{'suggestionmanagedinpdon'} =
184 format_date($suggestion->{'suggestionmanagedinpdon'});
188 ###############################################################################
189 my $dbh = C4::Context->dbh;
190 my $sth = $dbh->prepare("
191 SELECT bookfundnumber, bookfundname
193 WHERE bookfundgroupnumber=?
194 ORDER BY bookfundname
196 $sth->execute($bookfundgroupnumber);
200 while (my $data = $sth->fetchrow_hashref) {
202 ## book fund number of the suggestion
203 $data->{selected}=($data->{'bookfundnumber'} eq $suggestion->{'bookfundnumber'})? 1:0;
205 ## book fund name of the suggestion
206 if ($data->{'bookfundnumber'} eq $suggestion->{'bookfundnumber'}) {
207 $suggestion->{'bookfundname'} = $data->{'bookfundname'};
210 push( @bookfunds_loop, $data);
214 $suggestion->{'bookfunds_loop'} = \@bookfunds_loop;
217 ## name of the person who managed the suggestion in the General Purchase Department
218 ###################################################################################
220 my $dbh = C4::Context->dbh;
221 my $sth = $dbh->prepare("
222 SELECT firstname AS firstnamemanagedingpdby,
223 surname AS surnamemanagedingpdby
225 WHERE borrowernumber=?
227 $sth->execute($suggestion->{'suggestionmanagedingpdby'});
228 my $namemanagedingpdby = $sth->fetchrow_hashref;
230 $suggestion->{'firstnamemanagedingpdby'} = $namemanagedingpdby->{'firstnamemanagedingpdby'};
231 $suggestion->{'surnamemanagedingpdby'} = $namemanagedingpdby->{'surnamemanagedingpdby'};
234 ## name of the person who managed the suggestion in a Purchase Department
235 ###################################################################################
236 my $dbh = C4::Context->dbh;
237 my $sth = $dbh->prepare("
238 SELECT firstname AS firstnamemanagedinpdby,
239 surname AS surnamemanagedinpdby
241 WHERE borrowernumber=?
243 $sth->execute($suggestion->{'suggestionmanagedinpdby'});
244 my $namemanagedinpdby = $sth->fetchrow_hashref;
246 $suggestion->{'firstnamemanagedinpdby'} = $namemanagedinpdby->{'firstnamemanagedinpdby'};
247 $suggestion->{'surnamemanagedinpdby'} = $namemanagedinpdby->{'surnamemanagedinpdby'};
250 ## insert the suggestion into the table of suggestions
251 ################################################################################
252 push @suggestions_loop, $suggestion ;
255 ###################################################################################
257 ###################################################################################
261 suggestions_loop => \@suggestions_loop,
262 bookfundgroupnumber => $bookfundgroupnumber,
263 bookfundgroupname => $bookfundgroupname,
267 output_html_with_http_headers $input, $cookie, $template->output;