Bug 26214: Remove the use of jquery.checkboxes plugin on late orders page
[koha.git] / admin / library_groups.pl
blobdcf71c87a3e94365e28d62549ccd56d6c90b7d7f
1 #! /usr/bin/perl
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>.
20 use Modern::Perl;
21 use CGI qw ( -utf8 );
22 use C4::Context;
23 use C4::Auth;
24 use C4::Output;
26 use Koha::Libraries;
27 use Koha::Library::Group;
28 use Koha::Library::Groups;
30 my $cgi = new CGI;
32 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
34 template_name => "admin/library_groups.tt",
35 query => $cgi,
36 type => "intranet",
37 authnotrequired => 0,
38 flagsrequired => { parameters => 'manage_libraries' },
39 debug => 1,
43 my $action = $cgi->param('action') || q{};
44 my @messages;
46 if ( $action eq 'add' ) {
47 my $parent_id = $cgi->param('parent_id') || undef;
48 my $title = $cgi->param('title') || undef;
49 my $description = $cgi->param('description') || undef;
50 my $branchcode = $cgi->param('branchcode') || undef;
51 my $ft_hide_patron_info = $cgi->param('ft_hide_patron_info') || 0;
52 my $ft_search_groups_opac = $cgi->param('ft_search_groups_opac') || 0;
53 my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
54 my $ft_local_hold_group = $cgi->param('ft_local_hold_group') || 0;
56 if ( !$branchcode && Koha::Library::Groups->search( { title => $title } )->count() ) {
57 $template->param( error_duplicate_title => $title );
59 else {
60 my $group = eval {
61 Koha::Library::Group->new(
63 parent_id => $parent_id,
64 title => $title,
65 description => $description,
66 ft_hide_patron_info => $ft_hide_patron_info,
67 ft_search_groups_opac => $ft_search_groups_opac,
68 ft_search_groups_staff => $ft_search_groups_staff,
69 ft_local_hold_group => $ft_local_hold_group,
70 branchcode => $branchcode,
72 )->store();
74 if ($@) {
75 push @messages, { type => 'alert', code => 'error_on_insert' };
77 else {
78 $template->param( added => $group );
82 elsif ( $action eq 'edit' ) {
83 my $id = $cgi->param('id') || undef;
84 my $title = $cgi->param('title') || undef;
85 my $description = $cgi->param('description') || undef;
86 my $ft_hide_patron_info = $cgi->param('ft_hide_patron_info') || 0;
87 my $ft_search_groups_opac = $cgi->param('ft_search_groups_opac') || 0;
88 my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
89 my $ft_local_hold_group = $cgi->param('ft_local_hold_group') || 0;
91 if ($id) {
92 my $group = Koha::Library::Groups->find($id);
94 $group->set(
96 title => $title,
97 description => $description,
98 ft_hide_patron_info => $ft_hide_patron_info,
99 ft_search_groups_opac => $ft_search_groups_opac,
100 ft_search_groups_staff => $ft_search_groups_staff,
101 ft_local_hold_group => $ft_local_hold_group,
103 )->store();
105 $template->param( edited => $group );
108 elsif ( $action eq 'delete' ) {
109 my $id = $cgi->param('id');
111 my $group = Koha::Library::Groups->find($id);
113 if ($group) {
114 $group->delete();
115 $template->param(
116 deleted => {
117 title => $group->title(),
118 library => $group->library()
119 ? $group->library()->branchname
120 : undef
126 my $root_groups = Koha::Library::Groups->get_root_groups();
128 $template->param( root_groups => $root_groups, messages => \@messages, );
130 output_html_with_http_headers $cgi, $cookie, $template->output;