3 # Copyright 2002 paul.poulain@biblibre.com
4 # Copyright 2000-2002 Katipo Communications
5 # Copyright 2015 Koha Development Team
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
28 use Koha
::Authorities
;
29 use Koha
::Authority
::Types
;
32 my $authtypecode = $input->param('authtypecode');
33 my $op = $input->param('op') || 'list';
35 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
36 { template_name
=> "admin/authtypes.tt",
40 flagsrequired
=> { parameters
=> 'parameters_remaining_permissions' },
45 if ( $op eq 'add_form' ) {
47 if (defined $authtypecode) {
48 $authority_type = Koha
::Authority
::Types
->find($authtypecode);
51 $template->param( authority_type
=> $authority_type );
52 } elsif ( $op eq 'add_validate' ) {
53 my $authtypecode = $input->param('authtypecode');
54 my $authtypetext = $input->param('authtypetext');
55 my $auth_tag_to_report = $input->param('auth_tag_to_report');
56 my $summary = $input->param('summary');
57 my $is_a_modif = $input->param('is_a_modif');
60 my $authority_type = Koha
::Authority
::Types
->find($authtypecode);
61 $authority_type->authtypetext($authtypetext);
62 $authority_type->auth_tag_to_report($auth_tag_to_report);
63 $authority_type->summary($summary);
64 eval { $authority_type->store; };
66 push @messages, { type
=> 'error', code
=> 'error_on_update' };
68 push @messages, { type
=> 'message', code
=> 'success_on_update' };
71 my $authority_type = Koha
::Authority
::Type
->new(
72 { authtypecode
=> $authtypecode,
73 authtypetext
=> $authtypetext,
74 auth_tag_to_report
=> $auth_tag_to_report,
78 eval { $authority_type->store; };
80 push @messages, { type
=> 'error', code
=> 'error_on_insert' };
82 push @messages, { type
=> 'message', code
=> 'success_on_insert' };
87 } elsif ( $op eq 'delete_confirm' ) {
88 my $authority_type = Koha
::Authority
::Types
->find($authtypecode);
89 my $authorities_using_it = Koha
::Authorities
->search( { authtypecode
=> $authtypecode } )->count;
91 authority_type
=> $authority_type,
92 authorities_using_it
=> $authorities_using_it,
94 } elsif ( $op eq 'delete_confirmed' ) {
95 my $authorities_using_it = Koha
::Authorities
->search( { authtypecode
=> $authtypecode } )->count;
96 if ( $authorities_using_it == 0 ) {
97 my $authority_type = Koha
::Authority
::Types
->find($authtypecode);
98 my $deleted = eval { $authority_type->delete; };
100 if ( $@
or not $deleted ) {
101 push @messages, { type
=> 'error', code
=> 'error_on_delete' };
103 push @messages, { type
=> 'message', code
=> 'success_on_delete' };
106 push @messages, { type
=> 'error', code
=> 'error_on_delete' };
111 if ( $op eq 'list' ) {
112 my $authority_types = Koha
::Authority
::Types
->search( {}, { order_by
=> ['authtypecode'] } );
113 $template->param( authority_types
=> $authority_types, );
117 messages
=> \
@messages,
121 output_html_with_http_headers
$input, $cookie, $template->output;