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>.
22 subscription-frequencies.pl
26 Manage subscription frequencies
37 use C4::Serials::Frequency;
40 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
41 template_name => 'serials/subscription-frequencies.tt',
44 flagsrequired => { 'serials' => 1 },
48 my $op = $input->param('op');
50 if($op && ($op eq 'new' || $op eq 'modify')) {
52 push @units_loop, {val => $_} for (qw/ day week month year /);
55 my $frequencyid = $input->param('frequencyid');
56 my $frequency = GetSubscriptionFrequency($frequencyid);
57 foreach (@units_loop) {
58 if($frequency->{unit} and $_->{val} eq $frequency->{unit}) {
63 $template->param( %$frequency );
67 units_loop => \@units_loop,
70 output_html_with_http_headers $input, $cookie, $template->output;
74 if($op && ($op eq 'savenew' || $op eq 'savemod')) {
76 foreach (qw/ description unit issuesperunit unitsperissue displayorder /) {
77 $frequency->{$_} = $input->param($_);
79 $frequency->{unit} = undef if $frequency->{unit} eq '';
80 foreach (qw/issuesperunit unitsperissue/) {
81 $frequency->{$_} = 1 if $frequency->{$_} !~ /\d+/;
83 $frequency->{issuesperunit} = 1 if $frequency->{issuesperunit} < 1;
84 $frequency->{unitsperissue} = 1 if $frequency->{issuesperunit} != 1;
86 if($op eq 'savemod') {
87 $frequency->{id} = $input->param('id');
88 ModSubscriptionFrequency($frequency);
90 AddSubscriptionFrequency($frequency);
92 } elsif($op && $op eq 'del') {
93 my $frequencyid = $input->param('frequencyid');
96 my $confirm = $input->param('confirm');
98 DelSubscriptionFrequency($frequencyid);
100 my @subs = GetSubscriptionsWithFrequency($frequencyid);
103 frequencyid => $frequencyid,
105 subscriptions => \@subs
108 DelSubscriptionFrequency($frequencyid);
115 my @frequencies = GetSubscriptionFrequencies();
117 $template->param(frequencies_loop => \@frequencies);
118 $template->param($op => 1) if $op;
120 output_html_with_http_headers $input, $cookie, $template->output;