Bug 11533: (regression test) QP breaks authority search
[koha.git] / serials / subscription-numberpatterns.pl
blobc2a9800dc4242fa047df6bf0c966b671faa5ce28
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;
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 => { 'parameters' => 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 /);
108 my @locales = map {
109 chomp;
110 /^C|^POSIX$/ ? () : $_
111 } `locale -a`;
113 $template->param(
114 $op => 1,
115 frequencies_loop => \@frequencies,
116 subtypes_loop => \@subtypes,
117 locales => \@locales,
118 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
120 output_html_with_http_headers $input, $cookie, $template->output;
121 exit;
124 if($op && $op eq 'del') {
125 my $id = $input->param('id');
126 if ($id) {
127 my $confirm = $input->param('confirm');
128 if ($confirm) {
129 DelSubscriptionNumberpattern($id);
130 } else {
131 my @subs = GetSubscriptionsWithNumberpattern($id);
132 if (@subs) {
133 $template->param(
134 id => $id,
135 still_used => 1,
136 subscriptions => \@subs
138 } else {
139 DelSubscriptionNumberpattern($id);
145 my @numberpatterns_loop = GetSubscriptionNumberpatterns();
147 $template->param(
148 numberpatterns_loop => \@numberpatterns_loop,
151 output_html_with_http_headers $input, $cookie, $template->output;