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
33 use C4::Auth qw( get_template_and_user );
34 use C4::Output qw( output_html_with_http_headers );
35 use C4::Serials::Numberpattern qw(
36 AddSubscriptionNumberpattern
37 DelSubscriptionNumberpattern
38 GetSubscriptionNumberpattern
39 GetSubscriptionNumberpatternByName
40 GetSubscriptionNumberpatterns
41 GetSubscriptionsWithNumberpattern
42 ModSubscriptionNumberpattern
44 use C4::Serials::Frequency qw( GetSubscriptionFrequencies );
47 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
48 template_name => 'serials/subscription-numberpatterns.tt',
51 flagsrequired => { 'serials' => "*" }
54 my $op = $input->param('op');
56 if($op && $op eq 'savenew') {
57 my $label = $input->param('label');
59 foreach(qw/ label description numberingmethod displayorder
60 label1 label2 label3 add1 add2 add3 every1 every2 every3
61 setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3
62 numbering1 numbering2 numbering3 /) {
63 $numberpattern->{$_} = $input->param($_);
64 if($numberpattern->{$_} and $numberpattern->{$_} eq '') {
65 $numberpattern->{$_} = undef;
68 my $numberpattern2 = GetSubscriptionNumberpatternByName($label);
70 if(!defined $numberpattern2) {
71 AddSubscriptionNumberpattern($numberpattern);
74 $template->param(error_existing_numberpattern => 1);
75 $template->param(%$numberpattern);
77 } elsif ($op && $op eq 'savemod') {
78 my $id = $input->param('id');
79 my $label = $input->param('label');
80 my $numberpattern = GetSubscriptionNumberpattern($id);
82 if($numberpattern->{'label'} ne $label) {
83 my $numberpattern2 = GetSubscriptionNumberpatternByName($label);
84 if(defined $numberpattern2 && $id != $numberpattern2->{'id'}) {
89 foreach(qw/ id label description numberingmethod displayorder
90 label1 label2 label3 add1 add2 add3 every1 every2 every3
91 setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3
92 numbering1 numbering2 numbering3 /) {
93 $numberpattern->{$_} = $input->param($_) || undef;
95 ModSubscriptionNumberpattern($numberpattern);
98 $template->param(error_existing_numberpattern => 1);
102 if($op && ($op eq 'new' || $op eq 'modify')) {
103 if($op eq 'modify') {
104 my $id = $input->param('id');
106 my $numberpattern = GetSubscriptionNumberpattern($id);
107 $template->param(%$numberpattern);
112 my @frequencies = GetSubscriptionFrequencies();
113 my $languages = [ map {
115 language => $_->{iso639_2_code},
116 description => $_->{language_description} || $_->{language}
118 } @{ C4::Languages::getAllLanguages() } ];
122 frequencies_loop => \@frequencies,
123 locales => $languages,
125 output_html_with_http_headers $input, $cookie, $template->output;
129 if($op && $op eq 'del') {
130 my $id = $input->param('id');
132 my $confirm = $input->param('confirm');
134 DelSubscriptionNumberpattern($id);
136 my @subs = GetSubscriptionsWithNumberpattern($id);
141 subscriptions => \@subs
144 DelSubscriptionNumberpattern($id);
150 my @numberpatterns_loop = GetSubscriptionNumberpatterns();
153 numberpatterns_loop => \@numberpatterns_loop,
156 output_html_with_http_headers $input, $cookie, $template->output;