3 # Copyright 2016 ByWater Solutions
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>.
27 use Koha::Library::Group;
28 use Koha::Library::Groups;
32 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
34 template_name => "admin/library_groups.tt",
38 flagsrequired => { parameters => 'parameters_remaining_permissions' },
43 my $action = $cgi->param('action') || q{};
45 if ( $action eq 'add' ) {
46 my $parent_id = $cgi->param('parent_id') || undef;
47 my $title = $cgi->param('title') || undef;
48 my $description = $cgi->param('description') || undef;
49 my $branchcode = $cgi->param('branchcode') || undef;
51 if ( !$branchcode && Koha::Library::Groups->search( { title => $title } )->count() ) {
52 $template->param( error_duplicate_title => $title );
55 my $group = Koha::Library::Group->new(
57 parent_id => $parent_id,
59 description => $description,
60 branchcode => $branchcode,
64 $template->param( added => $group );
67 elsif ( $action eq 'edit' ) {
68 my $id = $cgi->param('id') || undef;
69 my $title = $cgi->param('title') || undef;
70 my $description = $cgi->param('description') || undef;
73 my $group = Koha::Library::Groups->find($id);
78 description => $description,
82 $template->param( edited => $group );
85 elsif ( $action eq 'delete' ) {
86 my $id = $cgi->param('id');
88 my $group = Koha::Library::Groups->find($id);
94 title => $group->title(),
95 library => $group->library()
96 ? $group->library()->branchname
103 my $root_groups = Koha::Library::Groups->get_root_groups();
105 $template->param( root_groups => $root_groups, );
107 output_html_with_http_headers $cgi, $cookie, $template->output;