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 public function preProcess() {
81 // store case id if present
82 $this->_caseId
= CRM_Utils_Request
::retrieve('caseid', 'String', $this, FALSE);
83 $this->_context
= CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
85 $cid = CRM_Utils_Request
::retrieve('cid', 'String', $this, FALSE);
87 // Allow request to specify email id rather than contact id
88 $toEmailId = CRM_Utils_Request
::retrieve('email_id', 'String', $this);
90 $toEmail = civicrm_api('email', 'getsingle', ['version' => 3, 'id' => $toEmailId]);
91 if (!empty($toEmail['email']) && !empty($toEmail['contact_id'])) {
92 $this->_toEmail
= $toEmail;
95 $cid = $toEmail['contact_id'];
96 $this->set('cid', $cid);
101 $cid = explode(',', $cid);
104 foreach ($cid as $val) {
105 $displayName[] = CRM_Contact_BAO_Contact
::displayName($val);
108 CRM_Utils_System
::setTitle(implode(',', $displayName) . ' - ' . ts('Email'));
111 CRM_Utils_System
::setTitle(ts('New Email'));
113 CRM_Contact_Form_Task_EmailCommon
::preProcessFromAddress($this);
115 if (!$cid && $this->_context
!= 'standalone') {
116 parent
::preProcess();
119 $this->assign('single', $this->_single
);
120 if (CRM_Core_Permission
::check('administer CiviCRM')) {
121 $this->assign('isAdmin', 1);
126 * Build the form object.
128 public function buildQuickForm() {
129 //enable form element
130 $this->assign('suppressForm', FALSE);
131 $this->assign('emailTask', TRUE);
133 CRM_Contact_Form_Task_EmailCommon
::buildQuickForm($this);
137 * Process the form after the input has been submitted and validated.
139 public function postProcess() {
140 CRM_Contact_Form_Task_EmailCommon
::postProcess($this);
144 * List available tokens for this form.
148 public function listTokens() {
149 $tokens = CRM_Core_SelectValues
::contactTokens();
151 if (isset($this->_caseId
) ||
isset($this->_caseIds
)) {
152 // For a single case, list tokens relevant for only that case type
153 $caseTypeId = isset($this->_caseId
) ? CRM_Core_DAO
::getFieldValue('CRM_Case_DAO_Case', $this->_caseId
, 'case_type_id') : NULL;
154 $tokens +
= CRM_Core_SelectValues
::caseTokens($caseTypeId);