From 53d30ca8958ee021c1435a2c4fd060b9499ae36e Mon Sep 17 00:00:00 2001 From: Lyon3 Team Date: Fri, 31 May 2013 10:56:56 +0200 Subject: [PATCH] Bug 9836 Filtering sort1 list according to patron category in patron data Sort1 criterias are often used as subcategories of patron ones This patch adds the possibility to link a sort1 criteria to a patron category in the Bsort1 authorised_values settings. Then in the patron edition Library management block, the sort1 list is filtered according to the selected patron category and displays only the criterias linked with it. --- admin/authorised_values.pl | 54 +++++++++++++++++--- installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 7 +++ .../prog/en/modules/admin/authorised_values.tt | 39 ++++++++++++++- .../prog/en/modules/members/memberentrygen.tt | 40 ++++++++++++++- members/memberentry.pl | 8 ++-- 6 files changed, 134 insertions(+), 15 deletions(-) diff --git a/admin/authorised_values.pl b/admin/authorised_values.pl index d344438..487a1c7 100755 --- a/admin/authorised_values.pl +++ b/admin/authorised_values.pl @@ -27,14 +27,13 @@ use C4::Context; use C4::Koha; use C4::Output; - sub AuthorizedValuesForCategory { my ($searchstring) = shift or return; my $dbh = C4::Context->dbh; $searchstring=~ s/\'/\\\'/g; my @data=split(' ',$searchstring); my $sth=$dbh->prepare(' - SELECT id, category, authorised_value, lib, lib_opac, imageurl + SELECT * FROM authorised_values WHERE (category = ?) ORDER BY category, authorised_value @@ -70,7 +69,7 @@ if ($op eq 'add_form') { my $data; my @selected_branches; if ($id) { - my $sth=$dbh->prepare("select id, category, authorised_value, lib, lib_opac, imageurl from authorised_values where id=?"); + my $sth=$dbh->prepare("select id, category, authorised_value, lib, lib_opac, linked_with, imageurl from authorised_values where id=?"); $sth->execute($id); $data=$sth->fetchrow_hashref; $sth = $dbh->prepare("SELECT b.branchcode, b.branchname FROM authorised_values_branches AS avb, branches AS b WHERE avb.branchcode = b.branchcode AND avb.av_id = ?;"); @@ -114,7 +113,36 @@ if ($op eq 'add_form') { offset => $offset, branches_loop => \@branches_loop, ); - + # Add borrower's categories select list, in case we'd like to bind a sort1 criteria to categories + my @linked_with = split ('\|', $data->{'linked_with'} ); + my @typeloop; + $template->param('allcatcodes'=>1) unless $data->{'linked_with'}; + if ($id){ + foreach (qw(C A S P I X)) { + my $action="WHERE category_type=?"; + my ($categories,$labels) = C4::Members::GetborCatFromCatType($_,$action); + my @categoryloop; + foreach my $cat (@$categories){ + my $selected = grep (/$cat/, @linked_with ) ? 1 : 0; + push @categoryloop,{ + 'categorycode' => $cat, + 'categoryname' => $labels->{$cat}, + 'selected' => $selected, + }; + } + my %typehash; + $typehash{'typename'}=$_; + my $typedescription = "typename_".$typehash{'typename'}; + $typehash{'categoryloop'}=\@categoryloop; + push @typeloop,{ + 'typename' => $_, + $typedescription => 1, + 'categoryloop' => \@categoryloop + }; + } + } + $template->param('typeloop' => \@typeloop); + ################## ADD_VALIDATE ################################## # called by add_form, used to insert/modify data in DB } elsif ($op eq 'add_validate') { @@ -141,13 +169,17 @@ if ($op eq 'add_form') { authorised_value = ?, lib = ?, lib_opac = ?, + linked_with = ?, imageurl = ? WHERE id=?' ); my $lib = $input->param('lib'); my $lib_opac = $input->param('lib_opac'); undef $lib if ($lib eq ""); # to insert NULL instead of a blank string undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string - $sth->execute($new_category, $new_authorised_value, $lib, $lib_opac, $imageurl, $id); + my @linked_with = $input->param('categorycode'); + # pipe after each code is necessary for correct filtering in memberentrygen.tt + my $linked_with = $linked_with[0] ne '' ? join ('|',@linked_with).'|' : ''; + $sth->execute($new_category, $new_authorised_value, $lib, $lib_opac, $linked_with, $imageurl, $id); if ( @branches ) { $sth = $dbh->prepare("DELETE FROM authorised_values_branches WHERE av_id = ?"); $sth->execute( $id ); @@ -173,13 +205,15 @@ if ($op eq 'add_form') { ($duplicate_entry) = $sth->fetchrow_array(); unless ( $duplicate_entry ) { my $sth=$dbh->prepare( 'INSERT INTO authorised_values - ( category, authorised_value, lib, lib_opac, imageurl ) - values (?, ?, ?, ?, ?)' ); + ( category, authorised_value, lib, lib_opac, linked_with, imageurl ) + values (?, ?, ?, ?, ?, ?)' ); my $lib = $input->param('lib'); my $lib_opac = $input->param('lib_opac'); undef $lib if ($lib eq ""); # to insert NULL instead of a blank string undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string - $sth->execute( $new_category, $new_authorised_value, $lib, $lib_opac, $imageurl ); + my @linked_with = $input->param('categorycode'); + my $linked_with = $linked_with[0] ne '' ? join ('|',@linked_with).'|' : ''; + $sth->execute( $new_category, $new_authorised_value, $lib, $lib_opac, $linked_with, $imageurl ); $id = $dbh->{'mysql_insertid'}; if ( @branches ) { $sth = $dbh->prepare( @@ -275,11 +309,15 @@ sub default_form { while ( my $branch = $sth->fetchrow_hashref ) { push @selected_branches, $branch; } + + + my %row_data; # get a fresh hash for the row data $row_data{category} = $results->[$i]{'category'}; $row_data{authorised_value} = $results->[$i]{'authorised_value'}; $row_data{lib} = $results->[$i]{'lib'}; $row_data{lib_opac} = $results->[$i]{'lib_opac'}; + $row_data{linked_with} = substr($results->[$i]{'linked_with'},0,-1) if $results->[$i]{'linked_with'} ;# remove last pipe just for display $row_data{imageurl} = getitemtypeimagelocation( 'intranet', $results->[$i]{'imageurl'} ); $row_data{edit} = "$script_name?op=add_form&id=".$results->[$i]{'id'}."&offset=$offset"; $row_data{delete} = "$script_name?op=delete_confirm&searchfield=$searchfield&id=".$results->[$i]{'id'}."&offset=$offset"; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index ca2f2b2..6eb612e 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -101,6 +101,7 @@ CREATE TABLE `authorised_values` ( -- stores values for authorized values catego `authorised_value` varchar(80) NOT NULL default '', -- code use to identify the authorized value `lib` varchar(200) default NULL, -- authorized value description as printed in the staff client `lib_opac` varchar(200) default NULL, -- authorized value description as printed in the OPAC + `linked_with` varchar(200) default NULL, -- borrower categorycode with it may be linked `imageurl` varchar(200) default NULL, -- authorized value URL PRIMARY KEY (`id`), KEY `name` (`category`), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index f3a90d8..8db3da5 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -6983,6 +6983,13 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ( SetVersion($DBversion); } +$DBversion = "3.13.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do("ALTER TABLE authorised_values ADD linked_with VARCHAR(200) default NULL AFTER lib_opac;"); + print "Upgrade to $DBversion done (Added linked_with to the authorised_values table)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt index 5ba3072..d1940c6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt @@ -103,6 +103,39 @@ $(document).ready(function() { + [% IF ( category == 'Bsort1' ) %] +
  • + +

    Select one or more categories (Ctrl key pressed) if you want this authorised value to be a subcategory of them only.

    +
  • + [% END %]
  • + + [% FOREACH sort1loo IN sort1loop %] + [% IF ( sort1loo.selected ) %] + + [% ELSE %] + + [% END %] + [% END %] + [% ELSE %] [% IF ( opduplicate ) %] diff --git a/members/memberentry.pl b/members/memberentry.pl index b7123f2..bf517ca 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -627,13 +627,13 @@ if (C4::Context->preference("memberofinstitution")){ # -------------------------------------------------------------------------------------------------------- -my $CGIsort = buildCGIsort("Bsort1","sort1",$data{'sort1'}); -if ($CGIsort) { - $template->param(CGIsort1 => $CGIsort); +my $sort1auth = GetAuthorisedValues('Bsort1',$data{'sort1'}); +if ($sort1auth) { + $template->param(sort1loop => $sort1auth); } $template->param( sort1 => $data{'sort1'}); # shouldn't this be in an "else" statement like the 2nd one? -$CGIsort = buildCGIsort("Bsort2","sort2",$data{'sort2'}); +my $CGIsort = buildCGIsort("Bsort2","sort2",$data{'sort2'}); if ($CGIsort) { $template->param(CGIsort2 => $CGIsort); } else { -- 1.7.2.5