3 # Copyright 2011 BibLibre SARL
4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
11 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with Koha; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 subscription-frequencies.pl
25 Manage subscription frequencies
36 use C4::Serials::Frequency;
39 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
40 template_name => 'serials/subscription-frequencies.tt',
44 flagsrequired => { 'parameters' => 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;