mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
[New] Add sendMail hook in subscription
Added sendMail hook in subscription, before a mail is sent to confirm a subscription. It makes it more flexible for modules to interact with it.
This commit is contained in:
parent
a5b86f74ce
commit
4df0efa43d
|
|
@ -300,57 +300,75 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && !
|
|||
if (!$error) {
|
||||
// Send confirmation Email
|
||||
if ($object->email && $sendalsoemail) { // $object is 'Adherent'
|
||||
$subject = '';
|
||||
$msg = '';
|
||||
|
||||
// Send subscription email
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||
$formmail = new FormMail($db);
|
||||
// Set output language
|
||||
$outputlangs = new Translate('', $conf);
|
||||
$outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
|
||||
// Load traductions files required by page
|
||||
$outputlangs->loadLangs(array("main", "members"));
|
||||
|
||||
// Get email content from template
|
||||
$arraydefaultmessage = null;
|
||||
$labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
|
||||
|
||||
if (!empty($labeltouse)) $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
|
||||
|
||||
if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
|
||||
$subject = $arraydefaultmessage->topic;
|
||||
$msg = $arraydefaultmessage->content;
|
||||
$parameters = array(
|
||||
'datesubscription' => $datesubscription,
|
||||
'amount' => $amount,
|
||||
'ccountid' => $accountid,
|
||||
'operation' => $operation,
|
||||
'label' => $label,
|
||||
'num_chq' => $num_chq,
|
||||
'emetteur_nom' => $emetteur_nom,
|
||||
'emetteur_banque' => $emetteur_banque,
|
||||
'datesubend' => $datesubend
|
||||
);
|
||||
$reshook = $hookmanager->executeHooks('sendMail', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
|
||||
if ($reshook < 0) {
|
||||
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
|
||||
}
|
||||
|
||||
$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
|
||||
complete_substitutions_array($substitutionarray, $outputlangs, $object);
|
||||
$subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
|
||||
$texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
|
||||
if (empty($reshook)) {
|
||||
$subject = '';
|
||||
$msg = '';
|
||||
|
||||
// Attach a file ?
|
||||
$file = '';
|
||||
$listofpaths = array();
|
||||
$listofnames = array();
|
||||
$listofmimes = array();
|
||||
if (is_object($object->invoice) && (!is_object($arraydefaultmessage) || intval($arraydefaultmessage->joinfiles))) {
|
||||
$invoicediroutput = $conf->facture->dir_output;
|
||||
$fileparams = dol_most_recent_file($invoicediroutput.'/'.$object->invoice->ref, preg_quote($object->invoice->ref, '/').'[^\-]+');
|
||||
$file = $fileparams['fullname'];
|
||||
// Send subscription email
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||
$formmail = new FormMail($db);
|
||||
// Set output language
|
||||
$outputlangs = new Translate('', $conf);
|
||||
$outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
|
||||
// Load traductions files required by page
|
||||
$outputlangs->loadLangs(array("main", "members"));
|
||||
|
||||
$listofpaths = array($file);
|
||||
$listofnames = array(basename($file));
|
||||
$listofmimes = array(dol_mimetype($file));
|
||||
}
|
||||
// Get email content from template
|
||||
$arraydefaultmessage = null;
|
||||
$labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
|
||||
|
||||
$moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/subscription.php'."\r\n";
|
||||
if (!empty($labeltouse)) $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
|
||||
|
||||
$result = $object->send_an_email($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames, "", "", 0, -1, '', $moreinheader);
|
||||
if ($result < 0) {
|
||||
$errmsg = $object->error;
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
} else {
|
||||
setEventMessages($langs->trans("EmailSentToMember", $object->email), null, 'mesgs');
|
||||
if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
|
||||
$subject = $arraydefaultmessage->topic;
|
||||
$msg = $arraydefaultmessage->content;
|
||||
}
|
||||
|
||||
$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
|
||||
complete_substitutions_array($substitutionarray, $outputlangs, $object);
|
||||
$subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
|
||||
$texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
|
||||
|
||||
// Attach a file ?
|
||||
$file = '';
|
||||
$listofpaths = array();
|
||||
$listofnames = array();
|
||||
$listofmimes = array();
|
||||
if (is_object($object->invoice) && (!is_object($arraydefaultmessage) || intval($arraydefaultmessage->joinfiles))) {
|
||||
$invoicediroutput = $conf->facture->dir_output;
|
||||
$fileparams = dol_most_recent_file($invoicediroutput.'/'.$object->invoice->ref, preg_quote($object->invoice->ref, '/').'[^\-]+');
|
||||
$file = $fileparams['fullname'];
|
||||
|
||||
$listofpaths = array($file);
|
||||
$listofnames = array(basename($file));
|
||||
$listofmimes = array(dol_mimetype($file));
|
||||
}
|
||||
|
||||
$moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/subscription.php'."\r\n";
|
||||
|
||||
$result = $object->send_an_email($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames, "", "", 0, -1, '', $moreinheader);
|
||||
if ($result < 0) {
|
||||
$errmsg = $object->error;
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
} else {
|
||||
setEventMessages($langs->trans("EmailSentToMember", $object->email), null, 'mesgs');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
setEventMessages($langs->trans("NoEmailSentToMember"), null, 'mesgs');
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user