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' },
45 my $branches = Koha
::Libraries
->search( {}, { order_by
=> ['branchname'] } )->unblessed;
47 if ( $op eq 'add_form' ) {
50 $desk = Koha
::Desks
->find($desk_id);
53 $template->param( desk
=> $desk, );
54 } elsif ( $op eq 'add_validate' ) {
55 my $desk_id = $input->param('desk_id');
56 my $desk_name = $input->param('desk_name');
57 my $branchcode = $input->param('branchcode');
59 if (Koha
::Desks
->find($desk_id)) {
60 my $desk = Koha
::Desks
->find($desk_id);
61 $desk->desk_name($desk_name);
62 $desk->branchcode($branchcode);
63 eval { $desk->store; };
65 push @messages, { type
=> 'error', code
=> 'error_on_update' };
67 push @messages, { type
=> 'message', code
=> 'success_on_update' };
70 my $desk = Koha
::Desk
->new(
73 desk_name
=> $desk_name,
74 branchcode
=> $branchcode,
77 eval { $desk->store; };
79 push @messages, { type
=> 'error', code
=> 'error_on_insert' };
81 push @messages, { type
=> 'message', code
=> 'success_on_insert' };
86 } elsif ( $op eq 'delete_confirm' ) {
87 my $desk = Koha
::Desks
->find($desk_id);
88 $template->param( desk
=> $desk, );
89 } elsif ( $op eq 'delete_confirmed' ) {
90 my $desk = Koha
::Desks
->find($desk_id);
91 my $deleted = eval { $desk->delete; };
93 if ( $@
or not $deleted ) {
94 push @messages, { type
=> 'error', code
=> 'error_on_delete' };
96 push @messages, { type
=> 'message', code
=> 'success_on_delete' };
101 if ( $op eq 'list' || ! $op) {
102 my $desks = Koha
::Desks
->search( { desk_name
=> { -like
=> "%$searchfield%" } } );
103 $template->param( desks
=> $desks, );
108 searchfield
=> $searchfield,
109 messages
=> \
@messages,
111 branches
=> $branches,
114 output_html_with_http_headers
$input, $cookie, $template->output;