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
23 ###################################################################################
29 use List::Util qw/min/;
31 use C4::Auth; # get_template_and_user
34 use C4::Koha; # GetAuthorisedValue
35 use C4::Dates qw/format_date format_date_in_iso/;
36 use C4::Branch; # GetBranches
39 ###############################################################################
43 my $ordernumber = $input->param('ordernumber');
45 my $op = $input->param('op');
49 ###############################################################################
51 my $dbh = C4::Context->dbh;
52 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
55 "/suggestion/suggestiondetails.tmpl",
59 flagsrequired => { catalogue => 1 },
65 if ($op eq "add_confirm") {
67 ################################################################################################
68 ################################################################################################
69 ## modify a suggestion
70 ################################################################################################
71 ################################################################################################
73 ## 'bookfundgroupnumber', 'bookfundnumber', 'audiencenumber'
74 my $bookfundgroup_loop = $input->param('bookfundgroup_loop');
75 my $bookfund_loop = $input->param('bookfund_loop');
76 my $audience_loop = $input->param('audience_loop');
78 $bookfundgroup_loop = ($bookfundgroup_loop eq "")? undef : $bookfundgroup_loop;
79 $bookfund_loop = ($bookfund_loop eq "")? undef : $bookfund_loop;
80 $audience_loop = ($audience_loop eq "")? undef : $audience_loop;
83 ## modify the suggestion
84 my $dbh = C4::Context->dbh;
85 my $sth = $dbh->prepare('
96 , bookfundgroupnumber = ?
100 WHERE ordernumber = ?
105 $input->param('title')?$input->param('title'):"",
106 $input->param('author')?$input->param('author'):"",
107 $input->param('copyrightdate')?$input->param('copyrightdate'):"",
108 $input->param('isbn')?$input->param('isbn'):"",
109 $input->param('publishercode')?$input->param('publishercode'):"",
110 $input->param('seriestitle')?$input->param('seriestitle'):"",
111 $input->param('note')?$input->param('note'):"",
112 $input->param('itemtype')?$input->param('itemtype'):"",
113 $input->param('rrp')?$input->param('rrp'):undef,
115 $bookfundgroup_loop ? $bookfund_loop: undef,
116 $bookfundgroup_loop ? $audience_loop : undef,
117 $input->param('branch_loop')?$input->param('branch_loop'):"",
118 $input->param('ordernumber'),
123 if ($input->param("aorr")) {
126 $input->param('ordernumber'),
127 $input->param("aorr"),
128 $input->param('reason'),
139 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=acceptorreject.pl\"></html>";
146 ################################################################################################
147 ################################################################################################
148 ## display the suggestion details
149 ################################################################################################
150 ################################################################################################
154 my $chooseabookfund=0;
155 my $chooseanaudience=0;
156 my $bookfundgroupname;
159 my $itemtypedescription;
160 my @suggestion_loop1;
162 ###################################################################################
163 ## get the suggestion (from 'aq2orders')
164 ###################################################################################
166 my $dbh = C4::Context->dbh;
167 my $sth = $dbh->prepare("
173 $sth->execute($ordernumber);
174 my $suggestion = $sth->fetchrow_hashref;
175 my $bookfundgroupnumber=$suggestion->{'bookfundgroupnumber'};
176 my $bookfundnumber=$suggestion->{'bookfundnumber'};
177 my $branchcode=$suggestion->{'branchcode'};
178 my $itemtype=$suggestion->{'itemtype'};
179 my $audiencenumber=$suggestion->{'audiencenumber'};
180 my $step=$suggestion->{'step'};
184 ###################################################################################
185 ## get data from other tables
186 ###################################################################################
188 ## get data about book fund groups
189 ###################################################################################
191 my $dbh = C4::Context->dbh;
192 my $sth = $dbh->prepare("
193 SELECT bookfundgroupnumber, bookfundgroupname
194 FROM aq2bookfundgroups
195 ORDER BY bookfundgroupname
199 my @bookfundgroup_loop;
201 while (my $data = $sth->fetchrow_hashref) {
202 if ($data->{'bookfundgroupnumber'} eq $bookfundgroupnumber) {
204 $bookfundgroupname=$data->{'bookfundgroupname'};
206 else {$data->{selected}=0;}
207 push(@bookfundgroup_loop, $data);
211 if ($bookfundgroupnumber) {$chooseabookfund=1;$chooseanaudience=1;}
213 ## get data about book funds
214 ###################################################################################
216 if ($bookfundgroupnumber) {
217 my $dbh = C4::Context->dbh;
218 my $sth = $dbh->prepare("
219 SELECT bookfundnumber, bookfundname
221 WHERE bookfundgroupnumber=?
222 ORDER BY bookfundname
225 $sth->execute($bookfundgroupnumber);
227 while (my $data = $sth->fetchrow_hashref) {
229 if ($data->{'bookfundnumber'} eq $bookfundnumber) {
231 $bookfundname=$data->{'bookfundname'};
237 push(@bookfund_loop, $data);
243 ## get data about audiences
244 ###################################################################################
246 if ($bookfundgroupnumber) {
247 my $dbh = C4::Context->dbh;
248 my $sth = $dbh->prepare("
249 SELECT audiencenumber, audiencename
251 WHERE bookfundgroupnumber=?
252 ORDER BY audiencename
255 $sth->execute($bookfundgroupnumber);
257 ## get 'audiencenumber' value (in the table 'aq2orders')
259 while (my $data = $sth->fetchrow_hashref) {
260 if ($data->{'audiencenumber'} eq $audiencenumber) {
262 $audiencename = $data->{'audiencename'};
264 else {$data->{selected}=0;}
266 push(@audience_loop, $data);
273 ###################################################################################
274 my $branches = GetBranches;
278 foreach my $thisbranch (keys %$branches) {
279 my %row = (branchcode => $thisbranch,
280 branchname => $branches->{$thisbranch}->{'branchname'},
282 if ($thisbranch eq $branchcode) {
284 $branchname=$branches->{$thisbranch}->{'branchname'};
286 else {$row{"selected"}=0;}
288 push @branch_loop, \%row;
293 ###################################################################################
294 my $dbh = C4::Context->dbh;
295 my $sth=$dbh->prepare("
296 SELECT description,itemtype
298 ORDER BY description");
303 while ( my $data = $sth->fetchrow_hashref ) {
304 if ($data->{'itemtype'} eq $itemtype) {
306 $itemtypedescription=$data->{'description'};
308 else { $data->{selected}=0;}
309 push( @itemtypeloop, $data);
315 ###################################################################################
317 ## name of the person who 1st wrote the suggestion
319 my $dbh = C4::Context->dbh;
320 my $sth = $dbh->prepare("
321 SELECT firstname AS firstnamesuggestedby,
322 surname AS surnamesuggestedby
324 WHERE borrowernumber=?
326 $sth->execute($suggestion->{'suggestedby'});
327 my $namesuggestedby = $sth->fetchrow_hashref;
330 ## name of the person who managed the suggestion in the General Purchase Department
332 my $dbh = C4::Context->dbh;
333 my $sth = $dbh->prepare("
334 SELECT firstname AS firstnamemanagedingpdby,
335 surname AS surnamemanagedingpdby
337 WHERE borrowernumber=?
339 $sth->execute($suggestion->{'suggestionmanagedingpdby'});
340 my $namemanagedingpdby = $sth->fetchrow_hashref;
344 ## name of the person who managed the suggestion in a Purchase Department
346 my $dbh = C4::Context->dbh;
347 my $sth = $dbh->prepare("
348 SELECT firstname AS firstnamemanagedinpdby,
349 surname AS surnamemanagedinpdby
351 WHERE borrowernumber=?
353 $sth->execute($suggestion->{'suggestionmanagedinpdby'});
354 my $namemanagedinpdby = $sth->fetchrow_hashref;
357 if ($chooseabookfund) {
358 $template->param(chooseabookfund => $chooseabookfund,);
361 if ($chooseanaudience) {
362 $template->param(chooseanaudience => $chooseanaudience,);
366 ## list of reasons why a suggestion can be rejected
367 ###################################################################################
368 my $reasons_loop = GetAuthorisedValues("SUGGEST");
371 ################################################################################################
372 ################################################################################################
374 ################################################################################################
375 ################################################################################################
380 ordernumber => $ordernumber,
382 ## other variables from 'aq2orders'
383 ########################################################################################
385 title => $suggestion->{'title'},
386 author => $suggestion->{'author'},
387 copyrightdate => $suggestion->{'copyrightdate'},
388 isbn => $suggestion->{'isbn'},
389 rrp => $suggestion->{'rrp'},
390 publishercode => $suggestion->{'publishercode'},
391 seriestitle => $suggestion->{'seriestitle'},
392 note => $suggestion->{'note'},
393 status => $suggestion->{'status'},
394 reason => $suggestion->{'reason'},
396 bookfundgroupnumber => $bookfundgroupnumber,
398 ## dates (metric format)
399 suggestioncreatedon => format_date($suggestion->{'suggestioncreatedon'}),
400 suggestionmanagedingpdon => format_date($suggestion->{'suggestionmanagedingpdon'}),
401 suggestionmanagedinpdon => format_date($suggestion->{'suggestionmanagedinpdon'}),
404 step2 => ($step==2)?1:0,
405 step3 => ($step==3)?1:0,
406 step2ormore => ($step>=2)?1:0,
407 accepted1 =>(($suggestion->{'status'} eq 'ACCEPTED') and $step==1)?1:0,
408 accepted2 =>(($suggestion->{'status'} eq 'ACCEPTED') and $step==2)?1:0,
409 rejected1 =>(($suggestion->{'status'} eq 'REJECTED') and $step==1)?1:0,
410 rejected2 => (($suggestion->{'status'} eq 'REJECTED') and $step==2)?1:0,
413 ## variables from other tables
414 ########################################################################################
417 bookfundgroup_loop => \@bookfundgroup_loop,
418 bookfund_loop => \@bookfund_loop,
419 audience_loop => \@audience_loop,
420 branch_loop => \@branch_loop,
421 itemtypeloop => \@itemtypeloop,
422 reasons_loop => $reasons_loop,
425 branchname => $branchname,
426 bookfundgroupname => $bookfundgroupname,
427 bookfundname => $bookfundname,
428 audiencename => $audiencename,
429 itemtypedescription => $itemtypedescription,
431 ## names (person who 1st write the suggestion, persons who managed the suggestion)
432 firstnamesuggestedby => $namesuggestedby->{'firstnamesuggestedby'},
433 surnamesuggestedby => $namesuggestedby->{'surnamesuggestedby'},
435 firstnamemanagedingpdby =>$namemanagedingpdby->{'firstnamemanagedingpdby'},
436 surnamemanagedingpdby =>$namemanagedingpdby->{'surnamemanagedingpdby'},
438 firstnamemanagedinpdby =>$namemanagedinpdby->{'firstnamemanagedinpdby'},
439 surnamemanagedinpdby =>$namemanagedinpdby->{'surnamemanagedinpdby'},
443 ########################################################################################
445 template => C4::Context->preference('template'),
451 output_html_with_http_headers $input, $cookie, $template->output;