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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (-23 / +21 lines)
Lines 145-180 Link Here
145
        return 0;
145
        return 0;
146
    }
146
    }
147
147
148
    function CalculateAge(dateofbirth) {
148
    function CalculateAge() {
149
        var today = new Date();
149
        if (!$("#dateofbirth").datepicker( 'getDate' )) {
150
        var dob = new Date($("#dateofbirth").datepicker( 'getDate' ));
150
            var elem = $("#dateofbirth").siblings(".hint").first().html('');
151
151
            return 1;
152
        var nowyear = today.getFullYear();
152
        }
153
        var nowmonth = today.getMonth();
154
        var nowday = today.getDate();
155
153
156
        var birthyear = dob.getFullYear();
154
        var dob = new Date($("#dateofbirth").datepicker( 'getDate' ));
157
        var birthmonth = dob.getMonth();
158
        var birthday = dob.getDate();
159
155
160
        var year = nowyear - birthyear;
156
        var year = dob.getFullYear();
161
        var month = nowmonth - birthmonth;
157
        var month = dob.getMonth();
162
        var day = nowday - birthday;
158
        var day = dob.getDate();
163
159
164
        if(day < 0) {
160
        $.ajax({
165
            month = parseInt(month) -1;
161
            url : '/cgi-bin/koha/svc/members/age',
166
        }
162
            type : 'GET',
163
            data: 'dateofbirth=' + year + '-' + month + '-' + day,
164
            dataType: 'json',
165
            success : function(json, statut){
166
                var age_string = "Age: ";
167
                if (json.years) { age_string += json.years + " year(s) "; }
168
                if (json.months) { age_string += json.months + " month(s) "; }
169
                var elem = $("#dateofbirth").siblings(".hint").first().html(age_string);
170
            },
171
        });
167
172
168
        if(month < 0) {
169
            year = parseInt(year) -1;
170
            month = 12 + month;
171
        }
172
173
173
        var age_string = "Age: ";
174
        var age_string = "Age: ";
174
        if (year) { age_string += year + " year(s) "; }
175
        if (month) { age_string += month + " month(s) "; }
176
175
177
        var elem = $("#dateofbirth").siblings(".hint").first().html(age_string);
178
    }
176
    }
179
177
180
178
(-)a/svc/members/age (-1 / +49 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2012 BibLibre
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use CGI qw ( -utf8 );
22
23
use C4::Auth qw( check_cookie_auth );
24
use JSON qw( to_json );
25
use C4::Members qw( GetAge );
26
binmode STDOUT, ":encoding(UTF-8)";
27
28
my $query = new CGI;
29
30
my ( $status, $sessionID ) = check_cookie_auth(
31
    $query->cookie('CGISESSID'),
32
    { borrowers => '*' },
33
);
34
35
unless ($status eq "ok") {
36
    print $query->header(-type => 'application/json', -status => '403 Forbidden');
37
    exit 0;
38
}
39
40
my $dateofbirth = $query->param('dateofbirth');
41
my ($age_year, $age_month) = GetAge($dateofbirth);
42
43
print $query->header(-type => 'application/json');
44
45
print to_json({
46
    years => $age_year,
47
    months => $age_month
48
});
49

Return to bug 15206