5e11dc87b1ecb1a336e924cbb1bd2b906baf0f00
[civicrm-core.git] / CRM / Activity / Page / AJAX.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2014
32 *
33 */
34
35 /**
36 * This class contains all the function that are called using AJAX (jQuery)
37 */
38 class CRM_Activity_Page_AJAX {
39 public static function getCaseActivity() {
40 $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer');
41 $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
42 $userID = CRM_Utils_Type::escape($_GET['userID'], 'Integer');
43 $context = CRM_Utils_Type::escape(CRM_Utils_Array::value('context', $_GET), 'String');
44
45 $sortMapper = array(
46 0 => 'display_date',
47 1 => 'ca.subject',
48 2 => 'ca.activity_type_id',
49 3 => 'acc.sort_name',
50 4 => 'cc.sort_name',
51 5 => 'ca.status_id',
52 );
53
54 $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
55 $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
56 $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
57 $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
58 $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
59
60 $params = $_POST;
61 if ($sort && $sortOrder) {
62 $params['sortname'] = $sort;
63 $params['sortorder'] = $sortOrder;
64 }
65 $params['page'] = ($offset / $rowCount) + 1;
66 $params['rp'] = $rowCount;
67
68 // get the activities related to given case
69 $activities = CRM_Case_BAO_Case::getCaseActivity($caseID, $params, $contactID, $context, $userID);
70
71 $iFilteredTotal = $iTotal = $params['total'];
72 $selectorElements = array(
73 'display_date',
74 'subject',
75 'type',
76 'with_contacts',
77 'reporter',
78 'status',
79 'links',
80 'class',
81 );
82
83 header('Content-Type: application/json');
84 echo CRM_Utils_JSON::encodeDataTableSelector($activities, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
85 CRM_Utils_System::civiExit();
86 }
87
88 public static function getCaseGlobalRelationships() {
89 $sortMapper = array(
90 0 => 'sort_name',
91 1 => 'phone',
92 2 => 'email',
93 );
94
95 $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
96 $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
97 $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
98 $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
99 $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
100
101 $params = $_POST;
102 //CRM-14466 initialize variable to avoid php notice
103 $sortSQL = "";
104 if ($sort && $sortOrder) {
105 $sortSQL = $sort . ' ' . $sortOrder;
106 }
107
108 // get the activities related to given case
109 $globalGroupInfo = array();
110
111 // get the total row count
112 $relGlobalTotalCount = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo, NULL, FALSE, TRUE, NULL, NULL);
113 // limit the rows
114 $relGlobal = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo, $sortSQL, $showLinks = TRUE, FALSE, $offset, $rowCount);
115
116 $iFilteredTotal = $iTotal = $relGlobalTotalCount;
117 $selectorElements = array('sort_name', 'phone', 'email');
118
119 header('Content-Type: application/json');
120 echo CRM_Utils_JSON::encodeDataTableSelector($relGlobal, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
121 CRM_Utils_System::civiExit();
122 }
123
124 public static function getCaseClientRelationships() {
125 $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer');
126 $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
127
128 $sortMapper = array(
129 0 => 'relation',
130 1 => 'name',
131 2 => 'phone',
132 3 => 'email',
133 );
134
135 $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
136 $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
137 $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
138 $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : 'relation';
139 $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
140
141 $params = $_POST;
142 if ($sort && $sortOrder) {
143 $sortSQL = $sort . ' ' . $sortOrder;
144 }
145
146 // Retrieve ALL client relationships
147 $relClient = CRM_Contact_BAO_Relationship::getRelationship($contactID,
148 CRM_Contact_BAO_Relationship::CURRENT,
149 0, 0, 0, NULL, NULL, FALSE
150 );
151
152 $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID);
153
154 // Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles
155 // so they don't show up twice.
156 $clientRelationships = array();
157 foreach ($relClient as $r) {
158 if (!array_key_exists($r['id'], $caseRelationships)) {
159 $clientRelationships[] = $r;
160 }
161 }
162
163 // sort clientRelationships array using jquery call params
164 foreach ($clientRelationships as $key => $row) {
165 $sortArray[$key] = $row[$sort];
166 }
167 $sort_type = "SORT_" . strtoupper($sortOrder);
168 array_multisort($sortArray, constant($sort_type), $clientRelationships);
169
170 //limit the rows
171 $allClientRelationships = $clientRelationships;
172 $clientRelationships = array_slice($allClientRelationships, $offset, $rowCount, TRUE);
173
174 // after sort we can update username fields to be a url
175 foreach ($clientRelationships as $key => $value) {
176 $clientRelationships[$key]['name'] = '<a href=' . CRM_Utils_System::url('civicrm/contact/view',
177 'action=view&reset=1&cid=' . $clientRelationships[$key]['cid']) . '>' . $clientRelationships[$key]['name'] . '</a>';
178 }
179
180 $iFilteredTotal = $iTotal = $params['total'] = count($allClientRelationships);
181 $selectorElements = array('relation', 'name', 'phone', 'email');
182
183 header('Content-Type: application/json');
184 echo CRM_Utils_JSON::encodeDataTableSelector($clientRelationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
185 CRM_Utils_System::civiExit();
186 }
187
188
189 public static function getCaseRoles() {
190 $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer');
191 $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
192
193 $sortMapper = array(
194 0 => 'relation',
195 1 => 'name',
196 2 => 'phone',
197 3 => 'email',
198 4 => 'actions',
199 );
200
201 $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
202 $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
203 $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
204 $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : 'relation';
205 $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
206
207 $params = $_POST;
208 if ($sort && $sortOrder) {
209 $sortSQL = $sort . ' ' . $sortOrder;
210 }
211
212 $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID);
213 $caseTypeName = CRM_Case_BAO_Case::getCaseType($caseID, 'name');
214 $xmlProcessor = new CRM_Case_XMLProcessor_Process();
215 $caseRoles = $xmlProcessor->get($caseTypeName, 'CaseRoles');
216
217 $hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities');
218
219 $managerRoleId = $xmlProcessor->getCaseManagerRoleId($caseTypeName);
220 if (!empty($managerRoleId)) {
221 $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')';
222 }
223
224 foreach ($caseRelationships as $key => $value) {
225 //calculate roles that don't have relationships
226 if (!empty($caseRoles[$value['relation_type']])) {
227 //keep naming from careRoles array
228 $caseRelationships[$key]['relation'] = $caseRoles[$value['relation_type']];
229 unset($caseRoles[$value['relation_type']]);
230 }
231 // mark orginal case relationships record to use on setting edit links below
232 $caseRelationships[$key]['source'] = 'caseRel';
233 }
234
235 $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($caseID);
236
237 // move/transform caseRoles array data to caseRelationships
238 // for sorting and display
239 // CRM-14466 added cid to the non-client array to avoid php notice
240 foreach ($caseRoles as $id => $value) {
241 if ($id != "client") {
242 $rel = array();
243 $rel['relation'] = $value;
244 $rel['relation_type'] = $id;
245 $rel['name'] = '(not assigned)';
246 $rel['phone'] = '';
247 $rel['email'] = '';
248 $rel['source'] = 'caseRoles';
249 $caseRelationships[] = $rel;
250 }
251 else {
252 foreach ($value as $clientRole) {
253 $relClient = array();
254 $relClient['relation'] = 'Client';
255 $relClient['name'] = $clientRole['sort_name'];
256 $relClient['phone'] = $clientRole['phone'];
257 $relClient['email'] = $clientRole['email'];
258 $relClient['cid'] = $clientRole['contact_id'];
259 $relClient['source'] = 'contact';
260 $caseRelationships[] = $relClient;
261 }
262 }
263 }
264
265 // sort clientRelationships array using jquery call params
266 foreach ($caseRelationships as $key => $row) {
267 $sortArray[$key] = $row[$sort];
268 }
269
270 $sort_type = "SORT_" . strtoupper($sortOrder);
271 array_multisort($sortArray, constant($sort_type), $caseRelationships);
272
273 //limit rows display
274 $allCaseRelationships = $caseRelationships;
275 $caseRelationships = array_slice($allCaseRelationships, $offset, $rowCount, TRUE);
276
277 // set user name, email and edit columns links
278 // idx will count number of current row / needed by edit links
279 $idx = 1;
280 foreach ($caseRelationships as &$row) {
281 // Get rid of the "<br />(Case Manager)" from label
282 list($typeLabel) = explode('<', $row['relation']);
283 // view user links
284 if (!empty($row['cid'])) {
285 $row['name'] = '<a class="view-contact" title="' . ts('View Contact') . '" href=' . CRM_Utils_System::url('civicrm/contact/view',
286 'action=view&reset=1&cid=' . $row['cid']) . '>' . $row['name'] . '</a>';
287 }
288 // email column links/icon
289 if ($row['email']) {
290 $row['email'] = '<a class="crm-hover-button crm-popup" href="' . CRM_Utils_System::url('civicrm/activity/email/add', 'reset=1&action=add&atype=3&cid=' . $row['cid']) . '&caseid=' . $caseID . '" title="' . ts('Send an Email') . '"><span class="icon ui-icon-mail-closed"></span></a>';
291 }
292 // edit links
293 $row['actions'] = '';
294 if ($hasAccessToAllCases) {
295 $contactType = empty($row['relation_type']) ? '' : (string) CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $row['relation_type'], 'contact_type_b');
296 $contactType = $contactType == 'Contact' ? '' : $contactType;
297 switch ($row['source']) {
298 case 'caseRel':
299 $row['actions']
300 = '<a href="#editCaseRoleDialog" title="' . ts('Reassign %1', array(1 => $typeLabel)) . '" class="crm-hover-button case-miniform" data-contact_type="' . $contactType . '" data-rel_type="' . $row['relation_type'] . '" data-rel_id="' . $row['rel_id'] . '"data-key="' . CRM_Core_Key::get('civicrm/ajax/relation') . '">' .
301 '<span class="icon ui-icon-pencil"></span>' .
302 '</a>' .
303 '<a href="#deleteCaseRoleDialog" title="' . ts('Remove %1', array(1 => $typeLabel)) . '" class="crm-hover-button case-miniform" data-contact_type="' . $contactType . '" data-rel_type="' . $row['relation_type'] . '" data-key="' . CRM_Core_Key::get('civicrm/ajax/delcaserole') . '">' .
304 '<span class="icon delete-icon"></span>' .
305 '</a>';
306 break;
307
308 case 'caseRoles':
309 $row['actions']
310 = '<a href="#editCaseRoleDialog" title="' . ts('Assign %1', array(1 => $typeLabel)) . '" class="crm-hover-button case-miniform" data-contact_type="' . $contactType . '" data-rel_type="' . $row['relation_type'] . '" data-key="' . CRM_Core_Key::get('civicrm/ajax/relation') . '">' .
311 '<span class="icon ui-icon-pencil"></span>' .
312 '</a>';
313 break;
314 }
315 }
316 $idx++;
317 }
318 $iFilteredTotal = $iTotal = $params['total'] = count($allCaseRelationships);
319 $selectorElements = array('relation', 'name', 'phone', 'email', 'actions');
320
321 header('Content-Type: application/json');
322 echo CRM_Utils_JSON::encodeDataTableSelector($caseRelationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
323 CRM_Utils_System::civiExit();
324 }
325
326 public static function convertToCaseActivity() {
327 $params = array('caseID', 'activityID', 'contactID', 'newSubject', 'targetContactIds', 'mode');
328 $vals = array();
329 foreach ($params as $param) {
330 $vals[$param] = CRM_Utils_Array::value($param, $_POST);
331 }
332
333 CRM_Utils_JSON::output(self::_convertToCaseActivity($vals));
334 }
335
336 /**
337 * @param array $params
338 *
339 * @return array
340 */
341 public static function _convertToCaseActivity($params) {
342 if (!$params['activityID'] || !$params['caseID']) {
343 return (array('error_msg' => 'required params missing.'));
344 }
345
346 $otherActivity = new CRM_Activity_DAO_Activity();
347 $otherActivity->id = $params['activityID'];
348 if (!$otherActivity->find(TRUE)) {
349 return (array('error_msg' => 'activity record is missing.'));
350 }
351 $actDateTime = CRM_Utils_Date::isoToMysql($otherActivity->activity_date_time);
352
353 //create new activity record.
354 $mainActivity = new CRM_Activity_DAO_Activity();
355 $mainActVals = array();
356 CRM_Core_DAO::storeValues($otherActivity, $mainActVals);
357
358 //get new activity subject.
359 if (!empty($params['newSubject'])) {
360 $mainActVals['subject'] = $params['newSubject'];
361 }
362
363 $mainActivity->copyValues($mainActVals);
364 $mainActivity->id = NULL;
365 $mainActivity->activity_date_time = $actDateTime;
366 //make sure this is current revision.
367 $mainActivity->is_current_revision = TRUE;
368 //drop all relations.
369 $mainActivity->parent_id = $mainActivity->original_id = NULL;
370
371 $mainActivity->save();
372 $mainActivityId = $mainActivity->id;
373 CRM_Activity_BAO_Activity::logActivityAction($mainActivity);
374 $mainActivity->free();
375
376 /* Mark previous activity as deleted. If it was a non-case activity
377 * then just change the subject.
378 */
379
380 if (in_array($params['mode'], array(
381 'move',
382 'file',
383 ))) {
384 $caseActivity = new CRM_Case_DAO_CaseActivity();
385 $caseActivity->case_id = $params['caseID'];
386 $caseActivity->activity_id = $otherActivity->id;
387 if ($params['mode'] == 'move' || $caseActivity->find(TRUE)) {
388 $otherActivity->is_deleted = 1;
389 }
390 else {
391 $otherActivity->subject = ts('(Filed on case %1)', array(
392 1 => $params['caseID'],
393 )) . ' ' . $otherActivity->subject;
394 }
395 $otherActivity->activity_date_time = $actDateTime;
396 $otherActivity->save();
397
398 $caseActivity->free();
399 }
400 $otherActivity->free();
401
402 $targetContacts = array();
403 if (!empty($params['targetContactIds'])) {
404 $targetContacts = array_unique(explode(',', $params['targetContactIds']));
405 }
406
407 $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
408 $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
409 $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
410 $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
411
412 $sourceContactID = CRM_Activity_BAO_Activity::getSourceContactID($params['activityID']);
413 $src_params = array(
414 'activity_id' => $mainActivityId,
415 'contact_id' => $sourceContactID,
416 'record_type_id' => $sourceID,
417 );
418 CRM_Activity_BAO_ActivityContact::create($src_params);
419
420 foreach ($targetContacts as $key => $value) {
421 $targ_params = array(
422 'activity_id' => $mainActivityId,
423 'contact_id' => $value,
424 'record_type_id' => $targetID,
425 );
426 CRM_Activity_BAO_ActivityContact::create($targ_params);
427 }
428
429 // typically this will be empty, since assignees on another case may be completely different
430 $assigneeContacts = array();
431 if (!empty($params['assigneeContactIds'])) {
432 $assigneeContacts = array_unique(explode(',', $params['assigneeContactIds']));
433 }
434 foreach ($assigneeContacts as $key => $value) {
435 $assigneeParams = array(
436 'activity_id' => $mainActivityId,
437 'contact_id' => $value,
438 'record_type_id' => $assigneeID,
439 );
440 CRM_Activity_BAO_ActivityContact::create($assigneeParams);
441 }
442
443 //attach newly created activity to case.
444 $caseActivity = new CRM_Case_DAO_CaseActivity();
445 $caseActivity->case_id = $params['caseID'];
446 $caseActivity->activity_id = $mainActivityId;
447 $caseActivity->save();
448 $error_msg = $caseActivity->_lastError;
449 $caseActivity->free();
450
451 $params['mainActivityId'] = $mainActivityId;
452 CRM_Activity_BAO_Activity::copyExtendedActivityData($params);
453
454 return (array('error_msg' => $error_msg, 'newId' => $mainActivity->id));
455 }
456
457 public static function getContactActivity() {
458 $contactID = CRM_Utils_Type::escape($_POST['contact_id'], 'Integer');
459 $context = CRM_Utils_Type::escape(CRM_Utils_Array::value('context', $_GET), 'String');
460
461 $sortMapper = array(
462 0 => 'activity_type',
463 1 => 'subject',
464 2 => 'source_contact_name',
465 3 => '',
466 4 => '',
467 5 => 'activity_date_time',
468 6 => 'status_id',
469 );
470
471 $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
472 $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
473 $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
474 $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
475 $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
476
477 $params = $_POST;
478 if ($sort && $sortOrder) {
479 $params['sortBy'] = $sort . ' ' . $sortOrder;
480 }
481
482 $params['page'] = ($offset / $rowCount) + 1;
483 $params['rp'] = $rowCount;
484
485 $params['contact_id'] = $contactID;
486 $params['context'] = $context;
487
488 // get the contact activities
489 $activities = CRM_Activity_BAO_Activity::getContactActivitySelector($params);
490
491 foreach ($activities as $key => $value) {
492 //Check if recurring activity
493 if (!empty($value['is_recurring_activity'])) {
494 if ($key == $value['is_recurring_activity']) {
495 $activities[$key]['activity_type'] = $activities[$key]['activity_type'] . '<br/><span class="bold">Recurring Activity - (Parent)</span>';
496 }
497 else {
498 $activities[$key]['activity_type'] = $activities[$key]['activity_type'] . '<br/><span class="bold">Recurring Activity - (Child)</span>';
499 }
500 }
501 }
502
503 // store the activity filter preference CRM-11761
504 $session = CRM_Core_Session::singleton();
505 $userID = $session->get('userID');
506 if ($userID) {
507 //flush cache before setting filter to account for global cache (memcache)
508 $domainID = CRM_Core_Config::domainID();
509 $cacheKey = CRM_Core_BAO_Setting::inCache(
510 CRM_Core_BAO_Setting::PERSONAL_PREFERENCES_NAME,
511 'activity_tab_filter',
512 NULL,
513 $userID,
514 TRUE,
515 $domainID,
516 TRUE
517 );
518 if ($cacheKey) {
519 CRM_Core_BAO_Setting::flushCache($cacheKey);
520 }
521
522 $activityFilter = array(
523 'activity_type_filter_id' => empty($params['activity_type_id']) ? '' : CRM_Utils_Type::escape($params['activity_type_id'], 'Integer'),
524 'activity_type_exclude_filter_id' => empty($params['activity_type_exclude_id']) ? '' : CRM_Utils_Type::escape($params['activity_type_exclude_id'], 'Integer'),
525 );
526
527 CRM_Core_BAO_Setting::setItem(
528 $activityFilter,
529 CRM_Core_BAO_Setting::PERSONAL_PREFERENCES_NAME,
530 'activity_tab_filter',
531 NULL,
532 $userID,
533 $userID
534 );
535 }
536
537 $iFilteredTotal = $iTotal = $params['total'];
538 $selectorElements = array(
539 'activity_type',
540 'subject',
541 'source_contact',
542 'target_contact',
543 'assignee_contact',
544 'activity_date',
545 'status',
546 'links',
547 'class',
548 );
549
550 header('Content-Type: application/json');
551 echo CRM_Utils_JSON::encodeDataTableSelector($activities, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
552 CRM_Utils_System::civiExit();
553 }
554
555 }