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-numberpatterns.pl
25 Manage numbering patterns
34 use C4::Serials::Numberpattern;
35 use C4::Serials::Frequency;
38 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
39 template_name => 'serials/subscription-numberpatterns.tt',
43 flagsrequired => { 'parameters' => 1 }
46 my $op = $input->param('op');
48 if($op && $op eq 'savenew') {
49 my $label = $input->param('label');
51 foreach(qw/ label description numberingmethod displayorder
52 label1 label2 label3 add1 add2 add3 every1 every2 every3
53 setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3
54 numbering1 numbering2 numbering3 /) {
55 $numberpattern->{$_} = $input->param($_);
56 if($numberpattern->{$_} and $numberpattern->{$_} eq '') {
57 $numberpattern->{$_} = undef;
60 my $numberpattern2 = GetSubscriptionNumberpatternByName($label);
62 if(!defined $numberpattern2) {
63 AddSubscriptionNumberpattern($numberpattern);
66 $template->param(error_existing_numberpattern => 1);
67 $template->param(%$numberpattern);
69 } elsif ($op && $op eq 'savemod') {
70 my $id = $input->param('id');
71 my $label = $input->param('label');
72 my $numberpattern = GetSubscriptionNumberpattern($id);
74 if($numberpattern->{'label'} ne $label) {
75 my $numberpattern2 = GetSubscriptionNumberpatternByName($label);
76 if(defined $numberpattern2 && $id != $numberpattern2->{'id'}) {
81 foreach(qw/ id label description numberingmethod displayorder
82 label1 label2 label3 add1 add2 add3 every1 every2 every3
83 setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3
84 numbering1 numbering2 numbering3 /) {
85 $numberpattern->{$_} = $input->param($_) || undef;
87 ModSubscriptionNumberpattern($numberpattern);
90 $template->param(error_existing_numberpattern => 1);
94 if($op && ($op eq 'new' || $op eq 'modify')) {
96 my $id = $input->param('id');
98 my $numberpattern = GetSubscriptionNumberpattern($id);
99 $template->param(%$numberpattern);
104 my @frequencies = GetSubscriptionFrequencies();
106 push @subtypes, { value => $_ } for (qw/ issues weeks months /);
109 /^C|^POSIX$/ ? () : $_
114 frequencies_loop => \@frequencies,
115 subtypes_loop => \@subtypes,
116 locales => \@locales,
117 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
119 output_html_with_http_headers $input, $cookie, $template->output;
123 if($op && $op eq 'del') {
124 my $id = $input->param('id');
126 my $confirm = $input->param('confirm');
128 DelSubscriptionNumberpattern($id);
130 my @subs = GetSubscriptionsWithNumberpattern($id);
135 subscriptions => \@subs
138 DelSubscriptionNumberpattern($id);
144 my @numberpatterns_loop = GetSubscriptionNumberpatterns();
147 numberpatterns_loop => \@numberpatterns_loop,
150 output_html_with_http_headers $input, $cookie, $template->output;