Bug 22053: ability to enable/disable some plugins
[koha.git] / serials / checkexpiration.pl
blobae888414444f5d3970be28a628f3c8511da0708f
1 #!/usr/bin/perl
4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 =head1 NAME
22 checkexpiration.pl
24 =head1 DESCRIPTION
26 This script check what subscription will expire before C<$datenumber $datelimit>
28 =head1 PARAMETERS
30 =over 4
32 =item title
33 To filter subscription on title
35 =item issn
36 To filter subscription on issn
38 =item date
39 The date to filter on.
41 =back
43 =cut
45 use Modern::Perl;
46 use CGI qw ( -utf8 );
47 use C4::Auth;
48 use C4::Serials; # GetExpirationDate
49 use C4::Output;
50 use C4::Context;
51 use Koha::DateUtils;
53 use DateTime;
55 my $query = new CGI;
57 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user (
59 template_name => "serials/checkexpiration.tt",
60 query => $query,
61 type => "intranet",
62 authnotrequired => 0,
63 flagsrequired => { serials => 'check_expiration' },
64 debug => 1,
68 my $title = $query->param('title');
69 my $issn = $query->param('issn');
70 my $branch = $query->param('branch');
71 my $date = $query->param('date');
72 $date = eval { dt_from_string( scalar $query->param('date') ) } if $date;
74 if ($date) {
75 my @subscriptions = SearchSubscriptions({ title => $title, issn => $issn, orderby => 'title' });
76 my @subscriptions_loop;
78 foreach my $subscription ( @subscriptions ) {
79 my $subscriptionid = $subscription->{'subscriptionid'};
80 my $expirationdate = GetExpirationDate($subscriptionid);
82 $subscription->{expirationdate} = $expirationdate;
84 next if $expirationdate !~ /\d{4}-\d{2}-\d{2}/; # next if not in ISO format.
86 next if $subscription->{closed};
87 if ( !C4::Context->preference("IndependentBranches")
88 or C4::Context->IsSuperLibrarian()
89 or ( ref $flags->{serials} and $flags->{serials}->{superserials} )
90 or ( !ref $flags->{serials} and $flags->{serials} == 1 ) )
92 $subscription->{cannotedit} = 0;
94 next if $subscription->{cannotedit};
96 my $expirationdate_dt = dt_from_string( $expirationdate, 'iso' );
97 if ( DateTime->compare( $date, $expirationdate_dt ) == 1
98 && ( !$branch || ( $subscription->{'branchcode'} eq $branch ) ) ) {
99 push @subscriptions_loop, $subscription;
103 $template->param (
104 title => $title,
105 issn => $issn,
106 numsubscription => scalar @subscriptions_loop,
107 date => $date,
108 subscriptions_loop => \@subscriptions_loop,
109 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
110 searched => 1,
114 my $can_change_library;;
115 if ( !C4::Context->preference("IndependentBranches")
116 or C4::Context->IsSuperLibrarian()
117 or ( ref $flags->{serials} and $flags->{serials}->{superserials} )
118 or ( !ref $flags->{serials} and $flags->{serials} == 1 ) )
120 $can_change_library = 1;
123 $template->param (
124 (uc(C4::Context->preference("marcflavour"))) => 1,
125 can_change_library => $can_change_library,
126 branch => $branch,
129 output_html_with_http_headers $query, $cookie, $template->output;