Bug 20793: (follow-up) Add style to the non-link hold count on detail page
[koha.git] / admin / categories.pl
blob358ef7d8c851782e350662bd26cc9d1173161446
1 #!/usr/bin/perl
3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2002 Paul Poulain
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use Modern::Perl;
23 use CGI qw ( -utf8 );
24 use C4::Context;
25 use C4::Auth;
26 use C4::Output;
27 use C4::Form::MessagingPreferences;
28 use Koha::Patrons;
29 use Koha::Database;
30 use Koha::DateUtils;
31 use Koha::Patron::Categories;
32 use Koha::Libraries;
34 my $input = new CGI;
35 my $searchfield = $input->param('description') // q||;
36 my $categorycode = $input->param('categorycode');
37 my $op = $input->param('op') // 'list';
38 my @messages;
40 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
42 template_name => "admin/categories.tt",
43 query => $input,
44 type => "intranet",
45 authnotrequired => 0,
46 flagsrequired => { parameters => 'parameters_remaining_permissions' },
47 debug => 1,
51 if ( $op eq 'add_form' ) {
52 my ( $category, $selected_branches );
53 if ($categorycode) {
54 $category = Koha::Patron::Categories->find($categorycode);
55 $selected_branches = $category->branch_limitations;
58 my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed;
59 my @branches_loop;
60 foreach my $branch ( @$branches ) {
61 my $selected = ( grep { $_ eq $branch->{branchcode} } @$selected_branches ) ? 1 : 0;
62 push @branches_loop,
63 { branchcode => $branch->{branchcode},
64 branchname => $branch->{branchname},
65 selected => $selected,
69 $template->param(
70 category => $category,
71 branches_loop => \@branches_loop,
74 if ( C4::Context->preference('EnhancedMessagingPreferences') ) {
75 C4::Form::MessagingPreferences::set_form_values(
76 { categorycode => $categorycode }, $template );
79 elsif ( $op eq 'add_validate' ) {
81 my $categorycode = $input->param('categorycode');
82 my $description = $input->param('description');
83 my $enrolmentperiod = $input->param('enrolmentperiod');
84 my $enrolmentperioddate = $input->param('enrolmentperioddate') || undef;
85 my $upperagelimit = $input->param('upperagelimit');
86 my $dateofbirthrequired = $input->param('dateofbirthrequired');
87 my $enrolmentfee = $input->param('enrolmentfee');
88 my $reservefee = $input->param('reservefee');
89 my $hidelostitems = $input->param('hidelostitems');
90 my $overduenoticerequired = $input->param('overduenoticerequired');
91 my $category_type = $input->param('category_type');
92 my $BlockExpiredPatronOpacActions = $input->param('BlockExpiredPatronOpacActions');
93 my $checkPrevCheckout = $input->param('checkprevcheckout');
94 my $default_privacy = $input->param('default_privacy');
95 my @branches = grep { $_ ne q{} } $input->multi_param('branches');
97 my $is_a_modif = $input->param("is_a_modif");
99 if ($enrolmentperioddate) {
100 $enrolmentperioddate = output_pref(
102 dt => dt_from_string($enrolmentperioddate),
103 dateformat => 'iso',
104 dateonly => 1,
109 if ($is_a_modif) {
110 my $category = Koha::Patron::Categories->find( $categorycode );
111 $category->categorycode($categorycode);
112 $category->description($description);
113 $category->enrolmentperiod($enrolmentperiod);
114 $category->enrolmentperioddate($enrolmentperioddate);
115 $category->upperagelimit($upperagelimit);
116 $category->dateofbirthrequired($dateofbirthrequired);
117 $category->enrolmentfee($enrolmentfee);
118 $category->reservefee($reservefee);
119 $category->hidelostitems($hidelostitems);
120 $category->overduenoticerequired($overduenoticerequired);
121 $category->category_type($category_type);
122 $category->BlockExpiredPatronOpacActions($BlockExpiredPatronOpacActions);
123 $category->checkprevcheckout($checkPrevCheckout);
124 $category->default_privacy($default_privacy);
125 eval {
126 $category->store;
127 $category->replace_branch_limitations( \@branches );
129 if ( $@ ) {
130 push @messages, {type => 'error', code => 'error_on_update' };
131 } else {
132 push @messages, { type => 'message', code => 'success_on_update' };
135 else {
136 my $category = Koha::Patron::Category->new({
137 categorycode => $categorycode,
138 description => $description,
139 enrolmentperiod => $enrolmentperiod,
140 enrolmentperioddate => $enrolmentperioddate,
141 upperagelimit => $upperagelimit,
142 dateofbirthrequired => $dateofbirthrequired,
143 enrolmentfee => $enrolmentfee,
144 reservefee => $reservefee,
145 hidelostitems => $hidelostitems,
146 overduenoticerequired => $overduenoticerequired,
147 category_type => $category_type,
148 BlockExpiredPatronOpacActions => $BlockExpiredPatronOpacActions,
149 checkprevcheckout => $checkPrevCheckout,
150 default_privacy => $default_privacy,
152 eval {
153 $category->store;
154 $category->replace_branch_limitations( \@branches );
157 if ( $@ ) {
158 push @messages, { type => 'error', code => 'error_on_insert' };
159 } else {
160 push @messages, { type => 'message', code => 'success_on_insert' };
164 if ( C4::Context->preference('EnhancedMessagingPreferences') ) {
165 C4::Form::MessagingPreferences::handle_form_action( $input,
166 { categorycode => scalar $input->param('categorycode') }, $template );
169 $searchfield = q||;
170 $op = 'list';
172 elsif ( $op eq 'delete_confirm' ) {
174 my $count = Koha::Patrons->search({
175 categorycode => $categorycode
176 })->count;
178 my $category = Koha::Patron::Categories->find($categorycode);
180 $template->param(
181 category => $category,
182 patrons_in_category => $count,
186 elsif ( $op eq 'delete_confirmed' ) {
187 my $categorycode = uc( $input->param('categorycode') );
189 my $category = Koha::Patron::Categories->find( $categorycode );
190 my $deleted = eval { $category->delete; };
192 if ( $@ or not $deleted ) {
193 push @messages, {type => 'error', code => 'error_on_delete' };
194 } else {
195 push @messages, { type => 'message', code => 'success_on_delete' };
198 $op = 'list';
201 if ( $op eq 'list' ) {
202 my $categories = Koha::Patron::Categories->search(
204 description => { -like => "$searchfield%" }
207 order_by => ['category_type', 'description', 'categorycode' ]
211 $template->param(
212 categories => $categories,
216 $template->param(
217 categorycode => $categorycode,
218 searchfield => $searchfield,
219 messages => \@messages,
220 op => $op,
223 output_html_with_http_headers $input, $cookie, $template->output;
225 exit 0;