3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class provides the functionality to email a group of contacts.
21 class CRM_Contact_Form_Task_Email
extends CRM_Contact_Form_Task
{
24 * Are we operating in "single mode".
26 * Single mode means sending email to one specific contact.
30 public $_single = FALSE;
33 * Are we operating in "single mode", i.e. sending email to one
38 public $_noEmails = FALSE;
41 * All the existing templates in the system.
45 public $_templates = NULL;
48 * Store "to" contact details.
51 public $_toContactDetails = [];
54 * Store all selected contact id's, that includes to, cc and bcc contacts
57 public $_allContactIds = [];
60 * Store only "to" contact ids.
63 public $_toContactIds = [];
66 * Store only "cc" contact ids.
69 public $_ccContactIds = [];
72 * Store only "bcc" contact ids.
75 public $_bccContactIds = [];
78 * Build all the data structures needed to build the form.
80 * @throws \CiviCRM_API3_Exception
81 * @throws \CRM_Core_Exception
83 public function preProcess() {
84 // store case id if present
85 $this->_caseId
= CRM_Utils_Request
::retrieve('caseid', 'String', $this, FALSE);
86 $this->_context
= CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
88 $cid = CRM_Utils_Request
::retrieve('cid', 'String', $this, FALSE);
90 // Allow request to specify email id rather than contact id
91 $toEmailId = CRM_Utils_Request
::retrieve('email_id', 'String', $this);
93 $toEmail = civicrm_api('email', 'getsingle', ['version' => 3, 'id' => $toEmailId]);
94 if (!empty($toEmail['email']) && !empty($toEmail['contact_id'])) {
95 $this->_toEmail
= $toEmail;
98 $cid = $toEmail['contact_id'];
99 $this->set('cid', $cid);
104 $cid = explode(',', $cid);
107 foreach ($cid as $val) {
108 $displayName[] = CRM_Contact_BAO_Contact
::displayName($val);
111 CRM_Utils_System
::setTitle(implode(',', $displayName) . ' - ' . ts('Email'));
114 CRM_Utils_System
::setTitle(ts('New Email'));
116 if ($this->_context
=== 'search') {
117 $this->_single
= TRUE;
119 CRM_Contact_Form_Task_EmailCommon
::preProcessFromAddress($this);
121 if (!$cid && $this->_context
!== 'standalone') {
122 parent
::preProcess();
125 $this->assign('single', $this->_single
);
126 if (CRM_Core_Permission
::check('administer CiviCRM')) {
127 $this->assign('isAdmin', 1);
132 * Build the form object.
134 public function buildQuickForm() {
135 //enable form element
136 $this->assign('suppressForm', FALSE);
137 $this->assign('emailTask', TRUE);
139 CRM_Contact_Form_Task_EmailCommon
::buildQuickForm($this);
143 * Process the form after the input has been submitted and validated.
145 public function postProcess() {
146 CRM_Contact_Form_Task_EmailCommon
::postProcess($this);
150 * List available tokens for this form.
154 public function listTokens() {
155 $tokens = CRM_Core_SelectValues
::contactTokens();
157 if (isset($this->_caseId
) ||
isset($this->_caseIds
)) {
158 // For a single case, list tokens relevant for only that case type
159 $caseTypeId = isset($this->_caseId
) ? CRM_Core_DAO
::getFieldValue('CRM_Case_DAO_Case', $this->_caseId
, 'case_type_id') : NULL;
160 $tokens +
= CRM_Core_SelectValues
::caseTokens($caseTypeId);