@@ -, +, @@ --- C4/Members/AttributeTypes.pm | 50 ++++++++++++++----- admin/patron-attr-types.pl | 14 ++++-- installer/data/mysql/updatedatabase.pl | 3 +- .../prog/en/modules/admin/patron-attr-types.tt | 13 ++--- .../prog/en/modules/members/memberentrygen.tt | 20 ++++---- members/memberentry.pl | 5 +- members/moremember.pl | 4 +- 7 files changed, 70 insertions(+), 39 deletions(-) --- a/C4/Members/AttributeTypes.pm +++ a/C4/Members/AttributeTypes.pm @@ -120,7 +120,8 @@ sub new { $self->{'staff_searchable'} = 0; $self->{'display_checkout'} = 0; $self->{'authorised_value_category'} = ''; - $self->{'category_type'} = ''; + $self->{'category_code'} = ''; + $self->{'category_description'} = ''; $self->{'class'} = ''; bless $self, $class; @@ -142,11 +143,15 @@ sub fetch { my $self = {}; my $dbh = C4::Context->dbh(); - my $sth = $dbh->prepare_cached("SELECT * FROM borrower_attribute_types WHERE code = ?"); + my $sth = $dbh->prepare_cached(" + SELECT borrower_attribute_types.*, categories.description AS category_description + FROM borrower_attribute_types + LEFT JOIN categories ON borrower_attribute_types.category_code=categories.categorycode + WHERE code =?"); $sth->execute($code); my $row = $sth->fetchrow_hashref; $sth->finish(); - return undef unless defined $row; + return undef unless defined $row; $self->{'code'} = $row->{'code'}; $self->{'description'} = $row->{'description'}; @@ -157,7 +162,8 @@ sub fetch { $self->{'staff_searchable'} = $row->{'staff_searchable'}; $self->{'display_checkout'} = $row->{'display_checkout'}; $self->{'authorised_value_category'} = $row->{'authorised_value_category'}; - $self->{'category_type'} = $row->{'category_type'}; + $self->{'category_code'} = $row->{'category_code'}; + $self->{'category_description'} = $row->{'category_description'}; $self->{'class'} = $row->{'class'}; bless $self, $class; @@ -190,13 +196,13 @@ sub store { staff_searchable = ?, authorised_value_category = ?, display_checkout = ?, - category_type = ?, + category_code = ?, class = ? WHERE code = ?"); } else { $sth = $dbh->prepare_cached("INSERT INTO borrower_attribute_types (description, repeatable, unique_id, opac_display, password_allowed, - staff_searchable, authorised_value_category, display_checkout, category_type, class, code) + staff_searchable, authorised_value_category, display_checkout, category_code, class, code) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); } @@ -208,7 +214,7 @@ sub store { $sth->bind_param(6, $self->{'staff_searchable'}); $sth->bind_param(7, $self->{'authorised_value_category'}); $sth->bind_param(8, $self->{'display_checkout'}); - $sth->bind_param(9, $self->{'category_type'}); + $sth->bind_param(9, $self->{'category_code'} || undef); $sth->bind_param(10, $self->{'class'}); $sth->bind_param(11, $self->{'code'}); $sth->execute; @@ -349,12 +355,12 @@ sub authorised_value_category { @_ ? $self->{'authorised_value_category'} = shift : $self->{'authorised_value_category'}; } -=head2 category_type +=head2 category_code =over 4 -my $category_type = $attr_type->category_type(); -$attr_type->category_type($category_type); +my $category_code = $attr_type->category_code(); +$attr_type->category_code($category_code); =back @@ -362,16 +368,34 @@ Accessor. =cut -sub category_type { +sub category_code { my $self = shift; - @_ ? $self->{'category_type'} = shift : $self->{'category_type'}; + @_ ? $self->{'category_code'} = shift : $self->{'category_code'}; +} + +=head2 category_description + +=over 4 + +my $category_description = $attr_type->category_description(); +$attr_type->category_description($category_description); + +=back + +Accessor. + +=cut + +sub category_description { + my $self = shift; + @_ ? $self->{'category_description'} = shift : $self->{'category_description'}; } =head2 class =over 4 -my $category_type = $attr_type->class(); +my $class = $attr_type->class(); $attr_type->class($class); =back --- a/admin/patron-attr-types.pl +++ a/admin/patron-attr-types.pl @@ -28,6 +28,7 @@ use C4::Auth; 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"; @@ -84,6 +85,7 @@ sub add_attribute_type_form { $template->param( attribute_type_form => 1, confirm_op => 'add_attribute_type_confirmed', + categories => GetBorrowercategoryList, ); authorised_value_category_list($template); pa_classes($template); @@ -113,7 +115,7 @@ sub error_add_attribute_type_form { $template->param(display_checkout_checked => 'checked="checked"'); } - $template->param( category_type => $input->param('category_type') ); + $template->param( category_code => $input->param('category_code') ); $template->param( class => $input->param('class') ); $template->param( @@ -158,7 +160,7 @@ 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_type($input->param('category_type')); + $attr_type->category_code($input->param('category_code')); $attr_type->class($input->param('class')); if ($op eq 'edit') { @@ -242,12 +244,14 @@ sub edit_attribute_type_form { authorised_value_category_list($template, $attr_type->authorised_value_category()); pa_classes( $template, $attr_type->class ); - $template->param ( category_type => $attr_type->category_type ); + $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, ); } @@ -256,7 +260,9 @@ sub patron_attribute_type_list { my $template = shift; my @attr_types = C4::Members::AttributeTypes::GetAttributeTypes(); - my @classes = sort uniq( map {$_->{class}} @attr_types ); + my @classes = uniq( map {$_->{class}} @attr_types ); + @classes = sort @classes; + my @attributes_loop; for my $class (@classes) { my @items; --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -4587,8 +4587,9 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { $DBversion = "3.06.00.XXX"; if (C4::Context->preference("Version") < TransformToNum($DBversion)) { - $dbh->do("ALTER TABLE borrower_attribute_types ADD COLUMN category_type VARCHAR(1) NOT NULL DEFAULT '' AFTER `display_checkout`"); + $dbh->do("ALTER TABLE borrower_attribute_types ADD COLUMN category_code VARCHAR(10) NULL DEFAULT NULL AFTER `display_checkout`"); $dbh->do("ALTER TABLE borrower_attribute_types ADD COLUMN class VARCHAR(255) NOT NULL DEFAULT '' AFTER `category_type`"); + $dbh->do("ALTER TABLE borrower_attribute_types ADD CONSTRAINT category_code_fk FOREIGN KEY (category_code) REFERENCES categories(categorycode)"); print "Upgrade to $DBversion done (New fields category_type and class in borrower_attribute_types table)\n"; SetVersion($DBversion); } --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt @@ -187,15 +187,12 @@ function CheckAttributeTypeForm(f) { enforced during batch patron import.
  • - - - [% IF category_type == 'A' %][% ELSE %][% END %] - [% IF category_type == 'C' %][% ELSE %][% END %] - [% IF category_type == 'S' %][% ELSE %][% END %] - [% IF category_type == 'I' %][% ELSE %][% END %] - [% IF category_type == 'P' %][% ELSE %][% END %] - [% IF category_type == 'X' %][% ELSE %][% END %] + [% FOREACH cat IN categories %] + [% IF ( cat.categorycode == category_code ) %][% ELSE %][% END %] + [% END %] Please let blank if you want these attributs to be for all types of patron. Else, select one type.
  • --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -24,12 +24,12 @@ document.form.country.value=RegExp.$4; }); - [% IF category_type %] - update_category_code( "[% category_type %]" ); + [% IF categorycode %] + update_category_code( "[% categorycode %]" ); [% ELSE %] if ( $("#categorycode").length > 0 ){ - var category_type = $("#categorycode").find("option:selected").attr("data-typename"); - update_category_code( category_type ); + var category_code = $("#categorycode").find("option:selected").val(); + update_category_code( category_code ); } [% END %] @@ -62,9 +62,9 @@ original.parentNode.insertBefore(clone, original.nextSibling); } - function update_category_code(category_type) { - if ( $(category_type).is("select") ) { - category_type = $("#categorycode").find("option:selected").attr("data-typename"); + function update_category_code(category_code) { + if ( $(category_code).is("select") ) { + category_code = $("#categorycode").find("option:selected").val(); } var mytables = $(".attributes_table>tbody"); @@ -72,10 +72,10 @@ $(this).hide() }); - mytables.find("tr[data-category_type="+category_type+"]").each(function(){ + mytables.find("tr[data-category_code="+category_code+"]").each(function(){ $(this).show(); }); - mytables.find("tr[data-category_type='']").each(function(){ + mytables.find("tr[data-category_code='']").each(function(){ $(this).show(); }); @@ -1225,7 +1225,7 @@ [% FOREACH patron_attribute IN pa_loo.items %] - + [% patron_attribute.code %] ([% patron_attribute.description %]) --- a/members/memberentry.pl +++ a/members/memberentry.pl @@ -752,7 +752,8 @@ sub patron_attributes_form { return; } my $attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); - my @classes = sort uniq( map {$_->{class}} @$attributes ); + my @classes = uniq( map {$_->{class}} @$attributes ); + @classes = sort @classes; # map patron's attributes into a more convenient structure my %attr_hash = (); @@ -772,7 +773,7 @@ sub patron_attributes_form { repeatable => $attr_type->repeatable(), password_allowed => $attr_type->password_allowed(), category => $attr_type->authorised_value_category(), - category_type => $attr_type->category_type(), + category_code => $attr_type->category_code(), password => '', }; if (exists $attr_hash{$attr_type->code()}) { --- a/members/moremember.pl +++ a/members/moremember.pl @@ -432,7 +432,9 @@ $template->param(%$data); if (C4::Context->preference('ExtendedPatronAttributes')) { my $attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); - my @classes = sort uniq( map {$_->{class}} @$attributes ); + my @classes = uniq( map {$_->{class}} @$attributes ); + @classes = sort @classes; + my @attributes_loop; for my $class (@classes) { my @items; --