3 # Copyright (C) 2020 BULAC
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>.
30 my $searchfield = $input->param('desk_name') // q||;
31 my $desk_id = $input->param('desk_id') || '';
32 my $op = $input->param('op') || 'list';
35 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36 { template_name => "admin/desks.tt",
40 flagsrequired => { parameters => 'manage_libraries' },
44 my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed;
46 if ( $op eq 'add_form' ) {
49 $desk = Koha::Desks->find($desk_id);
52 $template->param( desk => $desk, );
53 } elsif ( $op eq 'add_validate' ) {
54 my $desk_id = $input->param('desk_id');
55 my $desk_name = $input->param('desk_name');
56 my $branchcode = $input->param('branchcode');
58 if (Koha::Desks->find($desk_id)) {
59 my $desk = Koha::Desks->find($desk_id);
60 $desk->desk_name($desk_name);
61 $desk->branchcode($branchcode);
62 eval { $desk->store; };
64 push @messages, { type => 'error', code => 'error_on_update' };
66 push @messages, { type => 'message', code => 'success_on_update' };
69 my $desk = Koha::Desk->new(
72 desk_name => $desk_name,
73 branchcode => $branchcode,
76 eval { $desk->store; };
78 push @messages, { type => 'error', code => 'error_on_insert' };
80 push @messages, { type => 'message', code => 'success_on_insert' };
85 } elsif ( $op eq 'delete_confirm' ) {
86 my $desk = Koha::Desks->find($desk_id);
87 $template->param( desk => $desk, );
88 } elsif ( $op eq 'delete_confirmed' ) {
89 my $desk = Koha::Desks->find($desk_id);
90 my $deleted = eval { $desk->delete; };
92 if ( $@ or not $deleted ) {
93 push @messages, { type => 'error', code => 'error_on_delete' };
95 push @messages, { type => 'message', code => 'success_on_delete' };
100 if ( $op eq 'list' || ! $op) {
101 my $desks = Koha::Desks->search( { desk_name => { -like => "%$searchfield%" } } );
102 $template->param( desks => $desks, );
107 searchfield => $searchfield,
108 messages => \@messages,
110 branches => $branches,
113 output_html_with_http_headers $input, $cookie, $template->output;