3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
33 class CRM_Case_XMLProcessor_Report
extends CRM_Case_XMLProcessor
{
36 * The default variable defined.
44 public function __construct() {
48 * @param int $clientID
50 * @param string $activitySetName
51 * @param array $params
55 public function run($clientID, $caseID, $activitySetName, $params) {
56 $contents = self
::getCaseReport($clientID,
63 return CRM_Case_Audit_Audit
::run($contents, $clientID, $caseID);
66 public function getRedactionRules() {
68 'redactionStringRules',
69 'redactionRegexRules',
71 $
$rule = CRM_Case_PseudoConstant
::redactionRule($key);
74 foreach ($
$rule as & $val) {
75 //suffixed with a randomly generated 4-digit number
76 if ($key == 'redactionStringRules') {
77 $val .= rand(10000, 100000);
81 if (!empty($this->{'_' . $rule})) {
82 $this->{'_' . $rule} = CRM_Utils_Array
::crmArrayMerge($this->{'_' . $rule}, $
$rule);
85 $this->{'_' . $rule} = $
$rule;
92 * @param int $clientID
97 public function &caseInfo(
101 $case = $this->_redactionRegexRules
= array();
103 if (empty($this->_redactionStringRules
)) {
104 $this->_redactionStringRules
= array();
107 if ($this->_isRedact
== 1) {
108 $this->getRedactionRules();
111 $client = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'display_name');
113 // add Client to the strings to be redacted across the case session
114 if (!array_key_exists($client, $this->_redactionStringRules
)) {
115 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
116 array($client => 'name_' . rand(10000, 100000))
118 $clientSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'sort_name');
119 if (!array_key_exists($clientSortName, $this->_redactionStringRules
)) {
120 $this->_redactionStringRules
[$clientSortName] = $this->_redactionStringRules
[$client];
124 $case['clientName'] = $this->redact($client);
126 $dao = new CRM_Case_DAO_Case();
128 if ($dao->find(TRUE)) {
129 $case['subject'] = $dao->subject
;
130 $case['start_date'] = $dao->start_date
;
131 $case['end_date'] = $dao->end_date
;
132 $case['caseType'] = CRM_Case_BAO_Case
::getCaseType($caseID);
133 $case['caseTypeName'] = CRM_Case_BAO_Case
::getCaseType($caseID, 'name');
134 $case['status'] = CRM_Core_PseudoConstant
::getLabel('CRM_Case_BAO_Case', 'status_id', $dao->status_id
);
141 * @param string $activitySetName
145 public function getActivityTypes($xml, $activitySetName) {
146 foreach ($xml->ActivitySets
as $activitySetsXML) {
147 foreach ($activitySetsXML->ActivitySet
as $activitySetXML) {
148 if ((string ) $activitySetXML->name
== $activitySetName) {
149 $activityTypes = array();
150 $allActivityTypes = &$this->allActivityTypes();
151 foreach ($activitySetXML->ActivityTypes
as $activityTypesXML) {
152 foreach ($activityTypesXML as $activityTypeXML) {
153 $activityTypeName = (string ) $activityTypeXML->name
;
154 $activityTypeInfo = CRM_Utils_Array
::value($activityTypeName, $allActivityTypes);
155 if ($activityTypeInfo) {
156 $activityTypes[$activityTypeInfo['id']] = $activityTypeInfo;
160 return empty($activityTypes) ?
FALSE : $activityTypes;
169 * @param string $activitySetName
171 * @return null|string
173 public function getActivitySetLabel($xml, $activitySetName) {
174 foreach ($xml->ActivitySets
as $activitySetsXML) {
175 foreach ($activitySetsXML->ActivitySet
as $activitySetXML) {
176 if ((string ) $activitySetXML->name
== $activitySetName) {
177 return (string ) $activitySetXML->label
;
185 * @param int $clientID
187 * @param $activityTypes
190 public function getActivities($clientID, $caseID, $activityTypes, &$activities) {
191 // get all activities for this case that in this activityTypes set
192 foreach ($activityTypes as $aType) {
193 $map[$aType['id']] = $aType;
196 // get all core activities
197 $coreActivityTypes = CRM_Case_PseudoConstant
::caseActivityType(FALSE, TRUE);
199 foreach ($coreActivityTypes as $aType) {
200 $map[$aType['id']] = $aType;
203 $activityTypeIDs = implode(',', array_keys($map));
205 SELECT a.*, c.id as caseID
206 FROM civicrm_activity a,
208 civicrm_case_activity ac
209 WHERE a.is_current_revision = 1
211 AND a.activity_type_id IN ( $activityTypeIDs )
212 AND c.id = ac.case_id
213 AND a.id = ac.activity_id
217 $params = array(1 => array($caseID, 'Integer'));
218 $dao = CRM_Core_DAO
::executeQuery($query, $params);
219 while ($dao->fetch()) {
220 $activityTypeInfo = $map[$dao->activity_type_id
];
221 $activities[] = $this->getActivity($clientID,
229 * @param int $clientID
230 * @param int $activityID
231 * @param bool $anyActivity
236 public function &getActivityInfo($clientID, $activityID, $anyActivity = FALSE, $redact = 0) {
237 static $activityInfos = array();
239 $this->_isRedact
= 1;
240 $this->getRedactionRules();
243 $index = $activityID . '_' . (int) $anyActivity;
246 $index = $index . '_' . $clientID;
249 if (!array_key_exists($index, $activityInfos)) {
250 $activityInfos[$index] = array();
251 $selectCaseActivity = "";
252 $joinCaseActivity = "";
255 $selectCaseActivity = ", ca.case_id as caseID ";
256 $joinCaseActivity = " INNER JOIN civicrm_case_activity ca ON a.id = ca.activity_id ";
259 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
260 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
261 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
264 SELECT a.*, aa.contact_id as assigneeID, at.contact_id as targetID
265 {$selectCaseActivity}
266 FROM civicrm_activity a
268 LEFT JOIN civicrm_activity_contact at ON a.id = at.activity_id AND at.record_type_id = $targetID
269 LEFT JOIN civicrm_activity_contact aa ON a.id = aa.activity_id AND aa.record_type_id = $assigneeID
272 $params = array(1 => array($activityID, 'Integer'));
273 $dao = CRM_Core_DAO
::executeQuery($query, $params);
276 //if activity type is email get info of all activities.
277 if ($dao->activity_type_id
== CRM_Core_PseudoConstant
::getKey('CRM_Activity_DAO_Activity', 'activity_type_id', 'Email')) {
280 $activityTypes = CRM_Case_PseudoConstant
::caseActivityType(FALSE, $anyActivity);
281 $activityTypeInfo = NULL;
283 if (isset($activityTypes[$dao->activity_type_id
])) {
284 $activityTypeInfo = $activityTypes[$dao->activity_type_id
];
286 if ($activityTypeInfo) {
287 $activityInfos[$index] = $this->getActivity($clientID, $dao, $activityTypeInfo);
292 return $activityInfos[$index];
296 * @param int $clientID
297 * @param $activityDAO
298 * @param $activityTypeInfo
302 public function &getActivity($clientID, $activityDAO, &$activityTypeInfo) {
303 if (empty($this->_redactionStringRules
)) {
304 $this->_redactionStringRules
= array();
308 $activity['fields'] = array();
310 $clientID = CRM_Utils_Type
::escape($clientID, 'Integer');
311 if (!in_array($activityTypeInfo['name'], array(
316 $activity['editURL'] = CRM_Utils_System
::url('civicrm/case/activity',
317 "reset=1&cid={$clientID}&caseid={$activityDAO->caseID}&action=update&atype={$activityDAO->activity_type_id}&id={$activityDAO->id}"
321 $activity['editURL'] = '';
324 $client = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'display_name');
325 // add Client SortName as well as Display to the strings to be redacted across the case session
326 // suffixed with a randomly generated 4-digit number
327 if (!array_key_exists($client, $this->_redactionStringRules
)) {
328 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
329 array($client => 'name_' . rand(10000, 100000))
332 $clientSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'sort_name');
333 if (!array_key_exists($clientSortName, $this->_redactionStringRules
)) {
334 $this->_redactionStringRules
[$clientSortName] = $this->_redactionStringRules
[$client];
338 $activity['fields'][] = array(
340 'value' => $this->redact($client),
345 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
346 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
347 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
348 if (!empty($activityDAO->targetID
)) {
349 // Re-lookup the target ID since the DAO only has the first recipient if there are multiple.
350 // Maybe not the best solution.
351 $targetNames = CRM_Activity_BAO_ActivityContact
::getNames($activityDAO->id
, $targetID);
352 $processTarget = FALSE;
353 $label = ts('With Contact(s)');
354 if (in_array($activityTypeInfo['name'], array('Email', 'Inbound Email'))) {
355 $processTarget = TRUE;
356 $label = ts('Recipient');
358 if (!$processTarget) {
359 foreach ($targetNames as $targetID => $targetName) {
360 if ($targetID != $clientID) {
361 $processTarget = TRUE;
367 if ($processTarget) {
368 $targetRedacted = array();
369 foreach ($targetNames as $targetID => $target) {
370 // add Recipient SortName as well as Display to the strings to be redacted across the case session
371 // suffixed with a randomly generated 4-digit number
372 if (!array_key_exists($target, $this->_redactionStringRules
)) {
373 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
374 array($target => 'name_' . rand(10000, 100000))
376 $targetSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $targetID, 'sort_name');
377 if (!array_key_exists($targetSortName, $this->_redactionStringRules
)) {
378 $this->_redactionStringRules
[$targetSortName] = $this->_redactionStringRules
[$target];
381 $targetRedacted[] = $this->redact($target);
384 $activity['fields'][] = array(
386 'value' => implode('; ', $targetRedacted),
392 // Activity Type info is a special field
393 $activity['fields'][] = array(
394 'label' => ts('Activity Type'),
395 'value' => $activityTypeInfo['label'],
399 $activity['fields'][] = array(
400 'label' => ts('Subject'),
401 'value' => htmlspecialchars($this->redact($activityDAO->subject
)),
405 $creator = $this->getCreatedBy($activityDAO->id
);
406 // add Creator to the strings to be redacted across the case session
407 if (!array_key_exists($creator, $this->_redactionStringRules
)) {
408 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
409 array($creator => 'name_' . rand(10000, 100000))
412 $activity['fields'][] = array(
413 'label' => ts('Created By'),
414 'value' => $this->redact($creator),
417 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
418 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
419 $source_contact_id = CRM_Activity_BAO_Activity
::getActivityContact($activityDAO->id
, $sourceID);
420 $reporter = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
425 // add Reporter SortName as well as Display to the strings to be redacted across the case session
426 // suffixed with a randomly generated 4-digit number
427 if (!array_key_exists($reporter, $this->_redactionStringRules
)) {
428 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
429 array($reporter => 'name_' . rand(10000, 100000))
432 $reporterSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
436 if (!array_key_exists($reporterSortName, $this->_redactionStringRules
)) {
437 $this->_redactionStringRules
[$reporterSortName] = $this->_redactionStringRules
[$reporter];
441 $activity['fields'][] = array(
442 'label' => ts('Reported By'),
443 'value' => $this->redact($reporter),
447 if (!empty($activityDAO->assigneeID
)) {
448 //allow multiple assignee contacts.CRM-4503.
449 $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment
::getAssigneeNames(array($activityDAO->id
), TRUE);
451 foreach ($assignee_contact_names as & $assignee) {
452 // add Assignee to the strings to be redacted across the case session
453 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
454 array($assignee => 'name_' . rand(10000, 100000))
456 $assignee = $this->redact($assignee);
458 $assigneeContacts = implode(', ', $assignee_contact_names);
459 $activity['fields'][] = array(
460 'label' => ts('Assigned to'),
461 'value' => $assigneeContacts,
466 if ($activityDAO->medium_id
) {
467 $activity['fields'][] = array(
468 'label' => ts('Medium'),
469 'value' => CRM_Core_PseudoConstant
::getLabel('CRM_Activity_BAO_Activity', 'medium_id', $activityDAO->medium_id
),
474 $activity['fields'][] = array(
475 'label' => ts('Location'),
476 'value' => $activityDAO->location
,
480 $activity['fields'][] = array(
481 'label' => ts('Date and Time'),
482 'value' => $activityDAO->activity_date_time
,
486 $activity['fields'][] = array(
487 'label' => ts('Details'),
488 'value' => $this->redact(CRM_Utils_String
::stripAlternatives($activityDAO->details
)),
492 // Skip Duration field if empty (to avoid " minutes" output). Might want to do this for all fields at some point. dgg
493 if ($activityDAO->duration
) {
494 $activity['fields'][] = array(
495 'label' => ts('Duration'),
496 'value' => $activityDAO->duration
. ' ' . ts('minutes'),
500 $activity['fields'][] = array(
501 'label' => ts('Status'),
502 'value' => CRM_Core_PseudoConstant
::getLabel('CRM_Activity_DAO_Activity', 'activity_status_id',
503 $activityDAO->status_id
508 $activity['fields'][] = array(
509 'label' => ts('Priority'),
510 'value' => CRM_Core_PseudoConstant
::getLabel('CRM_Activity_DAO_Activity', 'priority_id',
511 $activityDAO->priority_id
516 //for now empty custom groups
517 $activity['customGroups'] = $this->getCustomData($clientID,
526 * @param int $clientID
527 * @param $activityDAO
528 * @param $activityTypeInfo
532 public function getCustomData($clientID, $activityDAO, &$activityTypeInfo) {
533 list($typeValues, $options, $sql) = $this->getActivityTypeCustomSQL($activityTypeInfo['id'], '%Y-%m-%d');
535 $params = array(1 => array($activityDAO->id
, 'Integer'));
537 $customGroups = array();
538 foreach ($sql as $tableName => $sqlClause) {
539 $dao = CRM_Core_DAO
::executeQuery($sqlClause, $params);
541 $customGroup = array();
542 foreach ($typeValues[$tableName] as $columnName => $typeValue) {
544 if (CRM_Utils_Array
::value('type', $typeValue) == 'Date') {
545 $value = $dao->$columnName;
548 $value = CRM_Core_BAO_CustomField
::displayValue($dao->$columnName, $typeValue['fieldID'], $activityDAO->id
);
552 // Note: this is already taken care in getDisplayValue above, but sometimes
553 // strings like '^A^A' creates problem. So to fix this special case -
554 if (strstr($value, CRM_Core_DAO
::VALUE_SEPARATOR
)) {
555 $value = trim($value, CRM_Core_DAO
::VALUE_SEPARATOR
);
557 if (CRM_Utils_Array
::value('type', $typeValue) == 'String' ||
558 CRM_Utils_Array
::value('type', $typeValue) == 'Memo'
560 $value = $this->redact($value);
562 elseif (CRM_Utils_Array
::value('type', $typeValue) == 'Link') {
563 $value = CRM_Utils_System
::formatWikiURL($value);
567 $customGroup[] = array(
568 'label' => $typeValue['label'],
570 'type' => $typeValue['type'],
571 'fieldID' => $typeValue['fieldID'],
574 $customGroups[$dao->groupTitle
] = $customGroup;
578 return empty($customGroups) ?
NULL : $customGroups;
582 * @param int $activityTypeID
583 * @param null $dateFormat
584 * @param bool $onlyActive
588 public function getActivityTypeCustomSQL($activityTypeID, $dateFormat = NULL, $onlyActive = TRUE) {
589 static $cache = array();
591 if (is_null($activityTypeID)) {
595 if (!isset($cache[$activityTypeID])) {
597 SELECT cg.title as groupTitle,
598 cg.table_name as tableName ,
599 cf.column_name as columnName,
603 cf.data_type as dataType ,
604 cf.html_type as htmlType ,
605 cf.option_group_id as optionGroupID
606 FROM civicrm_custom_group cg,
607 civicrm_custom_field cf
608 WHERE cf.custom_group_id = cg.id
609 AND cg.extends = 'Activity'
610 AND " . CRM_Core_Permission
::customGroupClause(CRM_Core_Permission
::VIEW
, 'cg.');
613 $query .= " AND cf.is_active = 1 ";
615 if ($activityTypeID) {
616 $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
. "%' )";
619 $query .= "AND cg.extends_entity_column_value IS NULL";
621 $query .= "ORDER BY cg.weight, cf.weight";
628 $dao = CRM_Core_DAO
::executeQuery($query, $params);
630 $result = $options = $sql = $groupTitle = array();
631 while ($dao->fetch()) {
632 if (!array_key_exists($dao->tableName
, $result)) {
633 $result[$dao->tableName
] = array();
634 $sql[$dao->tableName
] = array();
636 $result[$dao->tableName
][$dao->columnName
] = array(
637 'label' => $dao->label
,
638 'type' => $dao->dataType
,
639 'fieldID' => $dao->fieldID
,
642 $options[$dao->fieldID
] = array();
643 $options[$dao->fieldID
]['attributes'] = array(
644 'label' => $dao->label
,
645 'data_type' => $dao->dataType
,
646 'html_type' => $dao->htmlType
,
648 // since we want to add ISO date format.
649 if ($dateFormat && $dao->htmlType
== 'Select Date') {
650 $options[$dao->fieldID
]['attributes']['format'] = $dateFormat;
652 if ($dao->optionGroupID
) {
655 FROM civicrm_option_value
656 WHERE option_group_id = %1
659 $option = CRM_Core_DAO
::executeQuery($query, array(1 => array($dao->optionGroupID
, 'Positive')));
660 while ($option->fetch()) {
661 $dataType = $dao->dataType
;
662 if ($dataType == 'Int' ||
$dataType == 'Float') {
663 $num = round($option->value
, 2);
664 $options[$dao->fieldID
]["$num"] = $option->label
;
667 $options[$dao->fieldID
][$option->value
] = $option->label
;
672 $sql[$dao->tableName
][] = $dao->columnName
;
673 $groupTitle[$dao->tableName
] = $dao->groupTitle
;
676 foreach ($sql as $tableName => $values) {
677 $columnNames = implode(',', $values);
678 $title = CRM_Core_DAO
::escapeString($groupTitle[$tableName]);
679 $mysqlTableName = CRM_Utils_Type
::escape($tableName, 'MysqlColumnNameOrAlias');
681 SELECT '" . $title . "' as groupTitle, $columnNames
687 $cache[$activityTypeID] = array($result, $options, $sql);
689 return $cache[$activityTypeID];
693 * @param int $activityID
695 * @return null|string
697 public function getCreatedBy($activityID) {
699 SELECT c.display_name
700 FROM civicrm_contact c,
702 WHERE l.entity_table = 'civicrm_activity'
704 AND l.modified_id = c.id
708 $params = array(1 => array($activityID, 'Integer'));
709 return CRM_Core_DAO
::singleValueQuery($query, $params);
714 * @param bool $printReport
715 * @param array $replaceString
719 private function redact($string, $printReport = FALSE, $replaceString = array()) {
721 return CRM_Utils_String
::redaction($string, $replaceString);
723 elseif ($this->_isRedact
) {
724 $regexToReplaceString = CRM_Utils_String
::regex($string, $this->_redactionRegexRules
);
725 return CRM_Utils_String
::redaction($string, array_merge($this->_redactionStringRules
, $regexToReplaceString));
731 * @param int $clientID
733 * @param string $activitySetName
734 * @param array $params
735 * @param CRM_Core_Form $form
739 public static function getCaseReport($clientID, $caseID, $activitySetName, $params, $form) {
741 $template = CRM_Core_Smarty
::singleton();
743 $template->assign('caseId', $caseID);
744 $template->assign('clientID', $clientID);
745 $template->assign('activitySetName', $activitySetName);
747 if (!empty($params['is_redact'])) {
748 $form->_isRedact
= TRUE;
749 $template->assign('_isRedact', 'true');
752 $form->_isRedact
= FALSE;
753 $template->assign('_isRedact', 'false');
756 // first get all case information
757 $case = $form->caseInfo($clientID, $caseID);
758 $template->assign_by_ref('case', $case);
760 if ($params['include_activities'] == 1) {
761 $template->assign('includeActivities', 'All');
764 $template->assign('includeActivities', 'Missing activities only');
767 $xml = $form->retrieve($case['caseTypeName']);
769 $activitySetNames = CRM_Case_XMLProcessor_Process
::activitySets($xml->ActivitySets
);
770 $pageTitle = CRM_Utils_Array
::value($activitySetName, $activitySetNames);
771 $template->assign('pageTitle', $pageTitle);
773 if ($activitySetName) {
774 $activityTypes = $form->getActivityTypes($xml, $activitySetName);
777 $activityTypes = CRM_Case_XMLProcessor
::allActivityTypes();
780 if (!$activityTypes) {
784 // next get activity set Information
785 $activitySet = array(
786 'label' => $form->getActivitySetLabel($xml, $activitySetName),
787 'includeActivities' => 'All',
790 $template->assign_by_ref('activitySet', $activitySet);
792 //now collect all the information about activities
793 $activities = array();
794 $form->getActivities($clientID, $caseID, $activityTypes, $activities);
795 $template->assign_by_ref('activities', $activities);
797 // now run the template
798 $contents = $template->fetch('CRM/Case/XMLProcessor/Report.tpl');
802 public static function printCaseReport() {
803 $caseID = CRM_Utils_Request
::retrieve('caseID', 'Positive');
804 $clientID = CRM_Utils_Request
::retrieve('cid', 'Positive');
805 $activitySetName = CRM_Utils_Request
::retrieve('asn', 'String');
806 $isRedact = CRM_Utils_Request
::retrieve('redact', 'Boolean');
807 $includeActivities = CRM_Utils_Request
::retrieve('all', 'Positive');
808 $params = $otherRelationships = $globalGroupInfo = array();
809 $report = new CRM_Case_XMLProcessor_Report($isRedact);
810 if ($includeActivities) {
811 $params['include_activities'] = 1;
815 $params['is_redact'] = 1;
816 $report->_redactionStringRules
= array();
818 $template = CRM_Core_Smarty
::singleton();
820 //get case related relationships (Case Role)
821 $caseRelationships = CRM_Case_BAO_Case
::getCaseRoles($clientID, $caseID);
822 $caseType = CRM_Case_BAO_Case
::getCaseType($caseID, 'name');
824 $xmlProcessor = new CRM_Case_XMLProcessor_Process();
825 $caseRoles = $xmlProcessor->get($caseType, 'CaseRoles');
826 foreach ($caseRelationships as $key => & $value) {
827 if (!empty($caseRoles[$value['relation_type']])) {
828 unset($caseRoles[$value['relation_type']]);
831 if (!array_key_exists($value['name'], $report->_redactionStringRules
)) {
832 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
833 array($value['name'] => 'name_' . rand(10000, 100000))
836 $value['name'] = $report->redact($value['name'], TRUE, $report->_redactionStringRules
);
837 if (!empty($value['email']) &&
838 !array_key_exists($value['email'], $report->_redactionStringRules
)
840 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
841 array($value['email'] => 'email_' . rand(10000, 100000))
845 $value['email'] = $report->redact($value['email'], TRUE, $report->_redactionStringRules
);
847 if (!empty($value['phone']) &&
848 !array_key_exists($value['phone'], $report->_redactionStringRules
)
850 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
851 array($value['phone'] => 'phone_' . rand(10000, 100000))
854 $value['phone'] = $report->redact($value['phone'], TRUE, $report->_redactionStringRules
);
858 $caseRoles['client'] = CRM_Case_BAO_Case
::getContactNames($caseID);
860 foreach ($caseRoles['client'] as &$client) {
861 if (!array_key_exists(CRM_Utils_Array
::value('sort_name', $client), $report->_redactionStringRules
)) {
863 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
864 array(CRM_Utils_Array
::value('sort_name', $client) => 'name_' . rand(10000, 100000))
867 if (!array_key_exists(CRM_Utils_Array
::value('display_name', $client), $report->_redactionStringRules
)) {
868 $report->_redactionStringRules
[CRM_Utils_Array
::value('display_name', $client)] = $report->_redactionStringRules
[CRM_Utils_Array
::value('sort_name', $client)];
870 $client['sort_name'] = $report->redact(CRM_Utils_Array
::value('sort_name', $client), TRUE, $report->_redactionStringRules
);
871 if (!empty($client['email']) &&
872 !array_key_exists($client['email'], $report->_redactionStringRules
)
874 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
875 array($client['email'] => 'email_' . rand(10000, 100000))
878 $client['email'] = $report->redact(CRM_Utils_Array
::value('email', $client), TRUE, $report->_redactionStringRules
);
880 if (!empty($client['phone']) &&
881 !array_key_exists($client['phone'], $report->_redactionStringRules
)
883 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
884 array($client['phone'] => 'phone_' . rand(10000, 100000))
887 $client['phone'] = $report->redact(CRM_Utils_Array
::value('phone', $client), TRUE, $report->_redactionStringRules
);
890 // Retrieve ALL client relationships
891 $relClient = CRM_Contact_BAO_Relationship
::getRelationship($clientID,
892 CRM_Contact_BAO_Relationship
::CURRENT
,
893 0, 0, 0, NULL, NULL, FALSE
895 foreach ($relClient as $r) {
897 if (!array_key_exists($r['name'], $report->_redactionStringRules
)) {
898 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
899 array($r['name'] => 'name_' . rand(10000, 100000))
902 if (!array_key_exists($r['display_name'], $report->_redactionStringRules
)) {
903 $report->_redactionStringRules
[$r['display_name']] = $report->_redactionStringRules
[$r['name']];
905 $r['name'] = $report->redact($r['name'], TRUE, $report->_redactionStringRules
);
907 if (!empty($r['phone']) &&
908 !array_key_exists($r['phone'], $report->_redactionStringRules
)
910 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
911 array($r['phone'] => 'phone_' . rand(10000, 100000))
914 $r['phone'] = $report->redact($r['phone'], TRUE, $report->_redactionStringRules
);
916 if (!empty($r['email']) &&
917 !array_key_exists($r['email'], $report->_redactionStringRules
)
919 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
920 array($r['email'] => 'email_' . rand(10000, 100000))
923 $r['email'] = $report->redact($r['email'], TRUE, $report->_redactionStringRules
);
925 if (!array_key_exists($r['id'], $caseRelationships)) {
926 $otherRelationships[] = $r;
930 // Now global contact list that appears on all cases.
931 $relGlobal = CRM_Case_BAO_Case
::getGlobalContacts($globalGroupInfo);
932 foreach ($relGlobal as & $r) {
934 if (!array_key_exists($r['sort_name'], $report->_redactionStringRules
)) {
935 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
936 array($r['sort_name'] => 'name_' . rand(10000, 100000))
939 if (!array_key_exists($r['display_name'], $report->_redactionStringRules
)) {
940 $report->_redactionStringRules
[$r['display_name']] = $report->_redactionStringRules
[$r['sort_name']];
943 $r['sort_name'] = $report->redact($r['sort_name'], TRUE, $report->_redactionStringRules
);
944 if (!empty($r['phone']) &&
945 !array_key_exists($r['phone'], $report->_redactionStringRules
)
947 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
948 array($r['phone'] => 'phone_' . rand(10000, 100000))
951 $r['phone'] = $report->redact($r['phone'], TRUE, $report->_redactionStringRules
);
953 if (!empty($r['email']) &&
954 !array_key_exists($r['email'], $report->_redactionStringRules
)
956 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
957 array($r['email'] => 'email_' . rand(10000, 100000))
960 $r['email'] = $report->redact($r['email'], TRUE, $report->_redactionStringRules
);
964 // Retrieve custom values for cases.
965 $customValues = CRM_Core_BAO_CustomValueTable
::getEntityValues($caseID, 'Case');
966 $extends = array('case');
967 $groupTree = CRM_Core_BAO_CustomGroup
::getGroupDetail(NULL, NULL, $extends);
968 $caseCustomFields = array();
969 foreach ($groupTree as $gid => $group_values) {
970 foreach ($group_values['fields'] as $id => $field_values) {
971 if (array_key_exists($id, $customValues)) {
972 $caseCustomFields[$gid]['title'] = $group_values['title'];
973 $caseCustomFields[$gid]['values'][$id] = array(
974 'label' => $field_values['label'],
975 'value' => $customValues[$id],
980 $template->assign('caseRelationships', $caseRelationships);
981 $template->assign('caseRoles', $caseRoles);
982 $template->assign('otherRelationships', $otherRelationships);
983 $template->assign('globalRelationships', $relGlobal);
984 $template->assign('globalGroupInfo', $globalGroupInfo);
985 $template->assign('caseCustomFields', $caseCustomFields);
986 $contents = self
::getCaseReport($clientID,
992 $printReport = CRM_Case_Audit_Audit
::run($contents, $clientID, $caseID, TRUE);
994 CRM_Utils_System
::civiExit();