use C4::Dates qw/format_date format_date_in_iso/;
use C4::Input;
use C4::Log;
+use C4::Letters;
use C4::Branch; # GetBranches
-#use Smart::Comments;
-
use vars qw($debug);
BEGIN {
my $name_city=$input->param('name_city');
my $nodouble=$input->param('nodouble');
my $select_city=$input->param('select_city');
-my $zipcode=$input->param('zipcode');
-my $city=$input->param('city');
my $nok=$input->param('nok');
my $guarantorinfo=$input->param('guarantorinfo');
my $step=$input->param('step') || 0;
unless ($category_type or !($categorycode)){
my $borrowercategory= GetBorrowercategory($categorycode);
$category_type = $borrowercategory->{'category_type'};
+ my $category_name = $borrowercategory->{'description'};
+ $template->param("categoryname"=>$category_name);
}
$category_type="A" unless $category_type; # FIXME we should display a error message instead of a 500 error !
);
# recover the category type if the borrowers is a doublon
- my $tmpborrowercategory=GetBorrowercategory($check_category);
- $check_categorytype=$tmpborrowercategory->{'category_type'};
+ if ($check_category) {
+ my $tmpborrowercategory=GetBorrowercategory($check_category);
+ $check_categorytype=$tmpborrowercategory->{'category_type'};
+ }
}
#recover all data from guarantor address phone ,fax...
}
###############test to take the right zipcode and city name ##############
-if ( $guarantorid eq ''){
- $newdata{'city'}= $city;
- $newdata{'zipcode'}=$zipcode;
+if ($guarantorid eq '') {
+ # set only if parameter was passed from the form
+ $newdata{'city'} = $input->param('city') if defined($input->param('city'));
+ $newdata{'zipcode'} = $input->param('zipcode') if defined($input->param('zipcode'));
}
#builds default userid
$debug and warn "$op dates: " . join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry);
if ($op eq 'insert'){
# we know it's not a duplicate borrowernumber or there would already be an error
- $borrowernumber = &AddMember(%newdata);
+ $borrowernumber = &AddMember(%newdata);
+
+ # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
+ if ( C4::Context->preference("AutoEmailOpacUser") == 1 && $newdata{'userid'} && $newdata{'password'}) {
+ #look for defined primary email address, if blank - attempt to use borr.email and borr.emailpro instead
+ my $emailaddr;
+ if (C4::Context->preference("AutoEmailPrimaryAddress") ne 'OFF' &&
+ $newdata{C4::Context->preference("AutoEmailPrimaryAddress")} =~ /\w\@\w/ ) {
+ $emailaddr = $newdata{C4::Context->preference("AutoEmailPrimaryAddress")}
+ }
+ elsif ($newdata{email} =~ /\w\@\w/) {
+ $emailaddr = $newdata{email}
+ }
+ elsif ($newdata{emailpro} =~ /\w\@\w/) {
+ $emailaddr = $newdata{emailpro}
+ }
+ elsif ($newdata{B_email} =~ /\w\@\w/) {
+ $emailaddr = $newdata{B_email}
+ }
+ # if we manage to find a valid email address, send notice
+ if ($emailaddr) {
+ $newdata{emailaddr} = $emailaddr;
+ my $letter = getletter ('members', "ACCTDETAILS:$newdata{'branchcode'}") ;
+ # if $branch notice fails, then email a default notice instead.
+ $letter = getletter ('members', "ACCTDETAILS") if !$letter;
+ SendAlerts ( 'members' , \%newdata , $letter ) if $letter
+ }
+ }
+
if ($data{'organisations'}){
# need to add the members organisations
my @orgs=split(/\|/,$data{'organisations'});
my $branches=GetBranches($onlymine);
my $default;
-foreach my $branch (sort keys %$branches) {
+for my $branch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
push @select_branch,$branch;
$select_branches{$branch} = $branches->{$branch}->{'branchname'};
$default = C4::Context->userenv->{'branch'} if (C4::Context->userenv && C4::Context->userenv->{'branch'});