Lines 20-35
Link Here
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use CGI qw ( -utf8 ); |
22 |
use CGI qw ( -utf8 ); |
|
|
23 |
use Try::Tiny qw( try catch ); |
24 |
|
23 |
use C4::Auth qw( get_template_and_user ); |
25 |
use C4::Auth qw( get_template_and_user ); |
24 |
use C4::Output qw( output_html_with_http_headers ); |
26 |
use C4::Output qw( output_html_with_http_headers ); |
25 |
use Koha::RestrictionTypes; |
27 |
use Koha::Patron::Restriction::Types; |
26 |
|
28 |
|
27 |
my $input = CGI->new; |
29 |
my $input = CGI->new; |
28 |
my $op = $input->param('op') // 'list'; |
30 |
my $op = $input->param('op') // 'list'; |
29 |
my $code = uc $input->param('code'); |
31 |
my $code = uc $input->param('code'); |
30 |
my @messages = (); |
32 |
my @messages = (); |
31 |
|
33 |
|
32 |
|
|
|
33 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
34 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
34 |
{ |
35 |
{ |
35 |
template_name => "admin/restrictions.tt", |
36 |
template_name => "admin/restrictions.tt", |
Lines 43-53
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Link Here
|
43 |
if ( $op eq 'add_form') { |
44 |
if ( $op eq 'add_form') { |
44 |
# Get all existing restrictions, so we can do client-side validation |
45 |
# Get all existing restrictions, so we can do client-side validation |
45 |
$template->param( |
46 |
$template->param( |
46 |
existing => scalar Koha::RestrictionTypes->search() |
47 |
existing => scalar Koha::Patron::Restriction::Types->search() |
47 |
); |
48 |
); |
48 |
if ($code) { |
49 |
if ($code) { |
49 |
$template->param( |
50 |
$template->param( |
50 |
restriction => scalar Koha::RestrictionTypes->find($code) |
51 |
restriction => scalar Koha::Patron::Restriction::Types->find($code) |
51 |
); |
52 |
); |
52 |
} |
53 |
} |
53 |
} elsif ( $op eq 'add_validate' ) { |
54 |
} elsif ( $op eq 'add_validate' ) { |
Lines 57-63
if ( $op eq 'add_form') {
Link Here
|
57 |
|
58 |
|
58 |
if ($is_a_modif) { |
59 |
if ($is_a_modif) { |
59 |
# Check whether another restriction already has this display text |
60 |
# Check whether another restriction already has this display text |
60 |
my $dupe = Koha::RestrictionTypes->find({ |
61 |
my $dupe = Koha::Patron::Restriction::Types->find({ |
61 |
display_text => $display_text |
62 |
display_text => $display_text |
62 |
}); |
63 |
}); |
63 |
if ($dupe) { |
64 |
if ($dupe) { |
Lines 65-77
if ( $op eq 'add_form') {
Link Here
|
65 |
type => 'error', code => 'duplicate_display_text' |
66 |
type => 'error', code => 'duplicate_display_text' |
66 |
}; |
67 |
}; |
67 |
} else { |
68 |
} else { |
68 |
my $restriction = Koha::RestrictionTypes->find($code); |
69 |
my $restriction = Koha::Patron::Restriction::Types->find($code); |
69 |
$restriction->display_text($display_text); |
70 |
$restriction->display_text($display_text); |
70 |
$restriction->store; |
71 |
$restriction->store; |
|
|
72 |
push @messages, { type => 'message', code => 'update_success' }; |
71 |
} |
73 |
} |
72 |
} else { |
74 |
} else { |
73 |
# Check whether another restriction already has this code |
75 |
# Check whether another restriction already has this code |
74 |
my $dupe = Koha::RestrictionTypes->find($code); |
76 |
my $dupe = Koha::Patron::Restriction::Types->find($code); |
75 |
if ($dupe) { |
77 |
if ($dupe) { |
76 |
push @messages, { |
78 |
push @messages, { |
77 |
type => 'error', code => 'duplicate_code' |
79 |
type => 'error', code => 'duplicate_code' |
Lines 82-100
if ( $op eq 'add_form') {
Link Here
|
82 |
display_text => $display_text |
84 |
display_text => $display_text |
83 |
}); |
85 |
}); |
84 |
$restriction->store; |
86 |
$restriction->store; |
|
|
87 |
push @messages, { type => 'message', code => 'add_success' }; |
85 |
} |
88 |
} |
86 |
} |
89 |
} |
87 |
$op = 'list'; |
90 |
$op = 'list'; |
88 |
} elsif ( $op eq 'make_default' ) { |
91 |
} elsif ( $op eq 'make_default' ) { |
89 |
my $restriction = Koha::RestrictionTypes->find($code); |
92 |
my $restriction = Koha::Patron::Restriction::Types->find($code); |
90 |
$restriction->make_default; |
93 |
$restriction->make_default; |
91 |
$op = 'list'; |
94 |
$op = 'list'; |
92 |
} elsif ( $op eq 'delete_confirm' ) { |
95 |
} elsif ( $op eq 'delete_confirm' ) { |
93 |
$template->param( |
96 |
$template->param( |
94 |
restriction => scalar Koha::RestrictionTypes->find($code) |
97 |
restriction => scalar Koha::Patron::Restriction::Types->find($code) |
95 |
); |
98 |
); |
96 |
} elsif ( $op eq 'delete_confirmed' ) { |
99 |
} elsif ( $op eq 'delete_confirmed' ) { |
97 |
Koha::RestrictionTypes->find($code)->delete; |
100 |
try { |
|
|
101 |
Koha::Patron::Restriction::Types->find($code)->delete; |
102 |
push @messages, { type => 'message', code => 'delete_success' }; |
103 |
} |
104 |
catch { |
105 |
if ( blessed $_ ) { |
106 |
if ( $_->isa('Koha::Exceptions::CannotDeleteDefault') ) { |
107 |
push @messages, { type => 'error', code => 'delete_default' }; |
108 |
} |
109 |
elsif ( $_->isa('Koha::Exceptions::CannotDeleteSystem') ) { |
110 |
push @messages, { type => 'error', code => 'delete_system' }; |
111 |
} |
112 |
} |
113 |
} |
98 |
$op = 'list'; |
114 |
$op = 'list'; |
99 |
} |
115 |
} |
100 |
|
116 |
|
Lines 104-110
$template->param(
Link Here
|
104 |
); |
120 |
); |
105 |
|
121 |
|
106 |
if ( $op eq 'list' ) { |
122 |
if ( $op eq 'list' ) { |
107 |
my $restrictions = Koha::RestrictionTypes->search(); |
123 |
my $restrictions = Koha::Patron::Restriction::Types->search(); |
108 |
$template->param( |
124 |
$template->param( |
109 |
restrictions => $restrictions, |
125 |
restrictions => $restrictions, |
110 |
) |
126 |
) |