From ec3d03a6deef776e648ab6ad5d7ed27bc63d27e3 Mon Sep 17 00:00:00 2001 From: Lyon3 Team Date: Mon, 18 Mar 2013 13:25:03 +0100 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 | 45 ++++++++++++++++--- installer/data/mysql/updatedatabase.pl | 7 +++ .../prog/en/modules/admin/authorised_values.tt | 38 ++++++++++++++++ .../prog/en/modules/members/memberentrygen.tt | 34 ++++++++++++++- members/memberentry.pl | 8 ++-- 5 files changed, 119 insertions(+), 13 deletions(-) diff --git a/admin/authorised_values.pl b/admin/authorised_values.pl index c00bb64..387f1ff 100755 --- a/admin/authorised_values.pl +++ b/admin/authorised_values.pl @@ -27,14 +27,14 @@ 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 id, category, authorised_value, lib, lib_opac, imageurl + SELECT * FROM authorised_values WHERE (category = ?) ORDER BY category, authorised_value @@ -114,7 +114,34 @@ 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 a category +my @typeloop; +my $no_categories = 1; +foreach (qw(C A S P I X)) { + my $action="WHERE category_type=?"; + my ($categories,$labels) = C4::Members::GetborCatFromCatType($_,$action); + if(scalar(@$categories) > 0){ $no_categories = 0; } + my @categoryloop; + foreach my $cat (@$categories){ + push @categoryloop,{ + 'categorycode' => $cat, + 'categoryname' => $labels->{$cat}, + }; + } + my %typehash; + $typehash{'typename'}=$_; + my $typedescription = "typename_".$typehash{'typename'}; + $typehash{'categoryloop'}=\@categoryloop; + push @typeloop,{ + 'typename' => $_, + $typedescription => 1, + 'categoryloop' => \@categoryloop + }; +} +$template->param('typeloop' => \@typeloop, + no_categories => $no_categories); + ################## ADD_VALIDATE ################################## # called by add_form, used to insert/modify data in DB } elsif ($op eq 'add_validate') { @@ -141,13 +168,15 @@ 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'); + $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 +202,14 @@ 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'); + $sth->execute( $new_category, $new_authorised_value, $lib, $lib_opac, $linked_with, $imageurl ); $id = $dbh->{'mysql_insertid'}; if ( @branches ) { $sth = $dbh->prepare( @@ -280,6 +310,7 @@ sub default_form { $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} = C4::Members::GetBorrowercategory($results->[$i]{'linked_with'})->{description} if $results->[$i]{'linked_with'} ; $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/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 317680a..55e324c 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -6505,6 +6505,13 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.11.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("ALTER TABLE authorised_values ADD linked_with VARCHAR(80) default NULL AFTER lib_opac;"); + print "Upgrade to $DBversion done (Added linked_with to the authorised_values table)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) 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 790f0b5..e7ac269 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,34 @@ $(document).ready(function() { + [% IF ( category == 'Bsort1' ) %] +
  • + + +
  • + [% END %]