Merge remote-tracking branch 'upstream/4.6' into 4.6-master-2015-07-30-23-34-40
[civicrm-core.git] / CRM / Admin / Form / ScheduleReminders.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright (C) 2011 Marty Wright |
7 | Licensed to CiviCRM under the Academic Free License version 3.0. |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27 */
28
29 /**
30 *
31 * @package CRM
32 * @copyright CiviCRM LLC (c) 2004-2015
33 * $Id$
34 *
35 */
36
37 /**
38 * This class generates form components for Scheduling Reminders
39 *
40 */
41 class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form {
42
43 /**
44 * Scheduled Reminder ID.
45 */
46 protected $_id = NULL;
47
48 public $_freqUnits;
49
50 /**
51 * Build the form object.
52 *
53 * @return void
54 */
55 public function buildQuickForm() {
56 parent::buildQuickForm();
57 $this->_mappingID = $mappingID = NULL;
58 $providersCount = CRM_SMS_BAO_Provider::activeProviderCount();
59 $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
60
61 //CRM-16777: Don't provide access to administer schedule reminder page, with user that does not have 'administer CiviCRM' permission
62 if (empty($this->_context) && !CRM_Core_Permission::check('administer CiviCRM')) {
63 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
64 }
65 //CRM-16777: When user have ACLs 'edit' permission for specific event, do not give access to add, delete & updtae
66 //schedule reminder for other events.
67 else {
68 $this->_compId = CRM_Utils_Request::retrieve('compId', 'Integer', $this);
69 if (!CRM_Event_BAO_Event::checkPermission($this->_compId, CRM_Core_Permission::EDIT)) {
70 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
71 }
72 }
73
74 if ($this->_action & (CRM_Core_Action::DELETE)) {
75 $reminderName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionSchedule', $this->_id, 'title');
76 if ($this->_context == 'event') {
77 $this->_compId = CRM_Utils_Request::retrieve('compId', 'Integer', $this);
78 }
79 $this->assign('reminderName', $reminderName);
80 return;
81 }
82 elseif ($this->_action & (CRM_Core_Action::UPDATE)) {
83 $this->_mappingID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionSchedule', $this->_id, 'mapping_id');
84 if ($this->_context == 'event') {
85 $this->_compId = CRM_Utils_Request::retrieve('compId', 'Integer', $this);
86 }
87 }
88 elseif (!empty($this->_context)) {
89 if ($this->_context == 'event') {
90 $this->_compId = CRM_Utils_Request::retrieve('compId', 'Integer', $this);
91 $field = 'civicrm_event';
92 $isTemplate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_compId, 'is_template');
93 if ($isTemplate) {
94 $field = 'event_template';
95 }
96 $this->_mappingID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping', $field, 'id', 'entity_value');
97 if (!$this->_mappingID) {
98 CRM_Core_Error::fatal('Could not find mapping for event scheduled reminders.');
99 }
100 }
101 }
102
103 if (!empty($_POST) && !empty($_POST['entity']) && empty($this->_context)) {
104 $mappingID = $_POST['entity'][0];
105 }
106 elseif ($this->_mappingID) {
107 $mappingID = $this->_mappingID;
108 }
109
110 $this->add(
111 'text',
112 'title',
113 ts('Title'),
114 array('size' => 45, 'maxlength' => 128),
115 TRUE
116 );
117
118 $selectionOptions = CRM_Core_BAO_ActionSchedule::getSelection($mappingID);
119 extract($selectionOptions);
120 $this->assign('entityMapping', json_encode($entityMapping));
121 $this->assign('recipientMapping', json_encode($recipientMapping));
122
123 if (empty($this->_context)) {
124 if (empty($sel1)) {
125 CRM_Core_Error::fatal('Could not find mapping for scheduled reminders.');
126 }
127
128 $sel = &$this->add(
129 'hierselect',
130 'entity',
131 ts('Entity'),
132 array(
133 'name' => 'entity[0]',
134 'style' => 'vertical-align: top;',
135 )
136 );
137 $sel->setOptions(array($sel1, $sel2, $sel3));
138
139 if (is_a($sel->_elements[1], 'HTML_QuickForm_select')) {
140 // make second selector a multi-select -
141 $sel->_elements[1]->setMultiple(TRUE);
142 $sel->_elements[1]->setSize(5);
143 }
144
145 if (is_a($sel->_elements[2], 'HTML_QuickForm_select')) {
146 // make third selector a multi-select -
147 $sel->_elements[2]->setMultiple(TRUE);
148 $sel->_elements[2]->setSize(5);
149 }
150 }
151 else {
152 $options = $sel3[$this->_mappingID][0];
153 $attributes = array('multiple' => 'multiple', 'class' => 'crm-select2 huge', 'placeholder' => $options[0]);
154 unset($options[0]);
155 $this->add('select', 'entity', ts('Recipient(s)'), $options, TRUE, $attributes);
156 $this->assign('context', $this->_context);
157 }
158
159 //get the frequency units.
160 $this->_freqUnits = CRM_Core_SelectValues::getRecurringFrequencyUnits();
161
162 //pass the mapping ID in UPDATE mode
163 $mappings = CRM_Core_BAO_ActionSchedule::getMapping($mappingID);
164
165 $numericOptions = CRM_Core_SelectValues::getNumericOptions(0, 30);
166
167 //reminder_interval
168 $this->add('select', 'start_action_offset', ts('When'), $numericOptions);
169 $isActive = ts('Send email');
170 $recordActivity = ts('Record activity for automated email');
171 if ($providersCount) {
172 $this->assign('sms', $providersCount);
173 $isActive = ts('Send email or SMS');
174 $recordActivity = ts('Record activity for automated email or SMS');
175 $options = CRM_Core_OptionGroup::values('msg_mode');
176 $this->add('select', 'mode', ts('Send as'), $options);
177
178 $providers = CRM_SMS_BAO_Provider::getProviders(NULL, NULL, TRUE, 'is_default desc');
179
180 $providerSelect = array();
181 foreach ($providers as $provider) {
182 $providerSelect[$provider['id']] = $provider['title'];
183 }
184 $this->add('select', 'sms_provider_id', ts('SMS Provider'), $providerSelect, TRUE);
185 }
186
187 foreach ($this->_freqUnits as $val => $label) {
188 $freqUnitsDisplay[$val] = ts('%1(s)', array(1 => $label));
189 }
190
191 $this->addDate('absolute_date', ts('Start Date'), FALSE, array('formatType' => 'mailing'));
192
193 //reminder_frequency
194 $this->add('select', 'start_action_unit', ts('Frequency'), $freqUnitsDisplay, TRUE);
195
196 $condition = array(
197 'before' => ts('before'),
198 'after' => ts('after'),
199 );
200 //reminder_action
201 $this->add('select', 'start_action_condition', ts('Action Condition'), $condition);
202
203 $this->add('select', 'start_action_date', ts('Date Field'), $sel4, TRUE);
204
205 $this->addElement('checkbox', 'record_activity', $recordActivity);
206
207 $this->addElement('checkbox', 'is_repeat', ts('Repeat'),
208 NULL, array('onchange' => "return showHideByValue('is_repeat',true,'repeatFields','table-row','radio',false);")
209 );
210
211 $this->add('select', 'repetition_frequency_unit', ts('every'), $freqUnitsDisplay);
212 $this->add('select', 'repetition_frequency_interval', ts('every'), $numericOptions);
213 $this->add('select', 'end_frequency_unit', ts('until'), $freqUnitsDisplay);
214 $this->add('select', 'end_frequency_interval', ts('until'), $numericOptions);
215 $this->add('select', 'end_action', ts('Repetition Condition'), $condition, TRUE);
216 $this->add('select', 'end_date', ts('Date Field'), $sel4, TRUE);
217
218 $this->add('text', 'from_name', ts('From Name'));
219 $this->add('text', 'from_email', ts('From Email'));
220
221 $recipient = 'activity_contacts';
222 $recipientListingOptions = array();
223
224 if ($mappingID) {
225 $recipient = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping',
226 $mappingID,
227 'entity_recipient'
228 );
229 }
230
231 $limitOptions = array('' => '-neither-', 1 => ts('Limit to'), 0 => ts('Also include'));
232
233 $recipientLabels = array('activity' => ts('Recipients'), 'other' => ts('Limit or Add Recipients'));
234 $this->assign('recipientLabels', $recipientLabels);
235
236 $this->add('select', 'limit_to', ts('Limit Options'), $limitOptions, FALSE, array('onChange' => "showHideByValue('limit_to','','recipient', 'select','select',true);"));
237
238 $this->add('select', 'recipient', $recipientLabels['other'], $sel5[$recipient],
239 FALSE, array('onchange' => "showHideByValue('recipient','manual','recipientManual','table-row','select',false); showHideByValue('recipient','group','recipientGroup','table-row','select',false);")
240 );
241
242 if (!empty($this->_submitValues['recipient_listing'])) {
243 if (!empty($this->_context)) {
244 $recipientListingOptions = CRM_Core_BAO_ActionSchedule::getRecipientListing($this->_mappingID, $this->_submitValues['recipient']);
245 }
246 else {
247 $recipientListingOptions = CRM_Core_BAO_ActionSchedule::getRecipientListing($_POST['entity'][0], $_POST['recipient']);
248 }
249 }
250 elseif (!empty($this->_values['recipient_listing'])) {
251 $recipientListingOptions = CRM_Core_BAO_ActionSchedule::getRecipientListing($this->_values['mapping_id'], $this->_values['recipient']);
252 }
253
254 $this->add('select', 'recipient_listing', ts('Recipient Roles'), $recipientListingOptions, FALSE,
255 array('multiple' => TRUE, 'class' => 'crm-select2 huge', 'placeholder' => TRUE));
256
257 $this->addEntityRef('recipient_manual_id', ts('Manual Recipients'), array('multiple' => TRUE, 'create' => TRUE));
258
259 $this->add('select', 'group_id', ts('Group'),
260 CRM_Core_PseudoConstant::nestedGroup('Mailing'), FALSE, array('class' => 'crm-select2 huge')
261 );
262
263 CRM_Mailing_BAO_Mailing::commonCompose($this);
264
265 $this->add('text', 'subject', ts('Subject'),
266 CRM_Core_DAO::getAttribute('CRM_Core_DAO_ActionSchedule', 'subject')
267 );
268
269 $this->add('checkbox', 'is_active', $isActive);
270
271 $this->addFormRule(array('CRM_Admin_Form_ScheduleReminders', 'formRule'), $this);
272
273 $this->setPageTitle(ts('Scheduled Reminder'));
274 }
275
276 /**
277 * Global form rule.
278 *
279 * @param array $fields
280 * The input form values.
281 *
282 * @return bool|array
283 * true if no errors, else array of errors
284 */
285 public static function formRule($fields, $files, $self) {
286 $errors = array();
287 if ((array_key_exists(1, $fields['entity']) && $fields['entity'][1][0] === 0) ||
288 (array_key_exists(2, $fields['entity']) && $fields['entity'][2][0] == 0)
289 ) {
290 $errors['entity'] = ts('Please select appropriate value');
291 }
292
293 if (array_key_exists(1, $fields['entity']) && !is_numeric($fields['entity'][1][0])) {
294 if (count($fields['entity'][1]) > 1) {
295 $errors['entity'] = ts('You may only select one contact field per reminder');
296 }
297 elseif (!(array_key_exists(2, $fields['entity']) && $fields['entity'][2][0] > 0)) {
298 $errors['entity'] = ts('Please select whether the reminder is sent each year.');
299 }
300 }
301
302 if (!empty($fields['is_active']) &&
303 CRM_Utils_Array::value('mode', $fields) == 'SMS' &&
304 CRM_Utils_System::isNull($fields['subject'])
305 ) {
306 $errors['subject'] = ts('Subject is a required field.');
307 }
308
309 if (empty($self->_context) && CRM_Utils_System::isNull(CRM_Utils_Array::value(1, $fields['entity']))) {
310 $errors['entity'] = ts('Please select entity value');
311 }
312
313 if (!CRM_Utils_System::isNull($fields['absolute_date'])) {
314 if (CRM_Utils_Date::format(CRM_Utils_Date::processDate($fields['absolute_date'], NULL)) < CRM_Utils_Date::format(date('Ymd'))) {
315 $errors['absolute_date'] = ts('Absolute date cannot be earlier than the current time.');
316 }
317 }
318
319 $recipientKind = array(
320 'participant_role' => array(
321 'name' => 'participant role',
322 'target_id' => 'recipient_listing',
323 ),
324 'manual' => array(
325 'name' => 'recipient',
326 'target_id' => 'recipient_manual_id',
327 ),
328 );
329 if ($fields['limit_to'] != '' && array_key_exists($fields['recipient'], $recipientKind) && empty($fields[$recipientKind[$fields['recipient']]['target_id']])) {
330 $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']));
331 }
332
333 if (!empty($errors)) {
334 return $errors;
335 }
336
337 return empty($errors) ? TRUE : $errors;
338 }
339
340 /**
341 * @return int
342 */
343 public function setDefaultValues() {
344 if ($this->_action & CRM_Core_Action::ADD) {
345 $defaults['is_active'] = 1;
346 $defaults['mode'] = 'Email';
347 $defaults['record_activity'] = 1;
348 }
349 else {
350 $defaults = $this->_values;
351 $entityValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('entity_value', $defaults));
352 $entityStatus = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('entity_status', $defaults));
353 if (empty($this->_context)) {
354 $defaults['entity'][0] = CRM_Utils_Array::value('mapping_id', $defaults);
355 $defaults['entity'][1] = $entityValue;
356 $defaults['entity'][2] = $entityStatus;
357 }
358 else {
359 $defaults['entity'] = $entityStatus;
360 }
361 if ($absoluteDate = CRM_Utils_Array::value('absolute_date', $defaults)) {
362 list($date, $time) = CRM_Utils_Date::setDateDefaults($absoluteDate);
363 $defaults['absolute_date'] = $date;
364 }
365
366 if ($recipientListing = CRM_Utils_Array::value('recipient_listing', $defaults)) {
367 $defaults['recipient_listing'] = explode(CRM_Core_DAO::VALUE_SEPARATOR,
368 $recipientListing
369 );
370 }
371 $defaults['text_message'] = CRM_Utils_Array::value('body_text', $defaults);
372 $defaults['html_message'] = CRM_Utils_Array::value('body_html', $defaults);
373 $defaults['sms_text_message'] = CRM_Utils_Array::value('sms_body_text', $defaults);
374 $defaults['template'] = CRM_Utils_Array::value('msg_template_id', $defaults);
375 $defaults['SMStemplate'] = CRM_Utils_Array::value('sms_template_id', $defaults);
376 if (!empty($defaults['group_id'])) {
377 $defaults['recipient'] = 'group';
378 }
379 elseif (!empty($defaults['recipient_manual'])) {
380 $defaults['recipient'] = 'manual';
381 $defaults['recipient_manual_id'] = $defaults['recipient_manual'];
382 }
383 }
384
385 return $defaults;
386 }
387
388 /**
389 * Process the form submission.
390 *
391 *
392 * @return void
393 */
394 public function postProcess() {
395 if ($this->_action & CRM_Core_Action::DELETE) {
396 // delete reminder
397 CRM_Core_BAO_ActionSchedule::del($this->_id);
398 CRM_Core_Session::setStatus(ts('Selected Reminder has been deleted.'), ts('Record Deleted'), 'success');
399 if ($this->_context == 'event' && $this->_compId) {
400 $url = CRM_Utils_System::url('civicrm/event/manage/reminder',
401 "reset=1&action=browse&id={$this->_compId}&component={$this->_context}&setTab=1"
402 );
403 $session = CRM_Core_Session::singleton();
404 $session->pushUserContext($url);
405 }
406 return;
407 }
408 $values = $this->controller->exportValues($this->getName());
409
410 $keys = array(
411 'title',
412 'subject',
413 'absolute_date',
414 'group_id',
415 'record_activity',
416 'limit_to',
417 'mode',
418 'sms_provider_id',
419 'from_name',
420 'from_email',
421 );
422 foreach ($keys as $key) {
423 $params[$key] = CRM_Utils_Array::value($key, $values);
424 }
425
426 $params['is_repeat'] = CRM_Utils_Array::value('is_repeat', $values, 0);
427
428 $moreKeys = array(
429 'start_action_offset',
430 'start_action_unit',
431 'start_action_condition',
432 'start_action_date',
433 'repetition_frequency_unit',
434 'repetition_frequency_interval',
435 'end_frequency_unit',
436 'end_frequency_interval',
437 'end_action',
438 'end_date',
439 );
440
441 if ($absoluteDate = CRM_Utils_Array::value('absolute_date', $params)) {
442 $params['absolute_date'] = CRM_Utils_Date::processDate($absoluteDate);
443 $params['is_repeat'] = 0;
444 foreach ($moreKeys as $mkey) {
445 $params[$mkey] = 'null';
446 }
447 }
448 else {
449 $params['absolute_date'] = 'null';
450 foreach ($moreKeys as $mkey) {
451 $params[$mkey] = CRM_Utils_Array::value($mkey, $values);
452 }
453 }
454
455 $params['body_text'] = CRM_Utils_Array::value('text_message', $values);
456 $params['sms_body_text'] = CRM_Utils_Array::value('sms_text_message', $values);
457 $params['body_html'] = CRM_Utils_Array::value('html_message', $values);
458
459 if (CRM_Utils_Array::value('recipient', $values) == 'manual') {
460 $params['recipient_manual'] = CRM_Utils_Array::value('recipient_manual_id', $values);
461 $params['group_id'] = $params['recipient'] = $params['recipient_listing'] = 'null';
462 }
463 elseif (CRM_Utils_Array::value('recipient', $values) == 'group') {
464 $params['group_id'] = $values['group_id'];
465 $params['recipient_manual'] = $params['recipient'] = $params['recipient_listing'] = 'null';
466 }
467 elseif (!CRM_Utils_System::isNull($values['recipient_listing']) && !CRM_Utils_System::isNull($values['limit_to'])) {
468 $params['recipient'] = CRM_Utils_Array::value('recipient', $values);
469 $params['recipient_listing'] = implode(CRM_Core_DAO::VALUE_SEPARATOR,
470 CRM_Utils_Array::value('recipient_listing', $values)
471 );
472 $params['group_id'] = $params['recipient_manual'] = 'null';
473 }
474 else {
475 $params['recipient'] = CRM_Utils_Array::value('recipient', $values);
476 $params['group_id'] = $params['recipient_manual'] = $params['recipient_listing'] = 'null';
477 }
478
479 if (!empty($this->_mappingID) && !empty($this->_compId)) {
480 $params['mapping_id'] = $this->_mappingID;
481 $params['entity_value'] = $this->_compId;
482 $params['entity_status'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $values['entity']);
483 }
484 else {
485 $params['mapping_id'] = $values['entity'][0];
486 $entity_value = $values['entity'][1];
487 $entity_status = $values['entity'][2];
488 if ($params['mapping_id'] == 1) {
489 $params['limit_to'] = 1;
490 }
491
492 foreach (array('entity_value', 'entity_status') as $key) {
493 $params[$key] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $$key);
494 }
495 }
496
497 $params['is_active'] = CRM_Utils_Array::value('is_active', $values, 0);
498
499 if (CRM_Utils_Array::value('is_repeat', $values) == 0) {
500 $params['repetition_frequency_unit'] = 'null';
501 $params['repetition_frequency_interval'] = 'null';
502 $params['end_frequency_unit'] = 'null';
503 $params['end_frequency_interval'] = 'null';
504 $params['end_action'] = 'null';
505 $params['end_date'] = 'null';
506 }
507
508 if ($this->_action & CRM_Core_Action::UPDATE) {
509 $params['id'] = $this->_id;
510 }
511 elseif ($this->_action & CRM_Core_Action::ADD) {
512 // we do this only once, so name never changes
513 $params['name'] = CRM_Utils_String::munge($params['title'], '_', 64);
514 }
515
516 $modePrefixes = array('Mail' => NULL, 'SMS' => 'SMS');
517
518 if ($params['mode'] == 'Email' || empty($params['sms_provider_id'])) {
519 unset($modePrefixes['SMS']);
520 }
521 elseif ($params['mode'] == 'SMS') {
522 unset($modePrefixes['Mail']);
523 }
524
525 //TODO: handle postprocessing of SMS and/or Email info based on $modePrefixes
526
527 $composeFields = array(
528 'template',
529 'saveTemplate',
530 'updateTemplate',
531 'saveTemplateName',
532 );
533 $msgTemplate = NULL;
534 //mail template is composed
535
536 foreach ($modePrefixes as $prefix) {
537 $composeParams = array();
538 foreach ($composeFields as $key) {
539 $key = $prefix . $key;
540 if (!empty($values[$key])) {
541 $composeParams[$key] = $values[$key];
542 }
543 }
544
545 if (!empty($composeParams[$prefix . 'updateTemplate'])) {
546 $templateParams = array('is_active' => TRUE);
547 if ($prefix == 'SMS') {
548 $templateParams += array(
549 'msg_text' => $params['sms_body_text'],
550 'is_sms' => TRUE,
551 );
552 }
553 else {
554 $templateParams += array(
555 'msg_text' => $params['body_text'],
556 'msg_html' => $params['body_html'],
557 'msg_subject' => $params['subject'],
558 );
559 }
560 $templateParams['id'] = $values[$prefix . 'template'];
561
562 $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
563 }
564
565 if (!empty($composeParams[$prefix . 'saveTemplate'])) {
566 $templateParams = array('is_active' => TRUE);
567 if ($prefix == 'SMS') {
568 $templateParams += array(
569 'msg_text' => $params['sms_body_text'],
570 'is_sms' => TRUE,
571 );
572 }
573 else {
574 $templateParams += array(
575 'msg_text' => $params['body_text'],
576 'msg_html' => $params['body_html'],
577 'msg_subject' => $params['subject'],
578 );
579 }
580 $templateParams['msg_title'] = $composeParams[$prefix . 'saveTemplateName'];
581
582 $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
583 }
584
585 if ($prefix == 'SMS') {
586 if (isset($msgTemplate->id)) {
587 $params['sms_template_id'] = $msgTemplate->id;
588 }
589 else {
590 $params['sms_template_id'] = CRM_Utils_Array::value('SMStemplate', $values);
591 }
592 }
593 else {
594 if (isset($msgTemplate->id)) {
595 $params['msg_template_id'] = $msgTemplate->id;
596 }
597 else {
598 $params['msg_template_id'] = CRM_Utils_Array::value('template', $values);
599 }
600 }
601 }
602
603 $bao = CRM_Core_BAO_ActionSchedule::add($params);
604 // we need to set this on the form so that hooks can identify the created entity
605 $this->set('id', $bao->id);
606 $bao->free();
607
608 $status = ts("Your new Reminder titled %1 has been saved.",
609 array(1 => "<strong>{$values['title']}</strong>")
610 );
611
612 if ($this->_action) {
613 if ($this->_action & CRM_Core_Action::UPDATE) {
614 $status = ts("Your Reminder titled %1 has been updated.",
615 array(1 => "<strong>{$values['title']}</strong>")
616 );
617 }
618
619 if ($this->_context == 'event' && $this->_compId) {
620 $url = CRM_Utils_System::url('civicrm/event/manage/reminder', "reset=1&action=browse&id={$this->_compId}&component={$this->_context}&setTab=1");
621 $session = CRM_Core_Session::singleton();
622 $session->pushUserContext($url);
623 }
624 }
625 CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
626 }
627
628 /**
629 * List available tokens for this form.
630 *
631 * @return array
632 */
633 public function listTokens() {
634 $tokens = CRM_Core_SelectValues::contactTokens();
635 $tokens = array_merge(CRM_Core_SelectValues::activityTokens(), $tokens);
636 $tokens = array_merge(CRM_Core_SelectValues::eventTokens(), $tokens);
637 $tokens = array_merge(CRM_Core_SelectValues::membershipTokens(), $tokens);
638 return $tokens;
639 }
640
641 }