Bug 25067: (QA follow-up) Add +x on test files
[koha.git] / admin / authtypes.pl
blob4d032cfc03c7bc1a389077aeef1539d45fb1d9ee
1 #!/usr/bin/perl
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>.
22 use Modern::Perl;
23 use CGI qw ( -utf8 );
24 use C4::Context;
25 use C4::Auth;
26 use C4::Output;
28 use Koha::Authorities;
29 use Koha::Authority::Types;
31 my $input = CGI->new;
32 my $authtypecode = $input->param('authtypecode');
33 my $op = $input->param('op') || 'list';
34 my @messages;
35 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
36 { template_name => "admin/authtypes.tt",
37 query => $input,
38 type => "intranet",
39 flagsrequired => { parameters => 'manage_marc_frameworks' },
40 debug => 1,
44 if ( $op eq 'add_form' ) {
45 my $authority_type;
46 if (defined $authtypecode) {
47 $authority_type = Koha::Authority::Types->find($authtypecode);
50 $template->param( authority_type => $authority_type );
51 } elsif ( $op eq 'add_validate' ) {
52 my $authtypecode = $input->param('authtypecode');
53 my $authtypetext = $input->param('authtypetext');
54 my $auth_tag_to_report = $input->param('auth_tag_to_report');
55 my $summary = $input->param('summary');
56 my $is_a_modif = $input->param('is_a_modif');
58 if ($is_a_modif) {
59 my $authority_type = Koha::Authority::Types->find($authtypecode);
60 $authority_type->authtypetext($authtypetext);
61 $authority_type->auth_tag_to_report($auth_tag_to_report);
62 $authority_type->summary($summary);
63 eval { $authority_type->store; };
64 if ($@) {
65 push @messages, { type => 'error', code => 'error_on_update' };
66 } else {
67 push @messages, { type => 'message', code => 'success_on_update' };
69 } else {
70 my $authority_type = Koha::Authority::Type->new(
71 { authtypecode => $authtypecode,
72 authtypetext => $authtypetext,
73 auth_tag_to_report => $auth_tag_to_report,
74 summary => $summary,
77 eval { $authority_type->store; };
78 if ($@) {
79 push @messages, { type => 'error', code => 'error_on_insert' };
80 } else {
81 push @messages, { type => 'message', code => 'success_on_insert' };
84 $op = 'list';
86 } elsif ( $op eq 'delete_confirm' ) {
87 my $authority_type = Koha::Authority::Types->find($authtypecode);
88 my $authorities_using_it = Koha::Authorities->search( { authtypecode => $authtypecode } )->count;
89 $template->param(
90 authority_type => $authority_type,
91 authorities_using_it => $authorities_using_it,
93 } elsif ( $op eq 'delete_confirmed' ) {
94 my $authorities_using_it = Koha::Authorities->search( { authtypecode => $authtypecode } )->count;
95 if ( $authorities_using_it == 0 ) {
96 my $authority_type = Koha::Authority::Types->find($authtypecode);
97 my $deleted = eval { $authority_type->delete; };
99 if ( $@ or not $deleted ) {
100 push @messages, { type => 'error', code => 'error_on_delete' };
101 } else {
102 push @messages, { type => 'message', code => 'success_on_delete' };
104 } else {
105 push @messages, { type => 'error', code => 'error_on_delete' };
107 $op = 'list';
110 if ( $op eq 'list' ) {
111 my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypecode'] } );
112 $template->param( authority_types => $authority_types, );
115 $template->param(
116 messages => \@messages,
117 op => $op,
120 output_html_with_http_headers $input, $cookie, $template->output;