3 # Copyright 2019 Koha Development Team
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>.
22 use Try::Tiny qw( catch try );
25 use C4::Auth qw( get_template_and_user );
26 use C4::Output qw( output_html_with_http_headers );
28 use Koha::IllbatchStatus;
29 use Koha::IllbatchStatuses;
32 my $code = $input->param('code');
33 my $op = $input->param('op') || 'list';
36 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
38 template_name => "admin/ill_batch_statuses.tt",
41 flagsrequired => { parameters => 'ill' },
47 $status = Koha::IllbatchStatuses->find( { code => $code } );
50 if ( $op eq 'add_form' ) {
52 $template->param( status => $status );
54 } elsif ( $op eq 'add_validate' ) {
55 my $name = $input->param('name');
56 my $code = $input->param('code');
58 if ( not defined $status ) {
59 $status = Koha::IllbatchStatus->new(
69 $status->update_and_log( { name => $name } );
71 $status->create_and_log;
73 push @messages, { type => 'message', code => 'success_on_saving' };
75 push @messages, { type => 'error', code => 'error_on_saving' };
78 } elsif ( $op eq 'delete' ) {
80 $status->delete_and_log;
81 push @messages, { code => 'success_on_delete', type => 'message' };
83 push @messages, { code => 'error_on_delete', type => 'alert' };
88 if ( $op eq 'list' ) {
89 my $statuses = Koha::IllbatchStatuses->search();
90 $template->param( statuses => $statuses );
94 messages => \@messages,
98 output_html_with_http_headers $input, $cookie, $template->output;