Skip to content

Commit

Permalink
Fix: When selecting a carbon copy fro select list, mail was not attached
Browse files Browse the repository at this point in the history
to user.
  • Loading branch information
eldy committed Nov 4, 2014
1 parent 0b41df7 commit 0a0dd81
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 450 deletions.
139 changes: 6 additions & 133 deletions htdocs/comm/propal.php
Expand Up @@ -553,146 +553,19 @@
}
}

// 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
*/
if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! GETPOST('cancel')) {
$langs->load('mails');

if ($object->id > 0) {
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");
// Actions to send emails
$actiontypecode='AC_PROP';
$trigger_name='PROPAL_SENTBYMAIL';
$paramname='id';
$mode='emailfromproposal';
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';

$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
if ($action == 'modif' && $user->rights->propal->creer)
Expand Down
156 changes: 6 additions & 150 deletions htdocs/commande/card.php
Expand Up @@ -1151,162 +1151,18 @@
$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
*/
if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! GETPOST('cancel')) {
$langs->load('mails');

if ($object->id > 0) {
// $ref = dol_sanitizeFileName($object->ref);
// $file = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';

// 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'];
// Actions to send emails
$actiontypecode='AC_COM';
$trigger_name='ORDER_SENTBYMAIL';
$paramname='id';
$mode='emailfromorder';
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';

// 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 ($action == 'addcontact') {
Expand Down

0 comments on commit 0a0dd81

Please sign in to comment.