X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=admin%2Fpatron-attr-types.pl;h=3935f40f37d9625cac7176d3c35c56c453b6d560;hb=08382876306cfda839637c5f72a107b304458a8e;hp=29a0d901ad3bf5da61fbd8701e0c39819a829641;hpb=05be38d438c242496a5c205fffefcfbdfdb63d46;p=koha.git diff --git a/admin/patron-attr-types.pl b/admin/patron-attr-types.pl index 29a0d901ad..3935f40f37 100755 --- a/admin/patron-attr-types.pl +++ b/admin/patron-attr-types.pl @@ -19,27 +19,31 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -use strict; -use warnings; +use Modern::Perl; + use CGI; +use List::MoreUtils qw/uniq/; + use C4::Auth; +use C4::Branch; use C4::Context; use C4::Output; use C4::Koha; +use C4::Members qw/GetBorrowercategoryList/; use C4::Members::AttributeTypes; my $script_name = "/cgi-bin/koha/admin/patron-attr-types.pl"; -my $input = new CGI; +our $input = new CGI; my $op = $input->param('op') || ''; -my ($template, $loggedinuser, $cookie) +our ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "admin/patron-attr-types.tmpl", query => $input, type => "intranet", authnotrequired => 0, - flagsrequired => {parameters => 1}, + flagsrequired => {parameters => 'parameters_remaining_permissions'}, debug => 1, }); @@ -79,11 +83,23 @@ exit 0; sub add_attribute_type_form { my $template = shift; + my $branches = GetBranches; + my @branches_loop; + foreach my $branch (sort keys %$branches) { + push @branches_loop, { + branchcode => $$branches{$branch}{branchcode}, + branchname => $$branches{$branch}{branchname}, + }; + } + $template->param( attribute_type_form => 1, confirm_op => 'add_attribute_type_confirmed', + categories => GetBorrowercategoryList, + branches_loop => \@branches_loop, ); authorised_value_category_list($template); + pa_classes($template); } sub error_add_attribute_type_form { @@ -110,6 +126,9 @@ sub error_add_attribute_type_form { $template->param(display_checkout_checked => 'checked="checked"'); } + $template->param( category_code => $input->param('category_code') ); + $template->param( class => $input->param('class') ); + $template->param( attribute_type_form => 1, confirm_op => 'add_attribute_type_confirmed', @@ -152,6 +171,10 @@ sub add_update_attribute_type { $attr_type->password_allowed($password_allowed); my $display_checkout = $input->param('display_checkout'); $attr_type->display_checkout($display_checkout); + $attr_type->category_code($input->param('category_code')); + $attr_type->class($input->param('class')); + my @branches = $input->param('branches'); + $attr_type->branches( \@branches ); if ($op eq 'edit') { $template->param(edited_attribute_type => $attr_type->code()); @@ -209,6 +232,7 @@ sub edit_attribute_type_form { $template->param(code => $code); $template->param(description => $attr_type->description()); + $template->param(class => $attr_type->class()); if ($attr_type->repeatable()) { $template->param(repeatable_checked => 1); @@ -231,20 +255,60 @@ sub edit_attribute_type_form { $template->param(display_checkout_checked => 'checked="checked"'); } authorised_value_category_list($template, $attr_type->authorised_value_category()); + pa_classes( $template, $attr_type->class ); + + + my $branches = GetBranches; + my @branches_loop; + my $selected_branches = $attr_type->branches; + foreach my $branch (sort keys %$branches) { + my $selected = ( grep {$$_{branchcode} eq $branch} @$selected_branches ) ? 1 : 0; + push @branches_loop, { + branchcode => $branches->{$branch}{branchcode}, + branchname => $branches->{$branch}{branchname}, + selected => $selected, + }; + } + $template->param( branches_loop => \@branches_loop ); + + $template->param ( category_code => $attr_type->category_code ); + $template->param ( category_description => $attr_type->category_description ); $template->param( attribute_type_form => 1, edit_attribute_type => 1, confirm_op => 'edit_attribute_type_confirmed', + categories => GetBorrowercategoryList, ); } sub patron_attribute_type_list { my $template = shift; - - my @attr_types = C4::Members::AttributeTypes::GetAttributeTypes(); - $template->param(available_attribute_types => \@attr_types); + + my @attr_types = C4::Members::AttributeTypes::GetAttributeTypes( 1, 1 ); + + my @classes = uniq( map { $_->{class} } @attr_types ); + @classes = sort @classes; + + my @attributes_loop; + for my $class (@classes) { + my ( @items, $branches ); + for my $attr (@attr_types) { + next if $attr->{class} ne $class; + my $attr_type = C4::Members::AttributeTypes->fetch($attr->{code}); + $attr->{branches} = $attr_type->branches; + push @items, $attr; + } + my $lib = GetAuthorisedValueByCode( 'PA_CLASS', $class ) || $class; + push @attributes_loop, { + class => $class, + items => \@items, + lib => $lib, + branches => $branches, + }; + } + $template->param(available_attribute_types => \@attributes_loop); $template->param(display_list => 1); } @@ -261,3 +325,10 @@ sub authorised_value_category_list { } $template->param(authorised_value_categories => \@list); } + +sub pa_classes { + my $template = shift; + my $selected = @_ ? shift : ''; + + $template->param(classes_val_loop => GetAuthorisedValues( 'PA_CLASS', $selected ) ); +}