Lines 41-46
use Data::Dumper;
Link Here
|
41 |
use Koha::DateUtils; |
41 |
use Koha::DateUtils; |
42 |
use Koha::Calendar; |
42 |
use Koha::Calendar; |
43 |
use Carp; |
43 |
use Carp; |
|
|
44 |
use Date::Calc qw( |
45 |
Today |
46 |
Today_and_Now |
47 |
Add_Delta_YM |
48 |
Add_Delta_DHMS |
49 |
Date_to_Days |
50 |
Day_of_Week |
51 |
Add_Delta_Days |
52 |
); |
44 |
|
53 |
|
45 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
54 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
46 |
|
55 |
|
Lines 926-931
sub CanBookBeIssued {
Link Here
|
926 |
} |
935 |
} |
927 |
} |
936 |
} |
928 |
} |
937 |
} |
|
|
938 |
|
939 |
# |
940 |
# CHECK AGE RESTRICTION ON TITLE |
941 |
# |
942 |
|
943 |
# get $marker from preferences. Could be something like "FSK|PEGI|Alter|Age:" |
944 |
my $marker = C4::Context->preference('AgeRestrictionMarker' ); |
945 |
my $xmlfield = C4::Context->preference('AgeRestrictionField' ); |
946 |
my $xmlsubfield = C4::Context->preference('AgeRestrictionSubField' ); |
947 |
|
948 |
if (($marker) && ($xmlfield)) |
949 |
{ |
950 |
my $thesql; |
951 |
if ($xmlsubfield) { |
952 |
$thesql = "SELECT ExtractValue(( SELECT marcxml FROM biblioitems WHERE biblionumber=?), |
953 |
'//datafield[\@tag=\"${xmlfield}\"]/subfield[\@code=\"${xmlsubfield}\"]') AS mycode;"; |
954 |
} else { |
955 |
$thesql = "SELECT ExtractValue(( SELECT marcxml FROM biblioitems WHERE biblionumber=?), |
956 |
'//datafield[\@tag=\"${xmlfield}\"]]') AS mycode;"; |
957 |
} |
958 |
|
959 |
#Hard coded version |
960 |
#my $thesql = "SELECT ExtractValue(( SELECT marcxml FROM biblioitems WHERE biblionumber=?), |
961 |
# '//datafield[\@tag=\"521\"]/subfield[\@code=\"a\"]') AS mycode;"; |
962 |
|
963 |
my $mysth = $dbh->prepare($thesql); |
964 |
$mysth->execute( $item->{'itemnumber'} ); |
965 |
my $iteminfo = $mysth->fetchrow_hashref; |
966 |
$mysth->finish; |
967 |
|
968 |
my $values = uc( $iteminfo->{'mycode'} ); |
969 |
|
970 |
my @marker = split /\|/, $marker; |
971 |
|
972 |
# Split $value Something like FSK 16 or PEGI 6 |
973 |
my @values = split ' ', $values ; |
974 |
|
975 |
# Search first occurence of one of the labels |
976 |
my $index = 0; |
977 |
my $take = -1; |
978 |
for my $value (@values) { |
979 |
$index ++; |
980 |
if (grep {uc($_) eq $value} @marker) { |
981 |
$take = $index; |
982 |
last; |
983 |
} |
984 |
} |
985 |
|
986 |
# Index points to the next value |
987 |
my $restrictionyear = 0; |
988 |
if (($take <= $#values) && ($take >= 0)){ |
989 |
$restrictionyear += @values[$take]; |
990 |
} |
991 |
|
992 |
if ($restrictionyear > 0) { |
993 |
if ( $borrower->{'dateofbirth'} ) { |
994 |
my @alloweddate = split /-/,$borrower->{'dateofbirth'} ; |
995 |
@alloweddate[0] += $restrictionyear; |
996 |
#Prevent runtime eror on leap year (invalid date) |
997 |
if ((@alloweddate[1] == 02) && (@alloweddate[2] == 29)) { |
998 |
@alloweddate[2] = 28; |
999 |
} |
1000 |
|
1001 |
my $td = Date_to_Days(Today); |
1002 |
my $ad = Date_to_Days(@alloweddate); |
1003 |
|
1004 |
if ( Date_to_Days(Today) < Date_to_Days(@alloweddate) -1 ) { |
1005 |
if (C4::Context->preference('AgeRestrictionOverride ' )) { |
1006 |
$issuingimpossible{AGE_RESTRICTION} = "$restrictionyear"; |
1007 |
} |
1008 |
else { |
1009 |
$needsconfirmation{AGE_RESTRICTION} = "$restrictionyear"; |
1010 |
} |
1011 |
} |
1012 |
} |
1013 |
} |
1014 |
} |
1015 |
|
929 |
return ( \%issuingimpossible, \%needsconfirmation ); |
1016 |
return ( \%issuingimpossible, \%needsconfirmation ); |
930 |
} |
1017 |
} |
931 |
|
1018 |
|