View | Details | Raw Unified | Return to bug 7621
Collapse All | Expand All

(-)a/C4/Circulation.pm (+87 lines)
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
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (+13 lines)
Lines 208-213 Circulation: Link Here
208
                  no: "Don't prevent"
208
                  no: "Don't prevent"
209
            - patrons from checking out an item whose rental charge would take them over the limit.
209
            - patrons from checking out an item whose rental charge would take them over the limit.
210
        -
210
        -
211
            - pref: AgeRestrictionField
212
            - pref: AgeRestrictionSubField
213
            - "Marc field / subfield for age restriction. E.g. 521 a (Empty AgeRestrictionField - Do not apply age restriction)"
214
        -
215
            - pref: AgeRestrictionMarker
216
            - "E.g. FSK|PEGI|Age| (No white space near |). Entry in Marc field e.g. PEGI 6 (Empty - Do not apply age restriction)"
217
        -
218
            - pref: AgeRestrictionOverride
219
              choices:
220
                  yes: Prevent
221
                  no: "Don't prevent"
222
            - patrons from checking out an item whose age restriction would apply.
223
        -
211
            - Prevent patrons from checking out books if they have more than
224
            - Prevent patrons from checking out books if they have more than
212
            - pref: noissuescharge
225
            - pref: noissuescharge
213
              class: integer
226
              class: integer
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (-1 / +8 lines)
Lines 240-245 function refocus(calendar) { Link Here
240
<h3>Please confirm checkout</h3>
240
<h3>Please confirm checkout</h3>
241
241
242
<ul>
242
<ul>
243
[% IF ( AGE_RESTRICTION ) %]
244
    <li>Age restriction [% AGE_RESTRICTION %]. Check out anyway?</li>
245
[% END %]
246
243
[% IF ( DEBT ) %]
247
[% IF ( DEBT ) %]
244
    <li>The patron has a debt of [% DEBT %]</li>
248
    <li>The patron has a debt of [% DEBT %]</li>
245
[% END %]
249
[% END %]
Lines 391-396 function refocus(calendar) { Link Here
391
            <li>No more renewals possible</li>
395
            <li>No more renewals possible</li>
392
        [% END %]
396
        [% END %]
393
397
398
        [% IF ( AGE_RESTRICTION ) %]
399
            <li>Age restriction [% AGE_RESTRICTION %]</li>
400
        [% END %]
401
394
        [% IF ( EXPIRED ) %]
402
        [% IF ( EXPIRED ) %]
395
            <li>Patron's card is expired</li>
403
            <li>Patron's card is expired</li>
396
        [% END %]
404
        [% END %]
397
- 

Return to bug 7621