3 # Copyright 2019 PTFS Europe
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>.
23 use C4::Auth qw( get_template_and_user );
24 use C4::Output qw( output_html_with_http_headers );
25 use Koha::RestrictionTypes;
28 my $op = $input->param('op') // 'list';
29 my $code = uc $input->param('code');
33 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
35 template_name => "admin/restrictions.tt",
38 flagsrequired => { parameters => 'manage_patron_restrictions' },
43 if ( $op eq 'add_form') {
44 # Get all existing restrictions, so we can do client-side validation
46 existing => scalar Koha::RestrictionTypes->search()
50 restriction => scalar Koha::RestrictionTypes->find($code)
53 } elsif ( $op eq 'add_validate' ) {
55 my $display_text = $input->param('display_text');
56 my $is_a_modif = $input->param("is_a_modif");
59 # Check whether another restriction already has this display text
60 my $dupe = Koha::RestrictionTypes->find({
61 display_text => $display_text
65 type => 'error', code => 'duplicate_display_text'
68 my $restriction = Koha::RestrictionTypes->find($code);
69 $restriction->display_text($display_text);
73 # Check whether another restriction already has this code
74 my $dupe = Koha::RestrictionTypes->find($code);
77 type => 'error', code => 'duplicate_code'
80 my $restriction = Koha::RestrictionType->new({
82 display_text => $display_text
88 } elsif ( $op eq 'make_default' ) {
89 my $restriction = Koha::RestrictionTypes->find($code);
90 $restriction->make_default;
92 } elsif ( $op eq 'delete_confirm' ) {
94 restriction => scalar Koha::RestrictionTypes->find($code)
96 } elsif ( $op eq 'delete_confirmed' ) {
97 Koha::RestrictionTypes->find($code)->delete;
102 messages => \@messages,
106 if ( $op eq 'list' ) {
107 my $restrictions = Koha::RestrictionTypes->search();
109 restrictions => $restrictions,
113 output_html_with_http_headers $input, $cookie, $template->output;