CRM-19129 Allow Users to Select the From Address used for when sending Email Receipts
authorSeamus Lee <seamuslee001@gmail.com>
Tue, 26 Jul 2016 04:28:27 +0000 (14:28 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Mon, 1 Aug 2016 11:40:15 +0000 (21:40 +1000)
CRM/Contribute/Form/Task/PDF.php
templates/CRM/Contribute/Form/Task/PDF.tpl

index 0dd94859e600d89697319f90c884476a1690061b..6c064d0cb39cd88fec5f6f1dd013e0aec10be1b2 100644 (file)
@@ -93,7 +93,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'));
   }
@@ -104,7 +104,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';")
@@ -117,6 +119,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 not 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',
@@ -150,6 +154,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();
 
@@ -192,6 +200,14 @@ AND    {$this->_componentClause}";
       $objects['contribution']->receive_date = CRM_Utils_Date::isoToMysql($objects['contribution']->receive_date);
 
       $values = array();
+      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']);
 
index 7895f208fe767f13552555a2c7bd931b36f25c66..f3e96fc34faf0d23293d6280d83ec49156a4d021 100644 (file)
@@ -35,6 +35,9 @@
   <tr>
     <td>{$form.output.email_receipt.html}</td>
   </tr>
+  <tr id="selectEmailFrom" style="display: none">
+    <td>{$form.fromEmailAddress.label}: {$form.fromEmailAddress.html}</td>
+  </tr>
   <tr>
     <td>{$form.output.pdf_receipt.html}</td>
   </tr>