Permalink
Browse files

bug 659 fixed: borrower category age limitations are now taken into a…

…ccount

during member registration.

Warning: new external module required, Date::Calc
  • Loading branch information...
plg
plg committed Apr 21, 2006
1 parent 5550717 commit 06b2edfa3280f3073dbf1f323df5204ebf1cc9c6
Showing with 73 additions and 16 deletions.
  1. +4 −1 about.pl
  2. +3 −0 koha-tmpl/intranet-tmpl/prog/en/members/memberentryA.tmpl
  3. +66 −15 members/memberentry.pl
View
@@ -28,6 +28,7 @@
my $apacheVersion = `httpd -v`;
$apacheVersion = `httpd2 -v` unless $apacheVersion;
my $zebraVersion = `zebraidx -V`;
+# $apacheVersion = (`/usr/sbin/apache2 -V`)[0];
$template->param(
kohaVersion => $kohaVersion,
@@ -44,8 +45,10 @@
Event Net::LDAP PDF::API2
Mail::Sendmail MARC::Record Digest::MD5
HTML::Template DBD::mysql Date::Manip
- DBI Smart::Comments ZOOM
+ DBI Smart::Comments Net::Z3950::ZOOM
+ Date::Calc
/;
+
my @components = ();
foreach my $component (sort @component_names) {
@@ -42,6 +42,9 @@
<!-- TMPL_IF NAME="ERROR_login_exist" -->
<p>login/password already exist</p>
<!-- /TMPL_IF -->
+ <!-- TMPL_IF NAME="ERROR_age_limitations" -->
+ Member is too young or too old for this category
+ <!-- /TMPL_IF -->
</div>
<!-- /TMPL_IF -->
View
@@ -18,21 +18,27 @@
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
+# pragma
use strict;
+
+# external modules
+use Date::Calc qw/Today/;
+use CGI;
+use HTML::Template;
+use Date::Manip;
+use Digest::MD5 qw(md5_base64);
+
+# internal modules
use C4::Auth;
use C4::Context;
use C4::Output;
use C4::Interface::CGI::Output;
-use CGI;
use C4::Search;
use C4::Members;
use C4::Koha;
-use HTML::Template;
-use Date::Manip;
use C4::Date;
use C4::Input;
use C4::Log;
-use Digest::MD5 qw(md5_base64);
my $input = new CGI;
my %data;
@@ -65,6 +71,8 @@
my $select_city=$input->param('select_city');
my $nok=$input->param('nok');
+my @errors;
+
# $check_categorytype contains the value of duplicate borrowers category type to redirect in good template in step =2
my $check_categorytype=$input->param('check_categorytype');
# NOTE: Alert for ethnicity and ethnotes fields, they are unvalided in all borrowers form
@@ -87,7 +95,7 @@
$data{$key}=~ s/\'/\\\'/g;
$data{$key}=~ s/\"/\\\"/g;
}
- my @errors;
+
#############test for member being unique #############
if ($op eq 'add' && $step eq 2){
(my $category_type_send=$category_type ) if ($category_type eq 'I');
@@ -125,7 +133,29 @@
$data{'email'}=$guarantordata->{'email'};
$data{'emailpro'}=$guarantordata->{'emailpro'};
}
- }
+ }
+ if ($categorycode ne 'I') {
+ # is the age of the borrower compatible with age limitations of
+ # the borrower category
+ my $query = '
+SELECT upperagelimit,
+ dateofbirthrequired
+ FROM categories
+ WHERE categorycode = ?
+';
+ my $sth=$dbh->prepare($query);
+ $sth->execute($categorycode);
+ my $category_info = $sth->fetchrow_hashref;
+
+ my $age = get_age(format_date_in_iso($data{dateofbirth}));
+
+ if ($age > $category_info->{upperagelimit}
+ or $age < $category_info->{dateofbirthrequired}
+ ) {
+ push @errors, 'ERROR_age_limitations';
+ $nok = 1;
+ }
+ }
}
# STEP 2
if ($step eq 2) {
@@ -174,14 +204,6 @@
logaction($loggedinuser,"MEMBERS","add member", $borrowerid, "");
}
}
-
- if ($nok) {
- foreach my $error (@errors) {
- $template->param( $error => 1);
- }
- $template->param(nok => 1);
- $step--; # decrease step : go back to step 2, the step++ just before showing the template will go again to 3
- }
unless ($nok) {
if($destination eq "circ"){
@@ -384,8 +406,18 @@
$data{'opacnotes'} =~ s/\\//g;
$data{'borrowernotes'} =~ s/\\//g;
+
# increase step to see next page
- $step++;
+ if ($nok) {
+ foreach my $error (@errors) {
+ $template->param( $error => 1);
+ }
+ $template->param(nok => 1);
+ }
+ else {
+ $step++;
+ }
+
warn "CITY".$data{city};
$template->param(
BorrowerMandatoryField => C4::Context->preference("BorrowerMandatoryField"),#field to test with javascript
@@ -462,6 +494,25 @@
#$template->param(Institution => 1) if ($categorycode eq "I");
output_html_with_http_headers $input, $cookie, $template->output;
}
+
+sub get_age {
+ my ($date, $date_ref) = @_;
+
+ if (not defined $date_ref) {
+ $date_ref = sprintf('%04d-%02d-%02d', Today());
+ }
+
+ my ($year1, $month1, $day1) = split /-/, $date;
+ my ($year2, $month2, $day2) = split /-/, $date_ref;
+
+ my $age = $year2 - $year1;
+ if ($month1.$day1 > $month2.$day2) {
+ $age--;
+ }
+
+ return $age;
+}
+
# Local Variables:
# tab-width: 8
# End:

0 comments on commit 06b2edf

Please sign in to comment.