Merge pull request #2763 from colemanw/master
[civicrm-core.git] / CRM / Case / Form / Activity.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
32 * $Id$
33 *
34 */
35
36 /**
37 * This class create activities for a case
38 *
39 */
40 class CRM_Case_Form_Activity extends CRM_Activity_Form_Activity {
41
42 /**
43 * The default variable defined
44 *
45 * @var int
46 */
47 public $_caseId;
48
49 /**
50 * The default case type variable defined
51 *
52 * @var int
53 */
54 public $_caseType;
55
56 /**
57 * The default values of an activity
58 *
59 * @var array
60 */
61 public $_defaults = array();
62
63 /**
64 * The array of releted contact info
65 *
66 * @var array
67 */
68 public $_relatedContacts;
69
70 /**
71 * Function to build the form
72 *
73 * @return void
74 * @access public
75 */
76 function preProcess() {
77 $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'Positive', $this);
78 $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
79 if (!$this->_context) {
80 $this->_context = 'caseActivity';
81 }
82 $this->_crmDir = 'Case';
83 $this->assign('context', $this->_context);
84
85 $result = parent::preProcess();
86
87 $scheduleStatusId = CRM_Core_OptionGroup::getValue('activity_status', 'Scheduled', 'name');
88 $this->assign('scheduleStatusId', $scheduleStatusId);
89
90 if ($this->_cdType) {
91 return $result;
92 }
93
94 if (!$this->_caseId && $this->_activityId) {
95 $this->_caseId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseActivity', $this->_activityId,
96 'case_id', 'activity_id'
97 );
98 }
99 if ($this->_caseId) {
100 $this->assign('caseId', $this->_caseId);
101 }
102
103 if (!$this->_caseId ||
104 (!$this->_activityId && !$this->_activityTypeId)
105 ) {
106 CRM_Core_Error::fatal('required params missing.');
107 }
108
109 //check for case activity access.
110 if (!CRM_Case_BAO_Case::accessCiviCase()) {
111 CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
112 }
113 //validate case id.
114 if ($this->_caseId &&
115 !CRM_Core_Permission::check('access all cases and activities')
116 ) {
117 $session = CRM_Core_Session::singleton();
118 $allCases = CRM_Case_BAO_Case::getCases(TRUE, $session->get('userID'), 'any');
119 if (!array_key_exists($this->_caseId, $allCases)) {
120 CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
121 }
122 }
123
124 //validate case activity id.
125 if ($this->_activityId &&
126 ($this->_action & CRM_Core_Action::UPDATE)
127 ) {
128 $valid = CRM_Case_BAO_Case::checkPermission($this->_activityId, 'edit',
129 $this->_activityTypeId
130 );
131 if (!$valid) {
132 CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
133 }
134 }
135
136 $this->_caseType = CRM_Case_BAO_Case::getCaseType($this->_caseId, 'name');
137 $this->assign('caseType', $this->_caseType);
138
139 $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
140 $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients();
141 $this->assign('multiClient', $isMultiClient);
142
143 $clients = CRM_Case_BAO_Case::getContactNames($this->_caseId);
144 $this->assign('client_names', $clients);
145
146 // set context for pushUserContext and for statusBounce
147 if ($this->_context == 'fulltext') {
148 if ($this->_action == CRM_Core_Action::UPDATE || $this->_action == CRM_Core_Action::DELETE) {
149 $url = CRM_Utils_System::url('civicrm/contact/view/case',
150 "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$this->_caseId}&show=1&context={$this->_context}"
151 );
152 }
153 else {
154 $url = CRM_Utils_System::url('civicrm/contact/search/custom', 'force=1');
155 }
156 }
157 else {
158 $url = CRM_Utils_System::url('civicrm/contact/view/case',
159 "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$this->_caseId}&show=1"
160 );
161 }
162 if (!$this->_activityId) {
163 $caseTypes = CRM_Case_PseudoConstant::caseType();
164
165 if (empty($caseTypes) && ($this->_activityTypeName == 'Change Case Type') && !$this->_caseId) {
166 $url = CRM_Utils_System::url('civicrm/contact/view/case',
167 "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$this->_caseId}&show=1"
168 );
169 $session = CRM_Core_Session::singleton();
170 $session->pushUserContext($url);
171 CRM_Core_Error::statusBounce(ts("You do not have any active Case Types"));
172 }
173
174 // check if activity count is within the limit
175 $xmlProcessor = new CRM_Case_XMLProcessor_Process();
176 $activityInst = $xmlProcessor->getMaxInstance($this->_caseType);
177
178 // If not bounce back and also provide activity edit link
179 if (isset($activityInst[$this->_activityTypeName])) {
180 $activityCount = CRM_Case_BAO_Case::getCaseActivityCount($this->_caseId, $this->_activityTypeId);
181 if ($activityCount >= $activityInst[$this->_activityTypeName]) {
182 if ($activityInst[$this->_activityTypeName] == 1) {
183 $atArray = array('activity_type_id' => $this->_activityTypeId);
184 $activities = CRM_Case_BAO_Case::getCaseActivity($this->_caseId,
185 $atArray,
186 $this->_currentUserId
187 );
188 $activities = array_keys($activities);
189 $activities = $activities[0];
190 $editUrl = CRM_Utils_System::url('civicrm/case/activity',
191 "reset=1&cid={$this->_currentlyViewedContactId}&caseid={$this->_caseId}&action=update&id={$activities}"
192 );
193 }
194 CRM_Core_Error::statusBounce(ts("You can not add another '%1' activity to this case. %2",
195 array(
196 1 => $this->_activityTypeName,
197 2 => "Do you want to <a href='$editUrl'>edit the existing activity</a> ?"
198 )
199 ),
200 $url
201 );
202 }
203 }
204 }
205
206 $session = CRM_Core_Session::singleton();
207 $session->pushUserContext($url);
208 }
209
210 /**
211 * This function sets the default values for the form. For edit/view mode
212 * the default values are retrieved from the database
213 *
214 * @access public
215 *
216 * @return void
217 */
218 function setDefaultValues() {
219 $this->_defaults = parent::setDefaultValues();
220 $targetContactValues = array();
221
222 //get all clients.
223 $clients = CRM_Case_BAO_Case::getContactNames($this->_caseId);
224 if (isset($this->_activityId) && empty($_POST)) {
225 if (!CRM_Utils_Array::crmIsEmptyArray($this->_defaults['target_contact'])) {
226 $targetContactValues = array_combine(array_unique($this->_defaults['target_contact']),
227 explode(';', trim($this->_defaults['target_contact_value']))
228 );
229
230 //exclude all clients.
231 foreach ($clients as $clientId => $vals) {
232 if (array_key_exists($clientId, $targetContactValues)) {
233 unset($targetContactValues[$clientId]);
234 }
235 }
236 }
237 }
238 $this->assign('targetContactValues', empty($targetContactValues) ? FALSE : $targetContactValues);
239
240 //return form for ajax
241 if ($this->_cdType) {
242 return $this->_defaults;
243 }
244
245 if (isset($this->_encounterMedium)) {
246 $this->_defaults['medium_id'] = $this->_encounterMedium;
247 }
248 elseif (empty($this->_defaults['medium_id'])) {
249 // set default encounter medium CRM-4816
250 $medium = CRM_Core_OptionGroup::values('encounter_medium', FALSE, FALSE, FALSE, 'AND is_default = 1');
251 if (count($medium) == 1) {
252 $this->_defaults['medium_id'] = key($medium);
253 }
254 }
255
256 return $this->_defaults;
257 }
258
259 public function buildQuickForm() {
260 $this->_fields['source_contact_id']['label'] = ts('Reported By');
261 unset($this->_fields['status_id']['attributes']['required']);
262
263 if ($this->_caseType) {
264 $xmlProcessor = new CRM_Case_XMLProcessor_Process();
265 $aTypes = $xmlProcessor->get($this->_caseType, 'ActivityTypes', TRUE);
266
267 // remove Open Case activity type since we're inside an existing case
268 $openCaseID = CRM_Core_OptionGroup::getValue('activity_type', 'Open Case', 'name');
269 unset($aTypes[$openCaseID]);
270 asort($aTypes);
271 $this->_fields['followup_activity_type_id']['attributes'] = array(
272 '' => '- select activity type -'
273 ) + $aTypes;
274 }
275
276 $result = parent::buildQuickForm();
277
278 if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::DETACH | CRM_Core_Action::RENEW)) {
279 return;
280 }
281
282 if ($this->_cdType) {
283 return $result;
284 }
285
286 $this->assign('urlPath', 'civicrm/case/activity');
287
288 $encounterMediums = CRM_Case_PseudoConstant::encounterMedium();
289 // Fixme: what's the justification for this? It seems like it is just re-adding an option in case it is the default and disabled.
290 // Is that really a big problem?
291 if ($this->_activityTypeFile == 'OpenCase') {
292 $this->_encounterMedium = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId,
293 'medium_id'
294 );
295 if (!array_key_exists($this->_encounterMedium, $encounterMediums)) {
296 $encounterMediums[$this->_encounterMedium] = CRM_Core_OptionGroup::getLabel('encounter_medium',
297 $this->_encounterMedium,
298 FALSE
299 );
300 }
301 }
302
303 $this->add('select', 'medium_id', ts('Medium'), $encounterMediums, TRUE);
304
305 $this->_relatedContacts = CRM_Case_BAO_Case::getRelatedAndGlobalContacts($this->_caseId);
306 //add case client in send a copy selector.CRM-4438.
307 $relatedContacts = CRM_Case_BAO_Case::getContactNames($this->_caseId);
308 if (!empty($relatedContacts)) {
309 foreach ($relatedContacts as $relatedContact) {
310 $this->_relatedContacts[] = $relatedContact;
311 }
312 }
313
314 if (!empty($this->_relatedContacts)) {
315 $checkBoxes = array();
316 foreach ($this->_relatedContacts as $id => $row) {
317 $checkBoxes[$id] = $this->addElement('checkbox', $id, NULL, '');
318 }
319
320 $this->addGroup($checkBoxes, 'contact_check');
321 $this->addElement('checkbox', 'toggleSelect', NULL, NULL,
322 array('class' => 'select-rows')
323 );
324 $this->assign('searchRows', $this->_relatedContacts);
325 }
326
327 $this->addFormRule(array('CRM_Case_Form_Activity', 'formRule'), $this);
328 }
329
330 /**
331 * global form rule
332 *
333 * @param array $fields the input form values
334 * @param array $files the uploaded files if any
335 * @param array $options additional user data
336 *
337 * @return true if no errors, else array of errors
338 * @access public
339 * @static
340 */
341 static function formRule($fields, $files, $self) {
342 // skip form rule if deleting
343 if (CRM_Utils_Array::value('_qf_Activity_next_', $fields) == 'Delete' || CRM_Utils_Array::value('_qf_Activity_next_', $fields) == 'Restore') {
344 return TRUE;
345 }
346
347 return parent::formrule($fields, $files, $self);
348 }
349
350 /**
351 * Function to process the form
352 *
353 * @access public
354 *
355 * @return void
356 */
357 public function postProcess($params = NULL) {
358 $transaction = new CRM_Core_Transaction();
359
360 if ($this->_action & CRM_Core_Action::DELETE) {
361 $statusMsg = NULL;
362
363 //block deleting activities which affects
364 //case attributes.CRM-4543
365 $activityCondition = " AND v.name IN ('Open Case', 'Change Case Type', 'Change Case Status', 'Change Case Start Date')";
366 $caseAttributeActivities = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, $activityCondition);
367
368 if (!array_key_exists($this->_activityTypeId, $caseAttributeActivities)) {
369 $params = array('id' => $this->_activityId);
370 $activityDelete = CRM_Activity_BAO_Activity::deleteActivity($params, TRUE);
371 if ($activityDelete) {
372 $statusMsg = ts('The selected activity has been moved to the Trash. You can view and / or restore deleted activities by checking "Deleted Activities" from the Case Activities search filter (under Manage Case).<br />');
373 }
374 }
375 else {
376 $statusMsg = ts("Selected Activity cannot be deleted.");
377 }
378
379 $tagParams = array(
380 'entity_table' => 'civicrm_activity',
381 'entity_id' => $this->_activityId
382 );
383 CRM_Core_BAO_EntityTag::del($tagParams);
384
385 CRM_Core_Session::setStatus('', $statusMsg, 'info');
386 return;
387 }
388
389 if ($this->_action & CRM_Core_Action::RENEW) {
390 $statusMsg = NULL;
391 $params = array('id' => $this->_activityId);
392 $activityRestore = CRM_Activity_BAO_Activity::restoreActivity($params);
393 if ($activityRestore) {
394 $statusMsg = ts('The selected activity has been restored.<br />');
395 }
396 CRM_Core_Session::setStatus('', $statusMsg, 'info');
397 return;
398 }
399
400 // store the submitted values in an array
401 $params = $this->controller->exportValues($this->_name);
402
403 //set parent id if its edit mode
404 if ($parentId = CRM_Utils_Array::value('parent_id', $this->_defaults)) {
405 $params['parent_id'] = $parentId;
406 }
407
408 // required for status msg
409 $recordStatus = 'created';
410
411 // store the dates with proper format
412 $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']);
413 $params['activity_type_id'] = $this->_activityTypeId;
414
415 // format with contact (target contact) values
416 if (isset($params['contact'][1])) {
417 $params['target_contact_id'] = explode(',', $params['contact'][1]);
418 }
419 else {
420 $params['target_contact_id'] = array();
421 }
422
423 // format activity custom data
424 if (!empty($params['hidden_custom'])) {
425 if ($this->_activityId) {
426 // unset custom fields-id from params since we want custom
427 // fields to be saved for new activity.
428 foreach ($params as $key => $value) {
429 $match = array();
430 if (preg_match('/^(custom_\d+_)(\d+)$/', $key, $match)) {
431 $params[$match[1] . '-1'] = $params[$key];
432
433 // for autocomplete transfer hidden value instead of label
434 if ($params[$key] && isset($params[$key . '_id'])) {
435 $params[$match[1] . '-1_id'] = $params[$key . '_id'];
436 unset($params[$key . '_id']);
437 }
438 unset($params[$key]);
439 }
440 }
441 }
442
443 // build custom data getFields array
444 $customFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $this->_activityTypeId);
445 $customFields = CRM_Utils_Array::crmArrayMerge($customFields,
446 CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE,
447 NULL, NULL, TRUE
448 )
449 );
450 $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
451 $customFields,
452 $this->_activityId,
453 'Activity'
454 );
455 }
456
457 // assigning formatted value
458 if (!empty($params['assignee_contact_id'])) {
459 $params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']);
460 }
461 else {
462 $params['assignee_contact_id'] = array();
463 }
464
465
466 if (isset($this->_activityId)) {
467 // activity which hasn't been modified by a user yet
468 if ($this->_defaults['is_auto'] == 1) {
469 $params['is_auto'] = 0;
470 }
471
472 // always create a revision of an case activity. CRM-4533
473 $newActParams = $params;
474
475 // add target contact values in update mode
476 if (empty($params['target_contact_id']) && !empty($this->_defaults['target_contact'])) {
477 $newActParams['target_contact_id'] = $this->_defaults['target_contact'];
478 }
479
480 // record status for status msg
481 $recordStatus = 'updated';
482 }
483
484 if (!isset($newActParams)) {
485 // add more attachments if needed for old activity
486 CRM_Core_BAO_File::formatAttachment($params,
487 $params,
488 'civicrm_activity'
489 );
490
491 // call begin post process, before the activity is created/updated.
492 $this->beginPostProcess($params);
493 $params['case_id'] = $this->_caseId;
494 // activity create/update
495 $activity = CRM_Activity_BAO_Activity::create($params);
496
497 // call end post process, after the activity has been created/updated.
498 $this->endPostProcess($params, $activity);
499 }
500 else {
501 // since the params we need to set are very few, and we don't want rest of the
502 // work done by bao create method , lets use dao object to make the changes
503 $params = array('id' => $this->_activityId);
504 $params['is_current_revision'] = 0;
505 $activity = new CRM_Activity_DAO_Activity();
506 $activity->copyValues($params);
507 $activity->save();
508 }
509
510 // create a new version of activity if activity was found to
511 // have been modified/created by user
512 if (isset($newActParams)) {
513 // set proper original_id
514 if (!empty($this->_defaults['original_id'])) {
515 $newActParams['original_id'] = $this->_defaults['original_id'];
516 }
517 else {
518 $newActParams['original_id'] = $activity->id;
519 }
520 //is_current_revision will be set to 1 by default.
521
522 // add attachments if any
523 CRM_Core_BAO_File::formatAttachment($newActParams,
524 $newActParams,
525 'civicrm_activity'
526 );
527
528 // call begin post process, before the activity is created/updated.
529 $this->beginPostProcess($newActParams);
530 $newActParams['case_id'] = $this->_caseId;
531
532 $activity = CRM_Activity_BAO_Activity::create($newActParams);
533
534 // call end post process, after the activity has been created/updated.
535 $this->endPostProcess($newActParams, $activity);
536
537 // copy files attached to old activity if any, to new one,
538 // as long as users have not selected the 'delete attachment' option.
539 if (empty($newActParams['is_delete_attachment'])) {
540 CRM_Core_BAO_File::copyEntityFile('civicrm_activity', $this->_activityId,
541 'civicrm_activity', $activity->id
542 );
543 }
544
545 // copy back params to original var
546 $params = $newActParams;
547 }
548
549 if ($activity->id) {
550 // add tags if exists
551 $tagParams = array();
552 if (!empty($params['tag'])) {
553 foreach ($params['tag'] as $tag) {
554 $tagParams[$tag] = 1;
555 }
556 }
557
558 //save static tags
559 CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id);
560
561 //save free tags
562 if (isset($params['taglist']) && !empty($params['taglist'])) {
563 CRM_Core_Form_Tag::postProcess($params['taglist'], $activity->id, 'civicrm_activity', $this);
564 }
565 }
566
567 // update existing case record if needed
568 $caseParams = $params;
569 $caseParams['id'] = $this->_caseId;
570
571 if (!empty($caseParams['case_type_id'])) {
572 $caseParams['case_type_id'] = CRM_Core_DAO::VALUE_SEPARATOR . $caseParams['case_type_id'] . CRM_Core_DAO::VALUE_SEPARATOR;
573 }
574 if (!empty($caseParams['case_status_id'])) {
575 $caseParams['status_id'] = $caseParams['case_status_id'];
576 }
577
578 // unset params intended for activities only
579 unset($caseParams['subject'], $caseParams['details'],
580 $caseParams['status_id'], $caseParams['custom']
581 );
582 $case = CRM_Case_BAO_Case::create($caseParams);
583
584 // create case activity record
585 $caseParams = array(
586 'activity_id' => $activity->id,
587 'case_id' => $this->_caseId,
588 );
589 CRM_Case_BAO_Case::processCaseActivity($caseParams);
590
591 // Insert civicrm_log record for the activity (e.g. store the
592 // created / edited by contact id and date for the activity)
593 // Note - civicrm_log is already created by CRM_Activity_BAO_Activity::create()
594
595 // send copy to selected contacts.
596 $mailStatus = '';
597 $mailToContacts = array();
598
599 //CRM-5695
600 //check for notification settings for assignee contacts
601 $selectedContacts = array('contact_check');
602 $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
603 $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
604 if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
605 'activity_assignee_notification'
606 )
607 ) {
608 $selectedContacts[] = 'assignee_contact_id';
609 }
610
611 foreach ($selectedContacts as $dnt => $val) {
612 if (array_key_exists($val, $params) && !CRM_Utils_array::crmIsEmptyArray($params[$val])) {
613 if ($val == 'contact_check') {
614 $mailStatus = ts("A copy of the activity has also been sent to selected contacts(s).");
615 }
616 else {
617 $this->_relatedContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($activity->id), TRUE, FALSE);
618 $mailStatus .= ' ' . ts("A copy of the activity has also been sent to assignee contacts(s).");
619 }
620
621 //build an associative array with unique email addresses.
622 foreach ($params[$val] as $key => $value) {
623 if ($val == 'contact_check') {
624 $id = $key;
625 }
626 else {
627 $id = $value;
628 }
629
630 if (isset($id) && array_key_exists($id, $this->_relatedContacts)) {
631 //if email already exists in array then append with ', ' another role only otherwise add it to array.
632 if ($contactDetails = CRM_Utils_Array::value($this->_relatedContacts[$id]['email'], $mailToContacts)) {
633 $caseRole = CRM_Utils_Array::value('role', $this->_relatedContacts[$id]);
634 $mailToContacts[$this->_relatedContacts[$id]['email']]['role'] = $contactDetails['role'] . ', ' . $caseRole;
635 }
636 else {
637 $mailToContacts[$this->_relatedContacts[$id]['email']] = $this->_relatedContacts[$id];
638 }
639 }
640 }
641 }
642 }
643
644 if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) {
645 //include attachments while sending a copy of activity.
646 $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity',
647 $activity->id
648 );
649
650 $ics = new CRM_Activity_BAO_ICalendar($activity);
651 $ics->addAttachment($attachments, $mailToContacts);
652
653 $result = CRM_Case_BAO_Case::sendActivityCopy($this->_currentlyViewedContactId,
654 $activity->id, $mailToContacts, $attachments, $this->_caseId
655 );
656
657 $ics->cleanup();
658
659 if (empty($result)) {
660 $mailStatus = '';
661 }
662 }
663 else {
664 $mailStatus = '';
665 }
666
667 // create follow up activity if needed
668 $followupStatus = '';
669 if (!empty($params['followup_activity_type_id'])) {
670 $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params);
671
672 if ($followupActivity) {
673 $caseParams = array(
674 'activity_id' => $followupActivity->id,
675 'case_id' => $this->_caseId,
676 );
677 CRM_Case_BAO_Case::processCaseActivity($caseParams);
678 $followupStatus = ts("A followup activity has been scheduled.");
679 }
680 }
681
682 CRM_Core_Session::setStatus('', ts("'%1' activity has been %2. %3 %4",
683 array(
684 1 => $this->_activityTypeName,
685 2 => $recordStatus,
686 3 => $followupStatus,
687 4 => $mailStatus
688 )
689 ), 'info');
690 }
691 }
692