From 06b2edfa3280f3073dbf1f323df5204ebf1cc9c6 Mon Sep 17 00:00:00 2001 From: plg Date: Fri, 21 Apr 2006 14:32:09 +0000 Subject: [PATCH] bug 659 fixed: borrower category age limitations are now taken into account during member registration. Warning: new external module required, Date::Calc --- about.pl | 5 +- .../prog/en/members/memberentryA.tmpl | 3 + members/memberentry.pl | 81 +++++++++++++++---- 3 files changed, 73 insertions(+), 16 deletions(-) diff --git a/about.pl b/about.pl index cae86ff576..e6fd25a055 100755 --- a/about.pl +++ b/about.pl @@ -28,6 +28,7 @@ my $mysqlVersion = `mysql -V`; 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 @@ my @component_names = 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) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/members/memberentryA.tmpl b/koha-tmpl/intranet-tmpl/prog/en/members/memberentryA.tmpl index 5060176a24..632cd474a7 100755 --- a/koha-tmpl/intranet-tmpl/prog/en/members/memberentryA.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/members/memberentryA.tmpl @@ -42,6 +42,9 @@

login/password already exist

+ + Member is too young or too old for this category + diff --git a/members/memberentry.pl b/members/memberentry.pl index c4f2787740..a71c6cb452 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -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 $nodouble=$input->param('nodouble'); 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 @@ if ($op eq 'add' or $op eq 'modify') { $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 @@ if ($op eq 'add' or $op eq 'modify') { $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 @@ if ($op eq 'add' or $op eq 'modify') { 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 @@ if ($delete){ $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 @@ if ($delete){ #$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: -- 2.39.5