From 87feaadf1182d90f50f21f3cdc34b5cdd1204be2 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Tue, 26 Jul 2016 14:28:27 +1000 Subject: [PATCH] CRM-19129 Allow Users to Select the From Address used for when sending Email Receipts --- CRM/Contribute/Form/Task/PDF.php | 24 +++++++++++++++++++--- templates/CRM/Contribute/Form/Task/PDF.tpl | 3 +++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CRM/Contribute/Form/Task/PDF.php b/CRM/Contribute/Form/Task/PDF.php index 12b611428d..7304458e06 100644 --- a/CRM/Contribute/Form/Task/PDF.php +++ b/CRM/Contribute/Form/Task/PDF.php @@ -95,7 +95,7 @@ AND {$this->_componentClause}"; 'title' => ts('Search Results'), ), ); - + CRM_Contact_Form_Task_EmailCommon ::preProcessFromAddress($this); CRM_Utils_System::appendBreadCrumb($breadCrumb); CRM_Utils_System::setTitle(ts('Print Contribution Receipts')); } @@ -109,7 +109,9 @@ AND {$this->_componentClause}"; public function buildQuickForm() { $this->addElement('radio', 'output', NULL, ts('Email Receipts'), 'email_receipt', - array('onClick' => "document.getElementById('selectPdfFormat').style.display = 'none';") + array( + 'onClick' => "document.getElementById('selectPdfFormat').style.display = 'none'; + document.getElementById('selectEmailFrom').style.display = 'block';") ); $this->addElement('radio', 'output', NULL, ts('PDF Receipts'), 'pdf_receipt', array('onClick' => "document.getElementById('selectPdfFormat').style.display = 'block';") @@ -122,6 +124,8 @@ AND {$this->_componentClause}"; $this->add('checkbox', 'receipt_update', ts('Update receipt dates for these contributions'), FALSE); $this->add('checkbox', 'override_privacy', ts('Override privacy setting? (Do no email / Do not mail)'), FALSE); + $this->add('select', 'fromEmailAddress', ts('From Email'), $this->_fromEmails, FALSE, array('class' => 'crm-select2 huge')); + $this->addButtons(array( array( 'type' => 'next', @@ -158,6 +162,10 @@ AND {$this->_componentClause}"; $params = $this->controller->exportValues($this->_name); $elements = self::getElements($this->_contributionIds, $params, $this->_contactIds); + $fromEmail = $params['fromEmailAddress']; + $from = CRM_Utils_Array::value($fromEmail, $this->_emails); + $fromDetails = explode(' <', $from); + foreach ($elements['details'] as $contribID => $detail) { $input = $ids = $objects = array(); @@ -193,7 +201,17 @@ AND {$this->_componentClause}"; $objects['contribution']->receive_date = CRM_Utils_Date::isoToMysql($objects['contribution']->receive_date); $values = array(); - $mail = $elements['baseIPN']->sendMail($input, $ids, $objects, $values, FALSE, $elements['createPdf']); + + if (isset($params['fromEmailAddress']) && !$elements['createPdf']) { + $fromEmail = $params['fromEmailAddress']; + $from = CRM_Utils_Array::value($fromEmail, $this->_emails); + $fromDetails = explode(' <', $from); + $input['receipt_from_email'] = substr(trim($fromDetails[1]), 0, -1); + $input['receipt_from_name'] = str_replace('"', '', $fromDetails[0]); + } + + $mail = CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $objects['contribution']->id, $values, FALSE, + $elements['createPdf']); if ($mail['html']) { $message[] = $mail['html']; diff --git a/templates/CRM/Contribute/Form/Task/PDF.tpl b/templates/CRM/Contribute/Form/Task/PDF.tpl index d15eb2d525..87092c6138 100644 --- a/templates/CRM/Contribute/Form/Task/PDF.tpl +++ b/templates/CRM/Contribute/Form/Task/PDF.tpl @@ -35,6 +35,9 @@ {$form.output.email_receipt.html} + + {$form.fromEmailAddress.label}: {$form.fromEmailAddress.html} + {$form.output.pdf_receipt.html} -- 2.25.1