From bdaca0bcf2c1dc2ac2c4dee6591d7d74d7b930d6 Mon Sep 17 00:00:00 2001 From: Nahuel Angelinetti Date: Fri, 31 Oct 2008 15:51:44 +0100 Subject: [PATCH] [bug #2746][Replace previous patch] Do not allow an user to have an empty date If the user set an empty date as the expiration date during a patron modification, we recalculate the expiration date with sysprefs and the registration date. Before, when you set an empty date, 0000-00-00 is put in the database (too bad). --- members/memberentry.pl | 45 ++++++++++++++++++++++----------------------- 1 files changed, 22 insertions(+), 23 deletions(-) diff --git a/members/memberentry.pl b/members/memberentry.pl index dba1818..5dcb648 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -114,25 +114,25 @@ if ($op eq 'insert' || $op eq 'modify' || $op eq 'save') { $newdata{$key} = $input->param($key) if (defined $input->param($key)); $newdata{$key} =~ s/\"/"/gg unless $key eq 'borrowernotes' or $key eq 'opacnote'; } - my $dateobject = C4::Dates->new(); - my $syspref = $dateobject->regexp(); # same syspref format for all 3 dates - my $iso = $dateobject->regexp('iso'); # - foreach (qw(dateenrolled dateexpiry dateofbirth)) { - my $userdate = $newdata{$_} or next; - if ($userdate =~ /$syspref/) { - $newdata{$_} = format_date_in_iso($userdate); # if they match syspref format, then convert to ISO - } elsif ($userdate =~ /$iso/) { - warn "Date $_ ($userdate) is already in ISO format"; - } else { - ($userdate eq '0000-00-00') and warn "Data error: $_ is '0000-00-00'"; - $template->param( "ERROR_$_" => 1 ); # else ERROR! - push(@errors,"ERROR_$_"); - } - } + my $dateobject = C4::Dates->new(); + my $syspref = $dateobject->regexp(); # same syspref format for all 3 dates + my $iso = $dateobject->regexp('iso'); # + foreach (qw(dateenrolled dateexpiry dateofbirth)) { + my $userdate = $newdata{$_} or next; + if ($userdate =~ /$syspref/) { + $newdata{$_} = format_date_in_iso($userdate); # if they match syspref format, then convert to ISO + } elsif ($userdate =~ /$iso/) { + warn "Date $_ ($userdate) is already in ISO format"; + } else { + ($userdate eq '0000-00-00') and warn "Data error: $_ is '0000-00-00'"; + $template->param( "ERROR_$_" => 1 ); # else ERROR! + push(@errors,"ERROR_$_"); + } + } # check permission to modify login info. if (ref($borrower_data) && ($borrower_data->{'category_type'} eq 'S') && ! (C4::Auth::haspermission($dbh,$userenv->{'id'},{'staffaccess'=>1})) ) { - $NoUpdateLogin =1; - } + $NoUpdateLogin =1; + } } #############test for member being unique ############# @@ -224,7 +224,7 @@ if ($op eq 'save' || $op eq 'insert'){ } } -if ($op eq 'modify' || $op eq 'insert'){ +if ($op eq 'modify' || $op eq 'insert' || $op eq 'save' ){ unless ($newdata{'dateexpiry'}){ my $arg2 = $newdata{'dateenrolled'} || C4::Dates->today('iso'); $newdata{'dateexpiry'} = GetExpiryDate($newdata{'categorycode'},$arg2); @@ -315,11 +315,10 @@ if (C4::Context->preference("IndependantBranches")) { } } if ($op eq 'add'){ - my $arg2 = $newdata{'dateenrolled'} || C4::Dates->today('iso'); - $data{'dateexpiry'} = GetExpiryDate($newdata{'categorycode'},$arg2); - $template->param( updtype => 'I',step_1=>1,step_2=>1,step_3=>1, step_4 => 1); - -} + my $arg2 = $newdata{'dateenrolled'} || C4::Dates->today('iso'); + $data{'dateexpiry'} = GetExpiryDate($newdata{'categorycode'},$arg2); + $template->param( updtype => 'I',step_1=>1,step_2=>1,step_3=>1, step_4 => 1); +} if ($op eq "modify") { $template->param( updtype => 'M',modify => 1 ); $template->param( step_1=>1,step_2=>1,step_3=>1, step_4 => 1) unless $step; -- 1.5.6.3