3 # Copyright 2008 LibLime
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 use C4
::Members
::AttributeTypes
;
30 my $script_name = "/cgi-bin/koha/admin/patron-attr-types.pl";
33 my $op = $input->param('op') || '';
36 my ($template, $loggedinuser, $cookie)
37 = get_template_and_user
({template_name
=> "admin/patron-attr-types.tmpl",
41 flagsrequired
=> {parameters
=> 1},
45 $template->param(script_name
=> $script_name);
47 my $code = $input->param("code");
50 if ($op eq "edit_attribute_type") {
51 edit_attribute_type_form
($template, $code);
52 } elsif ($op eq "edit_attribute_type_confirmed") {
53 $display_list = add_update_attribute_type
('edit', $template, $code);
54 } elsif ($op eq "add_attribute_type") {
55 add_attribute_type_form
($template);
56 } elsif ($op eq "add_attribute_type_confirmed") {
57 $display_list = add_update_attribute_type
('add', $template, $code);
58 } elsif ($op eq "delete_attribute_type") {
59 $display_list = delete_attribute_type_form
($template, $code);
60 } elsif ($op eq "delete_attribute_type_confirmed") {
61 delete_attribute_type
($template, $code);
68 unless (C4
::Context
->preference('ExtendedPatronAttributes')) {
69 $template->param(WARNING_extended_attributes_off
=> 1);
71 patron_attribute_type_list
($template);
74 output_html_with_http_headers
$input, $cookie, $template->output;
78 sub add_attribute_type_form
{
82 attribute_type_form
=> 1,
83 confirm_op
=> 'add_attribute_type_confirmed',
85 authorised_value_category_list
($template);
88 sub error_add_attribute_type_form
{
91 $template->param(description
=> $input->param('description'));
93 if ($input->param('repeatable')) {
94 $template->param(repeatable_checked
=> 'checked="checked"');
96 if ($input->param('unique_id')) {
97 $template->param(unique_id_checked
=> 'checked="checked"');
99 if ($input->param('password_allowed')) {
100 $template->param(password_allowed_checked
=> 'checked="checked"');
102 if ($input->param('opac_display')) {
103 $template->param(opac_display_checked
=> 'checked="checked"');
105 if ($input->param('staff_searchable')) {
106 $template->param(staff_searchable_checked
=> 'checked="checked"');
110 attribute_type_form
=> 1,
111 confirm_op
=> 'add_attribute_type_confirmed',
113 authorised_value_category_list
($template, $input->param('authorised_value_category'));
116 sub add_update_attribute_type
{
118 my $template = shift;
121 my $description = $input->param('description');
125 $attr_type = C4
::Members
::AttributeTypes
->fetch($code);
126 $attr_type->description($description);
128 my $existing = C4
::Members
::AttributeTypes
->fetch($code);
129 if (defined($existing)) {
130 $template->param(duplicate_code_error
=> $code);
131 error_add_attribute_type_form
($template);
134 $attr_type = C4
::Members
::AttributeTypes
->new($code, $description);
135 my $repeatable = $input->param('repeatable');
136 $attr_type->repeatable($repeatable);
137 my $unique_id = $input->param('unique_id');
138 $attr_type->unique_id($unique_id);
141 my $opac_display = $input->param('opac_display');
142 $attr_type->opac_display($opac_display);
143 my $staff_searchable = $input->param('staff_searchable');
144 $attr_type->staff_searchable($staff_searchable);
145 my $authorised_value_category = $input->param('authorised_value_category');
146 $attr_type->authorised_value_category($authorised_value_category);
147 my $password_allowed = $input->param('password_allowed');
148 $attr_type->password_allowed($password_allowed);
151 $template->param(edited_attribute_type
=> $attr_type->code());
153 $template->param(added_attribute_type
=> $attr_type->code());
160 sub delete_attribute_type_form
{
161 my $template = shift;
164 my $attr_type = C4
::Members
::AttributeTypes
->fetch($code);
165 my $display_list = 0;
166 if (defined($attr_type)) {
168 delete_attribute_type_form
=> 1,
169 confirm_op
=> "delete_attribute_type_confirmed",
171 description
=> $attr_type->description(),
174 $template->param(ERROR_delete_not_found
=> $code);
177 return $display_list;
180 sub delete_attribute_type
{
181 my $template = shift;
184 my $attr_type = C4
::Members
::AttributeTypes
->fetch($code);
185 if (defined($attr_type)) {
186 if ($attr_type->num_patrons() > 0) {
187 $template->param(ERROR_delete_in_use
=> $code);
188 $template->param(ERROR_num_patrons
=> $attr_type->num_patrons());
190 $attr_type->delete();
191 $template->param(deleted_attribute_type
=> $code);
194 $template->param(ERROR_delete_not_found
=> $code);
198 sub edit_attribute_type_form
{
199 my $template = shift;
202 my $attr_type = C4
::Members
::AttributeTypes
->fetch($code);
204 $template->param(code
=> $code);
205 $template->param(description
=> $attr_type->description());
207 if ($attr_type->repeatable()) {
208 $template->param(repeatable_checked
=> 'checked="checked"');
210 $template->param(repeatable_disabled
=> 'disabled="disabled"');
211 if ($attr_type->unique_id()) {
212 $template->param(unique_id_checked
=> 'checked="checked"');
214 $template->param(unique_id_disabled
=> 'disabled="disabled"');
215 if ($attr_type->password_allowed()) {
216 $template->param(password_allowed_checked
=> 'checked="checked"');
218 if ($attr_type->opac_display()) {
219 $template->param(opac_display_checked
=> 'checked="checked"');
221 if ($attr_type->staff_searchable()) {
222 $template->param(staff_searchable_checked
=> 'checked="checked"');
225 authorised_value_category_list
($template, $attr_type->authorised_value_category());
228 attribute_type_form
=> 1,
229 edit_attribute_type
=> 1,
230 confirm_op
=> 'edit_attribute_type_confirmed',
235 sub patron_attribute_type_list
{
236 my $template = shift;
238 my @attr_types = C4
::Members
::AttributeTypes
::GetAttributeTypes
();
239 $template->param(available_attribute_types
=> \
@attr_types);
240 $template->param(display_list
=> 1);
243 sub authorised_value_category_list
{
244 my $template = shift;
245 my $selected = @_ ?
shift : '';
247 my $categories = GetAuthorisedValueCategories
();
249 foreach my $category (@
$categories) {
250 my $entry = { category
=> $category };
251 $entry->{selected
} = 1 if $category eq $selected;
254 $template->param(authorised_value_categories
=> \
@list);