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