Replaced CGI dropdown box call wich is deprecated
[koha.git] / serials / claims.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 use strict;
19 use warnings;
20 use CGI;
21 use C4::Auth;
22 use C4::Serials;
23 use C4::Acquisition;
24 use C4::Output;
25 use C4::Bookseller;
26 use C4::Context;
27 use C4::Letters;
28 my $input = CGI->new;
29
30 my $serialid = $input->param('serialid');
31 my $op = $input->param('op');
32 my $claimletter = $input->param('claimletter');
33 my $supplierid = $input->param('supplierid');
34 my $suppliername = $input->param('suppliername');
35 my $order = $input->param('order');
36 my $supplierlist = GetSuppliersWithLateIssues();
37 if ($supplierid) {
38     foreach my $s ( @{$supplierlist} ) {
39         if ($s->{id} == $supplierid ) {
40             $s->{selected} = 1;
41             last;
42         }
43     }
44 }
45
46 # open template first (security & userenv set here)
47 my ($template, $loggedinuser, $cookie)
48 = get_template_and_user({template_name => 'serials/claims.tmpl',
49             query => $input,
50             type => 'intranet',
51             authnotrequired => 0,
52             flagsrequired => {serials => 'claim_serials'},
53             debug => 1,
54             });
55
56 my @suploop;
57 for ( sort {$supplierlist{$a} cmp $supplierlist{$b} } keys %supplierlist ) {
58     my ($count, @dummy) = GetLateOrMissingIssues($_, "", $order);
59     push @suploop, {
60         id       => $_,
61         name     => $supplierlist{$_},
62         count    => $count,
63         selected => $_ == $supplierid,
64     };
65 }
66
67 my $letters = GetLetters('claimissues');
68 my @letters;
69 foreach (keys %{$letters}){
70     push @letters ,{code=>$_,name=> $letters->{$_}};
71 }
72
73 my $letter=((scalar(@letters)>1) || ($letters[0]->{name}||$letters[0]->{code}));
74 my  @missingissues;
75 my @supplierinfo;
76 if ($supplierid) {
77     @missingissues = GetLateOrMissingIssues($supplierid,$serialid,$order);
78     @supplierinfo=GetBookSeller($supplierid);
79 }
80
81 my $preview=0;
82 if($op && $op eq 'preview'){
83     $preview = 1;
84 } else {
85     my @serialnums=$input->param('serialid');
86     if (@serialnums) { # i.e. they have been flagged to generate claims
87         SendAlerts('claimissues',\@serialnums,$input->param("letter_code"));
88         my $cntupdate=UpdateClaimdateIssues(\@serialnums);
89         ### $cntupdate SHOULD be equal to scalar(@$serialnums)
90     }
91 }
92 $template->param('letters'=>\@letters,'letter'=>$letter);
93 $template->param(
94         order =>$order,
95         suploop => \@suploop,
96         phone => $supplierinfo[0]->{phone},
97         booksellerfax => $supplierinfo[0]->{booksellerfax},
98         bookselleremail => $supplierinfo[0]->{bookselleremail},
99         preview => $preview,
100         missingissues => \@missingissues,
101         supplierid => $supplierid,
102         claimletter => $claimletter,
103         supplierloop => \@supplierinfo,
104         dateformat    => C4::Context->preference("dateformat"),
105         DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
106         );
107 output_html_with_http_headers $input, $cookie, $template->output;