Merge pull request #2565 from deepak-srivastava/CRM-12467-soft-credit-search
[civicrm-core.git] / CRM / Core / BAO / Email.php
index 3643680896f8aeca47bf90cb4f15fcb747d4d407..5d6776938638bf3b337dac64bb12b60e9b22267a 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -75,14 +75,21 @@ class CRM_Core_BAO_Email extends CRM_Core_DAO_Email {
     $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
     $email->email = $strtolower($email->email);
 
-    // since we're setting bulkmail for 1 of this contact's emails, first reset all their emails to is_bulkmail false
-    // (only 1 email address can have is_bulkmail = true)
+    /*
+    * since we're setting bulkmail for 1 of this contact's emails, first reset all their other emails to is_bulkmail false
+    *  We shouldn't not set the current email to false even though we
+    *  are about to reset it to avoid contaminating the changelog if logging is enabled
+    * (only 1 email address can have is_bulkmail = true)
+    */
     if ($email->is_bulkmail != 'null' && $params['contact_id'] && !self::isMultipleBulkMail()) {
       $sql = "
 UPDATE civicrm_email
 SET    is_bulkmail = 0
 WHERE  contact_id = {$params['contact_id']}
 ";
+    if($hook == 'edit'){
+      $sql .= " AND id <> {$params['id']}";
+    }
       CRM_Core_DAO::executeQuery($sql);
     }
 
@@ -280,10 +287,12 @@ AND    reset_date IS NULL
     $contactID       = $session->get('userID');
     $fromEmailValues = array();
 
-    // add the domain email id
-    $domainEmail = CRM_Core_BAO_Domain::getNameAndEmail();
-    $domainEmail = "$domainEmail[0] <$domainEmail[1]>";
-    $fromEmailValues[$domainEmail] = htmlspecialchars($domainEmail);
+    // add all configured FROM email addresses
+    $domainFrom = CRM_Core_OptionGroup::values('from_email_address');
+    foreach (array_keys($domainFrom) as $k) {
+      $domainEmail = $domainFrom[$k];
+      $fromEmailValues[$domainEmail] = htmlspecialchars($domainEmail);
+    }
 
     // add logged in user's active email ids
     if ($contactID) {
@@ -298,7 +307,7 @@ AND    reset_date IS NULL
         $fromEmail = "$fromDisplayName <$email>";
         $fromEmailHtml = htmlspecialchars($fromEmail) . ' ' . $emailVal['locationType'];
 
-        if (CRM_Utils_Array::value('is_primary', $emailVal)) {
+        if (!empty($emailVal['is_primary'])) {
           $fromEmailHtml .= ' ' . ts('(preferred)');
         }
         $fromEmailValues[$fromEmail] = $fromEmailHtml;