3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
35 class CRM_Case_XMLProcessor_Report
extends CRM_Case_XMLProcessor
{
38 * The default variable defined.
46 public function __construct() {
50 * @param int $clientID
52 * @param string $activitySetName
53 * @param array $params
57 public function run($clientID, $caseID, $activitySetName, $params) {
58 $contents = self
::getCaseReport($clientID,
65 return CRM_Case_Audit_Audit
::run($contents, $clientID, $caseID);
68 public function &getRedactionRules() {
70 'redactionStringRules',
71 'redactionRegexRules',
73 $
$rule = CRM_Case_PseudoConstant
::redactionRule($key);
76 foreach ($
$rule as & $val) {
77 //suffixed with a randomly generated 4-digit number
78 if ($key == 'redactionStringRules') {
79 $val .= rand(10000, 100000);
83 if (!empty($this->{'_' . $rule})) {
84 $this->{'_' . $rule} = CRM_Utils_Array
::crmArrayMerge($this->{'_' . $rule}, $
$rule);
87 $this->{'_' . $rule} = $
$rule;
94 * @param int $clientID
99 public function &caseInfo(
103 $case = $this->_redactionRegexRules
= array();
105 if (empty($this->_redactionStringRules
)) {
106 $this->_redactionStringRules
= array();
109 if ($this->_isRedact
== 1) {
110 $this->getRedactionRules();
113 $client = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'display_name');
115 // add Client to the strings to be redacted across the case session
116 if (!array_key_exists($client, $this->_redactionStringRules
)) {
117 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
118 array($client => 'name_' . rand(10000, 100000))
120 $clientSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'sort_name');
121 if (!array_key_exists($clientSortName, $this->_redactionStringRules
)) {
122 $this->_redactionStringRules
[$clientSortName] = $this->_redactionStringRules
[$client];
126 $case['clientName'] = $this->redact($client);
128 $dao = new CRM_Case_DAO_Case();
130 if ($dao->find(TRUE)) {
131 $case['subject'] = $dao->subject
;
132 $case['start_date'] = $dao->start_date
;
133 $case['end_date'] = $dao->end_date
;
134 // FIXME: when we resolve if case_type_is single or multi-select
135 if (strpos($dao->case_type_id
, CRM_Core_DAO
::VALUE_SEPARATOR
) !== FALSE) {
136 $caseTypeID = substr($dao->case_type_id
, 1, -1);
139 $caseTypeID = $dao->case_type_id
;
141 $caseTypeIDs = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
145 $case['caseType'] = CRM_Case_BAO_Case
::getCaseType($caseID);
146 $case['caseTypeName'] = CRM_Case_BAO_Case
::getCaseType($caseID, 'name');
147 $case['status'] = CRM_Core_OptionGroup
::getLabel('case_status', $dao->status_id
, FALSE);
154 * @param string $activitySetName
158 public function getActivityTypes($xml, $activitySetName) {
159 foreach ($xml->ActivitySets
as $activitySetsXML) {
160 foreach ($activitySetsXML->ActivitySet
as $activitySetXML) {
161 if ((string ) $activitySetXML->name
== $activitySetName) {
162 $activityTypes = array();
163 $allActivityTypes = &$this->allActivityTypes();
164 foreach ($activitySetXML->ActivityTypes
as $activityTypesXML) {
165 foreach ($activityTypesXML as $activityTypeXML) {
166 $activityTypeName = (string ) $activityTypeXML->name
;
167 $activityTypeInfo = CRM_Utils_Array
::value($activityTypeName, $allActivityTypes);
168 if ($activityTypeInfo) {
169 $activityTypes[$activityTypeInfo['id']] = $activityTypeInfo;
173 return empty($activityTypes) ?
FALSE : $activityTypes;
182 * @param string $activitySetName
184 * @return null|string
186 public function getActivitySetLabel($xml, $activitySetName) {
187 foreach ($xml->ActivitySets
as $activitySetsXML) {
188 foreach ($activitySetsXML->ActivitySet
as $activitySetXML) {
189 if ((string ) $activitySetXML->name
== $activitySetName) {
190 return (string ) $activitySetXML->label
;
198 * @param int $clientID
200 * @param $activityTypes
203 public function getActivities($clientID, $caseID, $activityTypes, &$activities) {
204 // get all activities for this case that in this activityTypes set
205 foreach ($activityTypes as $aType) {
206 $map[$aType['id']] = $aType;
209 // get all core activities
210 $coreActivityTypes = CRM_Case_PseudoConstant
::caseActivityType(FALSE, TRUE);
212 foreach ($coreActivityTypes as $aType) {
213 $map[$aType['id']] = $aType;
216 $activityTypeIDs = implode(',', array_keys($map));
218 SELECT a.*, c.id as caseID
219 FROM civicrm_activity a,
221 civicrm_case_activity ac
222 WHERE a.is_current_revision = 1
224 AND a.activity_type_id IN ( $activityTypeIDs )
225 AND c.id = ac.case_id
226 AND a.id = ac.activity_id
230 $params = array(1 => array($caseID, 'Integer'));
231 $dao = CRM_Core_DAO
::executeQuery($query, $params);
232 while ($dao->fetch()) {
233 $activityTypeInfo = $map[$dao->activity_type_id
];
234 $activities[] = $this->getActivity($clientID,
242 * @param int $clientID
243 * @param int $activityID
244 * @param bool $anyActivity
249 public function &getActivityInfo($clientID, $activityID, $anyActivity = FALSE, $redact = 0) {
250 static $activityInfos = array();
252 $this->_isRedact
= 1;
253 $this->getRedactionRules();
256 $index = $activityID . '_' . (int) $anyActivity;
259 $index = $index . '_' . $clientID;
262 if (!array_key_exists($index, $activityInfos)) {
263 $activityInfos[$index] = array();
264 $selectCaseActivity = "";
265 $joinCaseActivity = "";
268 $selectCaseActivity = ", ca.case_id as caseID ";
269 $joinCaseActivity = " INNER JOIN civicrm_case_activity ca ON a.id = ca.activity_id ";
272 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
273 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
274 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
277 SELECT a.*, aa.contact_id as assigneeID, at.contact_id as targetID
278 {$selectCaseActivity}
279 FROM civicrm_activity a
281 LEFT JOIN civicrm_activity_contact at ON a.id = at.activity_id AND at.record_type_id = $targetID
282 LEFT JOIN civicrm_activity_contact aa ON a.id = aa.activity_id AND aa.record_type_id = $assigneeID
285 $params = array(1 => array($activityID, 'Integer'));
286 $dao = CRM_Core_DAO
::executeQuery($query, $params);
289 //if activity type is email get info of all activities.
290 if ($dao->activity_type_id
== CRM_Core_OptionGroup
::getValue('activity_type', 'Email', 'name')) {
293 $activityTypes = CRM_Case_PseudoConstant
::caseActivityType(FALSE, $anyActivity);
294 $activityTypeInfo = NULL;
296 if (isset($activityTypes[$dao->activity_type_id
])) {
297 $activityTypeInfo = $activityTypes[$dao->activity_type_id
];
299 if ($activityTypeInfo) {
300 $activityInfos[$index] = $this->getActivity($clientID, $dao, $activityTypeInfo);
305 return $activityInfos[$index];
309 * @param int $clientID
310 * @param $activityDAO
311 * @param $activityTypeInfo
315 public function &getActivity($clientID, $activityDAO, &$activityTypeInfo) {
316 if (empty($this->_redactionStringRules
)) {
317 $this->_redactionStringRules
= array();
321 $activity['fields'] = array();
323 $clientID = CRM_Utils_Type
::escape($clientID, 'Integer');
324 if (!in_array($activityTypeInfo['name'], array(
329 $activity['editURL'] = CRM_Utils_System
::url('civicrm/case/activity',
330 "reset=1&cid={$clientID}&caseid={$activityDAO->caseID}&action=update&atype={$activityDAO->activity_type_id}&id={$activityDAO->id}"
334 $activity['editURL'] = '';
337 $client = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'display_name');
338 // add Client SortName as well as Display to the strings to be redacted across the case session
339 // suffixed with a randomly generated 4-digit number
340 if (!array_key_exists($client, $this->_redactionStringRules
)) {
341 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
342 array($client => 'name_' . rand(10000, 100000))
345 $clientSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'sort_name');
346 if (!array_key_exists($clientSortName, $this->_redactionStringRules
)) {
347 $this->_redactionStringRules
[$clientSortName] = $this->_redactionStringRules
[$client];
351 $activity['fields'][] = array(
353 'value' => $this->redact($client),
358 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
359 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
360 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
361 if (!empty($activityDAO->targetID
)) {
362 // Re-lookup the target ID since the DAO only has the first recipient if there are multiple.
363 // Maybe not the best solution.
364 $targetNames = CRM_Activity_BAO_ActivityContact
::getNames($activityDAO->id
, $targetID);
365 $processTarget = FALSE;
366 $label = ts('With Contact(s)');
367 if (in_array($activityTypeInfo['name'], array('Email', 'Inbound Email'))) {
368 $processTarget = TRUE;
369 $label = ts('Recipient');
371 if (!$processTarget) {
372 foreach ($targetNames as $targetID => $targetName) {
373 if ($targetID != $clientID) {
374 $processTarget = TRUE;
380 if ($processTarget) {
381 $targetRedacted = array();
382 foreach ($targetNames as $targetID => $target) {
383 // add Recipient SortName as well as Display to the strings to be redacted across the case session
384 // suffixed with a randomly generated 4-digit number
385 if (!array_key_exists($target, $this->_redactionStringRules
)) {
386 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
387 array($target => 'name_' . rand(10000, 100000))
389 $targetSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $targetID, 'sort_name');
390 if (!array_key_exists($targetSortName, $this->_redactionStringRules
)) {
391 $this->_redactionStringRules
[$targetSortName] = $this->_redactionStringRules
[$target];
394 $targetRedacted[] = $this->redact($target);
397 $activity['fields'][] = array(
399 'value' => implode('; ', $targetRedacted),
405 // Activity Type info is a special field
406 $activity['fields'][] = array(
407 'label' => ts('Activity Type'),
408 'value' => $activityTypeInfo['label'],
412 $activity['fields'][] = array(
413 'label' => ts('Subject'),
414 'value' => htmlspecialchars($this->redact($activityDAO->subject
)),
418 $creator = $this->getCreatedBy($activityDAO->id
);
419 // add Creator to the strings to be redacted across the case session
420 if (!array_key_exists($creator, $this->_redactionStringRules
)) {
421 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
422 array($creator => 'name_' . rand(10000, 100000))
425 $activity['fields'][] = array(
426 'label' => ts('Created By'),
427 'value' => $this->redact($creator),
430 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
431 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
432 $source_contact_id = CRM_Activity_BAO_Activity
::getActivityContact($activityDAO->id
, $sourceID);
433 $reporter = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
438 // add Reporter SortName as well as Display to the strings to be redacted across the case session
439 // suffixed with a randomly generated 4-digit number
440 if (!array_key_exists($reporter, $this->_redactionStringRules
)) {
441 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
442 array($reporter => 'name_' . rand(10000, 100000))
445 $reporterSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
449 if (!array_key_exists($reporterSortName, $this->_redactionStringRules
)) {
450 $this->_redactionStringRules
[$reporterSortName] = $this->_redactionStringRules
[$reporter];
454 $activity['fields'][] = array(
455 'label' => ts('Reported By'),
456 'value' => $this->redact($reporter),
460 if (!empty($activityDAO->assigneeID
)) {
461 //allow multiple assignee contacts.CRM-4503.
462 $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment
::getAssigneeNames(array($activityDAO->id
), TRUE);
464 foreach ($assignee_contact_names as & $assignee) {
465 // add Assignee to the strings to be redacted across the case session
466 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
467 array($assignee => 'name_' . rand(10000, 100000))
469 $assignee = $this->redact($assignee);
471 $assigneeContacts = implode(', ', $assignee_contact_names);
472 $activity['fields'][] = array(
473 'label' => ts('Assigned to'),
474 'value' => $assigneeContacts,
479 if ($activityDAO->medium_id
) {
480 $activity['fields'][] = array(
481 'label' => ts('Medium'),
482 'value' => CRM_Core_OptionGroup
::getLabel('encounter_medium',
483 $activityDAO->medium_id
, FALSE
489 $activity['fields'][] = array(
490 'label' => ts('Location'),
491 'value' => $activityDAO->location
,
495 $activity['fields'][] = array(
496 'label' => ts('Date and Time'),
497 'value' => $activityDAO->activity_date_time
,
501 $activity['fields'][] = array(
502 'label' => ts('Details'),
503 'value' => $this->redact(CRM_Utils_String
::stripAlternatives($activityDAO->details
)),
507 // Skip Duration field if empty (to avoid " minutes" output). Might want to do this for all fields at some point. dgg
508 if ($activityDAO->duration
) {
509 $activity['fields'][] = array(
510 'label' => ts('Duration'),
511 'value' => $activityDAO->duration
. ' ' . ts('minutes'),
515 $activity['fields'][] = array(
516 'label' => ts('Status'),
517 'value' => CRM_Core_OptionGroup
::getLabel('activity_status',
518 $activityDAO->status_id
523 $activity['fields'][] = array(
524 'label' => ts('Priority'),
525 'value' => CRM_Core_OptionGroup
::getLabel('priority',
526 $activityDAO->priority_id
531 //for now empty custom groups
532 $activity['customGroups'] = $this->getCustomData($clientID,
541 * @param int $clientID
542 * @param $activityDAO
543 * @param $activityTypeInfo
547 public function getCustomData($clientID, $activityDAO, &$activityTypeInfo) {
548 list($typeValues, $options, $sql) = $this->getActivityTypeCustomSQL($activityTypeInfo['id'], '%Y-%m-%d');
550 $params = array(1 => array($activityDAO->id
, 'Integer'));
552 $customGroups = array();
553 foreach ($sql as $tableName => $sqlClause) {
554 $dao = CRM_Core_DAO
::executeQuery($sqlClause, $params);
556 $customGroup = array();
557 foreach ($typeValues[$tableName] as $columnName => $typeValue) {
558 $value = CRM_Core_BAO_CustomField
::getDisplayValue($dao->$columnName,
559 $typeValue['fieldID'],
563 if (CRM_Utils_Array
::value('type', $typeValue) == 'Date') {
564 $value = $dao->$columnName;
568 // Note: this is already taken care in getDisplayValue above, but sometimes
569 // strings like '^A^A' creates problem. So to fix this special case -
570 if (strstr($value, CRM_Core_DAO
::VALUE_SEPARATOR
)) {
571 $value = trim($value, CRM_Core_DAO
::VALUE_SEPARATOR
);
573 if (CRM_Utils_Array
::value('type', $typeValue) == 'String' ||
574 CRM_Utils_Array
::value('type', $typeValue) == 'Memo'
576 $value = $this->redact($value);
578 elseif (CRM_Utils_Array
::value('type', $typeValue) == 'File') {
579 $tableName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_EntityFile', $typeValue, 'entity_table');
580 $value = CRM_Core_BAO_File
::attachmentInfo($tableName, $activityDAO->id
);
582 elseif (CRM_Utils_Array
::value('type', $typeValue) == 'Link') {
583 $value = CRM_Utils_System
::formatWikiURL($value);
587 $customGroup[] = array(
588 'label' => $typeValue['label'],
590 'type' => $typeValue['type'],
591 'fieldID' => $typeValue['fieldID'],
594 $customGroups[$dao->groupTitle
] = $customGroup;
598 return empty($customGroups) ?
NULL : $customGroups;
602 * @param int $activityTypeID
603 * @param null $dateFormat
607 public function getActivityTypeCustomSQL($activityTypeID, $dateFormat = NULL) {
608 static $cache = array();
610 if (is_null($activityTypeID)) {
614 if (!isset($cache[$activityTypeID])) {
616 SELECT cg.title as groupTitle,
617 cg.table_name as tableName ,
618 cf.column_name as columnName,
622 cf.data_type as dataType ,
623 cf.html_type as htmlType ,
624 cf.option_group_id as optionGroupID
625 FROM civicrm_custom_group cg,
626 civicrm_custom_field cf
627 WHERE cf.custom_group_id = cg.id
628 AND cg.extends = 'Activity'";
630 if ($activityTypeID) {
631 $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
. "%' )";
634 $query .= "AND cg.extends_entity_column_value IS NULL";
636 $query .= "ORDER BY cg.weight, cf.weight";
643 $dao = CRM_Core_DAO
::executeQuery($query, $params);
645 $result = $options = $sql = $groupTitle = array();
646 while ($dao->fetch()) {
647 if (!array_key_exists($dao->tableName
, $result)) {
648 $result[$dao->tableName
] = array();
649 $sql[$dao->tableName
] = array();
651 $result[$dao->tableName
][$dao->columnName
] = array(
652 'label' => $dao->label
,
653 'type' => $dao->dataType
,
654 'fieldID' => $dao->fieldID
,
657 $options[$dao->fieldID
] = array();
658 $options[$dao->fieldID
]['attributes'] = array(
659 'label' => $dao->label
,
660 'data_type' => $dao->dataType
,
661 'html_type' => $dao->htmlType
,
663 // since we want to add ISO date format.
664 if ($dateFormat && $dao->htmlType
== 'Select Date') {
665 $options[$dao->fieldID
]['attributes']['format'] = $dateFormat;
667 if ($dao->optionGroupID
) {
670 FROM civicrm_option_value
671 WHERE option_group_id = {$dao->optionGroupID}
674 $option = CRM_Core_DAO
::executeQuery($query);
675 while ($option->fetch()) {
676 $dataType = $dao->dataType
;
677 if ($dataType == 'Int' ||
$dataType == 'Float') {
678 $num = round($option->value
, 2);
679 $options[$dao->fieldID
]["$num"] = $option->label
;
682 $options[$dao->fieldID
][$option->value
] = $option->label
;
687 $sql[$dao->tableName
][] = $dao->columnName
;
688 $groupTitle[$dao->tableName
] = $dao->groupTitle
;
691 foreach ($sql as $tableName => $values) {
692 $columnNames = implode(',', $values);
694 SELECT '{$groupTitle[$tableName]}' as groupTitle, $columnNames
700 $cache[$activityTypeID] = array($result, $options, $sql);
702 return $cache[$activityTypeID];
706 * @param int $activityID
708 * @return null|string
710 public function getCreatedBy($activityID) {
712 SELECT c.display_name
713 FROM civicrm_contact c,
715 WHERE l.entity_table = 'civicrm_activity'
717 AND l.modified_id = c.id
721 $params = array(1 => array($activityID, 'Integer'));
722 return CRM_Core_DAO
::singleValueQuery($query, $params);
727 * @param bool $printReport
728 * @param array $replaceString
732 private function redact($string, $printReport = FALSE, $replaceString = array()) {
734 return CRM_Utils_String
::redaction($string, $replaceString);
736 elseif ($this->_isRedact
) {
737 $regexToReplaceString = CRM_Utils_String
::regex($string, $this->_redactionRegexRules
);
738 return CRM_Utils_String
::redaction($string, array_merge($this->_redactionStringRules
, $regexToReplaceString));
744 * @param int $clientID
746 * @param string $activitySetName
747 * @param array $params
748 * @param CRM_Core_Form $form
752 public static function getCaseReport($clientID, $caseID, $activitySetName, $params, $form) {
754 $template = CRM_Core_Smarty
::singleton();
756 $template->assign('caseId', $caseID);
757 $template->assign('clientID', $clientID);
758 $template->assign('activitySetName', $activitySetName);
760 if (!empty($params['is_redact'])) {
761 $form->_isRedact
= TRUE;
762 $template->assign('_isRedact', 'true');
765 $form->_isRedact
= FALSE;
766 $template->assign('_isRedact', 'false');
769 // first get all case information
770 $case = $form->caseInfo($clientID, $caseID);
771 $template->assign_by_ref('case', $case);
773 if ($params['include_activities'] == 1) {
774 $template->assign('includeActivities', 'All');
777 $template->assign('includeActivities', 'Missing activities only');
780 $xml = $form->retrieve($case['caseTypeName']);
782 $activitySetNames = CRM_Case_XMLProcessor_Process
::activitySets($xml->ActivitySets
);
783 $pageTitle = CRM_Utils_Array
::value($activitySetName, $activitySetNames);
784 $template->assign('pageTitle', $pageTitle);
786 if ($activitySetName) {
787 $activityTypes = $form->getActivityTypes($xml, $activitySetName);
790 $activityTypes = CRM_Case_XMLProcessor
::allActivityTypes();
793 if (!$activityTypes) {
797 // next get activity set Informtion
798 $activitySet = array(
799 'label' => $form->getActivitySetLabel($xml, $activitySetName),
800 'includeActivities' => 'All',
803 $template->assign_by_ref('activitySet', $activitySet);
805 //now collect all the information about activities
806 $activities = array();
807 $form->getActivities($clientID, $caseID, $activityTypes, $activities);
808 $template->assign_by_ref('activities', $activities);
810 // now run the template
811 $contents = $template->fetch('CRM/Case/XMLProcessor/Report.tpl');
815 public static function printCaseReport() {
816 $caseID = CRM_Utils_Request
::retrieve('caseID', 'Positive', CRM_Core_DAO
::$_nullObject);
817 $clientID = CRM_Utils_Request
::retrieve('cid', 'Positive', CRM_Core_DAO
::$_nullObject);
818 $activitySetName = CRM_Utils_Request
::retrieve('asn', 'String', CRM_Core_DAO
::$_nullObject);
819 $isRedact = CRM_Utils_Request
::retrieve('redact', 'Boolean', CRM_Core_DAO
::$_nullObject);
820 $includeActivities = CRM_Utils_Request
::retrieve('all', 'Positive', CRM_Core_DAO
::$_nullObject);
821 $params = $otherRelationships = $globalGroupInfo = array();
822 $report = new CRM_Case_XMLProcessor_Report($isRedact);
823 if ($includeActivities) {
824 $params['include_activities'] = 1;
828 $params['is_redact'] = 1;
829 $report->_redactionStringRules
= array();
831 $template = CRM_Core_Smarty
::singleton();
833 //get case related relationships (Case Role)
834 $caseRelationships = CRM_Case_BAO_Case
::getCaseRoles($clientID, $caseID);
835 $caseType = CRM_Case_BAO_Case
::getCaseType($caseID, 'name');
837 $xmlProcessor = new CRM_Case_XMLProcessor_Process();
838 $caseRoles = $xmlProcessor->get($caseType, 'CaseRoles');
839 foreach ($caseRelationships as $key => & $value) {
840 if (!empty($caseRoles[$value['relation_type']])) {
841 unset($caseRoles[$value['relation_type']]);
844 if (!array_key_exists($value['name'], $report->_redactionStringRules
)) {
845 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
846 array($value['name'] => 'name_' . rand(10000, 100000))
849 $value['name'] = self
::redact($value['name'], TRUE, $report->_redactionStringRules
);
850 if (!empty($value['email']) &&
851 !array_key_exists($value['email'], $report->_redactionStringRules
)
853 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
854 array($value['email'] => 'email_' . rand(10000, 100000))
858 $value['email'] = self
::redact($value['email'], TRUE, $report->_redactionStringRules
);
860 if (!empty($value['phone']) &&
861 !array_key_exists($value['phone'], $report->_redactionStringRules
)
863 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
864 array($value['phone'] => 'phone_' . rand(10000, 100000))
867 $value['phone'] = self
::redact($value['phone'], TRUE, $report->_redactionStringRules
);
871 $caseRoles['client'] = CRM_Case_BAO_Case
::getContactNames($caseID);
873 if (!array_key_exists($caseRoles['client']['sort_name'], $report->_redactionStringRules
)) {
874 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
875 array($caseRoles['client']['sort_name'] => 'name_' . rand(10000, 100000))
878 if (!array_key_exists($caseRoles['client']['display_name'], $report->_redactionStringRules
)) {
879 $report->_redactionStringRules
[$caseRoles['client']['display_name']] = $report->_redactionStringRules
[$caseRoles['client']['sort_name']];
881 $caseRoles['client']['sort_name'] = self
::redact($caseRoles['client']['sort_name'], TRUE, $report->_redactionStringRules
);
882 if (!empty($caseRoles['client']['email']) &&
883 !array_key_exists($caseRoles['client']['email'], $report->_redactionStringRules
)
885 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
886 array($caseRoles['client']['email'] => 'email_' . rand(10000, 100000))
889 $caseRoles['client']['email'] = self
::redact($caseRoles['client']['email'], TRUE, $report->_redactionStringRules
);
891 if (!empty($caseRoles['client']['phone']) &&
892 !array_key_exists($caseRoles['client']['phone'], $report->_redactionStringRules
)
894 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
895 array($caseRoles['client']['phone'] => 'phone_' . rand(10000, 100000))
898 $caseRoles['client']['phone'] = self
::redact($caseRoles['client']['phone'], TRUE, $report->_redactionStringRules
);
901 // Retrieve ALL client relationships
902 $relClient = CRM_Contact_BAO_Relationship
::getRelationship($clientID,
903 CRM_Contact_BAO_Relationship
::CURRENT
,
904 0, 0, 0, NULL, NULL, FALSE
906 foreach ($relClient as $r) {
908 if (!array_key_exists($r['name'], $report->_redactionStringRules
)) {
909 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
910 array($r['name'] => 'name_' . rand(10000, 100000))
913 if (!array_key_exists($r['display_name'], $report->_redactionStringRules
)) {
914 $report->_redactionStringRules
[$r['display_name']] = $report->_redactionStringRules
[$r['name']];
916 $r['name'] = self
::redact($r['name'], TRUE, $report->_redactionStringRules
);
918 if (!empty($r['phone']) &&
919 !array_key_exists($r['phone'], $report->_redactionStringRules
)
921 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
922 array($r['phone'] => 'phone_' . rand(10000, 100000))
925 $r['phone'] = self
::redact($r['phone'], TRUE, $report->_redactionStringRules
);
927 if (!empty($r['email']) &&
928 !array_key_exists($r['email'], $report->_redactionStringRules
)
930 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
931 array($r['email'] => 'email_' . rand(10000, 100000))
934 $r['email'] = self
::redact($r['email'], TRUE, $report->_redactionStringRules
);
936 if (!array_key_exists($r['id'], $caseRelationships)) {
937 $otherRelationships[] = $r;
941 // Now global contact list that appears on all cases.
942 $relGlobal = CRM_Case_BAO_Case
::getGlobalContacts($globalGroupInfo);
943 foreach ($relGlobal as & $r) {
945 if (!array_key_exists($r['sort_name'], $report->_redactionStringRules
)) {
946 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
947 array($r['sort_name'] => 'name_' . rand(10000, 100000))
950 if (!array_key_exists($r['display_name'], $report->_redactionStringRules
)) {
951 $report->_redactionStringRules
[$r['display_name']] = $report->_redactionStringRules
[$r['sort_name']];
954 $r['sort_name'] = self
::redact($r['sort_name'], TRUE, $report->_redactionStringRules
);
956 if (!empty($r['phone']) &&
957 !array_key_exists($r['phone'], $report->_redactionStringRules
)
959 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
960 array($r['phone'] => 'phone_' . rand(10000, 100000))
963 $r['phone'] = self
::redact($r['phone'], TRUE, $report->_redactionStringRules
);
965 if (!empty($r['email']) &&
966 !array_key_exists($r['email'], $report->_redactionStringRules
)
968 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
969 array($r['email'] => 'email_' . rand(10000, 100000))
972 $r['email'] = self
::redact($r['email'], TRUE, $report->_redactionStringRules
);
976 $template->assign('caseRelationships', $caseRelationships);
977 $template->assign('caseRoles', $caseRoles);
978 $template->assign('otherRelationships', $otherRelationships);
979 $template->assign('globalRelationships', $relGlobal);
980 $template->assign('globalGroupInfo', $globalGroupInfo);
981 $contents = self
::getCaseReport($clientID,
987 $printReport = CRM_Case_Audit_Audit
::run($contents, $clientID, $caseID, TRUE);
989 CRM_Utils_System
::civiExit();