@@ -, +, @@ 1. Apply this patch 2. Run updatedatabase.pl 3. Log in to staff client and modify a patron 4. Under "Library managenet" a new field "Additional categories" should be visible 5. Select one or more additional catogaries for the patron 6. Save 7. Make a checkout for the modified patron 8. A new dropdown box labled "Choose category for this checkout:" should be visible on the checkout page 9. Choose one of the additional categories in the dropdown box and checkout 10.Confirm that appropriet circulation rules for the category was applied to the checkout --- C4/Members.pm | 59 +++++++++++++++++++++- circ/circulation.pl | 10 ++++ .../bug_15174-additional-categories.sql | 9 ++++ .../intranet-tmpl/prog/en/includes/circ-menu.inc | 3 ++ .../prog/en/modules/circ/circulation.tt | 10 ++++ .../en/modules/circ/circulation_batch_checkouts.tt | 15 ++++++ .../prog/en/modules/members/memberentrygen.tt | 32 ++++++++++++ members/memberentry.pl | 10 +++- 8 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_15174-additional-categories.sql --- a/C4/Members.pm +++ a/C4/Members.pm @@ -191,7 +191,6 @@ the value "1". sub GetMemberDetails { my ( $borrowernumber, $cardnumber ) = @_; my $dbh = C4::Context->dbh; - my $query; my $sth; if ($borrowernumber) { $sth = $dbh->prepare(" @@ -252,6 +251,16 @@ sub GetMemberDetails { $borrower->{'showname'} = $borrower->{'firstname'}; } + # fetch and add additional categories + my $query = ' + SELECT * FROM categories_additional + WHERE borrowernumber = ? + '; + $sth = $dbh->prepare($query); + $sth->execute( $borrower->{'borrowernumber'} ); + my @cats = map { $_->{'categorycode'} } @{ $sth->fetchall_arrayref( {} ) }; + $borrower->{'additionalcategories'} = \@cats; + # Handle setting the true behavior for BlockExpiredPatronOpacActions $borrower->{'BlockExpiredPatronOpacActions'} = C4::Context->preference('BlockExpiredPatronOpacActions') @@ -462,7 +471,18 @@ sub GetMember { my $data = $sth->fetchall_arrayref({}); #FIXME interface to this routine now allows generation of a result set #so whole array should be returned but bowhere in the current code expects this - if (@{$data} ) { + if ( @{$data} ) { + + # fetch and add additional categories + $select = ' + SELECT * FROM categories_additional + WHERE borrowernumber = ? + '; + $sth = $dbh->prepare($select); + $sth->execute( $data->[0]->{'borrowernumber'} ); + my @cats = map { $_->{'categorycode'} } @{ $sth->fetchall_arrayref( {} ) }; + $data->[0]->{'additionalcategories'} = \@cats; + return $data->[0]; } @@ -644,6 +664,7 @@ true on success, or false on failure sub ModMember { my (%data) = @_; + my $dbh = C4::Context->dbh; # test to know if you must update or not the borrower password if (exists $data{password}) { if ($data{password} eq '****' or $data{password} eq '') { @@ -663,6 +684,7 @@ sub ModMember { my @columns = $schema->source('Borrower')->columns; my $new_borrower = { map { join(' ', @columns) =~ /$_/ ? ( $_ => $data{$_} ) : () } keys(%data) }; delete $new_borrower->{flags}; + delete $new_borrower->{additionalcategories}; $new_borrower->{dateofbirth} ||= undef if exists $new_borrower->{dateofbirth}; $new_borrower->{dateenrolled} ||= undef if exists $new_borrower->{dateenrolled}; @@ -708,6 +730,25 @@ sub ModMember { NLSync({ 'borrowernumber' => $data{'borrowernumber'} }); } + # Update additional categories + my $query = ' + DELETE FROM categories_additional + WHERE borrowernumber = ? + '; + my $sth = $dbh->prepare($query); + $sth->execute($data{'borrowernumber'}); + if ( @{ $data{'additionalcategories'} } ) { + $query = ' + INSERT INTO categories_additional + ( categorycode, borrowernumber ) + VALUES ( ?, ? ) + '; + $sth = $dbh->prepare($query); + for my $cat ( @{ $data{'additionalcategories'} } ) { + $sth->execute( $cat, $data{'borrowernumber'} ); + } + } + logaction("MEMBERS", "MODIFY", $data{'borrowernumber'}, "UPDATE (executed w/ arg: $data{'borrowernumber'})") if C4::Context->preference("BorrowersLog"); } return $execute_success; @@ -769,6 +810,7 @@ sub AddMember { my @columns = $schema->source('Borrower')->columns; my $new_member = { map { join(' ',@columns) =~ /$_/ ? ( $_ => $data{$_} ) : () } keys(%data) } ; delete $new_member->{borrowernumber}; + delete $new_member->{additionalcategories}; my $rs = $schema->resultset('Borrower'); $data{borrowernumber} = $rs->create($new_member)->id; @@ -785,6 +827,19 @@ sub AddMember { }); } + # Add additional categories + if ( @{ $data{'additionalcategories'} } ) { + my $query = ' + INSERT INTO categories_additional + ( categorycode, borrowernumber ) + VALUES ( ?, ? ) + '; + my $sth = $dbh->prepare($query); + for my $cat ( @{ $data{'additionalcategories'} } ) { + $sth->execute( $cat, $data{borrowernumber} ); + } + } + # mysql_insertid is probably bad. not necessarily accurate and mysql-specific at best. logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog"); --- a/circ/circulation.pl +++ a/circ/circulation.pl @@ -235,6 +235,8 @@ if ( $print eq 'yes' && $borrowernumber ne '' ) { $borrowernumber = ''; } +my $category = $query->param('category'); + # # STEP 2 : FIND BORROWER # if there is a list of find borrowers.... @@ -329,12 +331,20 @@ if ($borrowernumber) { } +my %cats; +map {$cats{$_->{categorycode}} = $_} @{GetBorrowercategoryList()}; +$template->param(categories => \%cats); + # # STEP 3 : ISSUING # # if (@$barcodes) { my $checkout_infos; + + # set session category + $borrower->{categorycode} = $category if $category; + for my $barcode ( @$barcodes ) { my $template_params = { barcode => $barcode }; # always check for blockers on issuing --- a/installer/data/mysql/atomicupdate/bug_15174-additional-categories.sql +++ a/installer/data/mysql/atomicupdate/bug_15174-additional-categories.sql @@ -0,0 +1,9 @@ +DROP TABLE IF EXISTS `categories_additional`; +CREATE TABLE `categories_additional` ( -- association table between categories and borrowers + `id` int(11) NOT NULL auto_increment, + `categorycode` varchar(10) NOT NULL default '', + `borrowernumber` int(11) NOT NULL, + PRIMARY KEY (`id`), + CONSTRAINT `categories_additional_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE, + CONSTRAINT `categories_additional_ibfk_2` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; --- a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc @@ -59,6 +59,9 @@ [% END %] [% END %][% END %]
  • Category: [% categoryname %] ([% categorycode %])
  • + [% IF additionalcategories %] +
  • Additional categories: [% additionalcategories.join(', ') %]
  • + [% END %]
  • Home library: [% IF ( branchname ) %][% branchname %][% ELSE %][% branch %][% END %]