@@ -, +, @@ --- C4/Circulation.pm | 87 ++++++++++++++++++++ .../en/modules/admin/preferences/circulation.pref | 13 +++ .../prog/en/modules/circ/circulation.tt | 8 ++ 3 files changed, 108 insertions(+), 0 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -41,6 +41,15 @@ use Data::Dumper; use Koha::DateUtils; use Koha::Calendar; use Carp; +use Date::Calc qw( + Today + Today_and_Now + Add_Delta_YM + Add_Delta_DHMS + Date_to_Days + Day_of_Week + Add_Delta_Days +); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); @@ -926,6 +935,84 @@ sub CanBookBeIssued { } } } + + # + # CHECK AGE RESTRICTION ON TITLE + # + + # get $marker from preferences. Could be something like "FSK|PEGI|Alter|Age:" + my $marker = C4::Context->preference('AgeRestrictionMarker' ); + my $xmlfield = C4::Context->preference('AgeRestrictionField' ); + my $xmlsubfield = C4::Context->preference('AgeRestrictionSubField' ); + + if (($marker) && ($xmlfield)) + { + my $thesql; + if ($xmlsubfield) { + $thesql = "SELECT ExtractValue(( SELECT marcxml FROM biblioitems WHERE biblionumber=?), + '//datafield[\@tag=\"${xmlfield}\"]/subfield[\@code=\"${xmlsubfield}\"]') AS mycode;"; + } else { + $thesql = "SELECT ExtractValue(( SELECT marcxml FROM biblioitems WHERE biblionumber=?), + '//datafield[\@tag=\"${xmlfield}\"]]') AS mycode;"; + } + + #Hard coded version + #my $thesql = "SELECT ExtractValue(( SELECT marcxml FROM biblioitems WHERE biblionumber=?), + # '//datafield[\@tag=\"521\"]/subfield[\@code=\"a\"]') AS mycode;"; + + my $mysth = $dbh->prepare($thesql); + $mysth->execute( $item->{'itemnumber'} ); + my $iteminfo = $mysth->fetchrow_hashref; + $mysth->finish; + + my $values = uc( $iteminfo->{'mycode'} ); + + my @marker = split /\|/, $marker; + + # Split $value Something like FSK 16 or PEGI 6 + my @values = split ' ', $values ; + + # Search first occurence of one of the labels + my $index = 0; + my $take = -1; + for my $value (@values) { + $index ++; + if (grep {uc($_) eq $value} @marker) { + $take = $index; + last; + } + } + + # Index points to the next value + my $restrictionyear = 0; + if (($take <= $#values) && ($take >= 0)){ + $restrictionyear += @values[$take]; + } + + if ($restrictionyear > 0) { + if ( $borrower->{'dateofbirth'} ) { + my @alloweddate = split /-/,$borrower->{'dateofbirth'} ; + @alloweddate[0] += $restrictionyear; + #Prevent runtime eror on leap year (invalid date) + if ((@alloweddate[1] == 02) && (@alloweddate[2] == 29)) { + @alloweddate[2] = 28; + } + + my $td = Date_to_Days(Today); + my $ad = Date_to_Days(@alloweddate); + + if ( Date_to_Days(Today) < Date_to_Days(@alloweddate) -1 ) { + if (C4::Context->preference('AgeRestrictionOverride ' )) { + $issuingimpossible{AGE_RESTRICTION} = "$restrictionyear"; + } + else { + $needsconfirmation{AGE_RESTRICTION} = "$restrictionyear"; + } + } + } + } + } + return ( \%issuingimpossible, \%needsconfirmation ); } --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -208,6 +208,19 @@ Circulation: no: "Don't prevent" - patrons from checking out an item whose rental charge would take them over the limit. - + - pref: AgeRestrictionField + - pref: AgeRestrictionSubField + - "Marc field / subfield for age restriction. E.g. 521 a (Empty AgeRestrictionField - Do not apply age restriction)" + - + - pref: AgeRestrictionMarker + - "E.g. FSK|PEGI|Age| (No white space near |). Entry in Marc field e.g. PEGI 6 (Empty - Do not apply age restriction)" + - + - pref: AgeRestrictionOverride + choices: + yes: Prevent + no: "Don't prevent" + - patrons from checking out an item whose age restriction would apply. + - - Prevent patrons from checking out books if they have more than - pref: noissuescharge class: integer --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -240,6 +240,10 @@ function refocus(calendar) {

Please confirm checkout