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