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' ) {
57 elsif ( $op eq 'add_validate' ) {
58 my $name = $input->param('name');
59 my $code = $input->param('code');
61 if ( not defined $status ) {
62 $status = Koha::IllbatchStatus->new( {
70 $status->update_and_log({ name => $name });
72 $status->create_and_log;
74 push @messages, { type => 'message', code => 'success_on_saving' };
77 push @messages, { type => 'error', code => 'error_on_saving' };
81 elsif ( $op eq 'delete' ) {
83 $status->delete_and_log;
84 push @messages, { code => 'success_on_delete', type => 'message' };
87 push @messages, { code => 'error_on_delete', type => 'alert' };
92 if ( $op eq 'list' ) {
93 my $statuses = Koha::IllbatchStatuses->search();
94 $template->param( statuses => $statuses );
98 messages => \@messages,
102 output_html_with_http_headers $input, $cookie, $template->output;