[New] Add Presend form & Actions to send emails to Contact card

Add ability to send email to contact from the Contact card. Functionality was copied and adapted from the Third Party card.
This commit is contained in:
François J 2018-11-06 16:40:39 +01:00
parent f9a8b240ac
commit 29c71b31fe
3 changed files with 47 additions and 2 deletions

View File

@ -409,6 +409,13 @@ if (empty($reshook))
}
}
}
// Actions to send emails
$trigger_name='CONTACT_SENTBYMAIL';
$paramname='id';
$mode='emailfromcontact';
$trackid='con'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
}
@ -1252,7 +1259,18 @@ else
$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook))
{
if ($user->rights->societe->contact->creer)
if (! empty($object->email))
{
$langs->load("mails");
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=presend&amp;mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
}
else
{
$langs->load("mails");
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans('SendMail').'</a></div>';
}
if ($user->rights->societe->contact->creer)
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit">'.$langs->trans('Modify').'</a>';
}
@ -1281,6 +1299,14 @@ else
}
print "</div>";
// Presend form
$modelmail='contact';
$defaulttopic='Information';
$diroutput = $conf->contact->dir_output;
$trackid = 'con'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
}
}

View File

@ -113,7 +113,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$result=$object->fetch($id);
$sendtosocid=0; // Thirdparty on object
if (method_exists($object,"fetch_thirdparty") && ! in_array($object->element, array('societe','member','user','expensereport')))
if (method_exists($object,"fetch_thirdparty") && ! in_array($object->element, array('societe','member','user','expensereport', 'contact')))
{
$result=$object->fetch_thirdparty();
if ($object->element == 'user' && $result == 0) $result=1; // Even if not found, we consider ok
@ -130,6 +130,11 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$thirdparty=$object;
if ($thirdparty->id > 0) $sendtosocid=$thirdparty->id;
}
else if ($object->element == 'contact')
{
$contact=$object;
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');
if (is_object($hookmanager))
@ -171,6 +176,11 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
{
$tmparray[] = dol_string_nospecial($thirdparty->name, ' ', array(",")).' <'.$thirdparty->email.'>';
}
// Recipient was provided from combo list
elseif ($val == 'contact') // Id of contact
{
$tmparray[] = dol_string_nospecial($contact->name, ' ', array(",")).' <'.$contact->email.'>';
}
elseif ($val) // Id du contact
{
$tmparray[] = $thirdparty->contact_get_property((int) $val,'email');
@ -215,6 +225,11 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
{
$tmparray[] = dol_string_nospecial($thirdparty->name, ' ', array(",")).' <'.$thirdparty->email.'>';
}
// Recipient was provided from combo list
elseif ($val == 'contact') // Id of contact
{
$tmparray[] = dol_string_nospecial($contact->name, ' ', array(",")).' <'.$contact->email.'>';
}
elseif ($val) // Id du contact
{
$tmparray[] = $thirdparty->contact_get_property((int) $val,'email');

View File

@ -140,6 +140,10 @@ if ($action == 'presend')
$liste[$key] = $value;
}
}
elseif ($object->element == 'contact')
{
$liste['contact'] = $object->getFullName($langs)." <".$object->email.">";
}
elseif ($object->element == 'user' || $object->element == 'member')
{
$liste['thirdparty'] = $object->getFullName($langs)." <".$object->email.">";