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