Change contact summary email links from 'mailto' to email activity popup
authorColeman Watts <coleman@civicrm.org>
Wed, 6 Aug 2014 09:45:44 +0000 (10:45 +0100)
committerColeman Watts <coleman@civicrm.org>
Wed, 6 Aug 2014 09:45:44 +0000 (10:45 +0100)
CRM/Contact/Form/Task/Email.php
CRM/Contact/Form/Task/EmailCommon.php
templates/CRM/Contact/Page/Inline/Email.tpl

index 51d53b9c9ec9b35bc0ebed4fc1a396fb98e72510..37370be64c465970861d216449c2f6a6cca584c9 100644 (file)
@@ -104,7 +104,21 @@ class CRM_Contact_Form_Task_Email extends CRM_Contact_Form_Task {
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
 
     $cid = CRM_Utils_Request::retrieve('cid', 'String', $this, FALSE);
-    if ($cid){
+
+    // Allow request to specify email id rather than contact id
+    $toEmailId = CRM_Utils_Request::retrieve('email_id', 'String', $this);
+    if ($toEmailId) {
+      $toEmail = civicrm_api('email', 'getsingle', array('version' => 3, 'id' => $toEmailId));
+      if (!empty($toEmail['email']) && !empty($toEmail['contact_id'])) {
+        $this->_toEmail = $toEmail;
+      }
+      if (!$cid) {
+        $cid = $toEmail['contact_id'];
+        $this->set('cid', $cid);
+      }
+    }
+
+    if ($cid) {
       $cid = explode(',',$cid);
       $displayName = array();
 
index 6240778d9fb2718129639e39b506d211fa272d8d..cfb2f051ec780f928d8778876729e72d0569f1b6 100644 (file)
@@ -228,6 +228,10 @@ class CRM_Contact_Form_Task_EmailCommon {
           // build array's which are used to setdefaults
           if (in_array($contactId, $form->_toContactIds)) {
             $form->_toContactDetails[$contactId] = $form->_contactDetails[$contactId];
+            // If a particular address has been specified as the default, use that instead of contact's primary email
+            if (!empty($form->_toEmail) && $form->_toEmail['contact_id'] == $contactId) {
+              $email = $form->_toEmail['email'];
+            }
             $toArray[] = array(
               'text' => '"' . $value['sort_name'] . '" <' . $email . '>',
               'id' => "$contactId::{$email}",
index ea4ef84c6ceed14df5f516bcef355396133c0be5..5173302d540d5ef7a698ae522c1d820e2e2277b6 100644 (file)
         {if $privacy.do_not_email}<span class="icon privacy-flag do-not-email" title="{ts}Privacy flag: Do Not Email{/ts}"></span>{elseif $item.on_hold}<span class="icon privacy-flag email-hold" title="{ts}Email on hold - generally due to bouncing.{/ts}"></span>{/if}
       </div>
       <div class="crm-content crm-contact_email {if $item.is_primary eq 1}primary{/if}">
-        <a href="mailto:{$item.email}">{$item.email}</a>{if $item.on_hold == 2}&nbsp;({ts}On Hold - Opt Out{/ts}){elseif $item.on_hold}&nbsp;({ts}On Hold{/ts}){/if}{if $item.is_bulkmail}&nbsp;({ts}Bulk{/ts}){/if}
+        {if !$item.on_hold and !$privacy.do_not_email}
+          <a href="{crmURL p="civicrm/activity/email/add" q="action=add&reset=1&email_id=`$item.id`"}" class="crm-popup" title="{ts 1=$item.email}Send email to %1{/ts}">
+            {$item.email}
+          </a>
+        {else}
+          {$item.email}
+        {/if}
+        {if $item.on_hold == 2}&nbsp;({ts}On Hold - Opt Out{/ts}){elseif $item.on_hold}&nbsp;({ts}On Hold{/ts}){/if}{if $item.is_bulkmail}&nbsp;({ts}Bulk{/ts}){/if}
         {if $item.signature_text OR $item.signature_html}
         <span class="signature-link description">
           <a href="#" title="{ts}Signature{/ts}" onClick="showHideSignature( '{$blockId}' ); return false;">{ts}(signature){/ts}</a>