fixing permissions on scripts
[koha.git] / serials / claims.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5 use C4::Auth;
6 use C4::Serials;
7 use C4::Acquisition;
8 use C4::Output;
9 use C4::Bookseller;
10 use C4::Context;
11 use C4::Letters;
12
13 my $input = new CGI;
14
15 my $serialid = $input->param('serialid');
16 my $op = $input->param('op');
17 my $claimletter = $input->param('claimletter');
18 my $supplierid = $input->param('supplierid');
19 my $order = $input->param('order');
20 my %supplierlist = GetSuppliersWithLateIssues;
21 my @select_supplier;
22
23 foreach my $supplierid (keys %supplierlist){
24         my ($count, @dummy) = GetLateOrMissingIssues($supplierid,"",$order);
25         my $counting = $count;
26         $supplierlist{$supplierid} = $supplierlist{$supplierid}." ($counting)";
27         push @select_supplier, $supplierid
28 }
29
30 my $letters = GetLetters("claimissues");
31 my @letters;
32 foreach (keys %$letters){
33     push @letters ,{code=>$_,name=> $letters->{$_}};
34 }
35
36 my $letter=((scalar(@letters)>1)||($letters[0]->{name}||$letters[0]->{code}));
37 my ($count2, @missingissues) = GetLateOrMissingIssues($supplierid,$serialid,$order) if $supplierid;
38
39 my $CGIsupplier=CGI::scrolling_list( -name     => 'supplierid',
40                         -values   => \@select_supplier,
41                         -default  => $supplierid,
42                         -labels   => \%supplierlist,
43                         -size     => 1,
44                         -multiple => 0 
45             -onChange => 'onchange="submit();"');
46
47 my ($singlesupplier,@supplierinfo);
48 if($supplierid){
49    (@supplierinfo)=GetBookSeller($supplierid);
50 } else { # set up supplierid for the claim links out of main table if all suppliers is chosen
51    for(my $i=0; $i<@missingissues;$i++){
52        $missingissues[$i]->{'supplierid'} = getsupplierbyserialid($missingissues[$i]->{'serialid'});
53    }
54 }
55
56
57 my $preview=0;
58 if($op eq 'preview'){
59     $preview = 1;
60 }
61
62 if ($op eq "send_alert"){
63   my @serialnums=$input->param("serialid");
64   SendAlerts('claimissues',\@serialnums,$input->param("letter_code"));
65   my $cntupdate=UpdateClaimdateIssues(\@serialnums);
66   ### $cntupdate SHOULD be equal to scalar(@$serialnums)
67 }
68
69 my ($template, $loggedinuser, $cookie)
70 = get_template_and_user({template_name => "serials/claims.tmpl",
71                                 query => $input,
72                                 type => "intranet",
73                                 authnotrequired => 0,
74                                 flagsrequired => {serials => 1},
75                                 debug => 1,
76                                 });
77
78 $template->param('letters'=>\@letters,'letter'=>$letter);
79 $template->param(
80     order =>$order,
81         CGIsupplier => $CGIsupplier,
82     phone => $supplierinfo[0]->{phone},
83     booksellerfax => $supplierinfo[0]->{booksellerfax},
84     bookselleremail => $supplierinfo[0]->{bookselleremail},
85         preview => $preview,
86         missingissues => \@missingissues,
87         supplierid => $supplierid,
88         claimletter => $claimletter,
89         singlesupplier => $singlesupplier,
90         supplierloop => \@supplierinfo,
91         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
92                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
93                 IntranetNav => C4::Context->preference("IntranetNav"),
94         );
95 output_html_with_http_headers $input, $cookie, $template->output;