From 96fc46e2e1621effac5f51ff8d6a9ac79fb0551b Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Tue, 21 Jul 2009 17:07:37 +0200 Subject: [PATCH] MT 1717 : Opac descriptions for authorised values --- C4/Biblio.pm | 11 +++--- C4/Koha.pm | 29 +++++++++------- admin/authorised_values.pl | 34 ++++++++++++------- ...-opac-description-for-authorised-values.pl | 7 ++++ installer/data/mysql/kohastructure.sql | 1 + .../en/modules/admin/authorised_values.tmpl | 20 +++++++---- opac/opac-MARCdetail.pl | 4 +-- opac/opac-basket.pl | 4 +-- opac/opac-detail.pl | 6 ++-- opac/opac-search.pl | 4 +-- 10 files changed, 76 insertions(+), 44 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/0008-opac-description-for-authorised-values.pl diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 49b9108d3e..0e92d90025 100755 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1272,19 +1272,22 @@ sub GetCOinSBiblio { =over 4 my $subfieldvalue =get_authorised_value_desc( - $tag, $subf[$i][0],$subf[$i][1], '', $taglib, $category); + $tag, $subf[$i][0],$subf[$i][1], '', $taglib, $category, $opac); Retrieve the complete description for a given authorised value. Now takes $category and $value pair too. my $auth_value_desc =GetAuthorisedValueDesc( '','', 'DVD' ,'','','CCODE'); +If the optional $opac parameter is set to a true value, displays OPAC descriptions rather than normal ones when they exist. + + =back =cut sub GetAuthorisedValueDesc { - my ( $tag, $subfield, $value, $framework, $tagslib, $category ) = @_; + my ( $tag, $subfield, $value, $framework, $tagslib, $category, $opac ) = @_; my $dbh = C4::Context->dbh; if (!$category) { @@ -1308,11 +1311,11 @@ sub GetAuthorisedValueDesc { if ( $category ne "" ) { my $sth = $dbh->prepare( - "SELECT lib FROM authorised_values WHERE category = ? AND authorised_value = ?" + "SELECT lib, lib_opac FROM authorised_values WHERE category = ? AND authorised_value = ?" ); $sth->execute( $category, $value ); my $data = $sth->fetchrow_hashref; - return $data->{'lib'}; + return ($opac && $data->{'lib_opac'}) ? $data->{'lib_opac'} : $data->{'lib'}; } else { return $value; # if nothing is found return the original value diff --git a/C4/Koha.pm b/C4/Koha.pm index bfe60f2336..31bd6784db 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -1068,27 +1068,31 @@ sub GetAuthValCode { $authvalues = GetAuthorisedValues([$category], [$selected]); -This function returns all authorised values from the'authosied_value' table in a reference to array of hashrefs. +This function returns all authorised values from the'authorised_value' table in a reference to array of hashrefs. C<$category> returns authorised values for just one category (optional). +C<$opac> If set to a true value, displays OPAC descriptions rather than normal ones when they exist. + =cut sub GetAuthorisedValues { - my ($category,$selected) = @_; + my ($category,$selected,$opac) = @_; my @results; my $dbh = C4::Context->dbh; my $query = "SELECT * FROM authorised_values"; $query .= " WHERE category = '" . $category . "'" if $category; - $query .= " ORDER BY category, lib"; - + $query .= " ORDER BY category, lib, lib_opac"; my $sth = $dbh->prepare($query); $sth->execute; while (my $data=$sth->fetchrow_hashref) { - if ($selected eq $data->{'authorised_value'} ) { - $data->{'selected'} = 1; - } - push @results, $data; + if ($selected eq $data->{'authorised_value'} ) { + $data->{'selected'} = 1; + } + if ($opac && $data->{'lib_opac'}) { + $data->{'lib'} = $data->{'lib_opac'}; + } + push @results, $data; } #my $data = $sth->fetchall_arrayref({}); return \@results; #$data; @@ -1117,6 +1121,7 @@ sub GetAuthorisedValueCategories { =head2 GetKohaAuthorisedValues Takes $kohafield, $fwcode as parameters. + If $opac parameter is set to a true value, displays OPAC descriptions rather than normal ones when they exist. Returns hashref of Code => description Returns undef if no authorised value category is defined for the kohafield. @@ -1124,16 +1129,16 @@ sub GetAuthorisedValueCategories { =cut sub GetKohaAuthorisedValues { - my ($kohafield,$fwcode,$codedvalue) = @_; + my ($kohafield,$fwcode,$opac) = @_; $fwcode='' unless $fwcode; my %values; my $dbh = C4::Context->dbh; my $avcode = GetAuthValCode($kohafield,$fwcode); if ($avcode) { - my $sth = $dbh->prepare("select authorised_value, lib from authorised_values where category=? "); + my $sth = $dbh->prepare("select authorised_value, lib, lib_opac from authorised_values where category=? "); $sth->execute($avcode); - while ( my ($val, $lib) = $sth->fetchrow_array ) { - $values{$val}= $lib; + while ( my ($val, $lib, $lib_opac) = $sth->fetchrow_array ) { + $values{$val} = ($opac && $lib_opac) ? $lib_opac : $lib; } return \%values; } else { diff --git a/admin/authorised_values.pl b/admin/authorised_values.pl index c90b51f8a3..34d04fb818 100755 --- a/admin/authorised_values.pl +++ b/admin/authorised_values.pl @@ -33,7 +33,7 @@ sub AuthorizedValuesForCategory ($) { $searchstring=~ s/\'/\\\'/g; my @data=split(' ',$searchstring); my $sth=$dbh->prepare(' - SELECT id, category, authorised_value, lib, imageurl + SELECT id, category, authorised_value, lib, lib_opac, imageurl FROM authorised_values WHERE (category = ?) ORDER BY category, authorised_value @@ -73,7 +73,7 @@ $template->param( script_name => $script_name, if ($op eq 'add_form') { my $data; if ($id) { - my $sth=$dbh->prepare("select id, category, authorised_value, lib, imageurl from authorised_values where id=?"); + my $sth=$dbh->prepare("select id, category, authorised_value, lib, lib_opac, imageurl from authorised_values where id=?"); $sth->execute($id); $data=$sth->fetchrow_hashref; } else { @@ -93,6 +93,7 @@ if ($op eq 'add_form') { $template->param( category => $data->{'category'}, authorised_value => $data->{'authorised_value'}, lib => $data->{'lib'}, + lib_opac => $data->{'lib_opac'}, id => $data->{'id'}, imagesets => C4::Koha::getImageSets( checked => $data->{'imageurl'} ), offset => $offset, @@ -123,11 +124,14 @@ if ($op eq 'add_form') { SET category = ?, authorised_value = ?, lib = ?, + lib_opac = ?, 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 - $sth->execute($new_category, $new_authorised_value, $lib, $imageurl, $id); + 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); print "Content-Type: text/html\n\n"; exit; } @@ -139,11 +143,13 @@ if ($op eq 'add_form') { ($duplicate_entry) = $sth->fetchrow_array(); unless ( $duplicate_entry ) { my $sth=$dbh->prepare( 'INSERT INTO authorised_values - ( id, category, authorised_value, lib, imageurl ) - values (?, ?, ?, ?, ?)' ); + ( id, category, authorised_value, lib, lib_opac, 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 - $sth->execute($id, $new_category, $new_authorised_value, $lib, $imageurl ); + undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string + $sth->execute($id, $new_category, $new_authorised_value, $lib, $lib_opac, $imageurl ); print "Content-Type: text/html\n\nparam('category')."&offset=$offset\">"; exit; } @@ -158,12 +164,13 @@ if ($op eq 'add_form') { ################## DELETE_CONFIRM ################################## # called by default form, used to confirm deletion of data in DB } elsif ($op eq 'delete_confirm') { - my $sth=$dbh->prepare("select category,authorised_value,lib from authorised_values where id=?"); + my $sth=$dbh->prepare("select category,authorised_value,lib,lib_opac from authorised_values where id=?"); $sth->execute($id); my $data=$sth->fetchrow_hashref; $id = $input->param('id') unless $id; $template->param(searchfield => $searchfield, Tlib => $data->{'lib'}, + Tlib_opac => $data->{'lib_opac'}, Tvalue => $data->{'authorised_value'}, id =>$id, ); @@ -219,12 +226,13 @@ sub default_form { # builds value list for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){ 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{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"; + $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{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"; push(@loop_data, \%row_data); } diff --git a/installer/data/mysql/atomicupdate/0008-opac-description-for-authorised-values.pl b/installer/data/mysql/atomicupdate/0008-opac-description-for-authorised-values.pl new file mode 100755 index 0000000000..b5347f41fc --- /dev/null +++ b/installer/data/mysql/atomicupdate/0008-opac-description-for-authorised-values.pl @@ -0,0 +1,7 @@ +#! /usr/bin/perl +use strict; +use warnings; +use C4::Context; +my $dbh=C4::Context->dbh; +$dbh->do("ALTER TABLE authorised_values ADD COLUMN `lib_opac` VARCHAR(80) default NULL AFTER `lib`"); +print "Upgrade done (Added a lib_opac field in authorised_values table)\n"; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 409fa67196..a4b138673c 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -413,6 +413,7 @@ CREATE TABLE `authorised_values` ( `category` varchar(10) NOT NULL default '', `authorised_value` varchar(80) NOT NULL default '', `lib` varchar(80) default NULL, + `lib_opac` varchar(80) default NULL, `imageurl` varchar(200) default NULL, PRIMARY KEY (`id`), KEY `name` (`category`), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tmpl index 20b8712127..488dc10c09 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tmpl @@ -59,6 +59,10 @@
  • " /> +
  • +
  • + + " />
  • @@ -109,13 +113,16 @@ - + + - - - + + + + +
    CategoryVariable ValueDescriptionDescription (OPAC)
    " method="post"> @@ -189,10 +196,11 @@ the subfield is not entered through a free field, but though a list of authorize

    The list of status to describe a lost item

    + - + @@ -203,9 +211,9 @@ the subfield is not entered through a free field, but though a list of authorize - + diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index 51d1579be1..940104b277 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -170,7 +170,7 @@ for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) { } $subfield_data{marc_value} = GetAuthorisedValueDesc( $fields[$x_i]->tag(), - $subf[$i][0], $subf[$i][1], '', $tagslib ); + $subf[$i][0], $subf[$i][1], '', $tagslib, '', 'opac' ); } $subfield_data{marc_subfield} = $subf[$i][0]; $subfield_data{marc_tag} = $fields[$x_i]->tag(); @@ -241,7 +241,7 @@ foreach my $field (@fields) { else { $this_row{ $subf[$i][0] } = GetAuthorisedValueDesc( $field->tag(), $subf[$i][0], - $subf[$i][1], '', $tagslib ); + $subf[$i][1], '', $tagslib, '', 'opac' ); } } if (%this_row) { diff --git a/opac/opac-basket.pl b/opac/opac-basket.pl index a4383ab908..c044fee493 100755 --- a/opac/opac-basket.pl +++ b/opac/opac-basket.pl @@ -74,8 +74,8 @@ foreach my $biblionumber ( @bibs ) { $hasauthors = 1; } - my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}); - my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'} ); + my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac'); + my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac'); for my $itm (@items) { if ($itm->{'location'}){ diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 577510359e..bd4dc0a4e1 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -97,8 +97,8 @@ if ( $itemtype ) { $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} ); $dat->{'description'} = $itemtypes->{$itemtype}->{'description'}; } -my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}); -my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'} ); +my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac'); +my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac'); #coping with subscriptions my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber); @@ -422,7 +422,7 @@ if (C4::Context->preference("OPACShelfBrowser")) { $starting_homebranch->{code} = $result->{'homebranch'}; $starting_homebranch->{description} = $branches->{$result->{'homebranch'}}{branchname}; $starting_location->{code} = $result->{'location'}; - $starting_location->{description} = GetAuthorisedValueDesc('','', $result->{'location'} ,'','','LOC'); + $starting_location->{description} = GetAuthorisedValueDesc('','', $result->{'location'} ,'','','LOC', 'opac'); } diff --git a/opac/opac-search.pl b/opac/opac-search.pl index aa4118e7eb..b920a88978 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -147,8 +147,8 @@ if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') { push @itemtypesloop, \%row; } } else { - my $advsearchtypes = GetAuthorisedValues($advanced_search_types); - for my $thisitemtype (sort {$a->{'lib'} cmp $b->{'lib'}} @$advsearchtypes) { + my $advsearchtypes = GetAuthorisedValues($advanced_search_types, '', 'opac'); + for my $thisitemtype (@$advsearchtypes) { my %row =( number=>$cnt++, ccl => $advanced_search_types, -- 2.20.1
    Authorised values for category :
    Category Authorized value DescriptionDescription (OPAC) Icon Edit Delete
    " alt=""/>  ">Edit ">Delete