FIX Send email from expense report card.

FIX Alias name is not into the email recipient label.
This commit is contained in:
Laurent Destailleur 2019-09-23 12:36:12 +02:00
parent d5877e9c36
commit 8ac0383fa0

View File

@ -113,8 +113,8 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
{ {
$result=$object->fetch($id); $result=$object->fetch($id);
$sendtosocid=0; // Thirdparty on object $sendtosocid=0; // Id of related thirdparty
if (method_exists($object, "fetch_thirdparty") && ! in_array($object->element, array('societe','member','user','expensereport', 'contact'))) if (method_exists($object, "fetch_thirdparty") && ! in_array($object->element, array('societe', 'member', 'user', 'expensereport', 'contact')))
{ {
$result=$object->fetch_thirdparty(); $result=$object->fetch_thirdparty();
if ($object->element == 'user' && $result == 0) $result=1; // Even if not found, we consider ok if ($object->element == 'user' && $result == 0) $result=1; // Even if not found, we consider ok
@ -124,7 +124,14 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
elseif ($object->element == 'member' || $object->element == 'user') elseif ($object->element == 'member' || $object->element == 'user')
{ {
$thirdparty=$object; $thirdparty=$object;
if ($thirdparty->id > 0) $sendtosocid=$thirdparty->id; if ($object->socid > 0) $sendtosocid=$object->socid;
}
elseif ($object->element == 'expensereport')
{
$tmpuser=new User($db);
$tmpuser->fetch($object->fk_user_author);
$thirdparty=$tmpuser;
if ($object->socid > 0) $sendtosocid=$object->socid;
} }
elseif ($object->element == 'societe') elseif ($object->element == 'societe')
{ {
@ -136,7 +143,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$contact=$object; $contact=$object;
if ($contact->id > 0) $sendtosocid=$contact->fetch_thirdparty()->id; if ($contact->id > 0) $sendtosocid=$contact->fetch_thirdparty()->id;
} }
else dol_print_error('', 'Use actions_sendmails.in.php for an element/object that is not supported'); else dol_print_error('', "Use actions_sendmails.in.php for an element/object '".$object->element."' that is not supported");
if (is_object($hookmanager)) if (is_object($hookmanager))
{ {
@ -162,6 +169,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
if ($receiver == '-1') $receiver=array(); if ($receiver == '-1') $receiver=array();
else $receiver=array($receiver); else $receiver=array($receiver);
} }
$tmparray=array(); $tmparray=array();
if (trim($_POST['sendto'])) if (trim($_POST['sendto']))
{ {
@ -173,22 +181,23 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
foreach($receiver as $key=>$val) foreach($receiver as $key=>$val)
{ {
// Recipient was provided from combo list // Recipient was provided from combo list
if ($val == 'thirdparty') // Id of third party if ($val == 'thirdparty') // Key selected means currentthird party (may be usd for current member or current user too)
{ {
$tmparray[] = dol_string_nospecial($thirdparty->name, ' ', array(",")).' <'.$thirdparty->email.'>'; $tmparray[] = dol_string_nospecial($thirdparty->getFullName($langs), ' ', array(",")).' <'.$thirdparty->email.'>';
} }
// Recipient was provided from combo list // Recipient was provided from combo list
elseif ($val == 'contact') // Id of contact elseif ($val == 'contact') // Key selected means current contact
{ {
$tmparray[] = dol_string_nospecial($contact->name, ' ', array(",")).' <'.$contact->email.'>'; $tmparray[] = dol_string_nospecial($contact->getFullName($langs), ' ', array(",")).' <'.$contact->email.'>';
} }
elseif ($val) // Id du contact elseif ($val) // $val is the Id of a contact
{ {
$tmparray[] = $thirdparty->contact_get_property((int) $val, 'email'); $tmparray[] = $thirdparty->contact_get_property((int) $val, 'email');
$sendtoid[] = $val; $sendtoid[] = $val;
} }
} }
} }
if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT))
{ {
$receiveruser=$_POST['receiveruser']; $receiveruser=$_POST['receiveruser'];
@ -222,16 +231,16 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
foreach($receivercc as $key=>$val) foreach($receivercc as $key=>$val)
{ {
// Recipient was provided from combo list // Recipient was provided from combo list
if ($val == 'thirdparty') // Id of third party if ($val == 'thirdparty') // Key selected means currentthird party (may be usd for current member or current user too)
{ {
$tmparray[] = dol_string_nospecial($thirdparty->name, ' ', array(",")).' <'.$thirdparty->email.'>'; $tmparray[] = dol_string_nospecial($thirdparty->name, ' ', array(",")).' <'.$thirdparty->email.'>';
} }
// Recipient was provided from combo list // Recipient was provided from combo list
elseif ($val == 'contact') // Id of contact elseif ($val == 'contact') // Key selected means current contact
{ {
$tmparray[] = dol_string_nospecial($contact->name, ' ', array(",")).' <'.$contact->email.'>'; $tmparray[] = dol_string_nospecial($contact->name, ' ', array(",")).' <'.$contact->email.'>';
} }
elseif ($val) // Id du contact elseif ($val) // $val is the Id of a contact
{ {
$tmparray[] = $thirdparty->contact_get_property((int) $val, 'email'); $tmparray[] = $thirdparty->contact_get_property((int) $val, 'email');
//$sendtoid[] = $val; TODO Add also id of contact in CC ? //$sendtoid[] = $val; TODO Add also id of contact in CC ?
@ -414,27 +423,6 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$result=$mailfile->sendfile(); $result=$mailfile->sendfile();
if ($result) if ($result)
{ {
// Two hooks are available into method $mailfile->sendfile, so dedicated code is no more required
/*
if (! empty($conf->dolimail->enabled))
{
$mid = (GETPOST('mid','int') ? GETPOST('mid','int') : 0); // Original mail id is set ?
if ($mid)
{
// set imap flag answered if it is an answered mail
$dolimail=new DoliMail($db);
$dolimail->id = $mid;
$res=$dolimail->set_prop($user, 'answered',1);
}
if ($imap==1)
{
// write mail to IMAP Server
$movemail = $mailboxconfig->putMail($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$folder,$deliveryreceipt,$mailfile);
if ($movemail) setEventMessages($langs->trans("MailMovedToImapFolder",$folder), null, 'mesgs');
else setEventMessages($langs->trans("MailMovedToImapFolder_Warning",$folder), null, 'warnings');
}
}*/
// Initialisation of datas of object to call trigger // Initialisation of datas of object to call trigger
if (is_object($object)) if (is_object($object))
{ {