3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
35 class CRM_Case_XMLProcessor_Report
extends CRM_Case_XMLProcessor
{
38 * The default variable defined
44 public function __construct() {}
46 function run($clientID, $caseID, $activitySetName, $params) {
47 $contents = self
::getCaseReport($clientID,
54 return CRM_Case_Audit_Audit
::run($contents, $clientID, $caseID);
57 function &getRedactionRules() {
59 'redactionStringRules', 'redactionRegexRules') as $key => $rule) {
60 $
$rule = CRM_Case_PseudoConstant
::redactionRule($key);
63 foreach ($
$rule as & $val) {
64 //suffixed with a randomly generated 4-digit number
65 if ($key == 'redactionStringRules') {
66 $val .= rand(10000, 100000);
70 if (!empty($this->{'_' . $rule})) {
71 $this->{'_' . $rule} = CRM_Utils_Array
::crmArrayMerge($this->{'_' . $rule}, $
$rule);
74 $this->{'_' . $rule} = $
$rule;
80 function &caseInfo($clientID,
83 $case = $this->_redactionRegexRules
= array();
85 if (empty($this->_redactionStringRules
)) {
86 $this->_redactionStringRules
= array();
89 if ($this->_isRedact
== 1) {
90 $this->getRedactionRules();
93 $client = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'display_name');
95 // add Client to the strings to be redacted across the case session
96 if (!array_key_exists($client, $this->_redactionStringRules
)) {
97 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
98 array($client => 'name_' . rand(10000, 100000))
100 $clientSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'sort_name');
101 if (!array_key_exists($clientSortName, $this->_redactionStringRules
)) {
102 $this->_redactionStringRules
[$clientSortName] = $this->_redactionStringRules
[$client];
106 $case['clientName'] = $this->redact($client);
108 $dao = new CRM_Case_DAO_Case();
110 if ($dao->find(TRUE)) {
111 $case['subject'] = $dao->subject
;
112 $case['start_date'] = $dao->start_date
;
113 $case['end_date'] = $dao->end_date
;
114 // FIXME: when we resolve if case_type_is single or multi-select
115 if (strpos($dao->case_type_id
, CRM_Core_DAO
::VALUE_SEPARATOR
) !== FALSE) {
116 $caseTypeID = substr($dao->case_type_id
, 1, -1);
119 $caseTypeID = $dao->case_type_id
;
121 $caseTypeIDs = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
125 $case['caseType'] = CRM_Case_BAO_Case
::getCaseType($caseID);
126 $case['caseTypeName'] = CRM_Case_BAO_Case
::getCaseType($caseID, 'name');
127 $case['status'] = CRM_Core_OptionGroup
::getLabel('case_status', $dao->status_id
, FALSE);
132 function getActivityTypes($xml, $activitySetName) {
133 foreach ($xml->ActivitySets
as $activitySetsXML) {
134 foreach ($activitySetsXML->ActivitySet
as $activitySetXML) {
135 if ((string ) $activitySetXML->name
== $activitySetName) {
136 $activityTypes = array();
137 $allActivityTypes = &$this->allActivityTypes();
138 foreach ($activitySetXML->ActivityTypes
as $activityTypesXML) {
139 foreach ($activityTypesXML as $activityTypeXML) {
140 $activityTypeName = (string ) $activityTypeXML->name
;
141 $activityTypeInfo = CRM_Utils_Array
::value($activityTypeName, $allActivityTypes);
142 if ($activityTypeInfo) {
143 $activityTypes[$activityTypeInfo['id']] = $activityTypeInfo;
147 return empty($activityTypes) ?
FALSE : $activityTypes;
154 function getActivitySetLabel($xml, $activitySetName) {
155 foreach ($xml->ActivitySets
as $activitySetsXML) {
156 foreach ($activitySetsXML->ActivitySet
as $activitySetXML) {
157 if ((string ) $activitySetXML->name
== $activitySetName) {
158 return (string ) $activitySetXML->label
;
165 function getActivities($clientID, $caseID, $activityTypes, &$activities) {
166 // get all activities for this case that in this activityTypes set
167 foreach ($activityTypes as $aType) {
168 $map[$aType['id']] = $aType;
171 // get all core activities
172 $coreActivityTypes = CRM_Case_PseudoConstant
::caseActivityType(FALSE, TRUE);
174 foreach ($coreActivityTypes as $aType) {
175 $map[$aType['id']] = $aType;
178 $activityTypeIDs = implode(',', array_keys($map));
180 SELECT a.*, c.id as caseID
181 FROM civicrm_activity a,
183 civicrm_case_activity ac
184 WHERE a.is_current_revision = 1
186 AND a.activity_type_id IN ( $activityTypeIDs )
187 AND c.id = ac.case_id
188 AND a.id = ac.activity_id
192 $params = array(1 => array($caseID, 'Integer'));
193 $dao = CRM_Core_DAO
::executeQuery($query, $params);
194 while ($dao->fetch()) {
195 $activityTypeInfo = $map[$dao->activity_type_id
];
196 $activities[] = $this->getActivity($clientID,
203 function &getActivityInfo($clientID, $activityID, $anyActivity = FALSE, $redact = 0) {
204 static $activityInfos = array();
206 $this->_isRedact
= 1;
207 $this->getRedactionRules();
211 $index = $activityID . '_' . (int) $anyActivity;
214 $index = $index . '_' . $clientID;
218 if (!array_key_exists($index, $activityInfos)) {
219 $activityInfos[$index] = array();
220 $selectCaseActivity = "";
221 $joinCaseActivity = "";
224 $selectCaseActivity = ", ca.case_id as caseID ";
225 $joinCaseActivity = " INNER JOIN civicrm_case_activity ca ON a.id = ca.activity_id ";
228 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
229 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
230 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
233 SELECT a.*, aa.contact_id as assigneeID, at.contact_id as targetID
234 {$selectCaseActivity}
235 FROM civicrm_activity a
237 LEFT JOIN civicrm_activity_contact at ON a.id = at.activity_id AND at.record_type_id = $targetID
238 LEFT JOIN civicrm_activity_contact aa ON a.id = aa.activity_id AND aa.record_type_id = $assigneeID
241 $params = array(1 => array($activityID, 'Integer'));
242 $dao = CRM_Core_DAO
::executeQuery($query, $params);
245 //if activity type is email get info of all activities.
246 if ($dao->activity_type_id
== CRM_Core_OptionGroup
::getValue('activity_type', 'Email', 'name')) {
249 $activityTypes = $this->allActivityTypes(FALSE, $anyActivity);
250 $activityTypeInfo = NULL;
252 if (isset($activityTypes[$dao->activity_type_id
])) {
253 $activityTypeInfo = $activityTypes[$dao->activity_type_id
];
255 if ($activityTypeInfo) {
256 $activityInfos[$index] = $this->getActivity($clientID, $dao, $activityTypeInfo);
261 return $activityInfos[$index];
264 function &getActivity($clientID, $activityDAO, &$activityTypeInfo) {
265 if (empty($this->_redactionStringRules
)) {
266 $this->_redactionStringRules
= array();
270 $activity['fields'] = array();
272 $clientID = CRM_Utils_Type
::escape($clientID, 'Integer');
273 if (!in_array($activityTypeInfo['name'], array(
274 'Email', 'Inbound Email'))) {
275 $activity['editURL'] = CRM_Utils_System
::url('civicrm/case/activity',
276 "reset=1&cid={$clientID}&caseid={$activityDAO->caseID}&action=update&atype={$activityDAO->activity_type_id}&id={$activityDAO->id}"
280 $activity['editURL'] = '';
283 $client = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'display_name');
284 // add Client SortName as well as Display to the strings to be redacted across the case session
285 // suffixed with a randomly generated 4-digit number
286 if (!array_key_exists($client, $this->_redactionStringRules
)) {
287 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
288 array($client => 'name_' . rand(10000, 100000))
291 $clientSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'sort_name');
292 if (!array_key_exists($clientSortName, $this->_redactionStringRules
)) {
293 $this->_redactionStringRules
[$clientSortName] = $this->_redactionStringRules
[$client];
297 $activity['fields'][] = array(
299 'value' => $this->redact($client),
304 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
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 $label = ts('With Contact(s)');
313 if (in_array($activityTypeInfo['name'], array('Email', 'Inbound Email'))) {
314 $processTarget = TRUE;
315 $label = ts('Recipient');
317 if (!$processTarget) {
318 foreach ($targetNames as $targetID => $targetName) {
319 if ($targetID != $clientID) {
320 $processTarget = TRUE;
326 if ($processTarget) {
327 $targetRedacted = array();
328 foreach ($targetNames as $targetID => $target) {
329 // add Recipient SortName as well as Display to the strings to be redacted across the case session
330 // suffixed with a randomly generated 4-digit number
331 if (!array_key_exists($target, $this->_redactionStringRules
)) {
332 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
333 array($target => 'name_' . rand(10000, 100000))
335 $targetSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $targetID, 'sort_name');
336 if (!array_key_exists($targetSortName, $this->_redactionStringRules
)) {
337 $this->_redactionStringRules
[$targetSortName] = $this->_redactionStringRules
[$target];
340 $targetRedacted[] = $this->redact($target);
343 $activity['fields'][] = array(
345 'value' => implode('; ', $targetRedacted),
351 // Activity Type info is a special field
352 $activity['fields'][] = array(
353 'label' => ts('Activity Type'),
354 'value' => $activityTypeInfo['label'],
358 $activity['fields'][] = array(
359 'label' => ts('Subject'),
360 'value' => htmlspecialchars($this->redact($activityDAO->subject
)),
364 $creator = $this->getCreatedBy($activityDAO->id
);
365 // add Creator to the strings to be redacted across the case session
366 if (!array_key_exists($creator, $this->_redactionStringRules
)) {
367 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
368 array($creator => 'name_' . rand(10000, 100000))
371 $activity['fields'][] = array(
372 'label' => ts('Created By'),
373 'value' => $this->redact($creator),
376 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
377 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
378 $source_contact_id = CRM_Activity_BAO_Activity
::getActivityContact($activityDAO->id
, $sourceID);
379 $reporter = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
384 // add Reporter SortName as well as Display to the strings to be redacted across the case session
385 // suffixed with a randomly generated 4-digit number
386 if (!array_key_exists($reporter, $this->_redactionStringRules
)) {
387 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
388 array($reporter => 'name_' . rand(10000, 100000))
391 $reporterSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
392 $activityDAO->source_contact_id
,
395 if (!array_key_exists($reporterSortName, $this->_redactionStringRules
)) {
396 $this->_redactionStringRules
[$reporterSortName] = $this->_redactionStringRules
[$reporter];
400 $activity['fields'][] = array(
401 'label' => ts('Reported By'),
402 'value' => $this->redact($reporter),
406 if (!empty($activityDAO->assigneeID
)) {
407 //allow multiple assignee contacts.CRM-4503.
408 $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment
::getAssigneeNames($activityDAO->id
, TRUE);
410 foreach ($assignee_contact_names as & $assignee) {
411 // add Assignee to the strings to be redacted across the case session
412 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
413 array($assignee => 'name_' . rand(10000, 100000))
415 $assignee = $this->redact($assignee);
417 $assigneeContacts = implode(', ', $assignee_contact_names);
418 $activity['fields'][] = array(
419 'label' => ts('Assigned To'),
420 'value' => $assigneeContacts,
425 if ($activityDAO->medium_id
) {
426 $activity['fields'][] = array(
427 'label' => ts('Medium'),
428 'value' => CRM_Core_OptionGroup
::getLabel('encounter_medium',
429 $activityDAO->medium_id
, FALSE
435 $activity['fields'][] = array(
436 'label' => ts('Location'),
437 'value' => $activityDAO->location
,
441 $activity['fields'][] = array(
442 'label' => ts('Date and Time'),
443 'value' => $activityDAO->activity_date_time
,
447 $activity['fields'][] = array(
448 'label' => ts('Details'),
449 'value' => $this->redact(CRM_Utils_String
::stripAlternatives($activityDAO->details
)),
453 // Skip Duration field if empty (to avoid " minutes" output). Might want to do this for all fields at some point. dgg
454 if ($activityDAO->duration
) {
455 $activity['fields'][] = array(
456 'label' => ts('Duration'),
457 'value' => $activityDAO->duration
. ' ' . ts('minutes'),
461 $activity['fields'][] = array(
462 'label' => ts('Status'),
463 'value' => CRM_Core_OptionGroup
::getLabel('activity_status',
464 $activityDAO->status_id
469 $activity['fields'][] = array(
470 'label' => ts('Priority'),
471 'value' => CRM_Core_OptionGroup
::getLabel('priority',
472 $activityDAO->priority_id
477 //for now empty custom groups
478 $activity['customGroups'] = $this->getCustomData($clientID,
486 function getCustomData($clientID, $activityDAO, &$activityTypeInfo) {
487 list($typeValues, $options, $sql) = $this->getActivityTypeCustomSQL($activityTypeInfo['id'], '%Y-%m-%d');
489 $params = array(1 => array($activityDAO->id
, 'Integer'));
491 $customGroups = array();
492 foreach ($sql as $tableName => $sqlClause) {
493 $dao = CRM_Core_DAO
::executeQuery($sqlClause, $params);
495 $customGroup = array();
496 foreach ($typeValues[$tableName] as $columnName => $typeValue) {
497 $value = CRM_Core_BAO_CustomField
::getDisplayValue($dao->$columnName,
498 $typeValue['fieldID'],
502 if (CRM_Utils_Array
::value('type', $typeValue) == 'Date') {
503 $value = $dao->$columnName;
507 // Note: this is already taken care in getDisplayValue above, but sometimes
508 // strings like '^A^A' creates problem. So to fix this special case -
509 if (strstr($value, CRM_Core_DAO
::VALUE_SEPARATOR
)) {
510 $value = trim($value, CRM_Core_DAO
::VALUE_SEPARATOR
);
512 if (CRM_Utils_Array
::value('type', $typeValue) == 'String' ||
513 CRM_Utils_Array
::value('type', $typeValue) == 'Memo'
515 $value = $this->redact($value);
517 elseif (CRM_Utils_Array
::value('type', $typeValue) == 'File') {
518 $tableName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_EntityFile', $typeValue, 'entity_table');
519 $value = CRM_Core_BAO_File
::attachmentInfo($tableName, $activityDAO->id
);
521 elseif (CRM_Utils_Array
::value('type', $typeValue) == 'Link') {
522 $value = CRM_Utils_System
::formatWikiURL($value);
526 $customGroup[] = array(
527 'label' => $typeValue['label'],
529 'type' => $typeValue['type'],
532 $customGroups[$dao->groupTitle
] = $customGroup;
536 return empty($customGroups) ?
NULL : $customGroups;
539 function getActivityTypeCustomSQL($activityTypeID, $dateFormat = NULL) {
540 static $cache = array();
542 if (is_null($activityTypeID)) {
546 if (!isset($cache[$activityTypeID])) {
548 SELECT cg.title as groupTitle,
549 cg.table_name as tableName ,
550 cf.column_name as columnName,
554 cf.data_type as dataType ,
555 cf.html_type as htmlType ,
556 cf.option_group_id as optionGroupID
557 FROM civicrm_custom_group cg,
558 civicrm_custom_field cf
559 WHERE cf.custom_group_id = cg.id
560 AND cg.extends = 'Activity'";
562 if ($activityTypeID) {
563 $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
. "%' )";
566 $query .= "AND cg.extends_entity_column_value IS NULL";
568 $query .= "ORDER BY cf.weight";
570 1 => array($activityTypeID,
573 $dao = CRM_Core_DAO
::executeQuery($query, $params);
575 $result = $options = $sql = $groupTitle = array();
576 while ($dao->fetch()) {
577 if (!array_key_exists($dao->tableName
, $result)) {
578 $result[$dao->tableName
] = array();
579 $sql[$dao->tableName
] = array();
581 $result[$dao->tableName
][$dao->columnName
] = array(
582 'label' => $dao->label
,
583 'type' => $dao->dataType
,
584 'fieldID' => $dao->fieldID
,
587 $options[$dao->fieldID
] = array();
588 $options[$dao->fieldID
]['attributes'] = array(
589 'label' => $dao->label
,
590 'data_type' => $dao->dataType
,
591 'html_type' => $dao->htmlType
,
593 // since we want to add ISO date format.
594 if ($dateFormat && $dao->htmlType
== 'Select Date') {
595 $options[$dao->fieldID
]['attributes']['format'] = $dateFormat;
597 if ($dao->optionGroupID
) {
600 FROM civicrm_option_value
601 WHERE option_group_id = {$dao->optionGroupID}
604 $option = CRM_Core_DAO
::executeQuery($query);
605 while ($option->fetch()) {
606 $dataType = $dao->dataType
;
607 if ($dataType == 'Int' ||
$dataType == 'Float') {
608 $num = round($option->value
, 2);
609 $options[$dao->fieldID
]["$num"] = $option->label
;
612 $options[$dao->fieldID
][$option->value
] = $option->label
;
617 $sql[$dao->tableName
][] = $dao->columnName
;
618 $groupTitle[$dao->tableName
] = $dao->groupTitle
;
621 foreach ($sql as $tableName => $values) {
622 $columnNames = implode(',', $values);
624 SELECT '{$groupTitle[$tableName]}' as groupTitle, $columnNames
630 $cache[$activityTypeID] = array($result, $options, $sql);
632 return $cache[$activityTypeID];
635 function getCreatedBy($activityID) {
637 SELECT c.display_name
638 FROM civicrm_contact c,
640 WHERE l.entity_table = 'civicrm_activity'
642 AND l.modified_id = c.id
646 $params = array(1 => array($activityID, 'Integer'));
647 return CRM_Core_DAO
::singleValueQuery($query, $params);
650 private function redact($string, $printReport = FALSE, $replaceString = array(
653 return CRM_Utils_String
::redaction($string, $replaceString);
655 elseif ($this->_isRedact
) {
656 $regexToReplaceString = CRM_Utils_String
::regex($string, $this->_redactionRegexRules
);
657 return CRM_Utils_String
::redaction($string, array_merge($this->_redactionStringRules
, $regexToReplaceString));
662 function getCaseReport($clientID, $caseID, $activitySetName, $params, $form) {
664 $template = CRM_Core_Smarty
::singleton();
666 $template->assign('caseId', $caseID);
667 $template->assign('clientID', $clientID);
668 $template->assign('activitySetName', $activitySetName);
670 if (CRM_Utils_Array
::value('is_redact', $params)) {
671 $form->_isRedact
= TRUE;
672 $template->assign('_isRedact', 'true');
675 $form->_isRedact
= FALSE;
676 $template->assign('_isRedact', 'false');
679 // first get all case information
680 $case = $form->caseInfo($clientID, $caseID);
681 $template->assign_by_ref('case', $case);
683 if ($params['include_activities'] == 1) {
684 $template->assign('includeActivities', 'All');
687 $template->assign('includeActivities', 'Missing activities only');
690 $xml = $form->retrieve($case['caseTypeName']);
692 $activitySetNames = CRM_Case_XMLProcessor_Process
::activitySets($xml->ActivitySets
);
693 $pageTitle = CRM_Utils_Array
::value($activitySetName, $activitySetNames);
694 $template->assign('pageTitle', $pageTitle);
696 if ($activitySetName) {
697 $activityTypes = $form->getActivityTypes($xml, $activitySetName);
700 $activityTypes = CRM_Case_XMLProcessor
::allActivityTypes();
703 if (!$activityTypes) {
707 // next get activity set Informtion
708 $activitySet = array('label' => $form->getActivitySetLabel($xml, $activitySetName),
709 'includeActivities' => 'All',
712 $template->assign_by_ref('activitySet', $activitySet);
714 //now collect all the information about activities
715 $activities = array();
716 $form->getActivities($clientID, $caseID, $activityTypes, $activities);
717 $template->assign_by_ref('activities', $activities);
719 // now run the template
720 $contents = $template->fetch('CRM/Case/XMLProcessor/Report.tpl');
724 function printCaseReport() {
725 $caseID = CRM_Utils_Request
::retrieve('caseID', 'Positive', CRM_Core_DAO
::$_nullObject);
726 $clientID = CRM_Utils_Request
::retrieve('cid', 'Positive', CRM_Core_DAO
::$_nullObject);
727 $activitySetName = CRM_Utils_Request
::retrieve('asn', 'String', CRM_Core_DAO
::$_nullObject);
728 $isRedact = CRM_Utils_Request
::retrieve('redact', 'Boolean', CRM_Core_DAO
::$_nullObject);
729 $includeActivities = CRM_Utils_Request
::retrieve('all', 'Positive', CRM_Core_DAO
::$_nullObject);
730 $params = $otherRelationships = $globalGroupInfo = array();
731 $report = new CRM_Case_XMLProcessor_Report($isRedact);
732 if ($includeActivities) {
733 $params['include_activities'] = 1;
737 $params['is_redact'] = 1;
738 $report->_redactionStringRules
= array();
740 $template = CRM_Core_Smarty
::singleton();
742 //get case related relationships (Case Role)
743 $caseRelationships = CRM_Case_BAO_Case
::getCaseRoles($clientID, $caseID);
744 $caseType = CRM_Case_BAO_Case
::getCaseType($caseID, 'name');
746 $xmlProcessor = new CRM_Case_XMLProcessor_Process();
747 $caseRoles = $xmlProcessor->get($caseType, 'CaseRoles');
748 foreach ($caseRelationships as $key => & $value) {
749 if (CRM_Utils_Array
::value($value['relation_type'], $caseRoles)) {
750 unset($caseRoles[$value['relation_type']]);
753 if (!array_key_exists($value['name'], $report->_redactionStringRules
)) {
754 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
755 array($value['name'] => 'name_' . rand(10000, 100000))
758 $value['name'] = self
::redact($value['name'], TRUE, $report->_redactionStringRules
);
759 if (CRM_Utils_Array
::value('email', $value) &&
760 !array_key_exists($value['email'], $report->_redactionStringRules
)
762 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
763 array($value['email'] => 'email_' . rand(10000, 100000))
767 $value['email'] = self
::redact($value['email'], TRUE, $report->_redactionStringRules
);
769 if (CRM_Utils_Array
::value('phone', $value) &&
770 !array_key_exists($value['phone'], $report->_redactionStringRules
)
772 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
773 array($value['phone'] => 'phone_' . rand(10000, 100000))
776 $value['phone'] = self
::redact($value['phone'], TRUE, $report->_redactionStringRules
);
780 $caseRoles['client'] = CRM_Case_BAO_Case
::getContactNames($caseID);
782 if (!array_key_exists($caseRoles['client']['sort_name'], $report->_redactionStringRules
)) {
783 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
784 array($caseRoles['client']['sort_name'] => 'name_' . rand(10000, 100000))
787 if (!array_key_exists($caseRoles['client']['display_name'], $report->_redactionStringRules
)) {
788 $report->_redactionStringRules
[$caseRoles['client']['display_name']] = $report->_redactionStringRules
[$caseRoles['client']['sort_name']];
790 $caseRoles['client']['sort_name'] = self
::redact($caseRoles['client']['sort_name'], TRUE, $report->_redactionStringRules
);
791 if (CRM_Utils_Array
::value('email', $caseRoles['client']) &&
792 !array_key_exists($caseRoles['client']['email'], $report->_redactionStringRules
)
794 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
795 array($caseRoles['client']['email'] => 'email_' . rand(10000, 100000))
798 $caseRoles['client']['email'] = self
::redact($caseRoles['client']['email'], TRUE, $report->_redactionStringRules
);
800 if (CRM_Utils_Array
::value('phone', $caseRoles['client']) &&
801 !array_key_exists($caseRoles['client']['phone'], $report->_redactionStringRules
)
803 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
804 array($caseRoles['client']['phone'] => 'phone_' . rand(10000, 100000))
807 $caseRoles['client']['phone'] = self
::redact($caseRoles['client']['phone'], TRUE, $report->_redactionStringRules
);
810 // Retrieve ALL client relationships
811 $relClient = CRM_Contact_BAO_Relationship
::getRelationship($clientID,
812 CRM_Contact_BAO_Relationship
::CURRENT
,
813 0, 0, 0, NULL, NULL, FALSE
815 foreach ($relClient as $r) {
817 if (!array_key_exists($r['name'], $report->_redactionStringRules
)) {
818 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
819 array($r['name'] => 'name_' . rand(10000, 100000))
822 if (!array_key_exists($r['display_name'], $report->_redactionStringRules
)) {
823 $report->_redactionStringRules
[$r['display_name']] = $report->_redactionStringRules
[$r['name']];
825 $r['name'] = self
::redact($r['name'], TRUE, $report->_redactionStringRules
);
827 if (CRM_Utils_Array
::value('phone', $r) &&
828 !array_key_exists($r['phone'], $report->_redactionStringRules
)
830 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
831 array($r['phone'] => 'phone_' . rand(10000, 100000))
834 $r['phone'] = self
::redact($r['phone'], TRUE, $report->_redactionStringRules
);
836 if (CRM_Utils_Array
::value('email', $r) &&
837 !array_key_exists($r['email'], $report->_redactionStringRules
)
839 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
840 array($r['email'] => 'email_' . rand(10000, 100000))
843 $r['email'] = self
::redact($r['email'], TRUE, $report->_redactionStringRules
);
845 if (!array_key_exists($r['id'], $caseRelationships)) {
846 $otherRelationships[] = $r;
850 // Now global contact list that appears on all cases.
851 $relGlobal = CRM_Case_BAO_Case
::getGlobalContacts($globalGroupInfo);
852 foreach ($relGlobal as & $r) {
854 if (!array_key_exists($r['sort_name'], $report->_redactionStringRules
)) {
855 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
856 array($r['sort_name'] => 'name_' . rand(10000, 100000))
859 if (!array_key_exists($r['display_name'], $report->_redactionStringRules
)) {
860 $report->_redactionStringRules
[$r['display_name']] = $report->_redactionStringRules
[$r['sort_name']];
863 $r['sort_name'] = self
::redact($r['sort_name'], TRUE, $report->_redactionStringRules
);
865 if (CRM_Utils_Array
::value('phone', $r) &&
866 !array_key_exists($r['phone'], $report->_redactionStringRules
)
868 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
869 array($r['phone'] => 'phone_' . rand(10000, 100000))
872 $r['phone'] = self
::redact($r['phone'], TRUE, $report->_redactionStringRules
);
874 if (CRM_Utils_Array
::value('email', $r) &&
875 !array_key_exists($r['email'], $report->_redactionStringRules
)
877 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
878 array($r['email'] => 'email_' . rand(10000, 100000))
881 $r['email'] = self
::redact($r['email'], TRUE, $report->_redactionStringRules
);
885 $template->assign('caseRelationships', $caseRelationships);
886 $template->assign('caseRoles', $caseRoles);
887 $template->assign('otherRelationships', $otherRelationships);
888 $template->assign('globalRelationships', $relGlobal);
889 $template->assign('globalGroupInfo', $globalGroupInfo);
890 $contents = self
::getCaseReport($clientID,
896 $printReport = CRM_Case_Audit_Audit
::run($contents, $clientID, $caseID, TRUE);
898 CRM_Utils_System
::civiExit();