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>.
27 use C4
::Form
::MessagingPreferences
;
31 use Koha
::Patron
::Categories
;
35 my $searchfield = $input->param('description') // q
||;
36 my $categorycode = $input->param('categorycode');
37 my $op = $input->param('op') // 'list';
40 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
42 template_name
=> "admin/categories.tt",
46 flagsrequired
=> { parameters
=> 'manage_patron_categories' },
51 if ( $op eq 'add_form' ) {
52 my ( $category, $selected_branches );
54 $category = Koha
::Patron
::Categories
->find($categorycode);
55 $selected_branches = $category->branch_limitations;
58 my $branches = Koha
::Libraries
->search( {}, { order_by
=> ['branchname'] } )->unblessed;
60 foreach my $branch ( @
$branches ) {
61 my $selected = ( grep { $_ eq $branch->{branchcode
} } @
$selected_branches ) ?
1 : 0;
63 { branchcode
=> $branch->{branchcode
},
64 branchname
=> $branch->{branchname
},
65 selected
=> $selected,
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 $reset_password = $input->param('reset_password');
96 my $change_password = $input->param('change_password');
97 my $exclude_from_local_holds_priority = $input->param('exclude_from_local_holds_priority');
98 my @branches = grep { $_ ne q{} } $input->multi_param('branches');
100 $reset_password = undef if $reset_password eq -1;
101 $change_password = undef if $change_password eq -1;
103 my $is_a_modif = $input->param("is_a_modif");
105 if ($enrolmentperioddate) {
106 $enrolmentperioddate = output_pref
(
108 dt
=> dt_from_string
($enrolmentperioddate),
116 my $category = Koha
::Patron
::Categories
->find( $categorycode );
117 $category->categorycode($categorycode);
118 $category->description($description);
119 $category->enrolmentperiod($enrolmentperiod);
120 $category->enrolmentperioddate($enrolmentperioddate);
121 $category->upperagelimit($upperagelimit);
122 $category->dateofbirthrequired($dateofbirthrequired);
123 $category->enrolmentfee($enrolmentfee);
124 $category->reservefee($reservefee);
125 $category->hidelostitems($hidelostitems);
126 $category->overduenoticerequired($overduenoticerequired);
127 $category->category_type($category_type);
128 $category->BlockExpiredPatronOpacActions($BlockExpiredPatronOpacActions);
129 $category->checkprevcheckout($checkPrevCheckout);
130 $category->default_privacy($default_privacy);
131 $category->reset_password($reset_password);
132 $category->change_password($change_password);
133 $category->exclude_from_local_holds_priority($exclude_from_local_holds_priority);
136 $category->replace_branch_limitations( \
@branches );
139 push @messages, {type
=> 'error', code
=> 'error_on_update' };
141 push @messages, { type
=> 'message', code
=> 'success_on_update' };
145 my $category = Koha
::Patron
::Category
->new({
146 categorycode
=> $categorycode,
147 description
=> $description,
148 enrolmentperiod
=> $enrolmentperiod,
149 enrolmentperioddate
=> $enrolmentperioddate,
150 upperagelimit
=> $upperagelimit,
151 dateofbirthrequired
=> $dateofbirthrequired,
152 enrolmentfee
=> $enrolmentfee,
153 reservefee
=> $reservefee,
154 hidelostitems
=> $hidelostitems,
155 overduenoticerequired
=> $overduenoticerequired,
156 category_type
=> $category_type,
157 BlockExpiredPatronOpacActions
=> $BlockExpiredPatronOpacActions,
158 checkprevcheckout
=> $checkPrevCheckout,
159 default_privacy
=> $default_privacy,
160 reset_password
=> $reset_password,
161 change_password
=> $change_password,
162 exclude_from_local_holds_priority
=> $exclude_from_local_holds_priority,
166 $category->replace_branch_limitations( \
@branches );
170 push @messages, { type
=> 'error', code
=> 'error_on_insert' };
172 push @messages, { type
=> 'message', code
=> 'success_on_insert' };
176 if ( C4
::Context
->preference('EnhancedMessagingPreferences') ) {
177 C4
::Form
::MessagingPreferences
::handle_form_action
( $input,
178 { categorycode
=> scalar $input->param('categorycode') }, $template );
184 elsif ( $op eq 'delete_confirm' ) {
186 my $count = Koha
::Patrons
->search({
187 categorycode
=> $categorycode
190 my $category = Koha
::Patron
::Categories
->find($categorycode);
193 category
=> $category,
194 patrons_in_category
=> $count,
198 elsif ( $op eq 'delete_confirmed' ) {
199 my $categorycode = uc( $input->param('categorycode') );
201 my $category = Koha
::Patron
::Categories
->find( $categorycode );
202 my $deleted = eval { $category->delete; };
204 if ( $@
or not $deleted ) {
205 push @messages, {type
=> 'error', code
=> 'error_on_delete' };
207 push @messages, { type
=> 'message', code
=> 'success_on_delete' };
213 if ( $op eq 'list' ) {
214 my $categories = Koha
::Patron
::Categories
->search(
216 description
=> { -like
=> "$searchfield%" }
219 order_by
=> ['category_type', 'description', 'categorycode' ]
224 categories
=> $categories,
229 categorycode
=> $categorycode,
230 searchfield
=> $searchfield,
231 messages
=> \
@messages,
235 output_html_with_http_headers
$input, $cookie, $template->output;