Bug 24339: Add SIP2 payment types for installation
[koha.git] / serials / subscription-numberpatterns.pl
blob2bcce3a077f63a55d26ab211c7a78af36b7da715
1 #!/usr/bin/perl
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>.
20 =head1 NAME
22 subscription-numberpatterns.pl
24 =head1 DESCRIPTION
26 Manage numbering patterns
28 =cut
30 use Modern::Perl;
31 use CGI qw ( -utf8 );
33 use C4::Auth;
34 use C4::Output;
35 use C4::Serials::Numberpattern;
36 use C4::Serials::Frequency;
38 my $input = new CGI;
39 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
40 template_name => 'serials/subscription-numberpatterns.tt',
41 query => $input,
42 type => 'intranet',
43 authnotrequired => 0,
44 flagsrequired => { 'serials' => 1 }
45 } );
47 my $op = $input->param('op');
49 if($op && $op eq 'savenew') {
50 my $label = $input->param('label');
51 my $numberpattern;
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);
65 } else {
66 $op = 'new';
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);
74 my $mod_ok = 1;
75 if($numberpattern->{'label'} ne $label) {
76 my $numberpattern2 = GetSubscriptionNumberpatternByName($label);
77 if(defined $numberpattern2 && $id != $numberpattern2->{'id'}) {
78 $mod_ok = 0;
81 if($mod_ok) {
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);
89 } else {
90 $op = 'modify';
91 $template->param(error_existing_numberpattern => 1);
95 if($op && ($op eq 'new' || $op eq 'modify')) {
96 if($op eq 'modify') {
97 my $id = $input->param('id');
98 if(defined $id) {
99 my $numberpattern = GetSubscriptionNumberpattern($id);
100 $template->param(%$numberpattern);
101 } else {
102 $op = 'new';
105 my @frequencies = GetSubscriptionFrequencies();
106 my @subtypes;
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() } ];
116 $template->param(
117 $op => 1,
118 frequencies_loop => \@frequencies,
119 subtypes_loop => \@subtypes,
120 locales => $languages,
122 output_html_with_http_headers $input, $cookie, $template->output;
123 exit;
126 if($op && $op eq 'del') {
127 my $id = $input->param('id');
128 if ($id) {
129 my $confirm = $input->param('confirm');
130 if ($confirm) {
131 DelSubscriptionNumberpattern($id);
132 } else {
133 my @subs = GetSubscriptionsWithNumberpattern($id);
134 if (@subs) {
135 $template->param(
136 id => $id,
137 still_used => 1,
138 subscriptions => \@subs
140 } else {
141 DelSubscriptionNumberpattern($id);
147 my @numberpatterns_loop = GetSubscriptionNumberpatterns();
149 $template->param(
150 numberpatterns_loop => \@numberpatterns_loop,
153 output_html_with_http_headers $input, $cookie, $template->output;