3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2018
35 * This class generates form components for Scheduling Reminders.
37 class CRM_Admin_Form_ScheduleReminders
extends CRM_Admin_Form
{
40 * Scheduled Reminder ID.
42 protected $_id = NULL;
47 * Build the form object.
49 public function buildQuickForm() {
50 parent
::buildQuickForm();
51 $this->_mappingID
= $mappingID = NULL;
52 $providersCount = CRM_SMS_BAO_Provider
::activeProviderCount();
53 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this);
55 //CRM-16777: Don't provide access to administer schedule reminder page, with user that does not have 'administer CiviCRM' permission
56 if (empty($this->_context
) && !CRM_Core_Permission
::check('administer CiviCRM')) {
57 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
59 //CRM-16777: When user have ACLs 'edit' permission for specific event, do not give access to add, delete & updtae
60 //schedule reminder for other events.
62 $this->_compId
= CRM_Utils_Request
::retrieve('compId', 'Integer', $this);
63 if (!CRM_Event_BAO_Event
::checkPermission($this->_compId
, CRM_Core_Permission
::EDIT
)) {
64 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
68 if ($this->_action
& (CRM_Core_Action
::DELETE
)) {
69 $reminderName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_ActionSchedule', $this->_id
, 'title');
70 if ($this->_context
== 'event') {
71 $this->_compId
= CRM_Utils_Request
::retrieve('compId', 'Integer', $this);
73 $this->assign('reminderName', $reminderName);
76 elseif ($this->_action
& (CRM_Core_Action
::UPDATE
)) {
77 $this->_mappingID
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_ActionSchedule', $this->_id
, 'mapping_id');
78 if ($this->_context
== 'event') {
79 $this->_compId
= CRM_Utils_Request
::retrieve('compId', 'Integer', $this);
82 elseif (!empty($this->_context
)) {
83 if ($this->_context
== 'event') {
84 $this->_compId
= CRM_Utils_Request
::retrieve('compId', 'Integer', $this);
85 $isTemplate = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_compId
, 'is_template');
86 $mapping = CRM_Utils_Array
::first(CRM_Core_BAO_ActionSchedule
::getMappings(array(
87 'id' => $isTemplate ? CRM_Event_ActionMapping
::EVENT_TPL_MAPPING_ID
: CRM_Event_ActionMapping
::EVENT_NAME_MAPPING_ID
,
90 $this->_mappingID
= $mapping->getId();
93 CRM_Core_Error
::fatal('Could not find mapping for event scheduled reminders.');
98 if (!empty($_POST) && !empty($_POST['entity']) && empty($this->_context
)) {
99 $mappingID = $_POST['entity'][0];
101 elseif ($this->_mappingID
) {
102 $mappingID = $this->_mappingID
;
103 if ($this->_context
== 'event') {
104 $this->add('hidden', 'mappingID', $mappingID);
112 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_ActionSchedule', 'title'),
116 $mappings = CRM_Core_BAO_ActionSchedule
::getMappings();
117 $selectedMapping = $mappings[$mappingID ?
$mappingID : 1];
118 $entityRecipientLabels = $selectedMapping->getRecipientTypes() + CRM_Core_BAO_ActionSchedule
::getAdditionalRecipients();
119 $this->assign('entityMapping', json_encode(
120 CRM_Utils_Array
::collectMethod('getEntity', $mappings)
122 $this->assign('recipientMapping', json_encode(
123 array_combine(array_keys($entityRecipientLabels), array_keys($entityRecipientLabels))
126 if (empty($this->_context
)) {
132 'name' => 'entity[0]',
133 'style' => 'vertical-align: top;',
136 $sel->setOptions(array(
137 CRM_Utils_Array
::collectMethod('getLabel', $mappings),
138 CRM_Core_BAO_ActionSchedule
::getAllEntityValueLabels(),
139 CRM_Core_BAO_ActionSchedule
::getAllEntityStatusLabels(),
142 if (is_a($sel->_elements
[1], 'HTML_QuickForm_select')) {
143 // make second selector a multi-select -
144 $sel->_elements
[1]->setMultiple(TRUE);
145 $sel->_elements
[1]->setSize(5);
148 if (is_a($sel->_elements
[2], 'HTML_QuickForm_select')) {
149 // make third selector a multi-select -
150 $sel->_elements
[2]->setMultiple(TRUE);
151 $sel->_elements
[2]->setSize(5);
155 // Dig deeper - this code is sublimely stupid.
156 $allEntityStatusLabels = CRM_Core_BAO_ActionSchedule
::getAllEntityStatusLabels();
157 $options = $allEntityStatusLabels[$this->_mappingID
][0];
158 $attributes = array('multiple' => 'multiple', 'class' => 'crm-select2 huge', 'placeholder' => $options[0]);
160 $this->add('select', 'entity', ts('Recipient(s)'), $options, TRUE, $attributes);
161 $this->assign('context', $this->_context
);
164 //get the frequency units.
165 $this->_freqUnits
= CRM_Core_SelectValues
::getRecurringFrequencyUnits();
168 $this->add('number', 'start_action_offset', ts('When'), array('class' => 'six', 'min' => 0));
169 $this->addRule('start_action_offset', ts('Value should be a positive number'), 'positiveInteger');
171 $isActive = ts('Scheduled Reminder Active');
172 $recordActivity = ts('Record activity for automated email');
173 if ($providersCount) {
174 $this->assign('sms', $providersCount);
175 $recordActivity = ts('Record activity for automated email or SMS');
176 $options = CRM_Core_OptionGroup
::values('msg_mode');
177 $this->add('select', 'mode', ts('Send as'), $options);
179 $providers = CRM_SMS_BAO_Provider
::getProviders(NULL, NULL, TRUE, 'is_default desc');
181 $providerSelect = array();
182 foreach ($providers as $provider) {
183 $providerSelect[$provider['id']] = $provider['title'];
185 $this->add('select', 'sms_provider_id', ts('SMS Provider'), $providerSelect, TRUE);
188 foreach ($this->_freqUnits
as $val => $label) {
189 $freqUnitsDisplay[$val] = ts('%1(s)', array(1 => $label));
192 $this->addDate('absolute_date', ts('Start Date'), FALSE, array('formatType' => 'mailing'));
195 $this->add('select', 'start_action_unit', ts('Frequency'), $freqUnitsDisplay, TRUE);
198 'before' => ts('before'),
199 'after' => ts('after'),
202 $this->add('select', 'start_action_condition', ts('Action Condition'), $condition);
204 $this->add('select', 'start_action_date', ts('Date Field'), $selectedMapping->getDateFields(), TRUE);
206 $this->addElement('checkbox', 'record_activity', $recordActivity);
208 $this->addElement('checkbox', 'is_repeat', ts('Repeat'),
209 NULL, array('onchange' => "return showHideByValue('is_repeat',true,'repeatFields','table-row','radio',false);")
212 $this->add('select', 'repetition_frequency_unit', ts('every'), $freqUnitsDisplay);
213 $this->add('number', 'repetition_frequency_interval', ts('every'), array('class' => 'six', 'min' => 0));
214 $this->addRule('repetition_frequency_interval', ts('Value should be a positive number'), 'positiveInteger');
216 $this->add('select', 'end_frequency_unit', ts('until'), $freqUnitsDisplay);
217 $this->add('number', 'end_frequency_interval', ts('until'), array('class' => 'six', 'min' => 0));
218 $this->addRule('end_frequency_interval', ts('Value should be a positive number'), 'positiveInteger');
220 $this->add('select', 'end_action', ts('Repetition Condition'), $condition, TRUE);
221 $this->add('select', 'end_date', ts('Date Field'), $selectedMapping->getDateFields(), TRUE);
223 $this->add('text', 'from_name', ts('From Name'));
224 $this->add('text', 'from_email', ts('From Email'));
226 $recipientListingOptions = array();
229 $mapping = CRM_Utils_Array
::first(CRM_Core_BAO_ActionSchedule
::getMappings(array(
234 $limitOptions = array('' => '-neither-', 1 => ts('Limit to'), 0 => ts('Also include'));
236 $recipientLabels = array('activity' => ts('Recipients'), 'other' => ts('Limit or Add Recipients'));
237 $this->assign('recipientLabels', $recipientLabels);
239 $this->add('select', 'limit_to', ts('Limit Options'), $limitOptions, FALSE, array('onChange' => "showHideByValue('limit_to','','recipient', 'select','select',true);"));
241 $this->add('select', 'recipient', $recipientLabels['other'], $entityRecipientLabels,
242 FALSE, array('onchange' => "showHideByValue('recipient','manual','recipientManual','table-row','select',false); showHideByValue('recipient','group','recipientGroup','table-row','select',false);")
245 if (!empty($this->_submitValues
['recipient_listing'])) {
246 if (!empty($this->_context
)) {
247 $recipientListingOptions = CRM_Core_BAO_ActionSchedule
::getRecipientListing($this->_mappingID
, $this->_submitValues
['recipient']);
250 $recipientListingOptions = CRM_Core_BAO_ActionSchedule
::getRecipientListing($_POST['entity'][0], $_POST['recipient']);
253 elseif (!empty($this->_values
['recipient_listing'])) {
254 $recipientListingOptions = CRM_Core_BAO_ActionSchedule
::getRecipientListing($this->_values
['mapping_id'], $this->_values
['recipient']);
257 $this->add('select', 'recipient_listing', ts('Recipient Roles'), $recipientListingOptions, FALSE,
258 array('multiple' => TRUE, 'class' => 'crm-select2 huge', 'placeholder' => TRUE));
260 $this->addEntityRef('recipient_manual_id', ts('Manual Recipients'), array('multiple' => TRUE, 'create' => TRUE));
262 $this->add('select', 'group_id', ts('Group'),
263 CRM_Core_PseudoConstant
::nestedGroup('Mailing'), FALSE, array('class' => 'crm-select2 huge')
266 // multilingual only options
267 $multilingual = CRM_Core_I18n
::isMultilingual();
269 $smarty = CRM_Core_Smarty
::singleton();
270 $smarty->assign('multilingual', $multilingual);
272 $languages = CRM_Core_I18n
::languages(TRUE);
273 $languageFilter = $languages +
array(CRM_Core_I18n
::NONE
=> ts('Contacts with no preferred language'));
274 $element = $this->add('select', 'filter_contact_language', ts('Recipients language'), $languageFilter, FALSE,
275 array('multiple' => TRUE, 'class' => 'crm-select2', 'placeholder' => TRUE));
277 $communicationLanguage = array(
278 '' => ts('System default language'),
279 CRM_Core_I18n
::AUTO
=> ts('Follow recipient preferred language'),
281 $communicationLanguage = $communicationLanguage +
$languages;
282 $this->add('select', 'communication_language', ts('Communication language'), $communicationLanguage);
285 CRM_Mailing_BAO_Mailing
::commonCompose($this);
287 $this->add('text', 'subject', ts('Subject'),
288 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_ActionSchedule', 'subject')
291 $this->add('checkbox', 'is_active', $isActive);
293 $this->addFormRule(array('CRM_Admin_Form_ScheduleReminders', 'formRule'), $this);
295 $this->setPageTitle(ts('Scheduled Reminder'));
301 * @param array $fields
302 * The input form values.
303 * @param array $files
304 * @param CRM_Admin_Form_ScheduleReminders $self
307 * True if no errors, else array of errors
309 public static function formRule($fields, $files, $self) {
311 if ((array_key_exists(1, $fields['entity']) && $fields['entity'][1][0] === 0) ||
312 (array_key_exists(2, $fields['entity']) && $fields['entity'][2][0] == 0)
314 $errors['entity'] = ts('Please select appropriate value');
317 if (!empty($fields['is_active']) &&
318 CRM_Utils_System
::isNull($fields['subject'])
320 $errors['subject'] = ts('Subject is a required field.');
322 if (!empty($fields['is_active']) &&
323 CRM_Utils_System
::isNull(trim(strip_tags($fields['html_message'])))
325 $errors['html_message'] = ts('The HTML message is a required field.');
328 if (empty($self->_context
) && CRM_Utils_System
::isNull(CRM_Utils_Array
::value(1, $fields['entity']))) {
329 $errors['entity'] = ts('Please select entity value');
332 if (!CRM_Utils_System
::isNull($fields['absolute_date'])) {
333 if (CRM_Utils_Date
::format(CRM_Utils_Date
::processDate($fields['absolute_date'], NULL)) < CRM_Utils_Date
::format(date('Ymd'))) {
334 $errors['absolute_date'] = ts('Absolute date cannot be earlier than the current time.');
337 if (!CRM_Utils_Rule
::email($fields['from_email'])) {
338 $errors['from_email'] = ts('Please enter a valid email address.');
340 $recipientKind = array(
341 'participant_role' => array(
342 'name' => 'participant role',
343 'target_id' => 'recipient_listing',
346 'name' => 'recipient',
347 'target_id' => 'recipient_manual_id',
350 if ($fields['limit_to'] != '' && array_key_exists($fields['recipient'], $recipientKind) && empty($fields[$recipientKind[$fields['recipient']]['target_id']])) {
351 $errors[$recipientKind[$fields['recipient']]['target_id']] = ts('If "Also include" or "Limit to" are selected, you must specify at least one %1', array(1 => $recipientKind[$fields['recipient']]['name']));
355 if (!empty($fields['is_repeat']) &&
356 (empty($fields['repetition_frequency_interval']) ||
($fields['end_frequency_interval'] == NULL))
358 $errors['is_repeat'] = ts('If you are enabling repetition you must indicate the frequency and ending term.');
361 $actionSchedule = $self->parseActionSchedule($fields);
362 if ($actionSchedule->mapping_id
) {
363 $mapping = CRM_Core_BAO_ActionSchedule
::getMapping($actionSchedule->mapping_id
);
364 CRM_Utils_Array
::extend($errors, $mapping->validateSchedule($actionSchedule));
367 if (!empty($errors)) {
371 return empty($errors) ?
TRUE : $errors;
377 public function setDefaultValues() {
378 if ($this->_action
& CRM_Core_Action
::ADD
) {
379 $defaults['is_active'] = 1;
380 $defaults['mode'] = 'Email';
381 $defaults['record_activity'] = 1;
384 $defaults = $this->_values
;
385 $entityValue = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, CRM_Utils_Array
::value('entity_value', $defaults));
386 $entityStatus = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, CRM_Utils_Array
::value('entity_status', $defaults));
387 if (empty($this->_context
)) {
388 $defaults['entity'][0] = CRM_Utils_Array
::value('mapping_id', $defaults);
389 $defaults['entity'][1] = $entityValue;
390 $defaults['entity'][2] = $entityStatus;
393 $defaults['entity'] = $entityStatus;
395 if ($absoluteDate = CRM_Utils_Array
::value('absolute_date', $defaults)) {
396 list($date, $time) = CRM_Utils_Date
::setDateDefaults($absoluteDate);
397 $defaults['absolute_date'] = $date;
400 if ($recipientListing = CRM_Utils_Array
::value('recipient_listing', $defaults)) {
401 $defaults['recipient_listing'] = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
405 $defaults['text_message'] = CRM_Utils_Array
::value('body_text', $defaults);
406 $defaults['html_message'] = CRM_Utils_Array
::value('body_html', $defaults);
407 $defaults['sms_text_message'] = CRM_Utils_Array
::value('sms_body_text', $defaults);
408 $defaults['template'] = CRM_Utils_Array
::value('msg_template_id', $defaults);
409 $defaults['SMStemplate'] = CRM_Utils_Array
::value('sms_template_id', $defaults);
410 if (!empty($defaults['group_id'])) {
411 $defaults['recipient'] = 'group';
413 elseif (!empty($defaults['recipient_manual'])) {
414 $defaults['recipient'] = 'manual';
415 $defaults['recipient_manual_id'] = $defaults['recipient_manual'];
417 if ($contactLanguage = CRM_Utils_Array
::value('filter_contact_language', $defaults)) {
418 $defaults['filter_contact_language'] = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $contactLanguage);
426 * Process the form submission.
428 public function postProcess() {
429 if ($this->_action
& CRM_Core_Action
::DELETE
) {
431 CRM_Core_BAO_ActionSchedule
::del($this->_id
);
432 CRM_Core_Session
::setStatus(ts('Selected Reminder has been deleted.'), ts('Record Deleted'), 'success');
433 if ($this->_context
== 'event' && $this->_compId
) {
434 $url = CRM_Utils_System
::url('civicrm/event/manage/reminder',
435 "reset=1&action=browse&id={$this->_compId}&component={$this->_context}&setTab=1"
437 $session = CRM_Core_Session
::singleton();
438 $session->pushUserContext($url);
442 $values = $this->controller
->exportValues($this->getName());
443 $bao = $this->parseActionSchedule($values)->save();
445 // we need to set this on the form so that hooks can identify the created entity
446 $this->set('id', $bao->id
);
449 $status = ts("Your new Reminder titled %1 has been saved.",
450 array(1 => "<strong>{$values['title']}</strong>")
453 if ($this->_action
) {
454 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
455 $status = ts("Your Reminder titled %1 has been updated.",
456 array(1 => "<strong>{$values['title']}</strong>")
460 if ($this->_context
== 'event' && $this->_compId
) {
461 $url = CRM_Utils_System
::url('civicrm/event/manage/reminder', "reset=1&action=browse&id={$this->_compId}&component={$this->_context}&setTab=1");
462 $session = CRM_Core_Session
::singleton();
463 $session->pushUserContext($url);
466 CRM_Core_Session
::setStatus($status, ts('Saved'), 'success');
470 * @param array $values
471 * The submitted form values.
472 * @return CRM_Core_DAO_ActionSchedule
474 public function parseActionSchedule($values) {
489 foreach ($keys as $key) {
490 $params[$key] = CRM_Utils_Array
::value($key, $values);
493 $params['is_repeat'] = CRM_Utils_Array
::value('is_repeat', $values, 0);
496 'start_action_offset',
498 'start_action_condition',
500 'repetition_frequency_unit',
501 'repetition_frequency_interval',
502 'end_frequency_unit',
503 'end_frequency_interval',
508 if ($absoluteDate = CRM_Utils_Array
::value('absolute_date', $params)) {
509 $params['absolute_date'] = CRM_Utils_Date
::processDate($absoluteDate);
512 $params['absolute_date'] = 'null';
514 foreach ($moreKeys as $mkey) {
515 if ($params['absolute_date'] != 'null' && CRM_Utils_String
::startsWith($mkey, 'start_action')) {
516 $params[$mkey] = 'null';
519 $params[$mkey] = CRM_Utils_Array
::value($mkey, $values);
522 $params['body_text'] = CRM_Utils_Array
::value('text_message', $values);
523 $params['sms_body_text'] = CRM_Utils_Array
::value('sms_text_message', $values);
524 $params['body_html'] = CRM_Utils_Array
::value('html_message', $values);
526 if (CRM_Utils_Array
::value('recipient', $values) == 'manual') {
527 $params['recipient_manual'] = CRM_Utils_Array
::value('recipient_manual_id', $values);
528 $params['group_id'] = $params['recipient'] = $params['recipient_listing'] = 'null';
530 elseif (CRM_Utils_Array
::value('recipient', $values) == 'group') {
531 $params['group_id'] = $values['group_id'];
532 $params['recipient_manual'] = $params['recipient'] = $params['recipient_listing'] = 'null';
534 elseif (isset($values['recipient_listing']) && isset($values['limit_to']) && !CRM_Utils_System
::isNull($values['recipient_listing']) && !CRM_Utils_System
::isNull($values['limit_to'])) {
535 $params['recipient'] = CRM_Utils_Array
::value('recipient', $values);
536 $params['recipient_listing'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
537 CRM_Utils_Array
::value('recipient_listing', $values)
539 $params['group_id'] = $params['recipient_manual'] = 'null';
542 $params['recipient'] = CRM_Utils_Array
::value('recipient', $values);
543 $params['group_id'] = $params['recipient_manual'] = $params['recipient_listing'] = 'null';
546 if (!empty($this->_mappingID
) && !empty($this->_compId
)) {
547 $params['mapping_id'] = $this->_mappingID
;
548 $params['entity_value'] = $this->_compId
;
549 $params['entity_status'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
, $values['entity']);
552 $params['mapping_id'] = $values['entity'][0];
553 if ($params['mapping_id'] == 1) {
554 $params['limit_to'] = 1;
557 $entity_value = CRM_Utils_Array
::value(1, $values['entity'], array());
558 $entity_status = CRM_Utils_Array
::value(2, $values['entity'], array());
559 $params['entity_value'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
, $entity_value);
560 $params['entity_status'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
, $entity_status);
563 $params['is_active'] = CRM_Utils_Array
::value('is_active', $values, 0);
565 if (CRM_Utils_Array
::value('is_repeat', $values) == 0) {
566 $params['repetition_frequency_unit'] = 'null';
567 $params['repetition_frequency_interval'] = 'null';
568 $params['end_frequency_unit'] = 'null';
569 $params['end_frequency_interval'] = 'null';
570 $params['end_action'] = 'null';
571 $params['end_date'] = 'null';
574 // multilingual options
575 $params['filter_contact_language'] = CRM_Utils_Array
::value('filter_contact_language', $values, array());
576 $params['filter_contact_language'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
, $params['filter_contact_language']);
577 $params['communication_language'] = CRM_Utils_Array
::value('communication_language', $values, NULL);
579 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
580 $params['id'] = $this->_id
;
582 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
583 // we do this only once, so name never changes
584 $params['name'] = CRM_Utils_String
::munge($params['title'], '_', 64);
587 $modePrefixes = array('Mail' => NULL, 'SMS' => 'SMS');
589 if ($params['mode'] == 'Email' ||
empty($params['sms_provider_id'])) {
590 unset($modePrefixes['SMS']);
592 elseif ($params['mode'] == 'SMS') {
593 unset($modePrefixes['Mail']);
596 //TODO: handle postprocessing of SMS and/or Email info based on $modePrefixes
598 $composeFields = array(
605 //mail template is composed
607 foreach ($modePrefixes as $prefix) {
608 $composeParams = array();
609 foreach ($composeFields as $key) {
610 $key = $prefix . $key;
611 if (!empty($values[$key])) {
612 $composeParams[$key] = $values[$key];
616 if (!empty($composeParams[$prefix . 'updateTemplate'])) {
617 $templateParams = array('is_active' => TRUE);
618 if ($prefix == 'SMS') {
619 $templateParams +
= array(
620 'msg_text' => $params['sms_body_text'],
625 $templateParams +
= array(
626 'msg_text' => $params['body_text'],
627 'msg_html' => $params['body_html'],
628 'msg_subject' => $params['subject'],
631 $templateParams['id'] = $values[$prefix . 'template'];
633 $msgTemplate = CRM_Core_BAO_MessageTemplate
::add($templateParams);
636 if (!empty($composeParams[$prefix . 'saveTemplate'])) {
637 $templateParams = array('is_active' => TRUE);
638 if ($prefix == 'SMS') {
639 $templateParams +
= array(
640 'msg_text' => $params['sms_body_text'],
645 $templateParams +
= array(
646 'msg_text' => $params['body_text'],
647 'msg_html' => $params['body_html'],
648 'msg_subject' => $params['subject'],
651 $templateParams['msg_title'] = $composeParams[$prefix . 'saveTemplateName'];
653 $msgTemplate = CRM_Core_BAO_MessageTemplate
::add($templateParams);
656 if ($prefix == 'SMS') {
657 if (isset($msgTemplate->id
)) {
658 $params['sms_template_id'] = $msgTemplate->id
;
661 $params['sms_template_id'] = CRM_Utils_Array
::value('SMStemplate', $values);
665 if (isset($msgTemplate->id
)) {
666 $params['msg_template_id'] = $msgTemplate->id
;
669 $params['msg_template_id'] = CRM_Utils_Array
::value('template', $values);
674 $actionSchedule = new CRM_Core_DAO_ActionSchedule();
675 $actionSchedule->copyValues($params);
676 return $actionSchedule;
680 * List available tokens for this form.
684 public function listTokens() {
685 $tokens = CRM_Core_SelectValues
::contactTokens();
686 $tokens = array_merge(CRM_Core_SelectValues
::activityTokens(), $tokens);
687 $tokens = array_merge(CRM_Core_SelectValues
::eventTokens(), $tokens);
688 $tokens = array_merge(CRM_Core_SelectValues
::membershipTokens(), $tokens);
689 $tokens = array_merge(CRM_Core_SelectValues
::contributionTokens(), $tokens);