3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Case_XMLProcessor_Report
extends CRM_Case_XMLProcessor
{
20 * The default variable defined.
28 public function __construct() {
31 public function getRedactionRules() {
33 'redactionStringRules',
34 'redactionRegexRules',
36 $
$rule = CRM_Case_PseudoConstant
::redactionRule($key);
39 foreach ($
$rule as & $val) {
40 //suffixed with a randomly generated 4-digit number
41 if ($key == 'redactionStringRules') {
42 $val .= rand(10000, 100000);
46 if (!empty($this->{'_' . $rule})) {
47 $this->{'_' . $rule} = CRM_Utils_Array
::crmArrayMerge($this->{'_' . $rule}, $
$rule);
50 $this->{'_' . $rule} = $
$rule;
57 * @param int $clientID
62 public function &caseInfo(
66 $case = $this->_redactionRegexRules
= [];
68 if (empty($this->_redactionStringRules
)) {
69 $this->_redactionStringRules
= [];
72 if ($this->_isRedact
== 1) {
73 $this->getRedactionRules();
76 $client = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'display_name');
78 // add Client to the strings to be redacted across the case session
79 if (!array_key_exists($client, $this->_redactionStringRules
)) {
80 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
81 array($client => 'name_' . rand(10000, 100000))
83 $clientSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'sort_name');
84 if (!array_key_exists($clientSortName, $this->_redactionStringRules
)) {
85 $this->_redactionStringRules
[$clientSortName] = $this->_redactionStringRules
[$client];
89 $case['clientName'] = $this->redact($client);
91 $dao = new CRM_Case_DAO_Case();
93 if ($dao->find(TRUE)) {
94 $case['subject'] = $dao->subject
;
95 $case['start_date'] = $dao->start_date
;
96 $case['end_date'] = $dao->end_date
;
97 $case['caseType'] = CRM_Case_BAO_Case
::getCaseType($caseID);
98 $case['caseTypeName'] = CRM_Case_BAO_Case
::getCaseType($caseID, 'name');
99 $case['status'] = CRM_Core_PseudoConstant
::getLabel('CRM_Case_BAO_Case', 'status_id', $dao->status_id
);
106 * @param string $activitySetName
110 public function getActivityTypes($xml, $activitySetName) {
111 foreach ($xml->ActivitySets
as $activitySetsXML) {
112 foreach ($activitySetsXML->ActivitySet
as $activitySetXML) {
113 if ((string ) $activitySetXML->name
== $activitySetName) {
115 $allActivityTypes = CRM_Case_PseudoConstant
::caseActivityType(TRUE, TRUE);
116 foreach ($activitySetXML->ActivityTypes
as $activityTypesXML) {
117 foreach ($activityTypesXML as $activityTypeXML) {
118 $activityTypeName = (string ) $activityTypeXML->name
;
119 $activityTypeInfo = $allActivityTypes[$activityTypeName] ??
NULL;
120 if ($activityTypeInfo) {
121 $activityTypes[$activityTypeInfo['id']] = $activityTypeInfo;
125 return empty($activityTypes) ?
FALSE : $activityTypes;
134 * @param string $activitySetName
136 * @return null|string
138 public function getActivitySetLabel($xml, $activitySetName) {
139 foreach ($xml->ActivitySets
as $activitySetsXML) {
140 foreach ($activitySetsXML->ActivitySet
as $activitySetXML) {
141 if ((string ) $activitySetXML->name
== $activitySetName) {
142 return (string ) $activitySetXML->label
;
150 * @param int $clientID
152 * @param $activityTypes
155 public function getActivities($clientID, $caseID, $activityTypes, &$activities) {
156 // get all activities for this case that in this activityTypes set
157 foreach ($activityTypes as $aType) {
158 $map[$aType['id']] = $aType;
161 $activityTypeIDs = implode(',', array_keys($map));
163 SELECT a.*, c.id as caseID
164 FROM civicrm_activity a,
166 civicrm_case_activity ac
167 WHERE a.is_current_revision = 1
169 AND a.activity_type_id IN ( $activityTypeIDs )
170 AND c.id = ac.case_id
171 AND a.id = ac.activity_id
175 $params = array(1 => array($caseID, 'Integer'));
176 $dao = CRM_Core_DAO
::executeQuery($query, $params);
177 while ($dao->fetch()) {
178 $activityTypeInfo = $map[$dao->activity_type_id
];
179 $activities[] = $this->getActivity($clientID,
187 * @param int $clientID
188 * @param int $activityID
189 * @param bool $anyActivity
194 public function &getActivityInfo($clientID, $activityID, $anyActivity = FALSE, $redact = 0) {
195 static $activityInfos = [];
197 $this->_isRedact
= 1;
198 $this->getRedactionRules();
201 $index = $activityID . '_' . (int) $anyActivity;
204 $index = $index . '_' . $clientID;
207 if (!array_key_exists($index, $activityInfos)) {
208 $activityInfos[$index] = [];
209 $selectCaseActivity = "";
210 $joinCaseActivity = "";
213 $selectCaseActivity = ", ca.case_id as caseID ";
214 $joinCaseActivity = " INNER JOIN civicrm_case_activity ca ON a.id = ca.activity_id ";
217 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
218 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
219 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
222 SELECT a.*, aa.contact_id as assigneeID, at.contact_id as targetID
223 {$selectCaseActivity}
224 FROM civicrm_activity a
226 LEFT JOIN civicrm_activity_contact at ON a.id = at.activity_id AND at.record_type_id = $targetID
227 LEFT JOIN civicrm_activity_contact aa ON a.id = aa.activity_id AND aa.record_type_id = $assigneeID
230 $params = array(1 => array($activityID, 'Integer'));
231 $dao = CRM_Core_DAO
::executeQuery($query, $params);
234 //if activity type is email get info of all activities.
235 if ($dao->activity_type_id
== CRM_Core_PseudoConstant
::getKey('CRM_Activity_DAO_Activity', 'activity_type_id', 'Email')) {
238 $activityTypes = CRM_Case_PseudoConstant
::caseActivityType(FALSE, $anyActivity);
239 $activityTypeInfo = NULL;
241 if (isset($activityTypes[$dao->activity_type_id
])) {
242 $activityTypeInfo = $activityTypes[$dao->activity_type_id
];
244 if ($activityTypeInfo) {
245 $activityInfos[$index] = $this->getActivity($clientID, $dao, $activityTypeInfo);
250 return $activityInfos[$index];
254 * @param int $clientID
255 * @param $activityDAO
256 * @param $activityTypeInfo
260 public function &getActivity($clientID, $activityDAO, &$activityTypeInfo) {
261 if (empty($this->_redactionStringRules
)) {
262 $this->_redactionStringRules
= [];
266 $activity['fields'] = [];
268 $clientID = CRM_Utils_Type
::escape($clientID, 'Integer');
269 if (!in_array($activityTypeInfo['name'], array(
274 $activity['editURL'] = CRM_Utils_System
::url('civicrm/case/activity',
275 "reset=1&cid={$clientID}&caseid={$activityDAO->caseID}&action=update&atype={$activityDAO->activity_type_id}&id={$activityDAO->id}"
279 $activity['editURL'] = '';
282 $client = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'display_name');
283 // add Client SortName as well as Display to the strings to be redacted across the case session
284 // suffixed with a randomly generated 4-digit number
285 if (!array_key_exists($client, $this->_redactionStringRules
)) {
286 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
287 array($client => 'name_' . rand(10000, 100000))
290 $clientSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'sort_name');
291 if (!array_key_exists($clientSortName, $this->_redactionStringRules
)) {
292 $this->_redactionStringRules
[$clientSortName] = $this->_redactionStringRules
[$client];
296 $activity['fields'][] = array(
298 'label' => ts('Client'),
299 'value' => $this->redact($client),
304 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
305 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
306 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
307 if (!empty($activityDAO->targetID
)) {
308 // Re-lookup the target ID since the DAO only has the first recipient if there are multiple.
309 // Maybe not the best solution.
310 $targetNames = CRM_Activity_BAO_ActivityContact
::getNames($activityDAO->id
, $targetID);
311 $processTarget = FALSE;
312 $name = 'With Contact(s)';
313 $label = ts('With Contact(s)');
314 if (in_array($activityTypeInfo['name'], array('Email', 'Inbound Email'))) {
315 $processTarget = TRUE;
317 $label = ts('Recipient');
319 if (!$processTarget) {
320 foreach ($targetNames as $targetID => $targetName) {
321 if ($targetID != $clientID) {
322 $processTarget = TRUE;
328 if ($processTarget) {
329 $targetRedacted = [];
330 foreach ($targetNames as $targetID => $target) {
331 // add Recipient SortName as well as Display to the strings to be redacted across the case session
332 // suffixed with a randomly generated 4-digit number
333 if (!array_key_exists($target, $this->_redactionStringRules
)) {
334 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
335 array($target => 'name_' . rand(10000, 100000))
337 $targetSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $targetID, 'sort_name');
338 if (!array_key_exists($targetSortName, $this->_redactionStringRules
)) {
339 $this->_redactionStringRules
[$targetSortName] = $this->_redactionStringRules
[$target];
342 $targetRedacted[] = $this->redact($target);
345 $activity['fields'][] = array(
348 'value' => implode('; ', $targetRedacted),
354 // Activity Type info is a special field
355 $activity['fields'][] = array(
356 'name' => 'Activity Type',
357 'label' => ts('Activity Type'),
358 'value' => $activityTypeInfo['label'],
362 $activity['fields'][] = array(
364 'label' => ts('Subject'),
365 // TODO: Why is this being escaped at this point in the flow? Should
366 // this just be done in the tpl where all the other fields get escaped?
367 // Is anything depending on this currently or is it just a result of
368 // the see-sawing and some double-escaping that went back and forth
370 'value' => htmlspecialchars($this->redact($activityDAO->subject
)),
374 $creator = $this->getCreatedBy($activityDAO->id
);
375 // add Creator to the strings to be redacted across the case session
376 if (!array_key_exists($creator, $this->_redactionStringRules
)) {
377 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
378 array($creator => 'name_' . rand(10000, 100000))
381 $activity['fields'][] = array(
382 'name' => 'Created By',
383 'label' => ts('Created By'),
384 'value' => $this->redact($creator),
387 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
388 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
389 $source_contact_id = CRM_Activity_BAO_Activity
::getActivityContact($activityDAO->id
, $sourceID);
390 $reporter = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
395 // add Reporter SortName as well as Display to the strings to be redacted across the case session
396 // suffixed with a randomly generated 4-digit number
397 if (!array_key_exists($reporter, $this->_redactionStringRules
)) {
398 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
399 array($reporter => 'name_' . rand(10000, 100000))
402 $reporterSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
406 if (!array_key_exists($reporterSortName, $this->_redactionStringRules
)) {
407 $this->_redactionStringRules
[$reporterSortName] = $this->_redactionStringRules
[$reporter];
411 $activity['fields'][] = array(
412 'name' => 'Reported By',
413 'label' => ts('Reported By'),
414 'value' => $this->redact($reporter),
418 if (!empty($activityDAO->assigneeID
)) {
419 //allow multiple assignee contacts.CRM-4503.
420 $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment
::getAssigneeNames(array($activityDAO->id
), TRUE);
422 foreach ($assignee_contact_names as & $assignee) {
423 // add Assignee to the strings to be redacted across the case session
424 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
425 array($assignee => 'name_' . rand(10000, 100000))
427 $assignee = $this->redact($assignee);
429 $assigneeContacts = implode(', ', $assignee_contact_names);
430 $activity['fields'][] = array(
431 'name' => 'Assigned to',
432 'label' => ts('Assigned to'),
433 'value' => $assigneeContacts,
438 if ($activityDAO->medium_id
) {
439 $activity['fields'][] = array(
441 'label' => ts('Medium'),
442 'value' => CRM_Core_PseudoConstant
::getLabel('CRM_Activity_BAO_Activity', 'medium_id', $activityDAO->medium_id
),
447 $activity['fields'][] = array(
448 'name' => 'Location',
449 'label' => ts('Location'),
450 'value' => $activityDAO->location
,
454 $activity['fields'][] = array(
455 'name' => 'Date and Time',
456 'label' => ts('Date and Time'),
457 'value' => $activityDAO->activity_date_time
,
461 $activity['fields'][] = array(
463 'label' => ts('Details'),
464 'value' => $this->redact(CRM_Utils_String
::purifyHTML(CRM_Utils_String
::stripAlternatives($activityDAO->details
))),
468 // Skip Duration field if empty (to avoid " minutes" output). Might want to do this for all fields at some point. dgg
469 if ($activityDAO->duration
) {
470 $activity['fields'][] = array(
471 'name' => 'Duration',
472 'label' => ts('Duration'),
473 'value' => $activityDAO->duration
. ' ' . ts('minutes'),
477 $activity['fields'][] = array(
479 'label' => ts('Status'),
480 'value' => CRM_Core_PseudoConstant
::getLabel('CRM_Activity_DAO_Activity', 'activity_status_id',
481 $activityDAO->status_id
486 $activity['fields'][] = array(
487 'name' => 'Priority',
488 'label' => ts('Priority'),
489 'value' => CRM_Core_PseudoConstant
::getLabel('CRM_Activity_DAO_Activity', 'priority_id',
490 $activityDAO->priority_id
495 //for now empty custom groups
496 $activity['customGroups'] = $this->getCustomData($clientID,
505 * @param int $clientID
506 * @param $activityDAO
507 * @param $activityTypeInfo
511 public function getCustomData($clientID, $activityDAO, &$activityTypeInfo) {
512 list($typeValues, $options, $sql) = $this->getActivityTypeCustomSQL($activityTypeInfo['id'], '%Y-%m-%d');
514 $params = array(1 => array($activityDAO->id
, 'Integer'));
517 foreach ($sql as $tableName => $sqlClause) {
518 $dao = CRM_Core_DAO
::executeQuery($sqlClause, $params);
521 foreach ($typeValues[$tableName] as $columnName => $typeValue) {
523 if (CRM_Utils_Array
::value('type', $typeValue) == 'Date') {
524 $value = $dao->$columnName;
527 $value = CRM_Core_BAO_CustomField
::displayValue($dao->$columnName, $typeValue['fieldID'], $activityDAO->id
);
531 // Note: this is already taken care in getDisplayValue above, but sometimes
532 // strings like '^A^A' creates problem. So to fix this special case -
533 if (strstr($value, CRM_Core_DAO
::VALUE_SEPARATOR
)) {
534 $value = trim($value, CRM_Core_DAO
::VALUE_SEPARATOR
);
536 if (CRM_Utils_Array
::value('type', $typeValue) == 'String' ||
537 CRM_Utils_Array
::value('type', $typeValue) == 'Memo'
539 $value = $this->redact($value);
541 elseif (CRM_Utils_Array
::value('type', $typeValue) == 'Link') {
542 $value = CRM_Utils_System
::formatWikiURL($value);
546 $customGroup[] = array(
547 'label' => $typeValue['label'],
549 'type' => $typeValue['type'],
550 'fieldID' => $typeValue['fieldID'],
553 $customGroups[$dao->groupTitle
] = $customGroup;
557 return empty($customGroups) ?
NULL : $customGroups;
561 * @param int $activityTypeID
562 * @param null $dateFormat
563 * @param bool $onlyActive
567 public function getActivityTypeCustomSQL($activityTypeID, $dateFormat = NULL, $onlyActive = TRUE) {
570 if (is_null($activityTypeID)) {
574 if (!isset($cache[$activityTypeID])) {
576 SELECT cg.title as groupTitle,
577 cg.table_name as tableName ,
578 cf.column_name as columnName,
582 cf.data_type as dataType ,
583 cf.html_type as htmlType ,
584 cf.option_group_id as optionGroupID
585 FROM civicrm_custom_group cg,
586 civicrm_custom_field cf
587 WHERE cf.custom_group_id = cg.id
588 AND cg.extends = 'Activity'
589 AND " . CRM_Core_Permission
::customGroupClause(CRM_Core_Permission
::VIEW
, 'cg.');
592 $query .= " AND cf.is_active = 1 ";
594 if ($activityTypeID) {
595 $query .= "AND ( cg.extends_entity_column_value IS NULL OR cg.extends_entity_column_value LIKE '%" . CRM_Core_DAO
::VALUE_SEPARATOR
. "%1" . CRM_Core_DAO
::VALUE_SEPARATOR
. "%' )";
598 $query .= "AND cg.extends_entity_column_value IS NULL";
600 $query .= "ORDER BY cg.weight, cf.weight";
607 $dao = CRM_Core_DAO
::executeQuery($query, $params);
609 $result = $options = $sql = $groupTitle = [];
610 while ($dao->fetch()) {
611 if (!array_key_exists($dao->tableName
, $result)) {
612 $result[$dao->tableName
] = [];
613 $sql[$dao->tableName
] = [];
615 $result[$dao->tableName
][$dao->columnName
] = array(
616 'label' => $dao->label
,
617 'type' => $dao->dataType
,
618 'fieldID' => $dao->fieldID
,
621 $options[$dao->fieldID
] = [];
622 $options[$dao->fieldID
]['attributes'] = array(
623 'label' => $dao->label
,
624 'data_type' => $dao->dataType
,
625 'html_type' => $dao->htmlType
,
627 // since we want to add ISO date format.
628 if ($dateFormat && $dao->htmlType
== 'Select Date') {
629 $options[$dao->fieldID
]['attributes']['format'] = $dateFormat;
631 if ($dao->optionGroupID
) {
634 FROM civicrm_option_value
635 WHERE option_group_id = %1
638 $option = CRM_Core_DAO
::executeQuery($query, array(1 => array($dao->optionGroupID
, 'Positive')));
639 while ($option->fetch()) {
640 $dataType = $dao->dataType
;
641 if ($dataType == 'Int' ||
$dataType == 'Float') {
642 $num = round($option->value
, 2);
643 $options[$dao->fieldID
]["$num"] = $option->label
;
646 $options[$dao->fieldID
][$option->value
] = $option->label
;
651 $sql[$dao->tableName
][] = $dao->columnName
;
652 $groupTitle[$dao->tableName
] = $dao->groupTitle
;
655 foreach ($sql as $tableName => $values) {
656 $columnNames = implode(',', $values);
657 $title = CRM_Core_DAO
::escapeString($groupTitle[$tableName]);
658 $mysqlTableName = CRM_Utils_Type
::escape($tableName, 'MysqlColumnNameOrAlias');
660 SELECT '" . $title . "' as groupTitle, $columnNames
666 $cache[$activityTypeID] = array($result, $options, $sql);
668 return $cache[$activityTypeID];
672 * @param int $activityID
674 * @return null|string
676 public function getCreatedBy($activityID) {
678 SELECT c.display_name
679 FROM civicrm_contact c,
681 WHERE l.entity_table = 'civicrm_activity'
683 AND l.modified_id = c.id
687 $params = array(1 => array($activityID, 'Integer'));
688 return CRM_Core_DAO
::singleValueQuery($query, $params);
693 * @param bool $printReport
694 * @param array $replaceString
698 private function redact($string, $printReport = FALSE, $replaceString = []) {
700 return CRM_Utils_String
::redaction($string, $replaceString);
702 elseif ($this->_isRedact
) {
703 $regexToReplaceString = CRM_Utils_String
::regex($string, $this->_redactionRegexRules
);
704 return CRM_Utils_String
::redaction($string, array_merge($this->_redactionStringRules
, $regexToReplaceString));
710 * @param int $clientID
712 * @param string $activitySetName
713 * @param array $params
714 * @param CRM_Core_Form $form
718 public static function getCaseReport($clientID, $caseID, $activitySetName, $params, $form) {
720 $template = self
::populateCaseReportTemplate($clientID, $caseID, $activitySetName, $params, $form);
722 // now run the template
723 $contents = $template->fetch('CRM/Case/XMLProcessor/Report.tpl');
728 * @param int $clientID
730 * @param string $activitySetName
731 * @param array $params
732 * @param CRM_Core_Form $form
734 * @return CRM_Core_Smarty
736 public static function populateCaseReportTemplate($clientID, $caseID, $activitySetName, $params, $form) {
738 $template = CRM_Core_Smarty
::singleton();
740 $template->assign('caseId', $caseID);
741 $template->assign('clientID', $clientID);
742 $template->assign('activitySetName', $activitySetName);
744 if (!empty($params['is_redact'])) {
745 $form->_isRedact
= TRUE;
746 $template->assign('_isRedact', 'true');
749 $form->_isRedact
= FALSE;
750 $template->assign('_isRedact', 'false');
753 // first get all case information
754 $case = $form->caseInfo($clientID, $caseID);
755 $template->assign_by_ref('case', $case);
757 if (CRM_Utils_Array
::value('include_activities', $params) == 1) {
758 $template->assign('includeActivities', 'All');
761 $template->assign('includeActivities', 'Missing activities only');
764 $xml = $form->retrieve($case['caseTypeName']);
766 $activitySetNames = CRM_Case_XMLProcessor_Process
::activitySets($xml->ActivitySets
);
767 $pageTitle = $activitySetNames[$activitySetName] ??
NULL;
768 $template->assign('pageTitle', $pageTitle);
770 if ($activitySetName) {
771 $activityTypes = $form->getActivityTypes($xml, $activitySetName);
774 $activityTypes = CRM_Case_XMLProcessor
::allActivityTypes(FALSE, TRUE);
777 if (!$activityTypes) {
781 // next get activity set Information
782 $activitySet = array(
783 'label' => $form->getActivitySetLabel($xml, $activitySetName),
784 'includeActivities' => 'All',
787 $template->assign_by_ref('activitySet', $activitySet);
789 //now collect all the information about activities
791 $form->getActivities($clientID, $caseID, $activityTypes, $activities);
792 $template->assign_by_ref('activities', $activities);
797 public static function printCaseReport() {
798 $caseID = CRM_Utils_Request
::retrieve('caseID', 'Positive');
799 $clientID = CRM_Utils_Request
::retrieve('cid', 'Positive');
800 $activitySetName = CRM_Utils_Request
::retrieve('asn', 'String');
801 $isRedact = CRM_Utils_Request
::retrieve('redact', 'Boolean');
802 $includeActivities = CRM_Utils_Request
::retrieve('all', 'Positive');
803 $params = $otherRelationships = $globalGroupInfo = [];
804 $report = new CRM_Case_XMLProcessor_Report($isRedact);
805 if ($includeActivities) {
806 $params['include_activities'] = 1;
810 $params['is_redact'] = 1;
811 $report->_redactionStringRules
= [];
813 $template = CRM_Core_Smarty
::singleton();
815 //get case related relationships (Case Role)
816 $caseRelationships = CRM_Case_BAO_Case
::getCaseRoles($clientID, $caseID);
817 $caseType = CRM_Case_BAO_Case
::getCaseType($caseID, 'name');
819 $xmlProcessor = new CRM_Case_XMLProcessor_Process();
820 $caseRoles = $xmlProcessor->get($caseType, 'CaseRoles');
821 foreach ($caseRelationships as $key => & $value) {
822 if (!empty($caseRoles[$value['relation_type'] . '_' . $value['relationship_direction']])) {
823 unset($caseRoles[$value['relation_type'] . '_' . $value['relationship_direction']]);
826 if (!array_key_exists($value['name'], $report->_redactionStringRules
)) {
827 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
828 array($value['name'] => 'name_' . rand(10000, 100000))
831 $value['name'] = $report->redact($value['name'], TRUE, $report->_redactionStringRules
);
832 if (!empty($value['email']) &&
833 !array_key_exists($value['email'], $report->_redactionStringRules
)
835 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
836 array($value['email'] => 'email_' . rand(10000, 100000))
840 $value['email'] = $report->redact($value['email'], TRUE, $report->_redactionStringRules
);
842 if (!empty($value['phone']) &&
843 !array_key_exists($value['phone'], $report->_redactionStringRules
)
845 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
846 array($value['phone'] => 'phone_' . rand(10000, 100000))
849 $value['phone'] = $report->redact($value['phone'], TRUE, $report->_redactionStringRules
);
853 $caseRoles['client'] = CRM_Case_BAO_Case
::getContactNames($caseID);
855 foreach ($caseRoles['client'] as &$client) {
856 if (!array_key_exists(CRM_Utils_Array
::value('sort_name', $client), $report->_redactionStringRules
)) {
858 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
859 array(CRM_Utils_Array
::value('sort_name', $client) => 'name_' . rand(10000, 100000))
862 if (!array_key_exists(CRM_Utils_Array
::value('display_name', $client), $report->_redactionStringRules
)) {
863 $report->_redactionStringRules
[CRM_Utils_Array
::value('display_name', $client)] = $report->_redactionStringRules
[CRM_Utils_Array
::value('sort_name', $client)];
865 $client['sort_name'] = $report->redact(CRM_Utils_Array
::value('sort_name', $client), TRUE, $report->_redactionStringRules
);
866 if (!empty($client['email']) &&
867 !array_key_exists($client['email'], $report->_redactionStringRules
)
869 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
870 array($client['email'] => 'email_' . rand(10000, 100000))
873 $client['email'] = $report->redact(CRM_Utils_Array
::value('email', $client), TRUE, $report->_redactionStringRules
);
875 if (!empty($client['phone']) &&
876 !array_key_exists($client['phone'], $report->_redactionStringRules
)
878 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
879 array($client['phone'] => 'phone_' . rand(10000, 100000))
882 $client['phone'] = $report->redact(CRM_Utils_Array
::value('phone', $client), TRUE, $report->_redactionStringRules
);
885 // Retrieve ALL client relationships
886 $relClient = CRM_Contact_BAO_Relationship
::getRelationship($clientID,
887 CRM_Contact_BAO_Relationship
::CURRENT
,
888 0, 0, 0, NULL, NULL, FALSE
890 foreach ($relClient as $r) {
892 if (!array_key_exists($r['name'], $report->_redactionStringRules
)) {
893 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
894 array($r['name'] => 'name_' . rand(10000, 100000))
897 if (!array_key_exists($r['display_name'], $report->_redactionStringRules
)) {
898 $report->_redactionStringRules
[$r['display_name']] = $report->_redactionStringRules
[$r['name']];
900 $r['name'] = $report->redact($r['name'], TRUE, $report->_redactionStringRules
);
902 if (!empty($r['phone']) &&
903 !array_key_exists($r['phone'], $report->_redactionStringRules
)
905 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
906 array($r['phone'] => 'phone_' . rand(10000, 100000))
909 $r['phone'] = $report->redact($r['phone'], TRUE, $report->_redactionStringRules
);
911 if (!empty($r['email']) &&
912 !array_key_exists($r['email'], $report->_redactionStringRules
)
914 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
915 array($r['email'] => 'email_' . rand(10000, 100000))
918 $r['email'] = $report->redact($r['email'], TRUE, $report->_redactionStringRules
);
920 if (!array_key_exists($r['id'], $caseRelationships)) {
921 $otherRelationships[] = $r;
925 // Now global contact list that appears on all cases.
926 $relGlobal = CRM_Case_BAO_Case
::getGlobalContacts($globalGroupInfo);
927 foreach ($relGlobal as & $r) {
929 if (!array_key_exists($r['sort_name'], $report->_redactionStringRules
)) {
930 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
931 array($r['sort_name'] => 'name_' . rand(10000, 100000))
934 if (!array_key_exists($r['display_name'], $report->_redactionStringRules
)) {
935 $report->_redactionStringRules
[$r['display_name']] = $report->_redactionStringRules
[$r['sort_name']];
938 $r['sort_name'] = $report->redact($r['sort_name'], TRUE, $report->_redactionStringRules
);
939 if (!empty($r['phone']) &&
940 !array_key_exists($r['phone'], $report->_redactionStringRules
)
942 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
943 array($r['phone'] => 'phone_' . rand(10000, 100000))
946 $r['phone'] = $report->redact($r['phone'], TRUE, $report->_redactionStringRules
);
948 if (!empty($r['email']) &&
949 !array_key_exists($r['email'], $report->_redactionStringRules
)
951 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
952 array($r['email'] => 'email_' . rand(10000, 100000))
955 $r['email'] = $report->redact($r['email'], TRUE, $report->_redactionStringRules
);
959 // Retrieve custom values for cases.
960 $customValues = CRM_Core_BAO_CustomValueTable
::getEntityValues($caseID, 'Case');
961 $extends = array('case');
962 $groupTree = CRM_Core_BAO_CustomGroup
::getGroupDetail(NULL, NULL, $extends);
963 $caseCustomFields = [];
964 foreach ($groupTree as $gid => $group_values) {
965 foreach ($group_values['fields'] as $id => $field_values) {
966 if (array_key_exists($id, $customValues)) {
967 $caseCustomFields[$gid]['title'] = $group_values['title'];
968 $caseCustomFields[$gid]['values'][$id] = array(
969 'label' => $field_values['label'],
970 'value' => $customValues[$id],
975 $template->assign('caseRelationships', $caseRelationships);
976 $template->assign('caseRoles', $caseRoles);
977 $template->assign('otherRelationships', $otherRelationships);
978 $template->assign('globalRelationships', $relGlobal);
979 $template->assign('globalGroupInfo', $globalGroupInfo);
980 $template->assign('caseCustomFields', $caseCustomFields);
981 $contents = self
::getCaseReport($clientID,
987 $printReport = CRM_Case_Audit_Audit
::run($contents, $clientID, $caseID);
989 CRM_Utils_System
::civiExit();