X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcontact.pm;h=7f2470ab9869a8485be4b435b6231ff514a33fe3;hp=03023e5e7d80f8e3890769c54b1cfb8adf22e5fc;hb=231831c3aa77729fb0cf75557099659ab0082259;hpb=37e986126fa8e061b3e366d855eae067736dda3a diff --git a/FS/FS/contact.pm b/FS/FS/contact.pm index 03023e5e7..7f2470ab9 100644 --- a/FS/FS/contact.pm +++ b/FS/FS/contact.pm @@ -834,7 +834,38 @@ or there isn't one, returns the empty string. =cut sub by_selfservice_email { - my($class, $email) = @_; + my($class, $email, $case_insensitive) = @_; + + my $email_search = "emailaddress = '".$email."'"; + $email_search = "LOWER(emailaddress) = LOWER('".$email."')" if $case_insensitive; + + my $contact_email = qsearchs({ + 'table' => 'contact_email', + 'addl_from' => ' LEFT JOIN contact USING ( contactnum ) ', + 'extra_sql' => " + WHERE $email_search + AND ( contact.disabled IS NULL ) + AND EXISTS ( SELECT 1 FROM cust_contact + WHERE contact.contactnum = cust_contact.contactnum + AND cust_contact.selfservice_access = 'Y' + ) + ", + }) or return ''; + + $contact_email->contact; + +} + +=item by_selfservice_email_custnum EMAILADDRESS, CUSTNUM + +Alternate search constructor (class method). Given an email address and custnum, returns +the contact for that address and custnum. If that contact doesn't have selfservice access, +or there isn't one, returns the empty string. + +=cut + +sub by_selfservice_email_custnum { + my($class, $email, $custnum) = @_; my $contact_email = qsearchs({ 'table' => 'contact_email', @@ -845,6 +876,7 @@ sub by_selfservice_email { AND EXISTS ( SELECT 1 FROM cust_contact WHERE contact.contactnum = cust_contact.contactnum AND cust_contact.selfservice_access = 'Y' + AND cust_contact.custnum = $custnum ) ", }) or return '';