Bug 16699: Remove requirement from borrowernumberQueryParam
[koha.git] / serials / subscription-frequencies.pl
blobf3c6d572d373b2a399a59e3d28d1f8fdac77a859
1 #!/usr/bin/perl
3 # Copyright 2011-2013 Biblibre SARL
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 =head1 NAME
22 subscription-frequencies.pl
24 =head1 DESCRIPTION
26 Manage subscription frequencies
28 =cut
30 use Modern::Perl;
32 use CGI qw ( -utf8 );
34 use C4::Auth;
35 use C4::Output;
36 use C4::Serials;
37 use C4::Serials::Frequency;
39 my $input = new CGI;
40 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
41 template_name => 'serials/subscription-frequencies.tt',
42 query => $input,
43 type => 'intranet',
44 authnotrequired => 0,
45 flagsrequired => { 'serials' => 1 },
46 debug => 1,
47 } );
49 my $op = $input->param('op');
51 if($op && ($op eq 'new' || $op eq 'modify')) {
52 my @units_loop;
53 push @units_loop, {val => $_} for (qw/ day week month year /);
55 if($op eq 'modify') {
56 my $frequencyid = $input->param('frequencyid');
57 my $frequency = GetSubscriptionFrequency($frequencyid);
58 foreach (@units_loop) {
59 if($frequency->{unit} and $_->{val} eq $frequency->{unit}) {
60 $_->{selected} = 1;
61 last;
64 $template->param( %$frequency );
67 $template->param(
68 units_loop => \@units_loop,
69 $op => 1,
71 output_html_with_http_headers $input, $cookie, $template->output;
72 exit;
75 if($op && ($op eq 'savenew' || $op eq 'savemod')) {
76 my $frequency;
77 foreach (qw/ description unit issuesperunit unitsperissue displayorder /) {
78 $frequency->{$_} = $input->param($_);
80 $frequency->{unit} = undef if $frequency->{unit} eq '';
81 foreach (qw/issuesperunit unitsperissue/) {
82 $frequency->{$_} = 1 if $frequency->{$_} !~ /\d+/;
84 $frequency->{issuesperunit} = 1 if $frequency->{issuesperunit} < 1;
85 $frequency->{unitsperissue} = 1 if $frequency->{issuesperunit} != 1;
87 if($op eq 'savemod') {
88 $frequency->{id} = $input->param('id');
89 ModSubscriptionFrequency($frequency);
90 } else {
91 AddSubscriptionFrequency($frequency);
93 } elsif($op && $op eq 'del') {
94 my $frequencyid = $input->param('frequencyid');
96 if ($frequencyid) {
97 my $confirm = $input->param('confirm');
98 if ($confirm) {
99 DelSubscriptionFrequency($frequencyid);
100 } else {
101 my @subs = GetSubscriptionsWithFrequency($frequencyid);
102 if (@subs) {
103 $template->param(
104 frequencyid => $frequencyid,
105 still_used => 1,
106 subscriptions => \@subs
108 } else {
109 DelSubscriptionFrequency($frequencyid);
116 my @frequencies = GetSubscriptionFrequencies();
118 $template->param(frequencies_loop => \@frequencies);
119 $template->param($op => 1) if $op;
121 output_html_with_http_headers $input, $cookie, $template->output;