3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
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 // FIXME: when we resolve if case_type_is single or multi-select
133 if (strpos($dao->case_type_id
, CRM_Core_DAO
::VALUE_SEPARATOR
) !== FALSE) {
134 $caseTypeID = substr($dao->case_type_id
, 1, -1);
137 $caseTypeID = $dao->case_type_id
;
139 $caseTypeIDs = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
143 $case['caseType'] = CRM_Case_BAO_Case
::getCaseType($caseID);
144 $case['caseTypeName'] = CRM_Case_BAO_Case
::getCaseType($caseID, 'name');
145 $case['status'] = CRM_Core_OptionGroup
::getLabel('case_status', $dao->status_id
, FALSE);
152 * @param string $activitySetName
156 public function getActivityTypes($xml, $activitySetName) {
157 foreach ($xml->ActivitySets
as $activitySetsXML) {
158 foreach ($activitySetsXML->ActivitySet
as $activitySetXML) {
159 if ((string ) $activitySetXML->name
== $activitySetName) {
160 $activityTypes = array();
161 $allActivityTypes = &$this->allActivityTypes();
162 foreach ($activitySetXML->ActivityTypes
as $activityTypesXML) {
163 foreach ($activityTypesXML as $activityTypeXML) {
164 $activityTypeName = (string ) $activityTypeXML->name
;
165 $activityTypeInfo = CRM_Utils_Array
::value($activityTypeName, $allActivityTypes);
166 if ($activityTypeInfo) {
167 $activityTypes[$activityTypeInfo['id']] = $activityTypeInfo;
171 return empty($activityTypes) ?
FALSE : $activityTypes;
180 * @param string $activitySetName
182 * @return null|string
184 public function getActivitySetLabel($xml, $activitySetName) {
185 foreach ($xml->ActivitySets
as $activitySetsXML) {
186 foreach ($activitySetsXML->ActivitySet
as $activitySetXML) {
187 if ((string ) $activitySetXML->name
== $activitySetName) {
188 return (string ) $activitySetXML->label
;
196 * @param int $clientID
198 * @param $activityTypes
201 public function getActivities($clientID, $caseID, $activityTypes, &$activities) {
202 // get all activities for this case that in this activityTypes set
203 foreach ($activityTypes as $aType) {
204 $map[$aType['id']] = $aType;
207 // get all core activities
208 $coreActivityTypes = CRM_Case_PseudoConstant
::caseActivityType(FALSE, TRUE);
210 foreach ($coreActivityTypes as $aType) {
211 $map[$aType['id']] = $aType;
214 $activityTypeIDs = implode(',', array_keys($map));
216 SELECT a.*, c.id as caseID
217 FROM civicrm_activity a,
219 civicrm_case_activity ac
220 WHERE a.is_current_revision = 1
222 AND a.activity_type_id IN ( $activityTypeIDs )
223 AND c.id = ac.case_id
224 AND a.id = ac.activity_id
228 $params = array(1 => array($caseID, 'Integer'));
229 $dao = CRM_Core_DAO
::executeQuery($query, $params);
230 while ($dao->fetch()) {
231 $activityTypeInfo = $map[$dao->activity_type_id
];
232 $activities[] = $this->getActivity($clientID,
240 * @param int $clientID
241 * @param int $activityID
242 * @param bool $anyActivity
247 public function &getActivityInfo($clientID, $activityID, $anyActivity = FALSE, $redact = 0) {
248 static $activityInfos = array();
250 $this->_isRedact
= 1;
251 $this->getRedactionRules();
254 $index = $activityID . '_' . (int) $anyActivity;
257 $index = $index . '_' . $clientID;
260 if (!array_key_exists($index, $activityInfos)) {
261 $activityInfos[$index] = array();
262 $selectCaseActivity = "";
263 $joinCaseActivity = "";
266 $selectCaseActivity = ", ca.case_id as caseID ";
267 $joinCaseActivity = " INNER JOIN civicrm_case_activity ca ON a.id = ca.activity_id ";
270 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
271 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
272 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
275 SELECT a.*, aa.contact_id as assigneeID, at.contact_id as targetID
276 {$selectCaseActivity}
277 FROM civicrm_activity a
279 LEFT JOIN civicrm_activity_contact at ON a.id = at.activity_id AND at.record_type_id = $targetID
280 LEFT JOIN civicrm_activity_contact aa ON a.id = aa.activity_id AND aa.record_type_id = $assigneeID
283 $params = array(1 => array($activityID, 'Integer'));
284 $dao = CRM_Core_DAO
::executeQuery($query, $params);
287 //if activity type is email get info of all activities.
288 if ($dao->activity_type_id
== CRM_Core_PseudoConstant
::getKey('CRM_Activity_DAO_Activity', 'activity_type_id', 'Email')) {
291 $activityTypes = CRM_Case_PseudoConstant
::caseActivityType(FALSE, $anyActivity);
292 $activityTypeInfo = NULL;
294 if (isset($activityTypes[$dao->activity_type_id
])) {
295 $activityTypeInfo = $activityTypes[$dao->activity_type_id
];
297 if ($activityTypeInfo) {
298 $activityInfos[$index] = $this->getActivity($clientID, $dao, $activityTypeInfo);
303 return $activityInfos[$index];
307 * @param int $clientID
308 * @param $activityDAO
309 * @param $activityTypeInfo
313 public function &getActivity($clientID, $activityDAO, &$activityTypeInfo) {
314 if (empty($this->_redactionStringRules
)) {
315 $this->_redactionStringRules
= array();
319 $activity['fields'] = array();
321 $clientID = CRM_Utils_Type
::escape($clientID, 'Integer');
322 if (!in_array($activityTypeInfo['name'], array(
327 $activity['editURL'] = CRM_Utils_System
::url('civicrm/case/activity',
328 "reset=1&cid={$clientID}&caseid={$activityDAO->caseID}&action=update&atype={$activityDAO->activity_type_id}&id={$activityDAO->id}"
332 $activity['editURL'] = '';
335 $client = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'display_name');
336 // add Client SortName as well as Display to the strings to be redacted across the case session
337 // suffixed with a randomly generated 4-digit number
338 if (!array_key_exists($client, $this->_redactionStringRules
)) {
339 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
340 array($client => 'name_' . rand(10000, 100000))
343 $clientSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'sort_name');
344 if (!array_key_exists($clientSortName, $this->_redactionStringRules
)) {
345 $this->_redactionStringRules
[$clientSortName] = $this->_redactionStringRules
[$client];
349 $activity['fields'][] = array(
351 'value' => $this->redact($client),
356 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
357 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
358 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
359 if (!empty($activityDAO->targetID
)) {
360 // Re-lookup the target ID since the DAO only has the first recipient if there are multiple.
361 // Maybe not the best solution.
362 $targetNames = CRM_Activity_BAO_ActivityContact
::getNames($activityDAO->id
, $targetID);
363 $processTarget = FALSE;
364 $label = ts('With Contact(s)');
365 if (in_array($activityTypeInfo['name'], array('Email', 'Inbound Email'))) {
366 $processTarget = TRUE;
367 $label = ts('Recipient');
369 if (!$processTarget) {
370 foreach ($targetNames as $targetID => $targetName) {
371 if ($targetID != $clientID) {
372 $processTarget = TRUE;
378 if ($processTarget) {
379 $targetRedacted = array();
380 foreach ($targetNames as $targetID => $target) {
381 // add Recipient SortName as well as Display to the strings to be redacted across the case session
382 // suffixed with a randomly generated 4-digit number
383 if (!array_key_exists($target, $this->_redactionStringRules
)) {
384 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
385 array($target => 'name_' . rand(10000, 100000))
387 $targetSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $targetID, 'sort_name');
388 if (!array_key_exists($targetSortName, $this->_redactionStringRules
)) {
389 $this->_redactionStringRules
[$targetSortName] = $this->_redactionStringRules
[$target];
392 $targetRedacted[] = $this->redact($target);
395 $activity['fields'][] = array(
397 'value' => implode('; ', $targetRedacted),
403 // Activity Type info is a special field
404 $activity['fields'][] = array(
405 'label' => ts('Activity Type'),
406 'value' => $activityTypeInfo['label'],
410 $activity['fields'][] = array(
411 'label' => ts('Subject'),
412 'value' => htmlspecialchars($this->redact($activityDAO->subject
)),
416 $creator = $this->getCreatedBy($activityDAO->id
);
417 // add Creator to the strings to be redacted across the case session
418 if (!array_key_exists($creator, $this->_redactionStringRules
)) {
419 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
420 array($creator => 'name_' . rand(10000, 100000))
423 $activity['fields'][] = array(
424 'label' => ts('Created By'),
425 'value' => $this->redact($creator),
428 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
429 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
430 $source_contact_id = CRM_Activity_BAO_Activity
::getActivityContact($activityDAO->id
, $sourceID);
431 $reporter = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
436 // add Reporter SortName as well as Display to the strings to be redacted across the case session
437 // suffixed with a randomly generated 4-digit number
438 if (!array_key_exists($reporter, $this->_redactionStringRules
)) {
439 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
440 array($reporter => 'name_' . rand(10000, 100000))
443 $reporterSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
447 if (!array_key_exists($reporterSortName, $this->_redactionStringRules
)) {
448 $this->_redactionStringRules
[$reporterSortName] = $this->_redactionStringRules
[$reporter];
452 $activity['fields'][] = array(
453 'label' => ts('Reported By'),
454 'value' => $this->redact($reporter),
458 if (!empty($activityDAO->assigneeID
)) {
459 //allow multiple assignee contacts.CRM-4503.
460 $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment
::getAssigneeNames(array($activityDAO->id
), TRUE);
462 foreach ($assignee_contact_names as & $assignee) {
463 // add Assignee to the strings to be redacted across the case session
464 $this->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($this->_redactionStringRules
,
465 array($assignee => 'name_' . rand(10000, 100000))
467 $assignee = $this->redact($assignee);
469 $assigneeContacts = implode(', ', $assignee_contact_names);
470 $activity['fields'][] = array(
471 'label' => ts('Assigned to'),
472 'value' => $assigneeContacts,
477 if ($activityDAO->medium_id
) {
478 $activity['fields'][] = array(
479 'label' => ts('Medium'),
480 'value' => CRM_Core_OptionGroup
::getLabel('encounter_medium',
481 $activityDAO->medium_id
, FALSE
487 $activity['fields'][] = array(
488 'label' => ts('Location'),
489 'value' => $activityDAO->location
,
493 $activity['fields'][] = array(
494 'label' => ts('Date and Time'),
495 'value' => $activityDAO->activity_date_time
,
499 $activity['fields'][] = array(
500 'label' => ts('Details'),
501 'value' => $this->redact(CRM_Utils_String
::stripAlternatives($activityDAO->details
)),
505 // Skip Duration field if empty (to avoid " minutes" output). Might want to do this for all fields at some point. dgg
506 if ($activityDAO->duration
) {
507 $activity['fields'][] = array(
508 'label' => ts('Duration'),
509 'value' => $activityDAO->duration
. ' ' . ts('minutes'),
513 $activity['fields'][] = array(
514 'label' => ts('Status'),
515 'value' => CRM_Core_PseudoConstant
::getLabel('CRM_Activity_DAO_Activity', 'activity_status_id',
516 $activityDAO->status_id
521 $activity['fields'][] = array(
522 'label' => ts('Priority'),
523 'value' => CRM_Core_PseudoConstant
::getLabel('CRM_Activity_DAO_Activity', 'priority',
524 $activityDAO->priority_id
529 //for now empty custom groups
530 $activity['customGroups'] = $this->getCustomData($clientID,
539 * @param int $clientID
540 * @param $activityDAO
541 * @param $activityTypeInfo
545 public function getCustomData($clientID, $activityDAO, &$activityTypeInfo) {
546 list($typeValues, $options, $sql) = $this->getActivityTypeCustomSQL($activityTypeInfo['id'], '%Y-%m-%d');
548 $params = array(1 => array($activityDAO->id
, 'Integer'));
550 $customGroups = array();
551 foreach ($sql as $tableName => $sqlClause) {
552 $dao = CRM_Core_DAO
::executeQuery($sqlClause, $params);
554 $customGroup = array();
555 foreach ($typeValues[$tableName] as $columnName => $typeValue) {
557 if (CRM_Utils_Array
::value('type', $typeValue) == 'Date') {
558 $value = $dao->$columnName;
561 $value = CRM_Core_BAO_CustomField
::displayValue($dao->$columnName, $typeValue['fieldID'], $activityDAO->id
);
565 // Note: this is already taken care in getDisplayValue above, but sometimes
566 // strings like '^A^A' creates problem. So to fix this special case -
567 if (strstr($value, CRM_Core_DAO
::VALUE_SEPARATOR
)) {
568 $value = trim($value, CRM_Core_DAO
::VALUE_SEPARATOR
);
570 if (CRM_Utils_Array
::value('type', $typeValue) == 'String' ||
571 CRM_Utils_Array
::value('type', $typeValue) == 'Memo'
573 $value = $this->redact($value);
575 elseif (CRM_Utils_Array
::value('type', $typeValue) == 'Link') {
576 $value = CRM_Utils_System
::formatWikiURL($value);
580 $customGroup[] = array(
581 'label' => $typeValue['label'],
583 'type' => $typeValue['type'],
584 'fieldID' => $typeValue['fieldID'],
587 $customGroups[$dao->groupTitle
] = $customGroup;
591 return empty($customGroups) ?
NULL : $customGroups;
595 * @param int $activityTypeID
596 * @param null $dateFormat
600 public function getActivityTypeCustomSQL($activityTypeID, $dateFormat = NULL) {
601 static $cache = array();
603 if (is_null($activityTypeID)) {
607 if (!isset($cache[$activityTypeID])) {
609 SELECT cg.title as groupTitle,
610 cg.table_name as tableName ,
611 cf.column_name as columnName,
615 cf.data_type as dataType ,
616 cf.html_type as htmlType ,
617 cf.option_group_id as optionGroupID
618 FROM civicrm_custom_group cg,
619 civicrm_custom_field cf
620 WHERE cf.custom_group_id = cg.id
621 AND cg.extends = 'Activity'
622 AND " . CRM_Core_Permission
::customGroupClause(CRM_Core_Permission
::VIEW
, 'cg.');
624 if ($activityTypeID) {
625 $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
. "%' )";
628 $query .= "AND cg.extends_entity_column_value IS NULL";
630 $query .= "ORDER BY cg.weight, cf.weight";
637 $dao = CRM_Core_DAO
::executeQuery($query, $params);
639 $result = $options = $sql = $groupTitle = array();
640 while ($dao->fetch()) {
641 if (!array_key_exists($dao->tableName
, $result)) {
642 $result[$dao->tableName
] = array();
643 $sql[$dao->tableName
] = array();
645 $result[$dao->tableName
][$dao->columnName
] = array(
646 'label' => $dao->label
,
647 'type' => $dao->dataType
,
648 'fieldID' => $dao->fieldID
,
651 $options[$dao->fieldID
] = array();
652 $options[$dao->fieldID
]['attributes'] = array(
653 'label' => $dao->label
,
654 'data_type' => $dao->dataType
,
655 'html_type' => $dao->htmlType
,
657 // since we want to add ISO date format.
658 if ($dateFormat && $dao->htmlType
== 'Select Date') {
659 $options[$dao->fieldID
]['attributes']['format'] = $dateFormat;
661 if ($dao->optionGroupID
) {
664 FROM civicrm_option_value
665 WHERE option_group_id = %1
668 $option = CRM_Core_DAO
::executeQuery($query, array(1 => array($dao->optionGroupID
, 'Positive')));
669 while ($option->fetch()) {
670 $dataType = $dao->dataType
;
671 if ($dataType == 'Int' ||
$dataType == 'Float') {
672 $num = round($option->value
, 2);
673 $options[$dao->fieldID
]["$num"] = $option->label
;
676 $options[$dao->fieldID
][$option->value
] = $option->label
;
681 $sql[$dao->tableName
][] = $dao->columnName
;
682 $groupTitle[$dao->tableName
] = $dao->groupTitle
;
685 foreach ($sql as $tableName => $values) {
686 $columnNames = implode(',', $values);
687 $title = CRM_Core_DAO
::escapeString($groupTitle[$tableName]);
688 $mysqlTableName = CRM_Utils_Type
::escape($tableName, 'MysqlColumnNameOrAlias');
690 SELECT '" . $title . "' as groupTitle, $columnNames
696 $cache[$activityTypeID] = array($result, $options, $sql);
698 return $cache[$activityTypeID];
702 * @param int $activityID
704 * @return null|string
706 public function getCreatedBy($activityID) {
708 SELECT c.display_name
709 FROM civicrm_contact c,
711 WHERE l.entity_table = 'civicrm_activity'
713 AND l.modified_id = c.id
717 $params = array(1 => array($activityID, 'Integer'));
718 return CRM_Core_DAO
::singleValueQuery($query, $params);
723 * @param bool $printReport
724 * @param array $replaceString
728 private function redact($string, $printReport = FALSE, $replaceString = array()) {
730 return CRM_Utils_String
::redaction($string, $replaceString);
732 elseif ($this->_isRedact
) {
733 $regexToReplaceString = CRM_Utils_String
::regex($string, $this->_redactionRegexRules
);
734 return CRM_Utils_String
::redaction($string, array_merge($this->_redactionStringRules
, $regexToReplaceString));
740 * @param int $clientID
742 * @param string $activitySetName
743 * @param array $params
744 * @param CRM_Core_Form $form
748 public static function getCaseReport($clientID, $caseID, $activitySetName, $params, $form) {
750 $template = CRM_Core_Smarty
::singleton();
752 $template->assign('caseId', $caseID);
753 $template->assign('clientID', $clientID);
754 $template->assign('activitySetName', $activitySetName);
756 if (!empty($params['is_redact'])) {
757 $form->_isRedact
= TRUE;
758 $template->assign('_isRedact', 'true');
761 $form->_isRedact
= FALSE;
762 $template->assign('_isRedact', 'false');
765 // first get all case information
766 $case = $form->caseInfo($clientID, $caseID);
767 $template->assign_by_ref('case', $case);
769 if ($params['include_activities'] == 1) {
770 $template->assign('includeActivities', 'All');
773 $template->assign('includeActivities', 'Missing activities only');
776 $xml = $form->retrieve($case['caseTypeName']);
778 $activitySetNames = CRM_Case_XMLProcessor_Process
::activitySets($xml->ActivitySets
);
779 $pageTitle = CRM_Utils_Array
::value($activitySetName, $activitySetNames);
780 $template->assign('pageTitle', $pageTitle);
782 if ($activitySetName) {
783 $activityTypes = $form->getActivityTypes($xml, $activitySetName);
786 $activityTypes = CRM_Case_XMLProcessor
::allActivityTypes();
789 if (!$activityTypes) {
793 // next get activity set Information
794 $activitySet = array(
795 'label' => $form->getActivitySetLabel($xml, $activitySetName),
796 'includeActivities' => 'All',
799 $template->assign_by_ref('activitySet', $activitySet);
801 //now collect all the information about activities
802 $activities = array();
803 $form->getActivities($clientID, $caseID, $activityTypes, $activities);
804 $template->assign_by_ref('activities', $activities);
806 // now run the template
807 $contents = $template->fetch('CRM/Case/XMLProcessor/Report.tpl');
811 public static function printCaseReport() {
812 $caseID = CRM_Utils_Request
::retrieve('caseID', 'Positive');
813 $clientID = CRM_Utils_Request
::retrieve('cid', 'Positive');
814 $activitySetName = CRM_Utils_Request
::retrieve('asn', 'String');
815 $isRedact = CRM_Utils_Request
::retrieve('redact', 'Boolean');
816 $includeActivities = CRM_Utils_Request
::retrieve('all', 'Positive');
817 $params = $otherRelationships = $globalGroupInfo = array();
818 $report = new CRM_Case_XMLProcessor_Report($isRedact);
819 if ($includeActivities) {
820 $params['include_activities'] = 1;
824 $params['is_redact'] = 1;
825 $report->_redactionStringRules
= array();
827 $template = CRM_Core_Smarty
::singleton();
829 //get case related relationships (Case Role)
830 $caseRelationships = CRM_Case_BAO_Case
::getCaseRoles($clientID, $caseID);
831 $caseType = CRM_Case_BAO_Case
::getCaseType($caseID, 'name');
833 $xmlProcessor = new CRM_Case_XMLProcessor_Process();
834 $caseRoles = $xmlProcessor->get($caseType, 'CaseRoles');
835 foreach ($caseRelationships as $key => & $value) {
836 if (!empty($caseRoles[$value['relation_type']])) {
837 unset($caseRoles[$value['relation_type']]);
840 if (!array_key_exists($value['name'], $report->_redactionStringRules
)) {
841 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
842 array($value['name'] => 'name_' . rand(10000, 100000))
845 $value['name'] = $report->redact($value['name'], TRUE, $report->_redactionStringRules
);
846 if (!empty($value['email']) &&
847 !array_key_exists($value['email'], $report->_redactionStringRules
)
849 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
850 array($value['email'] => 'email_' . rand(10000, 100000))
854 $value['email'] = $report->redact($value['email'], TRUE, $report->_redactionStringRules
);
856 if (!empty($value['phone']) &&
857 !array_key_exists($value['phone'], $report->_redactionStringRules
)
859 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
860 array($value['phone'] => 'phone_' . rand(10000, 100000))
863 $value['phone'] = $report->redact($value['phone'], TRUE, $report->_redactionStringRules
);
867 $caseRoles['client'] = CRM_Case_BAO_Case
::getContactNames($caseID);
869 foreach ($caseRoles['client'] as &$client) {
870 if (!array_key_exists(CRM_Utils_Array
::value('sort_name', $client), $report->_redactionStringRules
)) {
872 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
873 array(CRM_Utils_Array
::value('sort_name', $client) => 'name_' . rand(10000, 100000))
876 if (!array_key_exists(CRM_Utils_Array
::value('display_name', $client), $report->_redactionStringRules
)) {
877 $report->_redactionStringRules
[CRM_Utils_Array
::value('display_name', $client)] = $report->_redactionStringRules
[CRM_Utils_Array
::value('sort_name', $client)];
879 $client['sort_name'] = $report->redact(CRM_Utils_Array
::value('sort_name', $client), TRUE, $report->_redactionStringRules
);
880 if (!empty($client['email']) &&
881 !array_key_exists($client['email'], $report->_redactionStringRules
)
883 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
884 array($client['email'] => 'email_' . rand(10000, 100000))
887 $client['email'] = $report->redact(CRM_Utils_Array
::value('email', $client), TRUE, $report->_redactionStringRules
);
889 if (!empty($client['phone']) &&
890 !array_key_exists($client['phone'], $report->_redactionStringRules
)
892 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
893 array($client['phone'] => 'phone_' . rand(10000, 100000))
896 $client['phone'] = $report->redact(CRM_Utils_Array
::value('phone', $client), TRUE, $report->_redactionStringRules
);
899 // Retrieve ALL client relationships
900 $relClient = CRM_Contact_BAO_Relationship
::getRelationship($clientID,
901 CRM_Contact_BAO_Relationship
::CURRENT
,
902 0, 0, 0, NULL, NULL, FALSE
904 foreach ($relClient as $r) {
906 if (!array_key_exists($r['name'], $report->_redactionStringRules
)) {
907 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
908 array($r['name'] => 'name_' . rand(10000, 100000))
911 if (!array_key_exists($r['display_name'], $report->_redactionStringRules
)) {
912 $report->_redactionStringRules
[$r['display_name']] = $report->_redactionStringRules
[$r['name']];
914 $r['name'] = $report->redact($r['name'], TRUE, $report->_redactionStringRules
);
916 if (!empty($r['phone']) &&
917 !array_key_exists($r['phone'], $report->_redactionStringRules
)
919 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
920 array($r['phone'] => 'phone_' . rand(10000, 100000))
923 $r['phone'] = $report->redact($r['phone'], TRUE, $report->_redactionStringRules
);
925 if (!empty($r['email']) &&
926 !array_key_exists($r['email'], $report->_redactionStringRules
)
928 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
929 array($r['email'] => 'email_' . rand(10000, 100000))
932 $r['email'] = $report->redact($r['email'], TRUE, $report->_redactionStringRules
);
934 if (!array_key_exists($r['id'], $caseRelationships)) {
935 $otherRelationships[] = $r;
939 // Now global contact list that appears on all cases.
940 $relGlobal = CRM_Case_BAO_Case
::getGlobalContacts($globalGroupInfo);
941 foreach ($relGlobal as & $r) {
943 if (!array_key_exists($r['sort_name'], $report->_redactionStringRules
)) {
944 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
945 array($r['sort_name'] => 'name_' . rand(10000, 100000))
948 if (!array_key_exists($r['display_name'], $report->_redactionStringRules
)) {
949 $report->_redactionStringRules
[$r['display_name']] = $report->_redactionStringRules
[$r['sort_name']];
952 $r['sort_name'] = $report->redact($r['sort_name'], TRUE, $report->_redactionStringRules
);
953 if (!empty($r['phone']) &&
954 !array_key_exists($r['phone'], $report->_redactionStringRules
)
956 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
957 array($r['phone'] => 'phone_' . rand(10000, 100000))
960 $r['phone'] = $report->redact($r['phone'], TRUE, $report->_redactionStringRules
);
962 if (!empty($r['email']) &&
963 !array_key_exists($r['email'], $report->_redactionStringRules
)
965 $report->_redactionStringRules
= CRM_Utils_Array
::crmArrayMerge($report->_redactionStringRules
,
966 array($r['email'] => 'email_' . rand(10000, 100000))
969 $r['email'] = $report->redact($r['email'], TRUE, $report->_redactionStringRules
);
973 // Retrieve custom values for cases.
974 $customValues = CRM_Core_BAO_CustomValueTable
::getEntityValues($caseID, 'Case');
975 $extends = array('case');
976 $groupTree = CRM_Core_BAO_CustomGroup
::getGroupDetail(NULL, NULL, $extends);
977 $caseCustomFields = array();
978 foreach ($groupTree as $gid => $group_values) {
979 foreach ($group_values['fields'] as $id => $field_values) {
980 if (array_key_exists($id, $customValues)) {
981 $caseCustomFields[$gid]['title'] = $group_values['title'];
982 $caseCustomFields[$gid]['values'][$id] = array(
983 'label' => $field_values['label'],
984 'value' => $customValues[$id],
989 $template->assign('caseRelationships', $caseRelationships);
990 $template->assign('caseRoles', $caseRoles);
991 $template->assign('otherRelationships', $otherRelationships);
992 $template->assign('globalRelationships', $relGlobal);
993 $template->assign('globalGroupInfo', $globalGroupInfo);
994 $template->assign('caseCustomFields', $caseCustomFields);
995 $contents = self
::getCaseReport($clientID,
1001 $printReport = CRM_Case_Audit_Audit
::run($contents, $clientID, $caseID, TRUE);
1003 CRM_Utils_System
::civiExit();