Fix: When selecting a carbon copy fro select list, mail was not attached
to user.
This commit is contained in:
parent
0b41df7c35
commit
0a0dd81c9a
@ -553,146 +553,19 @@ else if ($action == 'setstatut' && $user->rights->propal->cloturer && ! GETPOST(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add file in email form
|
|
||||||
if (GETPOST('addfile')) {
|
|
||||||
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
|
|
||||||
|
|
||||||
// Set tmp user directory TODO Use a dedicated directory for temp mails files
|
|
||||||
$vardir = $conf->user->dir_output . "/" . $user->id;
|
|
||||||
$upload_dir_tmp = $vardir . '/temp';
|
|
||||||
|
|
||||||
dol_add_file_process($upload_dir_tmp, 0, 0);
|
|
||||||
$action = 'presend';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove file in email form
|
|
||||||
if (GETPOST('removedfile')) {
|
|
||||||
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
|
|
||||||
|
|
||||||
// Set tmp user directory
|
|
||||||
$vardir = $conf->user->dir_output . "/" . $user->id;
|
|
||||||
$upload_dir_tmp = $vardir . '/temp';
|
|
||||||
|
|
||||||
// TODO Delete only files that was uploaded from email form
|
|
||||||
dol_remove_file_process($_POST['removedfile'], 0);
|
|
||||||
$action = 'presend';
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send mail
|
* Send mail
|
||||||
*/
|
*/
|
||||||
if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! GETPOST('cancel')) {
|
|
||||||
$langs->load('mails');
|
|
||||||
|
|
||||||
if ($object->id > 0) {
|
// Actions to send emails
|
||||||
if ($_POST['sendto']) {
|
$actiontypecode='AC_PROP';
|
||||||
// Le destinataire a ete fourni via le champ libre
|
$trigger_name='PROPAL_SENTBYMAIL';
|
||||||
$sendto = $_POST['sendto'];
|
$paramname='id';
|
||||||
$sendtoid = 0;
|
$mode='emailfromproposal';
|
||||||
} elseif ($_POST['receiver'] != '-1') {
|
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
|
||||||
// Recipient was provided from combo list
|
|
||||||
if ($_POST['receiver'] == 'thirdparty') // Id of third party
|
|
||||||
{
|
|
||||||
$sendto = $object->thirdparty->email;
|
|
||||||
$sendtoid = 0;
|
|
||||||
} else // Id du contact
|
|
||||||
{
|
|
||||||
$sendto = $object->thirdparty->contact_get_property($_POST['receiver'], 'email');
|
|
||||||
$sendtoid = $_POST['receiver'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dol_strlen($sendto)) {
|
|
||||||
$langs->load("commercial");
|
|
||||||
|
|
||||||
$from = $_POST['fromname'] . ' <' . $_POST['frommail'] . '>';
|
|
||||||
$replyto = $_POST['replytoname'] . ' <' . $_POST['replytomail'] . '>';
|
|
||||||
$message = $_POST['message'];
|
|
||||||
$sendtocc = $_POST['sendtocc'];
|
|
||||||
$sendtobcc = (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO)?'':$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO);
|
|
||||||
$deliveryreceipt = $_POST['deliveryreceipt'];
|
|
||||||
|
|
||||||
if (dol_strlen($_POST['subject']))
|
|
||||||
$subject = $_POST['subject'];
|
|
||||||
else
|
|
||||||
$subject = $langs->transnoentities('Propal') . ' ' . $object->ref;
|
|
||||||
$actiontypecode = 'AC_PROP';
|
|
||||||
$actionmsg = $langs->transnoentities('MailSentBy') . ' ' . $from . ' ' . $langs->transnoentities('To') . ' ' . $sendto;
|
|
||||||
if ($message) {
|
|
||||||
if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc);
|
|
||||||
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject);
|
|
||||||
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":");
|
|
||||||
$actionmsg = dol_concatdesc($actionmsg, $message);
|
|
||||||
}
|
|
||||||
$actionmsg2 = $langs->transnoentities('Action' . $actiontypecode);
|
|
||||||
|
|
||||||
// Create form object
|
|
||||||
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
|
|
||||||
$formmail = new FormMail($db);
|
|
||||||
|
|
||||||
$attachedfiles = $formmail->get_attached_files();
|
|
||||||
$filepath = $attachedfiles ['paths'];
|
|
||||||
$filename = $attachedfiles ['names'];
|
|
||||||
$mimetype = $attachedfiles ['mimes'];
|
|
||||||
|
|
||||||
// Envoi de la propal
|
|
||||||
require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
|
|
||||||
$mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, - 1);
|
|
||||||
if ($mailfile->error) {
|
|
||||||
setEventMessage($mailfile->error, 'errors');
|
|
||||||
} else {
|
|
||||||
$result = $mailfile->sendfile();
|
|
||||||
if ($result) {
|
|
||||||
// Initialisation donnees
|
|
||||||
$object->sendtoid = $sendtoid;
|
|
||||||
$object->actiontypecode = $actiontypecode;
|
|
||||||
$object->actionmsg = $actionmsg;
|
|
||||||
$object->actionmsg2 = $actionmsg2;
|
|
||||||
$object->fk_element = $object->id;
|
|
||||||
$object->elementtype = $object->element;
|
|
||||||
|
|
||||||
// Appel des triggers
|
|
||||||
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
|
||||||
$interface = new Interfaces($db);
|
|
||||||
$result = $interface->run_triggers('PROPAL_SENTBYMAIL', $object, $user, $langs, $conf);
|
|
||||||
if ($result < 0) {
|
|
||||||
$error++;
|
|
||||||
$object->errors = $interface->errors;
|
|
||||||
}
|
|
||||||
// Fin appel triggers
|
|
||||||
|
|
||||||
if (! $error) {
|
|
||||||
// Redirect here
|
|
||||||
// This avoid sending mail twice if going out and then back to page
|
|
||||||
$mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2));
|
|
||||||
setEventMessage($mesg);
|
|
||||||
header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
|
|
||||||
exit();
|
|
||||||
} else {
|
|
||||||
dol_print_error($db);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$langs->load("other");
|
|
||||||
if ($mailfile->error) {
|
|
||||||
$mesg .= $langs->trans('ErrorFailedToSendMail', $from, $sendto);
|
|
||||||
$mesg .= '<br>' . $mailfile->error;
|
|
||||||
} else {
|
|
||||||
$mesg .= 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
|
|
||||||
}
|
|
||||||
setEventMessage($mesg, 'errors');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$langs->load("other");
|
|
||||||
setEventMessage($langs->trans('ErrorMailRecipientIsEmpty') . '!', 'errors');
|
|
||||||
dol_syslog($langs->trans('ErrorMailRecipientIsEmpty'));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$langs->load("other");
|
|
||||||
setEventMessage($langs->trans('ErrorFailedToReadEntity', $langs->trans("Proposal")), 'errors');
|
|
||||||
dol_syslog($langs->trans('ErrorFailedToReadEntity', $langs->trans("Proposal")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Go back to draft
|
// Go back to draft
|
||||||
if ($action == 'modif' && $user->rights->propal->creer)
|
if ($action == 'modif' && $user->rights->propal->creer)
|
||||||
|
|||||||
@ -1151,162 +1151,18 @@ else if ($action == 'update_extras') {
|
|||||||
$action = 'edit_extras';
|
$action = 'edit_extras';
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Add file in email form
|
|
||||||
*/
|
|
||||||
if (GETPOST('addfile')) {
|
|
||||||
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
|
|
||||||
|
|
||||||
// Set tmp user directory TODO Use a dedicated directory for temp mails files
|
|
||||||
$vardir = $conf->user->dir_output . "/" . $user->id;
|
|
||||||
$upload_dir_tmp = $vardir . '/temp';
|
|
||||||
|
|
||||||
dol_add_file_process($upload_dir_tmp, 0, 0);
|
|
||||||
$action = 'presend';
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Remove file in email form
|
|
||||||
*/
|
|
||||||
if (GETPOST('removedfile')) {
|
|
||||||
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
|
|
||||||
|
|
||||||
// Set tmp user directory
|
|
||||||
$vardir = $conf->user->dir_output . "/" . $user->id;
|
|
||||||
$upload_dir_tmp = $vardir . '/temp';
|
|
||||||
|
|
||||||
// TODO Delete only files that was uploaded from email form
|
|
||||||
dol_remove_file_process(GETPOST('removedfile'), 0);
|
|
||||||
$action = 'presend';
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send mail
|
* Send mail
|
||||||
*/
|
*/
|
||||||
if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! GETPOST('cancel')) {
|
|
||||||
$langs->load('mails');
|
|
||||||
|
|
||||||
if ($object->id > 0) {
|
// Actions to send emails
|
||||||
// $ref = dol_sanitizeFileName($object->ref);
|
$actiontypecode='AC_COM';
|
||||||
// $file = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
|
$trigger_name='ORDER_SENTBYMAIL';
|
||||||
|
$paramname='id';
|
||||||
|
$mode='emailfromorder';
|
||||||
|
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
|
||||||
|
|
||||||
// if (is_readable($file))
|
|
||||||
// {
|
|
||||||
if (GETPOST('sendto')) {
|
|
||||||
// Le destinataire a ete fourni via le champ libre
|
|
||||||
$sendto = GETPOST('sendto');
|
|
||||||
$sendtoid = 0;
|
|
||||||
} elseif (GETPOST('receiver') != '-1') {
|
|
||||||
// Recipient was provided from combo list
|
|
||||||
if (GETPOST('receiver') == 'thirdparty') // Id of third party
|
|
||||||
{
|
|
||||||
$sendto = $object->thirdparty->email;
|
|
||||||
$sendtoid = 0;
|
|
||||||
} else // Id du contact
|
|
||||||
{
|
|
||||||
$sendto = $object->thirdparty->contact_get_property(GETPOST('receiver'), 'email');
|
|
||||||
$sendtoid = GETPOST('receiver');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dol_strlen($sendto)) {
|
|
||||||
$langs->load("commercial");
|
|
||||||
|
|
||||||
$from = GETPOST('fromname') . ' <' . GETPOST('frommail') . '>';
|
|
||||||
$replyto = GETPOST('replytoname') . ' <' . GETPOST('replytomail') . '>';
|
|
||||||
$message = GETPOST('message');
|
|
||||||
$sendtocc = GETPOST('sendtocc');
|
|
||||||
$sendtobcc = (empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO)?'':$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO);
|
|
||||||
$deliveryreceipt = GETPOST('deliveryreceipt');
|
|
||||||
|
|
||||||
if ($action == 'send') {
|
|
||||||
if (dol_strlen(GETPOST('subject')))
|
|
||||||
$subject = GETPOST('subject');
|
|
||||||
else
|
|
||||||
$subject = $langs->transnoentities('Order') . ' ' . $object->ref;
|
|
||||||
$actiontypecode = 'AC_COM';
|
|
||||||
$actionmsg = $langs->transnoentities('MailSentBy') . ' ' . $from . ' ' . $langs->transnoentities('To') . ' ' . $sendto;
|
|
||||||
if ($message) {
|
|
||||||
if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc);
|
|
||||||
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject);
|
|
||||||
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":");
|
|
||||||
$actionmsg = dol_concatdesc($actionmsg, $message);
|
|
||||||
}
|
|
||||||
$actionmsg2 = $langs->transnoentities('Action' . $actiontypecode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create form object
|
|
||||||
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
|
|
||||||
$formmail = new FormMail($db);
|
|
||||||
|
|
||||||
$attachedfiles = $formmail->get_attached_files();
|
|
||||||
$filepath = $attachedfiles ['paths'];
|
|
||||||
$filename = $attachedfiles ['names'];
|
|
||||||
$mimetype = $attachedfiles ['mimes'];
|
|
||||||
|
|
||||||
// Send mail
|
|
||||||
require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
|
|
||||||
$mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, - 1);
|
|
||||||
if ($mailfile->error) {
|
|
||||||
setEventMessage($mailfile->error, 'errors');
|
|
||||||
} else {
|
|
||||||
$result = $mailfile->sendfile();
|
|
||||||
if ($result) {
|
|
||||||
//Must not contain quotes
|
|
||||||
$mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2));
|
|
||||||
setEventMessage($mesg);
|
|
||||||
|
|
||||||
$error = 0;
|
|
||||||
|
|
||||||
// Initialisation donnees
|
|
||||||
$object->sendtoid = $sendtoid;
|
|
||||||
$object->actiontypecode = $actiontypecode;
|
|
||||||
$object->actionmsg = $actionmsg;
|
|
||||||
$object->actionmsg2 = $actionmsg2;
|
|
||||||
$object->fk_element = $object->id;
|
|
||||||
$object->elementtype = $object->element;
|
|
||||||
|
|
||||||
// Appel des triggers
|
|
||||||
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
|
||||||
$interface = new Interfaces($db);
|
|
||||||
$result = $interface->run_triggers('ORDER_SENTBYMAIL', $object, $user, $langs, $conf);
|
|
||||||
if ($result < 0) {
|
|
||||||
$error ++;
|
|
||||||
$this->errors = $interface->errors;
|
|
||||||
}
|
|
||||||
// Fin appel triggers
|
|
||||||
|
|
||||||
if ($error) {
|
|
||||||
dol_print_error($db);
|
|
||||||
} else {
|
|
||||||
// Redirect here
|
|
||||||
// This avoid sending mail twice if going out and then back to page
|
|
||||||
header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$langs->load("other");
|
|
||||||
if ($mailfile->error) {
|
|
||||||
$mesg .= $langs->trans('ErrorFailedToSendMail', $from, $sendto);
|
|
||||||
$mesg .= '<br>' . $mailfile->error;
|
|
||||||
} else {
|
|
||||||
$mesg .= 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
|
|
||||||
}
|
|
||||||
|
|
||||||
setEventMessage($mesg, 'errors');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$langs->load("other");
|
|
||||||
setEventMessage($langs->trans('ErrorMailRecipientIsEmpty') . '!', 'errors');
|
|
||||||
dol_syslog($langs->trans('ErrorMailRecipientIsEmpty'));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$langs->load("other");
|
|
||||||
setEventMessage($langs->trans('ErrorFailedToReadEntity', $langs->trans("Order")), 'errors');
|
|
||||||
dol_syslog($langs->trans('ErrorFailedToReadEntity', $langs->trans("Order")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $error && ! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->commande->creer) {
|
if (! $error && ! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->commande->creer) {
|
||||||
if ($action == 'addcontact') {
|
if ($action == 'addcontact') {
|
||||||
|
|||||||
@ -1550,178 +1550,24 @@ if (GETPOST('linkedOrder')) {
|
|||||||
$result = $object->add_object_linked('commande', GETPOST('linkedOrder'));
|
$result = $object->add_object_linked('commande', GETPOST('linkedOrder'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Add file in email form
|
|
||||||
*/
|
|
||||||
if (GETPOST('addfile')) {
|
|
||||||
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
|
|
||||||
|
|
||||||
// Set tmp user directory
|
|
||||||
$vardir = $conf->user->dir_output . "/" . $user->id;
|
|
||||||
$upload_dir_tmp = $vardir . '/temp';
|
|
||||||
|
|
||||||
dol_add_file_process($upload_dir_tmp, 0, 0);
|
|
||||||
$action = 'presend';
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Remove file in email form
|
|
||||||
*/
|
|
||||||
if (! empty($_POST['removedfile'])) {
|
|
||||||
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
|
|
||||||
|
|
||||||
// Set tmp user directory
|
|
||||||
$vardir = $conf->user->dir_output . "/" . $user->id;
|
|
||||||
$upload_dir_tmp = $vardir . '/temp';
|
|
||||||
|
|
||||||
// TODO Delete only files that was uploaded from email form
|
|
||||||
dol_remove_file_process($_POST['removedfile'], 0);
|
|
||||||
$action = 'presend';
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send mail
|
* Send mail
|
||||||
*/
|
*/
|
||||||
if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel']) {
|
|
||||||
$langs->load('mails');
|
|
||||||
|
|
||||||
$actiontypecode = '';
|
// Actions to send emails
|
||||||
$subject = '';
|
if (empty($id)) $id=$facid;
|
||||||
$actionmsg = '';
|
$actiontypecode='AC_FAC';
|
||||||
$actionmsg2 = '';
|
$trigger_name='BILL_SENTBYMAIL';
|
||||||
|
$paramname='id';
|
||||||
|
$mode='emailfrominvoice';
|
||||||
|
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
|
||||||
|
|
||||||
$result = $object->fetch($id);
|
|
||||||
$result = $object->fetch_thirdparty();
|
|
||||||
|
|
||||||
if ($result > 0) {
|
|
||||||
// $ref = dol_sanitizeFileName($object->ref);
|
|
||||||
// $file = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf';
|
|
||||||
|
|
||||||
// if (is_readable($file))
|
|
||||||
// {
|
|
||||||
if ($_POST['sendto']) {
|
|
||||||
// Le destinataire a ete fourni via le champ libre
|
|
||||||
$sendto = $_POST['sendto'];
|
|
||||||
$sendtoid = 0;
|
|
||||||
} elseif ($_POST['receiver'] != '-1') {
|
|
||||||
// Recipient was provided from combo list
|
|
||||||
if ($_POST['receiver'] == 'thirdparty') // Id of third party
|
|
||||||
{
|
|
||||||
$sendto = $object->thirdparty->email;
|
|
||||||
$sendtoid = 0;
|
|
||||||
} else // Id du contact
|
|
||||||
{
|
|
||||||
$sendto = $object->thirdparty->contact_get_property($_POST['receiver'], 'email');
|
|
||||||
$sendtoid = $_POST['receiver'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dol_strlen($sendto))
|
|
||||||
{
|
|
||||||
$langs->load("commercial");
|
|
||||||
|
|
||||||
$from = $_POST['fromname'] . ' <' . $_POST['frommail'] . '>';
|
|
||||||
$replyto = $_POST['replytoname'] . ' <' . $_POST['replytomail'] . '>';
|
|
||||||
$message = $_POST['message'];
|
|
||||||
$sendtocc = $_POST['sendtocc'];
|
|
||||||
$sendtobcc = (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO)?'':$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO);
|
|
||||||
$deliveryreceipt = $_POST['deliveryreceipt'];
|
|
||||||
|
|
||||||
if ($action == 'send' || $action == 'relance')
|
|
||||||
{
|
|
||||||
if (dol_strlen($_POST['subject']))
|
|
||||||
$subject = $_POST['subject'];
|
|
||||||
else
|
|
||||||
$subject = $langs->transnoentities('Bill') . ' ' . $object->ref;
|
|
||||||
$actiontypecode = 'AC_FAC';
|
|
||||||
$actionmsg = $langs->transnoentities('MailSentBy') . ' ' . $from . ' ' . $langs->transnoentities('To') . ' ' . $sendto;
|
|
||||||
if ($message) {
|
|
||||||
if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc);
|
|
||||||
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject);
|
|
||||||
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":");
|
|
||||||
$actionmsg = dol_concatdesc($actionmsg, $message);
|
|
||||||
}
|
|
||||||
// $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create form object
|
|
||||||
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
|
|
||||||
$formmail = new FormMail($db);
|
|
||||||
|
|
||||||
$attachedfiles = $formmail->get_attached_files();
|
|
||||||
$filepath = $attachedfiles['paths'];
|
|
||||||
$filename = $attachedfiles['names'];
|
|
||||||
$mimetype = $attachedfiles['mimes'];
|
|
||||||
|
|
||||||
// Send mail
|
|
||||||
require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
|
|
||||||
$mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, - 1);
|
|
||||||
if ($mailfile->error) {
|
|
||||||
setEventMessage($mailfile->error, 'errors');
|
|
||||||
} else {
|
|
||||||
$result = $mailfile->sendfile();
|
|
||||||
if ($result) {
|
|
||||||
$error = 0;
|
|
||||||
|
|
||||||
// Initialisation donnees
|
|
||||||
$object->sendtoid = $sendtoid;
|
|
||||||
$object->actiontypecode = $actiontypecode;
|
|
||||||
$object->actionmsg = $actionmsg; // Long text
|
|
||||||
$object->actionmsg2 = $actionmsg2; // Short text
|
|
||||||
$object->fk_element = $object->id;
|
|
||||||
$object->elementtype = $object->element;
|
|
||||||
|
|
||||||
// Appel des triggers
|
|
||||||
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
|
||||||
$interface = new Interfaces($db);
|
|
||||||
$result = $interface->run_triggers('BILL_SENTBYMAIL', $object, $user, $langs, $conf);
|
|
||||||
if ($result < 0) {
|
|
||||||
$error++;
|
|
||||||
$object->errors = $interface->errors;
|
|
||||||
}
|
|
||||||
// Fin appel triggers
|
|
||||||
|
|
||||||
if ($error) {
|
|
||||||
dol_print_error($db);
|
|
||||||
} else {
|
|
||||||
// Redirect here
|
|
||||||
// This avoid sending mail twice if going out and then back to page
|
|
||||||
$mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2));
|
|
||||||
setEventMessage($mesg);
|
|
||||||
header('Location: ' . $_SERVER["PHP_SELF"] . '?facid=' . $object->id);
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$langs->load("other");
|
|
||||||
|
|
||||||
if ($mailfile->error) {
|
|
||||||
$mesg .= $langs->trans('ErrorFailedToSendMail', $from, $sendto);
|
|
||||||
$mesg .= '<br>' . $mailfile->error;
|
|
||||||
} else {
|
|
||||||
$mesg .= 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
|
|
||||||
}
|
|
||||||
|
|
||||||
setEventMessage($mesg, 'errors');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$langs->load("other");
|
|
||||||
setEventMessage($langs->trans('ErrorMailRecipientIsEmpty') . '!', 'errors');
|
|
||||||
dol_syslog($langs->trans('ErrorMailRecipientIsEmpty'));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$langs->load("other");
|
|
||||||
setEventMessage($langs->trans('ErrorFailedToReadEntity', $langs->trans("Invoice")), 'errors');
|
|
||||||
dol_syslog('Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$action = 'presend';
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generate document
|
* Generate document
|
||||||
*/
|
*/
|
||||||
else if ($action == 'builddoc') // En get ou en post
|
if ($action == 'builddoc') // En get ou en post
|
||||||
{
|
{
|
||||||
$object->fetch($id);
|
$object->fetch($id);
|
||||||
$object->fetch_thirdparty();
|
$object->fetch_thirdparty();
|
||||||
|
|||||||
@ -87,10 +87,10 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
|
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
if ($_POST['sendto'])
|
if (trim($_POST['sendto']))
|
||||||
{
|
{
|
||||||
// Recipient is provided into free text
|
// Recipient is provided into free text
|
||||||
$sendto = $_POST['sendto'];
|
$sendto = trim($_POST['sendto']);
|
||||||
$sendtoid = 0;
|
$sendtoid = 0;
|
||||||
}
|
}
|
||||||
elseif ($_POST['receiver'] != '-1')
|
elseif ($_POST['receiver'] != '-1')
|
||||||
@ -107,6 +107,22 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
$sendtoid = $_POST['receiver'];
|
$sendtoid = $_POST['receiver'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (trim($_POST['sendtocc']))
|
||||||
|
{
|
||||||
|
$sendtocc = trim($_POST['sendtocc']);
|
||||||
|
}
|
||||||
|
elseif ($_POST['receivercc'] != '-1')
|
||||||
|
{
|
||||||
|
// Recipient was provided from combo list
|
||||||
|
if ($_POST['receivercc'] == 'thirdparty') // Id of third party
|
||||||
|
{
|
||||||
|
$sendtocc = $thirdparty->email;
|
||||||
|
}
|
||||||
|
else // Id du contact
|
||||||
|
{
|
||||||
|
$sendtocc = $thirdparty->contact_get_property($_POST['receivercc'],'email');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (dol_strlen($sendto))
|
if (dol_strlen($sendto))
|
||||||
{
|
{
|
||||||
@ -115,8 +131,8 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
$from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
|
$from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
|
||||||
$replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
|
$replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
|
||||||
$message = $_POST['message'];
|
$message = $_POST['message'];
|
||||||
$sendtocc = $_POST['sendtocc'];
|
$sendtocc = $sendtocc;
|
||||||
$sendtobcc='';
|
$sendtobcc= GETPOST('sendtoccc');
|
||||||
if ($mode == 'emailfromproposal') $sendtobcc = (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO)?'':$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO);
|
if ($mode == 'emailfromproposal') $sendtobcc = (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO)?'':$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO);
|
||||||
if ($mode == 'emailfromorder') $sendtobcc = (empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO)?'':$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO);
|
if ($mode == 'emailfromorder') $sendtobcc = (empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO)?'':$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO);
|
||||||
if ($mode == 'emailfrominvoice') $sendtobcc = (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO)?'':$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO);
|
if ($mode == 'emailfrominvoice') $sendtobcc = (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO)?'':$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO);
|
||||||
@ -172,7 +188,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
// Appel des triggers
|
// Appel des triggers
|
||||||
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
||||||
$interface=new Interfaces($db);
|
$interface=new Interfaces($db);
|
||||||
$result=$interface->run_triggers('COMPANY_SENTBYMAIL',$object,$user,$langs,$conf);
|
$result=$interface->run_triggers($trigger_name,$object,$user,$langs,$conf);
|
||||||
if ($result < 0) {
|
if ($result < 0) {
|
||||||
$error++; $this->errors=$interface->errors;
|
$error++; $this->errors=$interface->errors;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -520,6 +520,7 @@ if (empty($reshook))
|
|||||||
// Actions to send emails
|
// Actions to send emails
|
||||||
$id=$socid;
|
$id=$socid;
|
||||||
$actiontypecode='AC_OTH_AUTO';
|
$actiontypecode='AC_OTH_AUTO';
|
||||||
|
$trigger_name='COMPANY_SENTBYMAIL';
|
||||||
$paramname='socid';
|
$paramname='socid';
|
||||||
$mode='emailfromthirdparty';
|
$mode='emailfromthirdparty';
|
||||||
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
|
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user