3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
35 class CRM_Case_XMLProcessor_Report
extends CRM_Case_XMLProcessor
{
38 * The default variable defined
47 public function __construct() {}
52 * @param $activitySetName
57 function run($clientID, $caseID, $activitySetName, $params) {
58 $contents = self
::getCaseReport($clientID,
65 return CRM_Case_Audit_Audit
::run($contents, $clientID, $caseID);
68 function &getRedactionRules() {
70 'redactionStringRules', 'redactionRegexRules') as $key => $rule) {
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;
97 function &caseInfo($clientID,
100 $case = $this->_redactionRegexRules
= array();
102 if (empty($this->_redactionStringRules
)) {
103 $this->_redactionStringRules
= array();
106 if ($this->_isRedact
== 1) {
107 $this->getRedactionRules();
110 $client = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'display_name');
112 // add Client to the strings to be redacted across the case session
113 if (!array_key_exists($client, $this->_redactionStringRules
)) {
114 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
115 array($client => 'name_' . rand(10000, 100000))
117 $clientSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'sort_name');
118 if (!array_key_exists($clientSortName, $this->_redactionStringRules
)) {
119 $this->_redactionStringRules
[$clientSortName] = $this->_redactionStringRules
[$client];
123 $case['clientName'] = $this->redact($client);
125 $dao = new CRM_Case_DAO_Case();
127 if ($dao->find(TRUE)) {
128 $case['subject'] = $dao->subject
;
129 $case['start_date'] = $dao->start_date
;
130 $case['end_date'] = $dao->end_date
;
131 // FIXME: when we resolve if case_type_is single or multi-select
132 if (strpos($dao->case_type_id
, CRM_Core_DAO
::VALUE_SEPARATOR
) !== FALSE) {
133 $caseTypeID = substr($dao->case_type_id
, 1, -1);
136 $caseTypeID = $dao->case_type_id
;
138 $caseTypeIDs = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
142 $case['caseType'] = CRM_Case_BAO_Case
::getCaseType($caseID);
143 $case['caseTypeName'] = CRM_Case_BAO_Case
::getCaseType($caseID, 'name');
144 $case['status'] = CRM_Core_OptionGroup
::getLabel('case_status', $dao->status_id
, FALSE);
151 * @param $activitySetName
155 function getActivityTypes($xml, $activitySetName) {
156 foreach ($xml->ActivitySets
as $activitySetsXML) {
157 foreach ($activitySetsXML->ActivitySet
as $activitySetXML) {
158 if ((string ) $activitySetXML->name
== $activitySetName) {
159 $activityTypes = array();
160 $allActivityTypes = &$this->allActivityTypes();
161 foreach ($activitySetXML->ActivityTypes
as $activityTypesXML) {
162 foreach ($activityTypesXML as $activityTypeXML) {
163 $activityTypeName = (string ) $activityTypeXML->name
;
164 $activityTypeInfo = CRM_Utils_Array
::value($activityTypeName, $allActivityTypes);
165 if ($activityTypeInfo) {
166 $activityTypes[$activityTypeInfo['id']] = $activityTypeInfo;
170 return empty($activityTypes) ?
FALSE : $activityTypes;
179 * @param $activitySetName
181 * @return null|string
183 function getActivitySetLabel($xml, $activitySetName) {
184 foreach ($xml->ActivitySets
as $activitySetsXML) {
185 foreach ($activitySetsXML->ActivitySet
as $activitySetXML) {
186 if ((string ) $activitySetXML->name
== $activitySetName) {
187 return (string ) $activitySetXML->label
;
197 * @param $activityTypes
200 function getActivities($clientID, $caseID, $activityTypes, &$activities) {
201 // get all activities for this case that in this activityTypes set
202 foreach ($activityTypes as $aType) {
203 $map[$aType['id']] = $aType;
206 // get all core activities
207 $coreActivityTypes = CRM_Case_PseudoConstant
::caseActivityType(FALSE, TRUE);
209 foreach ($coreActivityTypes as $aType) {
210 $map[$aType['id']] = $aType;
213 $activityTypeIDs = implode(',', array_keys($map));
215 SELECT a.*, c.id as caseID
216 FROM civicrm_activity a,
218 civicrm_case_activity ac
219 WHERE a.is_current_revision = 1
221 AND a.activity_type_id IN ( $activityTypeIDs )
222 AND c.id = ac.case_id
223 AND a.id = ac.activity_id
227 $params = array(1 => array($caseID, 'Integer'));
228 $dao = CRM_Core_DAO
::executeQuery($query, $params);
229 while ($dao->fetch()) {
230 $activityTypeInfo = $map[$dao->activity_type_id
];
231 $activities[] = $this->getActivity($clientID,
241 * @param bool $anyActivity
246 function &getActivityInfo($clientID, $activityID, $anyActivity = FALSE, $redact = 0) {
247 static $activityInfos = array();
249 $this->_isRedact
= 1;
250 $this->getRedactionRules();
254 $index = $activityID . '_' . (int) $anyActivity;
257 $index = $index . '_' . $clientID;
261 if (!array_key_exists($index, $activityInfos)) {
262 $activityInfos[$index] = array();
263 $selectCaseActivity = "";
264 $joinCaseActivity = "";
267 $selectCaseActivity = ", ca.case_id as caseID ";
268 $joinCaseActivity = " INNER JOIN civicrm_case_activity ca ON a.id = ca.activity_id ";
271 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
272 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
273 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
276 SELECT a.*, aa.contact_id as assigneeID, at.contact_id as targetID
277 {$selectCaseActivity}
278 FROM civicrm_activity a
280 LEFT JOIN civicrm_activity_contact at ON a.id = at.activity_id AND at.record_type_id = $targetID
281 LEFT JOIN civicrm_activity_contact aa ON a.id = aa.activity_id AND aa.record_type_id = $assigneeID
284 $params = array(1 => array($activityID, 'Integer'));
285 $dao = CRM_Core_DAO
::executeQuery($query, $params);
288 //if activity type is email get info of all activities.
289 if ($dao->activity_type_id
== CRM_Core_OptionGroup
::getValue('activity_type', 'Email', 'name')) {
292 $activityTypes = $this->allActivityTypes(FALSE, $anyActivity);
293 $activityTypeInfo = NULL;
295 if (isset($activityTypes[$dao->activity_type_id
])) {
296 $activityTypeInfo = $activityTypes[$dao->activity_type_id
];
298 if ($activityTypeInfo) {
299 $activityInfos[$index] = $this->getActivity($clientID, $dao, $activityTypeInfo);
304 return $activityInfos[$index];
309 * @param $activityDAO
310 * @param $activityTypeInfo
314 function &getActivity($clientID, $activityDAO, &$activityTypeInfo) {
315 if (empty($this->_redactionStringRules
)) {
316 $this->_redactionStringRules
= array();
320 $activity['fields'] = array();
322 $clientID = CRM_Utils_Type
::escape($clientID, 'Integer');
323 if (!in_array($activityTypeInfo['name'], array(
324 'Email', 'Inbound Email'))) {
325 $activity['editURL'] = CRM_Utils_System
::url('civicrm/case/activity',
326 "reset=1&cid={$clientID}&caseid={$activityDAO->caseID}&action=update&atype={$activityDAO->activity_type_id}&id={$activityDAO->id}"
330 $activity['editURL'] = '';
333 $client = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'display_name');
334 // add Client SortName as well as Display to the strings to be redacted across the case session
335 // suffixed with a randomly generated 4-digit number
336 if (!array_key_exists($client, $this->_redactionStringRules
)) {
337 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
338 array($client => 'name_' . rand(10000, 100000))
341 $clientSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'sort_name');
342 if (!array_key_exists($clientSortName, $this->_redactionStringRules
)) {
343 $this->_redactionStringRules
[$clientSortName] = $this->_redactionStringRules
[$client];
347 $activity['fields'][] = array(
349 'value' => $this->redact($client),
354 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
355 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
356 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
357 if (!empty($activityDAO->targetID
)) {
358 // Re-lookup the target ID since the DAO only has the first recipient if there are multiple.
359 // Maybe not the best solution.
360 $targetNames = CRM_Activity_BAO_ActivityContact
::getNames($activityDAO->id
, $targetID);
361 $processTarget = FALSE;
362 $label = ts('With Contact(s)');
363 if (in_array($activityTypeInfo['name'], array('Email', 'Inbound Email'))) {
364 $processTarget = TRUE;
365 $label = ts('Recipient');
367 if (!$processTarget) {
368 foreach ($targetNames as $targetID => $targetName) {
369 if ($targetID != $clientID) {
370 $processTarget = TRUE;
376 if ($processTarget) {
377 $targetRedacted = array();
378 foreach ($targetNames as $targetID => $target) {
379 // add Recipient SortName as well as Display to the strings to be redacted across the case session
380 // suffixed with a randomly generated 4-digit number
381 if (!array_key_exists($target, $this->_redactionStringRules
)) {
382 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
383 array($target => 'name_' . rand(10000, 100000))
385 $targetSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $targetID, 'sort_name');
386 if (!array_key_exists($targetSortName, $this->_redactionStringRules
)) {
387 $this->_redactionStringRules
[$targetSortName] = $this->_redactionStringRules
[$target];
390 $targetRedacted[] = $this->redact($target);
393 $activity['fields'][] = array(
395 'value' => implode('; ', $targetRedacted),
401 // Activity Type info is a special field
402 $activity['fields'][] = array(
403 'label' => ts('Activity Type'),
404 'value' => $activityTypeInfo['label'],
408 $activity['fields'][] = array(
409 'label' => ts('Subject'),
410 'value' => htmlspecialchars($this->redact($activityDAO->subject
)),
414 $creator = $this->getCreatedBy($activityDAO->id
);
415 // add Creator to the strings to be redacted across the case session
416 if (!array_key_exists($creator, $this->_redactionStringRules
)) {
417 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
418 array($creator => 'name_' . rand(10000, 100000))
421 $activity['fields'][] = array(
422 'label' => ts('Created By'),
423 'value' => $this->redact($creator),
426 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
427 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
428 $source_contact_id = CRM_Activity_BAO_Activity
::getActivityContact($activityDAO->id
, $sourceID);
429 $reporter = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
434 // add Reporter SortName as well as Display to the strings to be redacted across the case session
435 // suffixed with a randomly generated 4-digit number
436 if (!array_key_exists($reporter, $this->_redactionStringRules
)) {
437 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
438 array($reporter => 'name_' . rand(10000, 100000))
441 $reporterSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
445 if (!array_key_exists($reporterSortName, $this->_redactionStringRules
)) {
446 $this->_redactionStringRules
[$reporterSortName] = $this->_redactionStringRules
[$reporter];
450 $activity['fields'][] = array(
451 'label' => ts('Reported By'),
452 'value' => $this->redact($reporter),
456 if (!empty($activityDAO->assigneeID
)) {
457 //allow multiple assignee contacts.CRM-4503.
458 $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment
::getAssigneeNames(array($activityDAO->id
), TRUE);
460 foreach ($assignee_contact_names as & $assignee) {
461 // add Assignee to the strings to be redacted across the case session
462 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
463 array($assignee => 'name_' . rand(10000, 100000))
465 $assignee = $this->redact($assignee);
467 $assigneeContacts = implode(', ', $assignee_contact_names);
468 $activity['fields'][] = array(
469 'label' => ts('Assigned To'),
470 'value' => $assigneeContacts,
475 if ($activityDAO->medium_id
) {
476 $activity['fields'][] = array(
477 'label' => ts('Medium'),
478 'value' => CRM_Core_OptionGroup
::getLabel('encounter_medium',
479 $activityDAO->medium_id
, FALSE
485 $activity['fields'][] = array(
486 'label' => ts('Location'),
487 'value' => $activityDAO->location
,
491 $activity['fields'][] = array(
492 'label' => ts('Date and Time'),
493 'value' => $activityDAO->activity_date_time
,
497 $activity['fields'][] = array(
498 'label' => ts('Details'),
499 'value' => $this->redact(CRM_Utils_String
::stripAlternatives($activityDAO->details
)),
503 // Skip Duration field if empty (to avoid " minutes" output). Might want to do this for all fields at some point. dgg
504 if ($activityDAO->duration
) {
505 $activity['fields'][] = array(
506 'label' => ts('Duration'),
507 'value' => $activityDAO->duration
. ' ' . ts('minutes'),
511 $activity['fields'][] = array(
512 'label' => ts('Status'),
513 'value' => CRM_Core_OptionGroup
::getLabel('activity_status',
514 $activityDAO->status_id
519 $activity['fields'][] = array(
520 'label' => ts('Priority'),
521 'value' => CRM_Core_OptionGroup
::getLabel('priority',
522 $activityDAO->priority_id
527 //for now empty custom groups
528 $activity['customGroups'] = $this->getCustomData($clientID,
538 * @param $activityDAO
539 * @param $activityTypeInfo
543 function getCustomData($clientID, $activityDAO, &$activityTypeInfo) {
544 list($typeValues, $options, $sql) = $this->getActivityTypeCustomSQL($activityTypeInfo['id'], '%Y-%m-%d');
546 $params = array(1 => array($activityDAO->id
, 'Integer'));
548 $customGroups = array();
549 foreach ($sql as $tableName => $sqlClause) {
550 $dao = CRM_Core_DAO
::executeQuery($sqlClause, $params);
552 $customGroup = array();
553 foreach ($typeValues[$tableName] as $columnName => $typeValue) {
554 $value = CRM_Core_BAO_CustomField
::getDisplayValue($dao->$columnName,
555 $typeValue['fieldID'],
559 if (CRM_Utils_Array
::value('type', $typeValue) == 'Date') {
560 $value = $dao->$columnName;
564 // Note: this is already taken care in getDisplayValue above, but sometimes
565 // strings like '^A^A' creates problem. So to fix this special case -
566 if (strstr($value, CRM_Core_DAO
::VALUE_SEPARATOR
)) {
567 $value = trim($value, CRM_Core_DAO
::VALUE_SEPARATOR
);
569 if (CRM_Utils_Array
::value('type', $typeValue) == 'String' ||
570 CRM_Utils_Array
::value('type', $typeValue) == 'Memo'
572 $value = $this->redact($value);
574 elseif (CRM_Utils_Array
::value('type', $typeValue) == 'File') {
575 $tableName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_EntityFile', $typeValue, 'entity_table');
576 $value = CRM_Core_BAO_File
::attachmentInfo($tableName, $activityDAO->id
);
578 elseif (CRM_Utils_Array
::value('type', $typeValue) == 'Link') {
579 $value = CRM_Utils_System
::formatWikiURL($value);
583 $customGroup[] = array(
584 'label' => $typeValue['label'],
586 'type' => $typeValue['type'],
589 $customGroups[$dao->groupTitle
] = $customGroup;
593 return empty($customGroups) ?
NULL : $customGroups;
597 * @param $activityTypeID
598 * @param null $dateFormat
602 function getActivityTypeCustomSQL($activityTypeID, $dateFormat = NULL) {
603 static $cache = array();
605 if (is_null($activityTypeID)) {
609 if (!isset($cache[$activityTypeID])) {
611 SELECT cg.title as groupTitle,
612 cg.table_name as tableName ,
613 cf.column_name as columnName,
617 cf.data_type as dataType ,
618 cf.html_type as htmlType ,
619 cf.option_group_id as optionGroupID
620 FROM civicrm_custom_group cg,
621 civicrm_custom_field cf
622 WHERE cf.custom_group_id = cg.id
623 AND cg.extends = 'Activity'";
625 if ($activityTypeID) {
626 $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
. "%' )";
629 $query .= "AND cg.extends_entity_column_value IS NULL";
631 $query .= "ORDER BY cf.weight";
633 1 => array($activityTypeID,
636 $dao = CRM_Core_DAO
::executeQuery($query, $params);
638 $result = $options = $sql = $groupTitle = array();
639 while ($dao->fetch()) {
640 if (!array_key_exists($dao->tableName
, $result)) {
641 $result[$dao->tableName
] = array();
642 $sql[$dao->tableName
] = array();
644 $result[$dao->tableName
][$dao->columnName
] = array(
645 'label' => $dao->label
,
646 'type' => $dao->dataType
,
647 'fieldID' => $dao->fieldID
,
650 $options[$dao->fieldID
] = array();
651 $options[$dao->fieldID
]['attributes'] = array(
652 'label' => $dao->label
,
653 'data_type' => $dao->dataType
,
654 'html_type' => $dao->htmlType
,
656 // since we want to add ISO date format.
657 if ($dateFormat && $dao->htmlType
== 'Select Date') {
658 $options[$dao->fieldID
]['attributes']['format'] = $dateFormat;
660 if ($dao->optionGroupID
) {
663 FROM civicrm_option_value
664 WHERE option_group_id = {$dao->optionGroupID}
667 $option = CRM_Core_DAO
::executeQuery($query);
668 while ($option->fetch()) {
669 $dataType = $dao->dataType
;
670 if ($dataType == 'Int' ||
$dataType == 'Float') {
671 $num = round($option->value
, 2);
672 $options[$dao->fieldID
]["$num"] = $option->label
;
675 $options[$dao->fieldID
][$option->value
] = $option->label
;
680 $sql[$dao->tableName
][] = $dao->columnName
;
681 $groupTitle[$dao->tableName
] = $dao->groupTitle
;
684 foreach ($sql as $tableName => $values) {
685 $columnNames = implode(',', $values);
687 SELECT '{$groupTitle[$tableName]}' as groupTitle, $columnNames
693 $cache[$activityTypeID] = array($result, $options, $sql);
695 return $cache[$activityTypeID];
701 * @return null|string
703 function getCreatedBy($activityID) {
705 SELECT c.display_name
706 FROM civicrm_contact c,
708 WHERE l.entity_table = 'civicrm_activity'
710 AND l.modified_id = c.id
714 $params = array(1 => array($activityID, 'Integer'));
715 return CRM_Core_DAO
::singleValueQuery($query, $params);
720 * @param bool $printReport
721 * @param array $replaceString
725 private function redact($string, $printReport = FALSE, $replaceString = array(
728 return CRM_Utils_String
::redaction($string, $replaceString);
730 elseif ($this->_isRedact
) {
731 $regexToReplaceString = CRM_Utils_String
::regex($string, $this->_redactionRegexRules
);
732 return CRM_Utils_String
::redaction($string, array_merge($this->_redactionStringRules
, $regexToReplaceString));
740 * @param $activitySetName
746 static function getCaseReport($clientID, $caseID, $activitySetName, $params, $form) {
748 $template = CRM_Core_Smarty
::singleton();
750 $template->assign('caseId', $caseID);
751 $template->assign('clientID', $clientID);
752 $template->assign('activitySetName', $activitySetName);
754 if (!empty($params['is_redact'])) {
755 $form->_isRedact
= TRUE;
756 $template->assign('_isRedact', 'true');
759 $form->_isRedact
= FALSE;
760 $template->assign('_isRedact', 'false');
763 // first get all case information
764 $case = $form->caseInfo($clientID, $caseID);
765 $template->assign_by_ref('case', $case);
767 if ($params['include_activities'] == 1) {
768 $template->assign('includeActivities', 'All');
771 $template->assign('includeActivities', 'Missing activities only');
774 $xml = $form->retrieve($case['caseTypeName']);
776 $activitySetNames = CRM_Case_XMLProcessor_Process
::activitySets($xml->ActivitySets
);
777 $pageTitle = CRM_Utils_Array
::value($activitySetName, $activitySetNames);
778 $template->assign('pageTitle', $pageTitle);
780 if ($activitySetName) {
781 $activityTypes = $form->getActivityTypes($xml, $activitySetName);
784 $activityTypes = CRM_Case_XMLProcessor
::allActivityTypes();
787 if (!$activityTypes) {
791 // next get activity set Informtion
792 $activitySet = array('label' => $form->getActivitySetLabel($xml, $activitySetName),
793 'includeActivities' => 'All',
796 $template->assign_by_ref('activitySet', $activitySet);
798 //now collect all the information about activities
799 $activities = array();
800 $form->getActivities($clientID, $caseID, $activityTypes, $activities);
801 $template->assign_by_ref('activities', $activities);
803 // now run the template
804 $contents = $template->fetch('CRM/Case/XMLProcessor/Report.tpl');
808 static function printCaseReport() {
809 $caseID = CRM_Utils_Request
::retrieve('caseID', 'Positive', CRM_Core_DAO
::$_nullObject);
810 $clientID = CRM_Utils_Request
::retrieve('cid', 'Positive', CRM_Core_DAO
::$_nullObject);
811 $activitySetName = CRM_Utils_Request
::retrieve('asn', 'String', CRM_Core_DAO
::$_nullObject);
812 $isRedact = CRM_Utils_Request
::retrieve('redact', 'Boolean', CRM_Core_DAO
::$_nullObject);
813 $includeActivities = CRM_Utils_Request
::retrieve('all', 'Positive', CRM_Core_DAO
::$_nullObject);
814 $params = $otherRelationships = $globalGroupInfo = array();
815 $report = new CRM_Case_XMLProcessor_Report($isRedact);
816 if ($includeActivities) {
817 $params['include_activities'] = 1;
821 $params['is_redact'] = 1;
822 $report->_redactionStringRules
= array();
824 $template = CRM_Core_Smarty
::singleton();
826 //get case related relationships (Case Role)
827 $caseRelationships = CRM_Case_BAO_Case
::getCaseRoles($clientID, $caseID);
828 $caseType = CRM_Case_BAO_Case
::getCaseType($caseID, 'name');
830 $xmlProcessor = new CRM_Case_XMLProcessor_Process();
831 $caseRoles = $xmlProcessor->get($caseType, 'CaseRoles');
832 foreach ($caseRelationships as $key => & $value) {
833 if (!empty($caseRoles[$value['relation_type']])) {
834 unset($caseRoles[$value['relation_type']]);
837 if (!array_key_exists($value['name'], $report->_redactionStringRules
)) {
838 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
839 array($value['name'] => 'name_' . rand(10000, 100000))
842 $value['name'] = self
::redact($value['name'], TRUE, $report->_redactionStringRules
);
843 if (!empty($value['email']) &&
844 !array_key_exists($value['email'], $report->_redactionStringRules
)
846 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
847 array($value['email'] => 'email_' . rand(10000, 100000))
851 $value['email'] = self
::redact($value['email'], TRUE, $report->_redactionStringRules
);
853 if (!empty($value['phone']) &&
854 !array_key_exists($value['phone'], $report->_redactionStringRules
)
856 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
857 array($value['phone'] => 'phone_' . rand(10000, 100000))
860 $value['phone'] = self
::redact($value['phone'], TRUE, $report->_redactionStringRules
);
864 $caseRoles['client'] = CRM_Case_BAO_Case
::getContactNames($caseID);
866 if (!array_key_exists($caseRoles['client']['sort_name'], $report->_redactionStringRules
)) {
867 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
868 array($caseRoles['client']['sort_name'] => 'name_' . rand(10000, 100000))
871 if (!array_key_exists($caseRoles['client']['display_name'], $report->_redactionStringRules
)) {
872 $report->_redactionStringRules
[$caseRoles['client']['display_name']] = $report->_redactionStringRules
[$caseRoles['client']['sort_name']];
874 $caseRoles['client']['sort_name'] = self
::redact($caseRoles['client']['sort_name'], TRUE, $report->_redactionStringRules
);
875 if (!empty($caseRoles['client']['email']) &&
876 !array_key_exists($caseRoles['client']['email'], $report->_redactionStringRules
)
878 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
879 array($caseRoles['client']['email'] => 'email_' . rand(10000, 100000))
882 $caseRoles['client']['email'] = self
::redact($caseRoles['client']['email'], TRUE, $report->_redactionStringRules
);
884 if (!empty($caseRoles['client']['phone']) &&
885 !array_key_exists($caseRoles['client']['phone'], $report->_redactionStringRules
)
887 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
888 array($caseRoles['client']['phone'] => 'phone_' . rand(10000, 100000))
891 $caseRoles['client']['phone'] = self
::redact($caseRoles['client']['phone'], TRUE, $report->_redactionStringRules
);
894 // Retrieve ALL client relationships
895 $relClient = CRM_Contact_BAO_Relationship
::getRelationship($clientID,
896 CRM_Contact_BAO_Relationship
::CURRENT
,
897 0, 0, 0, NULL, NULL, FALSE
899 foreach ($relClient as $r) {
901 if (!array_key_exists($r['name'], $report->_redactionStringRules
)) {
902 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
903 array($r['name'] => 'name_' . rand(10000, 100000))
906 if (!array_key_exists($r['display_name'], $report->_redactionStringRules
)) {
907 $report->_redactionStringRules
[$r['display_name']] = $report->_redactionStringRules
[$r['name']];
909 $r['name'] = self
::redact($r['name'], TRUE, $report->_redactionStringRules
);
911 if (!empty($r['phone']) &&
912 !array_key_exists($r['phone'], $report->_redactionStringRules
)
914 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
915 array($r['phone'] => 'phone_' . rand(10000, 100000))
918 $r['phone'] = self
::redact($r['phone'], TRUE, $report->_redactionStringRules
);
920 if (!empty($r['email']) &&
921 !array_key_exists($r['email'], $report->_redactionStringRules
)
923 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
924 array($r['email'] => 'email_' . rand(10000, 100000))
927 $r['email'] = self
::redact($r['email'], TRUE, $report->_redactionStringRules
);
929 if (!array_key_exists($r['id'], $caseRelationships)) {
930 $otherRelationships[] = $r;
934 // Now global contact list that appears on all cases.
935 $relGlobal = CRM_Case_BAO_Case
::getGlobalContacts($globalGroupInfo);
936 foreach ($relGlobal as & $r) {
938 if (!array_key_exists($r['sort_name'], $report->_redactionStringRules
)) {
939 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
940 array($r['sort_name'] => 'name_' . rand(10000, 100000))
943 if (!array_key_exists($r['display_name'], $report->_redactionStringRules
)) {
944 $report->_redactionStringRules
[$r['display_name']] = $report->_redactionStringRules
[$r['sort_name']];
947 $r['sort_name'] = self
::redact($r['sort_name'], TRUE, $report->_redactionStringRules
);
949 if (!empty($r['phone']) &&
950 !array_key_exists($r['phone'], $report->_redactionStringRules
)
952 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
953 array($r['phone'] => 'phone_' . rand(10000, 100000))
956 $r['phone'] = self
::redact($r['phone'], TRUE, $report->_redactionStringRules
);
958 if (!empty($r['email']) &&
959 !array_key_exists($r['email'], $report->_redactionStringRules
)
961 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
962 array($r['email'] => 'email_' . rand(10000, 100000))
965 $r['email'] = self
::redact($r['email'], TRUE, $report->_redactionStringRules
);
969 $template->assign('caseRelationships', $caseRelationships);
970 $template->assign('caseRoles', $caseRoles);
971 $template->assign('otherRelationships', $otherRelationships);
972 $template->assign('globalRelationships', $relGlobal);
973 $template->assign('globalGroupInfo', $globalGroupInfo);
974 $contents = self
::getCaseReport($clientID,
980 $printReport = CRM_Case_Audit_Audit
::run($contents, $clientID, $caseID, TRUE);
982 CRM_Utils_System
::civiExit();