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');
44 my $bookfundgroupname = $input->param('bookfundgroupname');
46 my $op = $input->param('op');
48 my $bookfundgroupnumber = $input->param('bookfundgroupnumber');
51 my $dbh = C4::Context->dbh;
52 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
55 "/suggestion/suggestiondetailspd.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 $bookfund_loop = ($input->param('bookfund_loop') eq "")?undef:$input->param('bookfund_loop');
75 my $audience_loop = ($input->param('audience_loop') eq "")?undef:$input->param('audience_loop');
77 ## modify the suggestion
78 my $dbh = C4::Context->dbh;
79 my $sth = $dbh->prepare('
90 , bookfundgroupnumber = ?
99 $input->param('title')?$input->param('title'):"",
100 $input->param('author')?$input->param('author'):"",
101 $input->param('copyrightdate')?$input->param('copyrightdate'):"",
102 $input->param('isbn')?$input->param('isbn'):"",
103 $input->param('publishercode')?$input->param('publishercode'):"",
104 $input->param('seriestitle')?$input->param('seriestitle'):"",
105 $input->param('note')?$input->param('note'):"",
106 $input->param('itemtype')?$input->param('itemtype'):"",
107 $input->param('rrp')?$input->param('rrp'):undef,
108 $bookfundgroupnumber ? $bookfundgroupnumber : undef,
109 $bookfundgroupnumber ? $bookfund_loop: undef,
110 $bookfundgroupnumber ? $audience_loop : undef,
111 $input->param('branch_loop')?$input->param('branch_loop'):"",
112 $input->param('ordernumber'),
117 if ($input->param("aorr")) {
120 $input->param('ordernumber'),
121 $input->param("aorr"),
122 $input->param('reason'),
123 $bookfundgroupnumber,
134 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=acceptorrejectpd.pl?bookfundgroupnumber=".$bookfundgroupnumber."\"></html>";
140 ################################################################################################
141 ################################################################################################
142 ## display the suggestion details
143 ################################################################################################
144 ################################################################################################
147 my $chooseabookfund=0;
148 my $chooseanaudience=0;
149 my $bookfundgroupname;
152 my $itemtypedescription;
154 ###################################################################################
155 ## get the suggestion (from 'aq2orders')
156 ###################################################################################
158 my $dbh = C4::Context->dbh;
159 my $sth = $dbh->prepare("
165 $sth->execute($ordernumber);
166 my $suggestion = $sth->fetchrow_hashref;
167 my $bookfundgroupnumber=$suggestion->{'bookfundgroupnumber'};
168 my $bookfundnumber=$suggestion->{'bookfundnumber'};
169 my $branchcode=$suggestion->{'branchcode'};
170 my $itemtype=$suggestion->{'itemtype'};
171 my $audiencenumber=$suggestion->{'audiencenumber'};
172 my $step=$suggestion->{'step'};
176 ###################################################################################
177 ## get data from other tables
178 ###################################################################################
180 ## get data about book fund groups
181 ###################################################################################
183 my $dbh = C4::Context->dbh;
184 my $sth = $dbh->prepare("
185 SELECT bookfundgroupname
186 FROM aq2bookfundgroups
187 WHERE bookfundgroupnumber=?
190 $sth->execute($bookfundgroupnumber);
192 $bookfundgroupname = $sth->fetchrow_hashref->{'bookfundgroupname'};
196 ## get data about book funds
197 ###################################################################################
199 if ($bookfundgroupnumber) {
200 my $dbh = C4::Context->dbh;
201 my $sth = $dbh->prepare("
202 SELECT bookfundnumber, bookfundname
204 WHERE bookfundgroupnumber=?
205 ORDER BY bookfundname
208 $sth->execute($bookfundgroupnumber);
210 while (my $data = $sth->fetchrow_hashref) {
212 if ($data->{'bookfundnumber'} eq $bookfundnumber) {
214 $bookfundname=$data->{'bookfundname'};
220 push(@bookfund_loop, $data);
226 ## get data about audiences
227 ###################################################################################
229 if ($bookfundgroupnumber) {
230 my $dbh = C4::Context->dbh;
231 my $sth = $dbh->prepare("
232 SELECT audiencenumber, audiencename
234 WHERE bookfundgroupnumber=?
235 ORDER BY audiencename
238 $sth->execute($bookfundgroupnumber);
240 ## get 'audiencenumber' value (in the table 'aq2orders')
242 while (my $data = $sth->fetchrow_hashref) {
243 if ($data->{'audiencenumber'} eq $audiencenumber) {
245 $audiencename = $data->{'audiencename'};
247 else {$data->{selected}=0;}
249 push(@audience_loop, $data);
256 ###################################################################################
257 my $branches = GetBranches;
261 foreach my $thisbranch (keys %$branches) {
262 my %row = (branchcode => $thisbranch,
263 branchname => $branches->{$thisbranch}->{'branchname'},
265 if ($thisbranch eq $branchcode) {
267 $branchname=$branches->{$thisbranch}->{'branchname'};
269 else {$row{"selected"}=0;}
271 push @branch_loop, \%row;
276 ###################################################################################
277 my $dbh = C4::Context->dbh;
278 my $sth=$dbh->prepare("
279 SELECT description,itemtype
281 ORDER BY description");
286 while ( my $data = $sth->fetchrow_hashref ) {
287 if ($data->{'itemtype'} eq $itemtype) {
289 $itemtypedescription=$data->{'description'};
291 else { $data->{selected}=0;}
292 push( @itemtypeloop, $data);
298 ###################################################################################
300 ## name of the person who 1st wrote the suggestion
301 my $dbh = C4::Context->dbh;
302 my $sth = $dbh->prepare("
303 SELECT firstname AS firstnamesuggestedby,
304 surname AS surnamesuggestedby
306 WHERE borrowernumber=?
308 $sth->execute($suggestion->{'suggestedby'});
309 my $namesuggestedby = $sth->fetchrow_hashref;
312 ## name of the person who managed the suggestion in the General Purchase Department
314 my $dbh = C4::Context->dbh;
315 my $sth = $dbh->prepare("
316 SELECT firstname AS firstnamemanagedingpdby,
317 surname AS surnamemanagedingpdby
319 WHERE borrowernumber=?
321 $sth->execute($suggestion->{'suggestionmanagedingpdby'});
322 my $namemanagedingpdby = $sth->fetchrow_hashref;
326 ## name of the person who managed the suggestion in a Purchase Department
327 my $dbh = C4::Context->dbh;
328 my $sth = $dbh->prepare("
329 SELECT firstname AS firstnamemanagedinpdby,
330 surname AS surnamemanagedinpdby
332 WHERE borrowernumber=?
334 $sth->execute($suggestion->{'suggestionmanagedinpdby'});
335 my $namemanagedinpdby = $sth->fetchrow_hashref;
338 if ($chooseabookfund) {
339 $template->param(chooseabookfund => $chooseabookfund,);
340 warn "valeur de chooseabookfund = $chooseabookfund";
343 if ($chooseanaudience) {
344 $template->param(chooseanaudience => $chooseanaudience,);
345 warn "valeur de chooseanaudience = $chooseanaudience";
349 ## list of reasons why a suggestion can be rejected
350 ###################################################################################
352 my $reasons_loop = GetAuthorisedValues("SUGGEST");
355 ################################################################################################
356 ################################################################################################
358 ################################################################################################
359 ################################################################################################
363 ##argument en entrée du script
365 ordernumber => $ordernumber,
367 ## other variables from 'aq2orders'
368 ########################################################################################
370 title => $suggestion->{'title'},
371 author => $suggestion->{'author'},
372 copyrightdate => $suggestion->{'copyrightdate'},
373 isbn => $suggestion->{'isbn'},
374 rrp => $suggestion->{'rrp'},
375 publishercode => $suggestion->{'publishercode'},
376 seriestitle => $suggestion->{'seriestitle'},
377 note => $suggestion->{'note'},
378 reason => $suggestion->{'reason'},
379 reasons_loop => $reasons_loop,
380 bookfundgroupnumber => $bookfundgroupnumber,
381 bookfundgroup_loop => $bookfundgroupnumber,
383 ## dates 'metric format'
384 suggestioncreatedon => format_date($suggestion->{'suggestioncreatedon'}),
385 suggestionmanagedingpdon => format_date($suggestion->{'suggestionmanagedingpdon'}),
386 suggestionmanagedinpdon => format_date($suggestion->{'suggestionmanagedinpdon'}),
388 ## suggestions'status
389 status => $suggestion->{'status'},
390 step2 => ($step==2)?1:0,
391 step3 => ($step==3)?1:0,
392 step3ormore => ($step>=3)?1:0,
393 rejected3 => (($suggestion->{'status'} eq "REJECTED") and ($step==3))?1:0,
396 ## variables from other tables
397 ########################################################################################
400 bookfund_loop => \@bookfund_loop,
401 audience_loop => \@audience_loop,
402 branch_loop => \@branch_loop,
403 itemtypeloop => \@itemtypeloop,
405 ## names (person who 1st write the suggestion, persons who managed the suggestion)
406 firstnamesuggestedby => $namesuggestedby->{'firstnamesuggestedby'},
407 surnamesuggestedby => $namesuggestedby->{'surnamesuggestedby'},
409 firstnamemanagedingpdby =>$namemanagedingpdby->{'firstnamemanagedingpdby'},
410 surnamemanagedingpdby =>$namemanagedingpdby->{'surnamemanagedingpdby'},
412 firstnamemanagedinpdby =>$namemanagedinpdby->{'firstnamemanagedinpdby'},
413 surnamemanagedinpdby =>$namemanagedinpdby->{'surnamemanagedinpdby'},
416 branchname => $branchname,
417 bookfundgroupname => $bookfundgroupname,
418 bookfundname => $bookfundname,
419 audiencename => $audiencename,
420 itemtypedescription => $itemtypedescription,
422 template => C4::Context->preference('template'),
428 output_html_with_http_headers $input, $cookie, $template->output;