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-numberpatterns.pl
26 Manage numbering patterns
35 use C4
::Serials
::Numberpattern
;
36 use C4
::Serials
::Frequency
;
39 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user
( {
40 template_name
=> 'serials/subscription-numberpatterns.tt',
44 flagsrequired
=> { 'serials' => 1 }
47 my $op = $input->param('op');
49 if($op && $op eq 'savenew') {
50 my $label = $input->param('label');
52 foreach(qw
/ label description numberingmethod displayorder
53 label1 label2 label3 add1 add2 add3 every1 every2 every3
54 setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3
55 numbering1 numbering2 numbering3
/) {
56 $numberpattern->{$_} = $input->param($_);
57 if($numberpattern->{$_} and $numberpattern->{$_} eq '') {
58 $numberpattern->{$_} = undef;
61 my $numberpattern2 = GetSubscriptionNumberpatternByName
($label);
63 if(!defined $numberpattern2) {
64 AddSubscriptionNumberpattern
($numberpattern);
67 $template->param(error_existing_numberpattern
=> 1);
68 $template->param(%$numberpattern);
70 } elsif ($op && $op eq 'savemod') {
71 my $id = $input->param('id');
72 my $label = $input->param('label');
73 my $numberpattern = GetSubscriptionNumberpattern
($id);
75 if($numberpattern->{'label'} ne $label) {
76 my $numberpattern2 = GetSubscriptionNumberpatternByName
($label);
77 if(defined $numberpattern2 && $id != $numberpattern2->{'id'}) {
82 foreach(qw
/ id label description numberingmethod displayorder
83 label1 label2 label3 add1 add2 add3 every1 every2 every3
84 setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3
85 numbering1 numbering2 numbering3
/) {
86 $numberpattern->{$_} = $input->param($_) || undef;
88 ModSubscriptionNumberpattern
($numberpattern);
91 $template->param(error_existing_numberpattern
=> 1);
95 if($op && ($op eq 'new' || $op eq 'modify')) {
97 my $id = $input->param('id');
99 my $numberpattern = GetSubscriptionNumberpattern
($id);
100 $template->param(%$numberpattern);
105 my @frequencies = GetSubscriptionFrequencies
();
107 push @subtypes, { value
=> $_ } for (qw
/ issues weeks months /);
109 my $languages = [ map {
111 language
=> $_->{iso639_2_code
},
112 description
=> $_->{language_description
} || $_->{language
}
114 } @
{ C4
::Languages
::getAllLanguages
() } ];
118 frequencies_loop
=> \
@frequencies,
119 subtypes_loop
=> \
@subtypes,
120 locales
=> $languages,
122 output_html_with_http_headers
$input, $cookie, $template->output;
126 if($op && $op eq 'del') {
127 my $id = $input->param('id');
129 my $confirm = $input->param('confirm');
131 DelSubscriptionNumberpattern
($id);
133 my @subs = GetSubscriptionsWithNumberpattern
($id);
138 subscriptions
=> \
@subs
141 DelSubscriptionNumberpattern
($id);
147 my @numberpatterns_loop = GetSubscriptionNumberpatterns
();
150 numberpatterns_loop
=> \
@numberpatterns_loop,
153 output_html_with_http_headers
$input, $cookie, $template->output;