NEW Add substitution key __SENDEREMAIL_SIGNATURE__

This commit is contained in:
Laurent Destailleur 2022-09-10 15:55:36 +02:00
parent 740d2b418d
commit 439bef8e0e
10 changed files with 75 additions and 26 deletions

View File

@ -295,6 +295,7 @@ if ($mode != 'focus' && $mode != 'mandatory') {
if ($mode != 'sortorder') {
$substitutionarray = getCommonSubstitutionArray($langs, 2, array('object', 'objectamount')); // Must match list into GETPOST
unset($substitutionarray['__USER_SIGNATURE__']);
unset($substitutionarray['__SENDEREMAIL_SIGNATURE__']);
$texthelp = $langs->trans("FollowingConstantsWillBeSubstituted").'<br>';
foreach ($substitutionarray as $key => $val) {
$texthelp .= $key.' -> '.$val.'<br>';

View File

@ -51,6 +51,7 @@ $substitutionarrayfortest = array(
'__USER_LOGIN__' => $user->login,
'__USER_EMAIL__' => $user->email,
'__USER_SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $usersignature : ''), // Done into actions_sendmails
'__SENDEREMAIL_SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $usersignature : ''), // Done into actions_sendmails
'__ID__' => 'RecipientIdRecord',
//'__EMAIL__' => 'RecipientEMail', // Done into actions_sendmails
'__LASTNAME__' => 'RecipientLastname',

View File

@ -50,6 +50,7 @@ $substitutionarrayfortest = array(
//'__EMAIL__' => 'RecipientEMail', // Done into actions_sendmails
'__CHECK_READ__' => (!empty($object) && is_object($object) && is_object($object->thirdparty)) ? '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$object->thirdparty->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>' : '',
'__USER_SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $usersignature : ''), // Done into actions_sendmails
'__SENDEREMAIL_SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $usersignature : ''), // Done into actions_sendmails
'__LOGIN__' => $user->login,
'__LASTNAME__' => 'RecipientLastname',
'__FIRSTNAME__' => 'RecipientFirstname',

View File

@ -381,14 +381,17 @@ if ($action != 'create') {
if ($action == 'edit') {
print '<table class="border centpercent tableforfield">';
print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" name="label" value="'.(GETPOSTISSET('label') ? GETPOST('label', 'alphanohtml') : $object->label).'"></td></tr>';
print '<tr><td>'.$langs->trans("Email").'</td><td><input type="text" name="email" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alphanohtml') : $object->email).'"></td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" name="label" class="width300" value="'.(GETPOSTISSET('label') ? GETPOST('label', 'alphanohtml') : $object->label).'"></td></tr>';
print '<tr><td>'.$langs->trans("Email").'</td><td>';
print img_picto('', 'email', 'class="pictofixedwidth"');
print '<input type="text" name="email" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alphanohtml') : $object->email).'"></td></tr>';
print '<tr><td>'.$langs->trans("Signature").'</td><td>';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor = new DolEditor('signature', (GETPOSTISSET('signature') ? GETPOST('signature', 'restricthtml') : $object->signature), '', 138, 'dolibarr_notes', 'In', true, true, empty($conf->global->FCKEDITOR_ENABLE_USERSIGN) ? 0 : 1, ROWS_4, '90%');
print $doleditor->Create(1);
print '</td></tr>';
print '<tr><td>'.$langs->trans("User").'</td><td>';
print img_picto('', 'user', 'class="pictofixedwidth"');
print $form->select_dolusers((GETPOSTISSET('private') ? GETPOST('private', 'int') : $object->private), 'private', 1, null, 0, ($user->admin ? '' : $user->id));
print '</td></tr>';
print '<tr><td>'.$langs->trans("Position").'</td><td><input type="text" name="position" class="maxwidth50" value="'.(GETPOSTISSET('position') ? GETPOST('position', 'int') : $object->position).'"></td></tr>';
@ -410,14 +413,17 @@ if ($action != 'create') {
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
*/
print '<table class="border centpercent tableforfield">';
print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" name="label" value="'.GETPOST('label', 'alphanohtml').'" autofocus></td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("Email").'</td><td><input type="text" name="email" value="'.GETPOST('email', 'alphanohtml').'"></td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" name="label" class="width300" value="'.GETPOST('label', 'alphanohtml').'" autofocus></td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("Email").'</td><td>';
print img_picto('', 'email', 'class="pictofixedwidth"');
print '<input type="text" name="email" value="'.GETPOST('email', 'alphanohtml').'"></td></tr>';
print '<tr><td>'.$langs->trans("Signature").'</td><td>';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor = new DolEditor('signature', GETPOST('signature'), '', 138, 'dolibarr_notes', 'In', true, true, empty($conf->global->FCKEDITOR_ENABLE_USERSIGN) ? 0 : 1, ROWS_4, '90%');
print $doleditor->Create(1);
print '</td></tr>';
print '<tr><td>'.$langs->trans("User").'</td><td>';
print img_picto('', 'user', 'class="pictofixedwidth"');
print $form->select_dolusers((GETPOSTISSET('private') ? GETPOST('private', 'int') : -1), 'private', 1, null, 0, ($user->admin ? '' : $user->id));
print '</td></tr>';
print '<tr><td>'.$langs->trans("Position").'</td><td><input type="text" name="position" class="maxwidth50" value="'.GETPOST('position', 'int').'"></td></tr>';

View File

@ -47,6 +47,7 @@ $substitutionarrayfortest = array(
'__LASTNAME__' => 'TESTLastname',
'__FIRSTNAME__' => 'TESTFirstname',
'__USER_SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $usersignature : ''),
'__SENDEREMAIL_SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $usersignature : ''), // Done into actions_sendmails
//'__PERSONALIZED__' => 'TESTPersonalized' // Hiden because not used yet
);
complete_substitutions_array($substitutionarrayfortest, $langs);

View File

@ -221,6 +221,7 @@ if (empty($reshook)) {
$substitutionarray['__OTHER4__'] = $other4;
$substitutionarray['__OTHER5__'] = $other5;
$substitutionarray['__USER_SIGNATURE__'] = $signature; // Signature is empty when ran from command line or taken from user in parameter)
$substitutionarray['__SENDEREMAIL_SIGNATURE__'] = $signature; // Signature is empty when ran from command line or taken from user in parameter)
$substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.urlencode($obj->tag).'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'&email='.urlencode($obj->email).'&mtid='.$obj->rowid.'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
$substitutionarray['__UNSUBSCRIBE__'] = '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.urlencode($obj->tag).'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'&email='.urlencode($obj->email).'&mtid='.$obj->rowid.'" target="_blank" rel="noopener noreferrer">'.$langs->trans("MailUnsubcribe").'</a>';
$substitutionarray['__UNSUBSCRIBE_URL__'] = DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.urlencode($obj->tag).'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'&email='.urlencode($obj->email).'&mtid='.$obj->rowid;

View File

@ -2101,7 +2101,7 @@ if ($action == 'create') {
if ($object->statut == 0 && $nbofservices) {
if ($user->rights->contrat->creer) {
print dolGetButtonAction($langs->trans('Validate'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid&amp;token='.newToken(), '', true, $params);
print dolGetButtonAction($langs->trans('Validate'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=valid&token='.newToken(), '', true, $params);
} else {
$params['attr']['title'] = $langs->trans("NotEnoughPermissions");
print dolGetButtonAction($langs->trans('Validate'), '', 'default', '#', '', false, $params);
@ -2129,7 +2129,7 @@ if ($action == 'create') {
if (isModEnabled('facture') && $object->statut > 0) {
$langs->load("bills");
if ($user->rights->facture->creer) {
print dolGetButtonAction($langs->trans('CreateBill'), '', 'default', DOL_URL_ROOT.'/compta/facture/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->thirdparty->id, '', true, $params);
print dolGetButtonAction($langs->trans('CreateBill'), '', 'default', DOL_URL_ROOT.'/compta/facture/card.php?action=create&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->thirdparty->id, '', true, $params);
} else {
$params['attr']['title'] = $langs->trans("NotEnoughPermissions");
print dolGetButtonAction($langs->trans('CreateBill'), '', 'default', '#', '', false, $params);
@ -2138,14 +2138,14 @@ if ($action == 'create') {
if ($object->nbofservicesclosed > 0 || $object->nbofserviceswait > 0) {
if ($user->rights->contrat->activer) {
print dolGetButtonAction($langs->trans('ActivateAllContracts'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=activate&amp;token='.newToken(), '', true, $params);
print dolGetButtonAction($langs->trans('ActivateAllContracts'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=activate&token='.newToken(), '', true, $params);
} else {
print dolGetButtonAction($langs->trans('ActivateAllContracts'), '', 'default', '#', '', false, $params);
}
}
if ($object->nbofservicesclosed < $nbofservices) {
if ($user->rights->contrat->desactiver) {
print dolGetButtonAction($langs->trans('CloseAllContracts'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=close&amp;token='.newToken(), '', true, $params);
print dolGetButtonAction($langs->trans('CloseAllContracts'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=close&token='.newToken(), '', true, $params);
} else {
print dolGetButtonAction($langs->trans('CloseAllContracts'), '', 'default', '#', '', false, $params);
}
@ -2169,7 +2169,7 @@ if ($action == 'create') {
// Clone
if ($user->rights->contrat->creer) {
print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;socid='.$object->socid.'&amp;action=clone&amp;token='.newToken(), '', true, $params);
print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&token='.newToken(), '', true, $params);
}
// On peut supprimer entite si

View File

@ -648,19 +648,9 @@ class FormMail extends Form
}
}
// Set the default "From"
$defaultfrom = '';
$reshook = $hookmanager->executeHooks('getDefaultFromEmail', $parameters, $this);
if (empty($reshook)) {
$defaultfrom = $this->fromtype;
}
if (!empty($hookmanager->resArray['defaultfrom'])) {
$defaultfrom = $hookmanager->resArray['defaultfrom'];
}
// Using combo here make the '<email>' no more visible on list.
//$out.= ' '.$form->selectarray('fromtype', $liste, $this->fromtype, 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 1, '', $disablebademails);
$out .= ' '.$form->selectarray('fromtype', $liste, $defaultfrom, 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 0, '', $disablebademails);
$out .= ' '.$form->selectarray('fromtype', $liste, $this->fromtype, 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 0, '', $disablebademails);
}
$out .= "</td></tr>\n";
@ -920,6 +910,9 @@ class FormMail extends Form
if (strpos($defaultmessage, '__USER_SIGNATURE__') !== false && dol_textishtml($this->substit['__USER_SIGNATURE__'])) {
$atleastonecomponentishtml++;
}
if (strpos($defaultmessage, '__SENDEREMAIL_SIGNATURE__') !== false && dol_textishtml($this->substit['__SENDEREMAIL_SIGNATURE__'])) {
$atleastonecomponentishtml++;
}
if (strpos($defaultmessage, '__ONLINE_PAYMENT_TEXT_AND_URL__') !== false && dol_textishtml($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
$atleastonecomponentishtml++;
}
@ -933,6 +926,9 @@ class FormMail extends Form
if (!dol_textishtml($this->substit['__USER_SIGNATURE__'])) {
$this->substit['__USER_SIGNATURE__'] = dol_nl2br($this->substit['__USER_SIGNATURE__']);
}
if (!dol_textishtml($this->substit['__SENDEREMAIL_SIGNATURE__'])) {
$this->substit['__SENDEREMAIL_SIGNATURE__'] = dol_nl2br($this->substit['__SENDEREMAIL_SIGNATURE__']);
}
if (!dol_textishtml($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
$this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = dol_nl2br($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__']);
}
@ -1612,7 +1608,8 @@ class FormMail extends Form
$tmparray['__OTHER3__'] = 'Other3';
$tmparray['__OTHER4__'] = 'Other4';
$tmparray['__OTHER5__'] = 'Other5';
$tmparray['__USER_SIGNATURE__'] = 'TagSignature';
$tmparray['__USER_SIGNATURE__'] = 'TagUserSignature';
$tmparray['__SENDEREMAIL_SIGNATURE__'] = 'TagEmailSenderSignature';
$tmparray['__CHECK_READ__'] = 'TagCheckMail';
$tmparray['__UNSUBSCRIBE__'] = 'TagUnsubscribe';
//,'__PERSONALIZED__' => 'Personalized' // Hidden because not used yet in mass emailing

View File

@ -7295,9 +7295,12 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null,
if (empty($exclude) || !in_array('user', $exclude)) {
// Add SIGNATURE into substitutionarray first, so, when we will make the substitution,
// this will include signature content first and then replace var found into content of signature
$signature = $user->signature;
//var_dump($onlykey);
$emailsendersignature = $user->signature; // dy default, we use the signature of current user. We must complete substitution with signature in c_email_senderprofile of array after calling getCommonSubstitutionArray()
$usersignature = $user->signature;
$substitutionarray = array_merge($substitutionarray, array(
'__USER_SIGNATURE__' => (string) (($signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? ($onlykey == 2 ? dol_trunc(dol_string_nohtmltag($signature), 30) : $signature) : '')
'__SENDEREMAIL_SIGNATURE__' => (string) ((empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? ($onlykey == 2 ? dol_trunc('SignatureFromTheSelectedSenderProfile', 30) : $emailsendersignature) : ''),
'__USER_SIGNATURE__' => (string) (($usersignature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? ($onlykey == 2 ? dol_trunc(dol_string_nohtmltag($usersignature), 30) : $usersignature) : '')
));
if (is_object($user)) {
@ -7928,13 +7931,13 @@ function make_substitutions($text, $substitutionarray, $outputlangs = null, $con
}
}
// Make substitition for array $substitutionarray
// Make substitution for array $substitutionarray
foreach ($substitutionarray as $key => $value) {
if (!isset($value)) {
continue; // If value is null, it same than not having substitution key at all into array, we do not replace.
}
if ($key == '__USER_SIGNATURE__' && (!empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) {
if (($key == '__USER_SIGNATURE__' || $key == '__SENDEREMAIL_SIGNATURE__') && (!empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) {
$value = ''; // Protection
}

View File

@ -156,6 +156,22 @@ if ($action == 'presend') {
$formmail->fromtype = 'special';
}
// Set the default "From"
$defaultfrom = '';
if (GETPOSTISSET('fromtype')) {
$defaultfrom = GETPOST('fromtype');
} else {
$parameters = array();
$reshook = $hookmanager->executeHooks('getDefaultFromEmail', $parameters, $formmail);
if (empty($reshook)) {
$defaultfrom = $formmail->fromtype;
}
if (!empty($hookmanager->resArray['defaultfrom'])) {
$defaultfrom = $hookmanager->resArray['defaultfrom'];
}
}
$formmail->fromtype = $defaultfrom;
$formmail->trackid = empty($trackid) ? '' : $trackid;
$formmail->inreplyto = empty($inreplyto) ? '' : $inreplyto;
$formmail->withfrom = 1;
@ -212,11 +228,33 @@ if ($action == 'presend') {
}
// Make substitution in email content
if ($object) {
if (!empty($object)) {
// First we set ->substit (useless, it will be erased later) and ->substit_lines
$formmail->setSubstitFromObject($object, $langs);
}
$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, $arrayoffamiliestoexclude, $object);
// Overwrite __SENDEREMAIL_SIGNATURE__ with value select into form
if ($formmail->fromtype) {
$reg = array();
if (preg_match('/user/', $formmail->fromtype, $reg)) {
$emailsendersignature = $user->signature;
} elseif (preg_match('/company/', $formmail->fromtype, $reg)) {
$emailsendersignature = '';
} elseif (preg_match('/senderprofile_(\d+)/', $formmail->fromtype, $reg)) {
$sql = "SELECT rowid, label, email FROM ".$db->prefix()."c_email_senderprofile";
$sql .= " WHERE rowid = ".((int) $reg[1]);
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
if ($obj) {
$emailsendersignature = $obj->label;
}
}
}
}
$substitutionarray['__SENDEREMAIL_SIGNATURE__'] = $emailsendersignature;
$substitutionarray['__CHECK_READ__'] = "";
if (is_object($object) && is_object($object->thirdparty)) {
$checkRead= '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php';