@@ -, +, @@ with borrower's age without using categories --- C4/Biblio.pm | 11 ++-- C4/Circulation.pm | 62 +++++++++++++++++++- installer/data/mysql/sysprefs.sql | 2 + installer/data/mysql/updatedatabase.pl | 12 ++++ .../en/modules/admin/preferences/circulation.pref | 9 +++ .../prog/en/modules/circ/circulation.tt | 8 +++ 6 files changed, 98 insertions(+), 6 deletions(-) --- a/C4/Biblio.pm +++ a/C4/Biblio.pm @@ -3317,7 +3317,8 @@ sub _koha_modify_biblioitem_nonmarc { cn_suffix = ?, cn_sort = ?, totalissues = ?, - ean = ? + ean = ? + agerestriction = ? where biblioitemnumber = ? "; my $sth = $dbh->prepare($query); @@ -3329,8 +3330,7 @@ sub _koha_modify_biblioitem_nonmarc { $biblioitem->{'pages'}, $biblioitem->{'bnotes'}, $biblioitem->{'size'}, $biblioitem->{'place'}, $biblioitem->{'lccn'}, $biblioitem->{'url'}, $biblioitem->{'biblioitems.cn_source'}, $biblioitem->{'cn_class'}, $biblioitem->{'cn_item'}, $biblioitem->{'cn_suffix'}, $cn_sort, $biblioitem->{'totalissues'}, - $biblioitem->{'ean'}, - $biblioitem->{'biblioitemnumber'} + $biblioitem->{'ean'}, $biblioitem->{'agerestriction'}, $biblioitem->{'biblioitemnumber'} ); if ( $dbh->errstr ) { $error .= "ERROR in _koha_modify_biblioitem_nonmarc $query" . $dbh->errstr; @@ -3382,7 +3382,8 @@ sub _koha_add_biblioitem { cn_suffix = ?, cn_sort = ?, totalissues = ?, - ean = ? + ean = ? + agerestriction = ? "; my $sth = $dbh->prepare($query); $sth->execute( @@ -3393,7 +3394,7 @@ sub _koha_add_biblioitem { $biblioitem->{'pages'}, $biblioitem->{'bnotes'}, $biblioitem->{'size'}, $biblioitem->{'place'}, $biblioitem->{'lccn'}, $biblioitem->{'marc'}, $biblioitem->{'url'}, $biblioitem->{'biblioitems.cn_source'}, $biblioitem->{'cn_class'}, $biblioitem->{'cn_item'}, $biblioitem->{'cn_suffix'}, $cn_sort, - $biblioitem->{'totalissues'}, $biblioitem->{'ean'} + $biblioitem->{'totalissues'}, $biblioitem->{'ean'}, $biblioitem->{'agerestriction'} ); my $bibitemnum = $dbh->{'mysql_insertid'}; --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -42,7 +42,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); BEGIN { @@ -931,6 +939,58 @@ sub CanBookBeIssued { } } } + # + # CHECK AGE RESTRICTION + # + + # get $marker from preferences. Could be something like "FSK|PEGI|Alter|Age:" + my $marker = C4::Context->preference('AgeRestrictionMarker' ); + + if ($marker) + { + # Split $value to something like FSK 16 or PEGI 6 + my @marker = split /\|/, $marker; + my @values = split ' ', $biblioitem->{'agerestriction'} ; + + # Search first occurence of one of the markers + 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 runime 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, \%alerts ); } --- a/installer/data/mysql/sysprefs.sql +++ a/installer/data/mysql/sysprefs.sql @@ -369,3 +369,5 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('SuspendHoldsIntranet', '1', NULL , 'Allow holds to be suspended from the intranet.', 'YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('SuspendHoldsOpac', '1', NULL , 'Allow holds to be suspended from the OPAC.', 'YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('DefaultLanguageField008','','Fill in the default language for field 008 Range 35-37 (e.g. eng, nor, ger, see MARC Code List for Languages)','','Free'); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AgeRestrictionMarker','','Markers for age restriction indication, e.g. FSK|PEGI|Age|',NULL,'free'); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AgeRestrictionOverride',0,'Do not prevent patrons from checking out an item whose age restriction would apply.',NULL,'YesNo'); --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -5343,6 +5343,18 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion = "XXX"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + # biblioitems changes + $dbh->do("ALTER TABLE 'biblioitems' ADD COLUMN 'agerestriction' VARCHAR(255) DEFAULT NULL AFTER 'cn_sort'"); + # preferences changes + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AgeRestrictionMarker','','Markers for age restriction indication, e.g. FSK|PEGI|Age|',NULL,'free')"); + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AgeRestrictionOverride',0,'Do not prevent patrons from checking out an item whose age restriction would apply.',NULL,'YesNo')"); + + print "Upgrade to $DBversion done (Add colum agerestriction to bilioitems, add system preferences AgeRestrictionMarker and AgeRestrictionOverride)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) --- 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,15 @@ Circulation: no: "Prevent" - patrons from checking out an item whose rental charge would take them over the limit. - + - pref: AgeRestrictionMarker + - "E.g. FSK|PEGI|Age| (No white space near |). Entry in MARC field (e.g. 521a) as defined for agerestriction in Koha to MARC mapping. Values e.g. FSK|PEGI|Age| . Entry e.g. in 521a like FSK 12 or PEGI 12 would then mean: Borrower must be 12 years old. (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 @@ -245,6 +245,10 @@ function refocus(calendar) {

Please confirm checkout