Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
0f03f337 | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
0f03f337 | 31 | * @copyright CiviCRM LLC (c) 2004-2017 |
6a488035 TO |
32 | */ |
33 | class CRM_Case_XMLProcessor_Report extends CRM_Case_XMLProcessor { | |
34 | ||
35 | /** | |
fe482240 | 36 | * The default variable defined. |
6a488035 TO |
37 | * |
38 | * @var boolean | |
39 | */ | |
40 | protected $_isRedact; | |
41 | ||
4c6ce474 | 42 | /** |
4c6ce474 | 43 | */ |
e547f744 TO |
44 | public function __construct() { |
45 | } | |
6a488035 | 46 | |
4c6ce474 | 47 | /** |
100fef9d CW |
48 | * @param int $clientID |
49 | * @param int $caseID | |
50 | * @param string $activitySetName | |
c490a46a | 51 | * @param array $params |
4c6ce474 EM |
52 | * |
53 | * @return mixed | |
54 | */ | |
00be9182 | 55 | public function run($clientID, $caseID, $activitySetName, $params) { |
6a488035 TO |
56 | $contents = self::getCaseReport($clientID, |
57 | $caseID, | |
58 | $activitySetName, | |
59 | $params, | |
60 | $this | |
61 | ); | |
62 | ||
63 | return CRM_Case_Audit_Audit::run($contents, $clientID, $caseID); | |
64 | } | |
65 | ||
a7e52def | 66 | public function getRedactionRules() { |
6a488035 | 67 | foreach (array( |
353ffa53 | 68 | 'redactionStringRules', |
acb1052e | 69 | 'redactionRegexRules', |
353ffa53 | 70 | ) as $key => $rule) { |
6a488035 TO |
71 | $$rule = CRM_Case_PseudoConstant::redactionRule($key); |
72 | ||
73 | if (!empty($$rule)) { | |
74 | foreach ($$rule as & $val) { | |
75 | //suffixed with a randomly generated 4-digit number | |
76 | if ($key == 'redactionStringRules') { | |
77 | $val .= rand(10000, 100000); | |
78 | } | |
79 | } | |
80 | ||
81 | if (!empty($this->{'_' . $rule})) { | |
82 | $this->{'_' . $rule} = CRM_Utils_Array::crmArrayMerge($this->{'_' . $rule}, $$rule); | |
83 | } | |
84 | else { | |
85 | $this->{'_' . $rule} = $$rule; | |
86 | } | |
87 | } | |
88 | } | |
89 | } | |
90 | ||
4c6ce474 | 91 | /** |
100fef9d CW |
92 | * @param int $clientID |
93 | * @param int $caseID | |
4c6ce474 EM |
94 | * |
95 | * @return array | |
96 | */ | |
acb1052e | 97 | public function &caseInfo( |
28d4d481 | 98 | $clientID, |
6a488035 TO |
99 | $caseID |
100 | ) { | |
101 | $case = $this->_redactionRegexRules = array(); | |
102 | ||
103 | if (empty($this->_redactionStringRules)) { | |
104 | $this->_redactionStringRules = array(); | |
105 | } | |
106 | ||
107 | if ($this->_isRedact == 1) { | |
108 | $this->getRedactionRules(); | |
109 | } | |
110 | ||
111 | $client = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'display_name'); | |
112 | ||
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)) | |
117 | ); | |
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]; | |
121 | } | |
122 | } | |
123 | ||
124 | $case['clientName'] = $this->redact($client); | |
125 | ||
126 | $dao = new CRM_Case_DAO_Case(); | |
127 | $dao->id = $caseID; | |
128 | if ($dao->find(TRUE)) { | |
353ffa53 | 129 | $case['subject'] = $dao->subject; |
6a488035 | 130 | $case['start_date'] = $dao->start_date; |
353ffa53 | 131 | $case['end_date'] = $dao->end_date; |
6a488035 TO |
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); | |
135 | } | |
136 | else { | |
137 | $caseTypeID = $dao->case_type_id; | |
138 | } | |
139 | $caseTypeIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, | |
140 | $dao->case_type_id | |
141 | ); | |
142 | ||
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); | |
146 | } | |
147 | return $case; | |
148 | } | |
149 | ||
4c6ce474 EM |
150 | /** |
151 | * @param $xml | |
100fef9d | 152 | * @param string $activitySetName |
4c6ce474 EM |
153 | * |
154 | * @return array|bool | |
155 | */ | |
00be9182 | 156 | public function getActivityTypes($xml, $activitySetName) { |
6a488035 TO |
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; | |
168 | } | |
169 | } | |
170 | } | |
171 | return empty($activityTypes) ? FALSE : $activityTypes; | |
172 | } | |
173 | } | |
174 | } | |
175 | return FALSE; | |
176 | } | |
177 | ||
4c6ce474 EM |
178 | /** |
179 | * @param $xml | |
100fef9d | 180 | * @param string $activitySetName |
4c6ce474 EM |
181 | * |
182 | * @return null|string | |
183 | */ | |
00be9182 | 184 | public function getActivitySetLabel($xml, $activitySetName) { |
6a488035 TO |
185 | foreach ($xml->ActivitySets as $activitySetsXML) { |
186 | foreach ($activitySetsXML->ActivitySet as $activitySetXML) { | |
187 | if ((string ) $activitySetXML->name == $activitySetName) { | |
188 | return (string ) $activitySetXML->label; | |
189 | } | |
190 | } | |
191 | } | |
192 | return NULL; | |
193 | } | |
194 | ||
4c6ce474 | 195 | /** |
100fef9d CW |
196 | * @param int $clientID |
197 | * @param int $caseID | |
4c6ce474 EM |
198 | * @param $activityTypes |
199 | * @param $activities | |
200 | */ | |
00be9182 | 201 | public function getActivities($clientID, $caseID, $activityTypes, &$activities) { |
6a488035 TO |
202 | // get all activities for this case that in this activityTypes set |
203 | foreach ($activityTypes as $aType) { | |
204 | $map[$aType['id']] = $aType; | |
205 | } | |
206 | ||
207 | // get all core activities | |
208 | $coreActivityTypes = CRM_Case_PseudoConstant::caseActivityType(FALSE, TRUE); | |
209 | ||
210 | foreach ($coreActivityTypes as $aType) { | |
211 | $map[$aType['id']] = $aType; | |
212 | } | |
213 | ||
214 | $activityTypeIDs = implode(',', array_keys($map)); | |
215 | $query = " | |
216 | SELECT a.*, c.id as caseID | |
217 | FROM civicrm_activity a, | |
218 | civicrm_case c, | |
219 | civicrm_case_activity ac | |
220 | WHERE a.is_current_revision = 1 | |
221 | AND a.is_deleted =0 | |
222 | AND a.activity_type_id IN ( $activityTypeIDs ) | |
223 | AND c.id = ac.case_id | |
224 | AND a.id = ac.activity_id | |
225 | AND ac.case_id = %1 | |
226 | "; | |
227 | ||
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, | |
233 | $dao, | |
234 | $activityTypeInfo | |
235 | ); | |
236 | } | |
237 | } | |
238 | ||
4c6ce474 | 239 | /** |
100fef9d CW |
240 | * @param int $clientID |
241 | * @param int $activityID | |
4c6ce474 EM |
242 | * @param bool $anyActivity |
243 | * @param int $redact | |
244 | * | |
245 | * @return mixed | |
246 | */ | |
00be9182 | 247 | public function &getActivityInfo($clientID, $activityID, $anyActivity = FALSE, $redact = 0) { |
6a488035 TO |
248 | static $activityInfos = array(); |
249 | if ($redact) { | |
250 | $this->_isRedact = 1; | |
251 | $this->getRedactionRules(); | |
252 | } | |
253 | ||
6a488035 TO |
254 | $index = $activityID . '_' . (int) $anyActivity; |
255 | ||
256 | if ($clientID) { | |
257 | $index = $index . '_' . $clientID; | |
258 | } | |
259 | ||
6a488035 TO |
260 | if (!array_key_exists($index, $activityInfos)) { |
261 | $activityInfos[$index] = array(); | |
262 | $selectCaseActivity = ""; | |
263 | $joinCaseActivity = ""; | |
264 | ||
265 | if ($clientID) { | |
266 | $selectCaseActivity = ", ca.case_id as caseID "; | |
267 | $joinCaseActivity = " INNER JOIN civicrm_case_activity ca ON a.id = ca.activity_id "; | |
268 | } | |
269 | ||
44f817d4 | 270 | $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate'); |
9e74e3ce | 271 | $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); |
272 | $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); | |
8ef12e64 | 273 | |
6a488035 | 274 | $query = " |
5a1bd70b | 275 | SELECT a.*, aa.contact_id as assigneeID, at.contact_id as targetID |
6a488035 TO |
276 | {$selectCaseActivity} |
277 | FROM civicrm_activity a | |
278 | {$joinCaseActivity} | |
9e74e3ce | 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 | |
6a488035 TO |
281 | WHERE a.id = %1 |
282 | "; | |
283 | $params = array(1 => array($activityID, 'Integer')); | |
284 | $dao = CRM_Core_DAO::executeQuery($query, $params); | |
285 | ||
286 | if ($dao->fetch()) { | |
287 | //if activity type is email get info of all activities. | |
288 | if ($dao->activity_type_id == CRM_Core_OptionGroup::getValue('activity_type', 'Email', 'name')) { | |
289 | $anyActivity = TRUE; | |
290 | } | |
a953bf20 | 291 | $activityTypes = CRM_Case_PseudoConstant::caseActivityType(FALSE, $anyActivity); |
6a488035 TO |
292 | $activityTypeInfo = NULL; |
293 | ||
294 | if (isset($activityTypes[$dao->activity_type_id])) { | |
295 | $activityTypeInfo = $activityTypes[$dao->activity_type_id]; | |
296 | } | |
297 | if ($activityTypeInfo) { | |
298 | $activityInfos[$index] = $this->getActivity($clientID, $dao, $activityTypeInfo); | |
299 | } | |
300 | } | |
301 | } | |
302 | ||
303 | return $activityInfos[$index]; | |
304 | } | |
305 | ||
4c6ce474 | 306 | /** |
100fef9d | 307 | * @param int $clientID |
4c6ce474 EM |
308 | * @param $activityDAO |
309 | * @param $activityTypeInfo | |
310 | * | |
311 | * @return array | |
312 | */ | |
00be9182 | 313 | public function &getActivity($clientID, $activityDAO, &$activityTypeInfo) { |
6a488035 TO |
314 | if (empty($this->_redactionStringRules)) { |
315 | $this->_redactionStringRules = array(); | |
316 | } | |
317 | ||
318 | $activity = array(); | |
319 | $activity['fields'] = array(); | |
320 | if ($clientID) { | |
321 | $clientID = CRM_Utils_Type::escape($clientID, 'Integer'); | |
322 | if (!in_array($activityTypeInfo['name'], array( | |
353ffa53 | 323 | 'Email', |
acb1052e | 324 | 'Inbound Email', |
353ffa53 TO |
325 | )) |
326 | ) { | |
6a488035 TO |
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}" | |
329 | ); | |
330 | } | |
331 | else { | |
332 | $activity['editURL'] = ''; | |
333 | } | |
334 | ||
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)) | |
341 | ); | |
342 | ||
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]; | |
346 | } | |
347 | } | |
348 | ||
349 | $activity['fields'][] = array( | |
350 | 'label' => 'Client', | |
351 | 'value' => $this->redact($client), | |
352 | 'type' => 'String', | |
353 | ); | |
354 | } | |
355 | ||
44f817d4 | 356 | $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate'); |
034500d4 | 357 | $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); |
358 | $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); | |
6a488035 TO |
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. | |
353ffa53 | 362 | $targetNames = CRM_Activity_BAO_ActivityContact::getNames($activityDAO->id, $targetID); |
6a488035 | 363 | $processTarget = FALSE; |
353ffa53 | 364 | $label = ts('With Contact(s)'); |
22d5fc65 | 365 | if (in_array($activityTypeInfo['name'], array('Email', 'Inbound Email'))) { |
6a488035 TO |
366 | $processTarget = TRUE; |
367 | $label = ts('Recipient'); | |
368 | } | |
369 | if (!$processTarget) { | |
370 | foreach ($targetNames as $targetID => $targetName) { | |
371 | if ($targetID != $clientID) { | |
372 | $processTarget = TRUE; | |
373 | break; | |
374 | } | |
375 | } | |
376 | } | |
377 | ||
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)) | |
386 | ); | |
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]; | |
390 | } | |
391 | } | |
392 | $targetRedacted[] = $this->redact($target); | |
393 | } | |
394 | ||
395 | $activity['fields'][] = array( | |
396 | 'label' => $label, | |
397 | 'value' => implode('; ', $targetRedacted), | |
398 | 'type' => 'String', | |
399 | ); | |
400 | } | |
401 | } | |
402 | ||
403 | // Activity Type info is a special field | |
404 | $activity['fields'][] = array( | |
22d5fc65 | 405 | 'label' => ts('Activity Type'), |
6a488035 TO |
406 | 'value' => $activityTypeInfo['label'], |
407 | 'type' => 'String', | |
408 | ); | |
409 | ||
410 | $activity['fields'][] = array( | |
22d5fc65 | 411 | 'label' => ts('Subject'), |
6a488035 TO |
412 | 'value' => htmlspecialchars($this->redact($activityDAO->subject)), |
413 | 'type' => 'Memo', | |
414 | ); | |
415 | ||
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)) | |
421 | ); | |
422 | } | |
423 | $activity['fields'][] = array( | |
22d5fc65 | 424 | 'label' => ts('Created By'), |
6a488035 TO |
425 | 'value' => $this->redact($creator), |
426 | 'type' => 'String', | |
427 | ); | |
44f817d4 | 428 | $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate'); |
034500d4 | 429 | $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); |
430 | $source_contact_id = CRM_Activity_BAO_Activity::getActivityContact($activityDAO->id, $sourceID); | |
6a488035 | 431 | $reporter = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', |
034500d4 | 432 | $source_contact_id, |
6a488035 TO |
433 | 'display_name' |
434 | ); | |
435 | ||
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)) | |
441 | ); | |
442 | ||
443 | $reporterSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', | |
353ffa53 | 444 | $source_contact_id, |
6a488035 TO |
445 | 'sort_name' |
446 | ); | |
447 | if (!array_key_exists($reporterSortName, $this->_redactionStringRules)) { | |
448 | $this->_redactionStringRules[$reporterSortName] = $this->_redactionStringRules[$reporter]; | |
449 | } | |
450 | } | |
451 | ||
452 | $activity['fields'][] = array( | |
22d5fc65 | 453 | 'label' => ts('Reported By'), |
6a488035 TO |
454 | 'value' => $this->redact($reporter), |
455 | 'type' => 'String', | |
456 | ); | |
457 | ||
458 | if (!empty($activityDAO->assigneeID)) { | |
459 | //allow multiple assignee contacts.CRM-4503. | |
90b05581 | 460 | $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($activityDAO->id), TRUE); |
6a488035 TO |
461 | |
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)) | |
466 | ); | |
467 | $assignee = $this->redact($assignee); | |
468 | } | |
469 | $assigneeContacts = implode(', ', $assignee_contact_names); | |
470 | $activity['fields'][] = array( | |
3bd48a28 | 471 | 'label' => ts('Assigned to'), |
6a488035 TO |
472 | 'value' => $assigneeContacts, |
473 | 'type' => 'String', | |
474 | ); | |
475 | } | |
476 | ||
477 | if ($activityDAO->medium_id) { | |
478 | $activity['fields'][] = array( | |
22d5fc65 | 479 | 'label' => ts('Medium'), |
6a488035 TO |
480 | 'value' => CRM_Core_OptionGroup::getLabel('encounter_medium', |
481 | $activityDAO->medium_id, FALSE | |
482 | ), | |
483 | 'type' => 'String', | |
484 | ); | |
485 | } | |
486 | ||
487 | $activity['fields'][] = array( | |
22d5fc65 | 488 | 'label' => ts('Location'), |
6a488035 TO |
489 | 'value' => $activityDAO->location, |
490 | 'type' => 'String', | |
491 | ); | |
492 | ||
493 | $activity['fields'][] = array( | |
22d5fc65 | 494 | 'label' => ts('Date and Time'), |
6a488035 TO |
495 | 'value' => $activityDAO->activity_date_time, |
496 | 'type' => 'Date', | |
497 | ); | |
498 | ||
499 | $activity['fields'][] = array( | |
22d5fc65 | 500 | 'label' => ts('Details'), |
6a488035 TO |
501 | 'value' => $this->redact(CRM_Utils_String::stripAlternatives($activityDAO->details)), |
502 | 'type' => 'Memo', | |
503 | ); | |
504 | ||
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( | |
22d5fc65 | 508 | 'label' => ts('Duration'), |
6a488035 TO |
509 | 'value' => $activityDAO->duration . ' ' . ts('minutes'), |
510 | 'type' => 'Int', | |
511 | ); | |
512 | } | |
513 | $activity['fields'][] = array( | |
22d5fc65 | 514 | 'label' => ts('Status'), |
6a488035 TO |
515 | 'value' => CRM_Core_OptionGroup::getLabel('activity_status', |
516 | $activityDAO->status_id | |
517 | ), | |
518 | 'type' => 'String', | |
519 | ); | |
520 | ||
521 | $activity['fields'][] = array( | |
22d5fc65 | 522 | 'label' => ts('Priority'), |
6a488035 TO |
523 | 'value' => CRM_Core_OptionGroup::getLabel('priority', |
524 | $activityDAO->priority_id | |
525 | ), | |
526 | 'type' => 'String', | |
527 | ); | |
528 | ||
529 | //for now empty custom groups | |
530 | $activity['customGroups'] = $this->getCustomData($clientID, | |
531 | $activityDAO, | |
532 | $activityTypeInfo | |
533 | ); | |
534 | ||
535 | return $activity; | |
536 | } | |
537 | ||
4c6ce474 | 538 | /** |
100fef9d | 539 | * @param int $clientID |
4c6ce474 EM |
540 | * @param $activityDAO |
541 | * @param $activityTypeInfo | |
542 | * | |
543 | * @return array|null | |
544 | */ | |
00be9182 | 545 | public function getCustomData($clientID, $activityDAO, &$activityTypeInfo) { |
6a488035 TO |
546 | list($typeValues, $options, $sql) = $this->getActivityTypeCustomSQL($activityTypeInfo['id'], '%Y-%m-%d'); |
547 | ||
548 | $params = array(1 => array($activityDAO->id, 'Integer')); | |
549 | ||
550 | $customGroups = array(); | |
551 | foreach ($sql as $tableName => $sqlClause) { | |
552 | $dao = CRM_Core_DAO::executeQuery($sqlClause, $params); | |
553 | if ($dao->fetch()) { | |
554 | $customGroup = array(); | |
555 | foreach ($typeValues[$tableName] as $columnName => $typeValue) { | |
6a488035 TO |
556 | |
557 | if (CRM_Utils_Array::value('type', $typeValue) == 'Date') { | |
558 | $value = $dao->$columnName; | |
559 | } | |
2e894314 CW |
560 | else { |
561 | $value = CRM_Core_BAO_CustomField::displayValue($dao->$columnName, $typeValue['fieldID']); | |
562 | } | |
6a488035 TO |
563 | |
564 | if ($value) { | |
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); | |
569 | } | |
570 | if (CRM_Utils_Array::value('type', $typeValue) == 'String' || | |
571 | CRM_Utils_Array::value('type', $typeValue) == 'Memo' | |
572 | ) { | |
573 | $value = $this->redact($value); | |
574 | } | |
575 | elseif (CRM_Utils_Array::value('type', $typeValue) == 'File') { | |
576 | $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $typeValue, 'entity_table'); | |
577 | $value = CRM_Core_BAO_File::attachmentInfo($tableName, $activityDAO->id); | |
578 | } | |
579 | elseif (CRM_Utils_Array::value('type', $typeValue) == 'Link') { | |
580 | $value = CRM_Utils_System::formatWikiURL($value); | |
581 | } | |
582 | } | |
583 | //$typeValue | |
584 | $customGroup[] = array( | |
585 | 'label' => $typeValue['label'], | |
586 | 'value' => $value, | |
587 | 'type' => $typeValue['type'], | |
dc7c0d62 | 588 | 'fieldID' => $typeValue['fieldID'], |
6a488035 TO |
589 | ); |
590 | } | |
591 | $customGroups[$dao->groupTitle] = $customGroup; | |
592 | } | |
593 | } | |
594 | ||
595 | return empty($customGroups) ? NULL : $customGroups; | |
596 | } | |
597 | ||
4c6ce474 | 598 | /** |
100fef9d | 599 | * @param int $activityTypeID |
4c6ce474 EM |
600 | * @param null $dateFormat |
601 | * | |
602 | * @return mixed | |
603 | */ | |
00be9182 | 604 | public function getActivityTypeCustomSQL($activityTypeID, $dateFormat = NULL) { |
6a488035 TO |
605 | static $cache = array(); |
606 | ||
607 | if (is_null($activityTypeID)) { | |
608 | $activityTypeID = 0; | |
609 | } | |
610 | ||
611 | if (!isset($cache[$activityTypeID])) { | |
612 | $query = " | |
613 | SELECT cg.title as groupTitle, | |
614 | cg.table_name as tableName , | |
615 | cf.column_name as columnName, | |
616 | cf.label as label , | |
617 | cg.id as groupID , | |
618 | cf.id as fieldID , | |
619 | cf.data_type as dataType , | |
620 | cf.html_type as htmlType , | |
621 | cf.option_group_id as optionGroupID | |
622 | FROM civicrm_custom_group cg, | |
623 | civicrm_custom_field cf | |
624 | WHERE cf.custom_group_id = cg.id | |
fb6aa4b9 | 625 | AND cg.extends = 'Activity' |
626 | AND " . CRM_Core_Permission::customGroupClause(CRM_Core_Permission::VIEW, 'cg.'); | |
6a488035 TO |
627 | |
628 | if ($activityTypeID) { | |
629 | $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 . "%' )"; | |
630 | } | |
631 | else { | |
632 | $query .= "AND cg.extends_entity_column_value IS NULL"; | |
633 | } | |
a5c0c7f2 | 634 | $query .= "ORDER BY cg.weight, cf.weight"; |
6a488035 | 635 | $params = array( |
353ffa53 TO |
636 | 1 => array( |
637 | $activityTypeID, | |
6a488035 | 638 | 'Integer', |
acb1052e | 639 | ), |
353ffa53 | 640 | ); |
6a488035 TO |
641 | $dao = CRM_Core_DAO::executeQuery($query, $params); |
642 | ||
643 | $result = $options = $sql = $groupTitle = array(); | |
644 | while ($dao->fetch()) { | |
645 | if (!array_key_exists($dao->tableName, $result)) { | |
646 | $result[$dao->tableName] = array(); | |
647 | $sql[$dao->tableName] = array(); | |
648 | } | |
649 | $result[$dao->tableName][$dao->columnName] = array( | |
650 | 'label' => $dao->label, | |
651 | 'type' => $dao->dataType, | |
652 | 'fieldID' => $dao->fieldID, | |
653 | ); | |
654 | ||
655 | $options[$dao->fieldID] = array(); | |
656 | $options[$dao->fieldID]['attributes'] = array( | |
657 | 'label' => $dao->label, | |
658 | 'data_type' => $dao->dataType, | |
659 | 'html_type' => $dao->htmlType, | |
660 | ); | |
661 | // since we want to add ISO date format. | |
662 | if ($dateFormat && $dao->htmlType == 'Select Date') { | |
663 | $options[$dao->fieldID]['attributes']['format'] = $dateFormat; | |
664 | } | |
665 | if ($dao->optionGroupID) { | |
666 | $query = " | |
667 | SELECT label, value | |
668 | FROM civicrm_option_value | |
78c187fb | 669 | WHERE option_group_id = %1 |
6a488035 TO |
670 | "; |
671 | ||
78c187fb | 672 | $option = CRM_Core_DAO::executeQuery($query, array(1 => array($dao->optionGroupID, 'Positive'))); |
6a488035 TO |
673 | while ($option->fetch()) { |
674 | $dataType = $dao->dataType; | |
675 | if ($dataType == 'Int' || $dataType == 'Float') { | |
676 | $num = round($option->value, 2); | |
677 | $options[$dao->fieldID]["$num"] = $option->label; | |
678 | } | |
679 | else { | |
680 | $options[$dao->fieldID][$option->value] = $option->label; | |
681 | } | |
682 | } | |
683 | } | |
684 | ||
685 | $sql[$dao->tableName][] = $dao->columnName; | |
686 | $groupTitle[$dao->tableName] = $dao->groupTitle; | |
687 | } | |
688 | ||
689 | foreach ($sql as $tableName => $values) { | |
690 | $columnNames = implode(',', $values); | |
79acbc27 SL |
691 | $title = CRM_Core_DAO::escapeString($groupTitle[$tableName]); |
692 | $mysqlTableName = CRM_Utils_Type::escape($tableName, 'MysqlColumnNameOrAlias'); | |
6a488035 | 693 | $sql[$tableName] = " |
79acbc27 SL |
694 | SELECT '" . $title . "' as groupTitle, $columnNames |
695 | FROM $mysqlTableName | |
6a488035 TO |
696 | WHERE entity_id = %1 |
697 | "; | |
698 | } | |
699 | ||
700 | $cache[$activityTypeID] = array($result, $options, $sql); | |
701 | } | |
702 | return $cache[$activityTypeID]; | |
703 | } | |
704 | ||
4c6ce474 | 705 | /** |
100fef9d | 706 | * @param int $activityID |
4c6ce474 EM |
707 | * |
708 | * @return null|string | |
709 | */ | |
00be9182 | 710 | public function getCreatedBy($activityID) { |
6a488035 TO |
711 | $query = " |
712 | SELECT c.display_name | |
713 | FROM civicrm_contact c, | |
714 | civicrm_log l | |
715 | WHERE l.entity_table = 'civicrm_activity' | |
716 | AND l.entity_id = %1 | |
717 | AND l.modified_id = c.id | |
718 | LIMIT 1 | |
719 | "; | |
720 | ||
721 | $params = array(1 => array($activityID, 'Integer')); | |
722 | return CRM_Core_DAO::singleValueQuery($query, $params); | |
723 | } | |
724 | ||
4c6ce474 EM |
725 | /** |
726 | * @param $string | |
727 | * @param bool $printReport | |
728 | * @param array $replaceString | |
729 | * | |
730 | * @return mixed | |
731 | */ | |
c490a46a | 732 | private function redact($string, $printReport = FALSE, $replaceString = array()) { |
6a488035 TO |
733 | if ($printReport) { |
734 | return CRM_Utils_String::redaction($string, $replaceString); | |
735 | } | |
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)); | |
739 | } | |
740 | return $string; | |
741 | } | |
742 | ||
4c6ce474 | 743 | /** |
100fef9d CW |
744 | * @param int $clientID |
745 | * @param int $caseID | |
746 | * @param string $activitySetName | |
c490a46a CW |
747 | * @param array $params |
748 | * @param CRM_Core_Form $form | |
4c6ce474 EM |
749 | * |
750 | * @return mixed | |
751 | */ | |
00be9182 | 752 | public static function getCaseReport($clientID, $caseID, $activitySetName, $params, $form) { |
6a488035 TO |
753 | |
754 | $template = CRM_Core_Smarty::singleton(); | |
755 | ||
756 | $template->assign('caseId', $caseID); | |
757 | $template->assign('clientID', $clientID); | |
758 | $template->assign('activitySetName', $activitySetName); | |
759 | ||
a7488080 | 760 | if (!empty($params['is_redact'])) { |
6a488035 TO |
761 | $form->_isRedact = TRUE; |
762 | $template->assign('_isRedact', 'true'); | |
763 | } | |
764 | else { | |
765 | $form->_isRedact = FALSE; | |
766 | $template->assign('_isRedact', 'false'); | |
767 | } | |
768 | ||
769 | // first get all case information | |
770 | $case = $form->caseInfo($clientID, $caseID); | |
771 | $template->assign_by_ref('case', $case); | |
772 | ||
773 | if ($params['include_activities'] == 1) { | |
774 | $template->assign('includeActivities', 'All'); | |
775 | } | |
776 | else { | |
777 | $template->assign('includeActivities', 'Missing activities only'); | |
778 | } | |
779 | ||
780 | $xml = $form->retrieve($case['caseTypeName']); | |
781 | ||
782 | $activitySetNames = CRM_Case_XMLProcessor_Process::activitySets($xml->ActivitySets); | |
783 | $pageTitle = CRM_Utils_Array::value($activitySetName, $activitySetNames); | |
784 | $template->assign('pageTitle', $pageTitle); | |
785 | ||
786 | if ($activitySetName) { | |
787 | $activityTypes = $form->getActivityTypes($xml, $activitySetName); | |
788 | } | |
789 | else { | |
790 | $activityTypes = CRM_Case_XMLProcessor::allActivityTypes(); | |
791 | } | |
792 | ||
793 | if (!$activityTypes) { | |
794 | return FALSE; | |
795 | } | |
796 | ||
b44e3f84 | 797 | // next get activity set Information |
e547f744 | 798 | $activitySet = array( |
353ffa53 | 799 | 'label' => $form->getActivitySetLabel($xml, $activitySetName), |
6a488035 TO |
800 | 'includeActivities' => 'All', |
801 | 'redact' => 'false', | |
802 | ); | |
803 | $template->assign_by_ref('activitySet', $activitySet); | |
804 | ||
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); | |
809 | ||
810 | // now run the template | |
811 | $contents = $template->fetch('CRM/Case/XMLProcessor/Report.tpl'); | |
812 | return $contents; | |
813 | } | |
814 | ||
00be9182 | 815 | public static function printCaseReport() { |
a3d827a7 CW |
816 | $caseID = CRM_Utils_Request::retrieve('caseID', 'Positive'); |
817 | $clientID = CRM_Utils_Request::retrieve('cid', 'Positive'); | |
818 | $activitySetName = CRM_Utils_Request::retrieve('asn', 'String'); | |
819 | $isRedact = CRM_Utils_Request::retrieve('redact', 'Boolean'); | |
820 | $includeActivities = CRM_Utils_Request::retrieve('all', 'Positive'); | |
353ffa53 TO |
821 | $params = $otherRelationships = $globalGroupInfo = array(); |
822 | $report = new CRM_Case_XMLProcessor_Report($isRedact); | |
6a488035 TO |
823 | if ($includeActivities) { |
824 | $params['include_activities'] = 1; | |
825 | } | |
826 | ||
827 | if ($isRedact) { | |
828 | $params['is_redact'] = 1; | |
829 | $report->_redactionStringRules = array(); | |
830 | } | |
831 | $template = CRM_Core_Smarty::singleton(); | |
832 | ||
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'); | |
836 | ||
837 | $xmlProcessor = new CRM_Case_XMLProcessor_Process(); | |
838 | $caseRoles = $xmlProcessor->get($caseType, 'CaseRoles'); | |
839 | foreach ($caseRelationships as $key => & $value) { | |
a7488080 | 840 | if (!empty($caseRoles[$value['relation_type']])) { |
6a488035 TO |
841 | unset($caseRoles[$value['relation_type']]); |
842 | } | |
843 | if ($isRedact) { | |
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)) | |
847 | ); | |
848 | } | |
a7e52def | 849 | $value['name'] = $report->redact($value['name'], TRUE, $report->_redactionStringRules); |
a7488080 | 850 | if (!empty($value['email']) && |
6a488035 TO |
851 | !array_key_exists($value['email'], $report->_redactionStringRules) |
852 | ) { | |
853 | $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, | |
854 | array($value['email'] => 'email_' . rand(10000, 100000)) | |
855 | ); | |
856 | } | |
857 | ||
a7e52def | 858 | $value['email'] = $report->redact($value['email'], TRUE, $report->_redactionStringRules); |
6a488035 | 859 | |
a7488080 | 860 | if (!empty($value['phone']) && |
6a488035 TO |
861 | !array_key_exists($value['phone'], $report->_redactionStringRules) |
862 | ) { | |
863 | $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, | |
864 | array($value['phone'] => 'phone_' . rand(10000, 100000)) | |
865 | ); | |
866 | } | |
a7e52def | 867 | $value['phone'] = $report->redact($value['phone'], TRUE, $report->_redactionStringRules); |
6a488035 TO |
868 | } |
869 | } | |
870 | ||
871 | $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($caseID); | |
872 | if ($isRedact) { | |
a7e52def | 873 | foreach ($caseRoles['client'] as &$client) { |
874 | if (!array_key_exists(CRM_Utils_Array::value('sort_name', $client), $report->_redactionStringRules)) { | |
6a488035 | 875 | |
a7e52def | 876 | $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, |
877 | array(CRM_Utils_Array::value('sort_name', $client) => 'name_' . rand(10000, 100000)) | |
878 | ); | |
879 | } | |
880 | if (!array_key_exists(CRM_Utils_Array::value('display_name', $client), $report->_redactionStringRules)) { | |
881 | $report->_redactionStringRules[CRM_Utils_Array::value('display_name', $client)] = $report->_redactionStringRules[CRM_Utils_Array::value('sort_name', $client)]; | |
882 | } | |
883 | $client['sort_name'] = $report->redact(CRM_Utils_Array::value('sort_name', $client), TRUE, $report->_redactionStringRules); | |
01217591 | 884 | if (!empty($client['email']) && |
885 | !array_key_exists($client['email'], $report->_redactionStringRules) | |
a7e52def | 886 | ) { |
887 | $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, | |
01217591 | 888 | array($client['email'] => 'email_' . rand(10000, 100000)) |
a7e52def | 889 | ); |
890 | } | |
891 | $client['email'] = $report->redact(CRM_Utils_Array::value('email', $client), TRUE, $report->_redactionStringRules); | |
892 | ||
01217591 | 893 | if (!empty($client['phone']) && |
894 | !array_key_exists($client['phone'], $report->_redactionStringRules) | |
a7e52def | 895 | ) { |
896 | $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, | |
01217591 | 897 | array($client['phone'] => 'phone_' . rand(10000, 100000)) |
a7e52def | 898 | ); |
899 | } | |
900 | $client['phone'] = $report->redact(CRM_Utils_Array::value('phone', $client), TRUE, $report->_redactionStringRules); | |
6a488035 | 901 | } |
6a488035 | 902 | } |
6a488035 TO |
903 | // Retrieve ALL client relationships |
904 | $relClient = CRM_Contact_BAO_Relationship::getRelationship($clientID, | |
905 | CRM_Contact_BAO_Relationship::CURRENT, | |
906 | 0, 0, 0, NULL, NULL, FALSE | |
907 | ); | |
908 | foreach ($relClient as $r) { | |
909 | if ($isRedact) { | |
910 | if (!array_key_exists($r['name'], $report->_redactionStringRules)) { | |
911 | $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, | |
912 | array($r['name'] => 'name_' . rand(10000, 100000)) | |
913 | ); | |
914 | } | |
915 | if (!array_key_exists($r['display_name'], $report->_redactionStringRules)) { | |
916 | $report->_redactionStringRules[$r['display_name']] = $report->_redactionStringRules[$r['name']]; | |
917 | } | |
a7e52def | 918 | $r['name'] = $report->redact($r['name'], TRUE, $report->_redactionStringRules); |
6a488035 | 919 | |
a7488080 | 920 | if (!empty($r['phone']) && |
6a488035 TO |
921 | !array_key_exists($r['phone'], $report->_redactionStringRules) |
922 | ) { | |
923 | $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, | |
924 | array($r['phone'] => 'phone_' . rand(10000, 100000)) | |
925 | ); | |
926 | } | |
a7e52def | 927 | $r['phone'] = $report->redact($r['phone'], TRUE, $report->_redactionStringRules); |
6a488035 | 928 | |
a7488080 | 929 | if (!empty($r['email']) && |
6a488035 TO |
930 | !array_key_exists($r['email'], $report->_redactionStringRules) |
931 | ) { | |
932 | $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, | |
933 | array($r['email'] => 'email_' . rand(10000, 100000)) | |
934 | ); | |
935 | } | |
a7e52def | 936 | $r['email'] = $report->redact($r['email'], TRUE, $report->_redactionStringRules); |
6a488035 TO |
937 | } |
938 | if (!array_key_exists($r['id'], $caseRelationships)) { | |
939 | $otherRelationships[] = $r; | |
940 | } | |
941 | } | |
942 | ||
943 | // Now global contact list that appears on all cases. | |
944 | $relGlobal = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo); | |
945 | foreach ($relGlobal as & $r) { | |
946 | if ($isRedact) { | |
947 | if (!array_key_exists($r['sort_name'], $report->_redactionStringRules)) { | |
948 | $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, | |
949 | array($r['sort_name'] => 'name_' . rand(10000, 100000)) | |
950 | ); | |
951 | } | |
952 | if (!array_key_exists($r['display_name'], $report->_redactionStringRules)) { | |
953 | $report->_redactionStringRules[$r['display_name']] = $report->_redactionStringRules[$r['sort_name']]; | |
954 | } | |
955 | ||
a7e52def | 956 | $r['sort_name'] = $report->redact($r['sort_name'], TRUE, $report->_redactionStringRules); |
a7488080 | 957 | if (!empty($r['phone']) && |
6a488035 TO |
958 | !array_key_exists($r['phone'], $report->_redactionStringRules) |
959 | ) { | |
960 | $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, | |
961 | array($r['phone'] => 'phone_' . rand(10000, 100000)) | |
962 | ); | |
963 | } | |
a7e52def | 964 | $r['phone'] = $report->redact($r['phone'], TRUE, $report->_redactionStringRules); |
6a488035 | 965 | |
a7488080 | 966 | if (!empty($r['email']) && |
6a488035 TO |
967 | !array_key_exists($r['email'], $report->_redactionStringRules) |
968 | ) { | |
969 | $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, | |
970 | array($r['email'] => 'email_' . rand(10000, 100000)) | |
971 | ); | |
972 | } | |
a7e52def | 973 | $r['email'] = $report->redact($r['email'], TRUE, $report->_redactionStringRules); |
6a488035 TO |
974 | } |
975 | } | |
976 | ||
b077cff9 JM |
977 | // Retrieve custom values for cases. |
978 | $customValues = CRM_Core_BAO_CustomValueTable::getEntityValues($caseID, 'Case'); | |
979 | $extends = array('case'); | |
980 | $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends); | |
981 | $caseCustomFields = array(); | |
219af4d3 CW |
982 | while (list($gid, $group_values) = each($groupTree)) { |
983 | while (list($id, $field_values) = each($group_values['fields'])) { | |
984 | if (array_key_exists($id, $customValues)) { | |
985 | $caseCustomFields[$gid]['title'] = $group_values['title']; | |
986 | $caseCustomFields[$gid]['values'][$id] = array( | |
b077cff9 JM |
987 | 'label' => $field_values['label'], |
988 | 'value' => $customValues[$id], | |
989 | ); | |
990 | } | |
991 | } | |
992 | } | |
6a488035 TO |
993 | $template->assign('caseRelationships', $caseRelationships); |
994 | $template->assign('caseRoles', $caseRoles); | |
995 | $template->assign('otherRelationships', $otherRelationships); | |
996 | $template->assign('globalRelationships', $relGlobal); | |
997 | $template->assign('globalGroupInfo', $globalGroupInfo); | |
b077cff9 | 998 | $template->assign('caseCustomFields', $caseCustomFields); |
6a488035 TO |
999 | $contents = self::getCaseReport($clientID, |
1000 | $caseID, | |
1001 | $activitySetName, | |
1002 | $params, | |
1003 | $report | |
1004 | ); | |
1005 | $printReport = CRM_Case_Audit_Audit::run($contents, $clientID, $caseID, TRUE); | |
1006 | echo $printReport; | |
1007 | CRM_Utils_System::civiExit(); | |
1008 | } | |
96025800 | 1009 | |
6a488035 | 1010 | } |