Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * |
33 | */ | |
34 | ||
35 | /** | |
36 | * This class contains all the function that are called using AJAX (jQuery) | |
37 | */ | |
38 | class CRM_Activity_Page_AJAX { | |
00be9182 | 39 | public static function getCaseActivity() { |
353ffa53 | 40 | $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer'); |
6a488035 | 41 | $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer'); |
353ffa53 TO |
42 | $userID = CRM_Utils_Type::escape($_GET['userID'], 'Integer'); |
43 | $context = CRM_Utils_Type::escape(CRM_Utils_Array::value('context', $_GET), 'String'); | |
6a488035 TO |
44 | |
45 | $sortMapper = array( | |
32864ccf | 46 | 0 => 'display_date', |
353ffa53 TO |
47 | 1 => 'ca.subject', |
48 | 2 => 'ca.activity_type_id', | |
32864ccf | 49 | 3 => 'acc.sort_name', |
353ffa53 TO |
50 | 4 => 'cc.sort_name', |
51 | 5 => 'ca.status_id', | |
6a488035 TO |
52 | ); |
53 | ||
353ffa53 TO |
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; | |
6a488035 TO |
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']; | |
353ffa53 TO |
72 | $selectorElements = array( |
73 | 'display_date', | |
74 | 'subject', | |
75 | 'type', | |
76 | 'with_contacts', | |
77 | 'reporter', | |
78 | 'status', | |
79 | 'links', | |
79d7553f | 80 | 'class', |
353ffa53 | 81 | ); |
6a488035 TO |
82 | |
83 | echo CRM_Utils_JSON::encodeDataTableSelector($activities, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); | |
84 | CRM_Utils_System::civiExit(); | |
85 | } | |
86 | ||
00be9182 | 87 | public static function getCaseGlobalRelationships() { |
6a488035 | 88 | $sortMapper = array( |
32864ccf | 89 | 0 => 'sort_name', |
353ffa53 TO |
90 | 1 => 'phone', |
91 | 2 => 'email', | |
6a488035 | 92 | ); |
1d85d241 | 93 | |
353ffa53 TO |
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; | |
6a488035 | 98 | $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; |
5b6db2c7 | 99 | |
6a488035 | 100 | $params = $_POST; |
5b6db2c7 | 101 | //CRM-14466 initialize variable to avoid php notice |
7a53d599 | 102 | $sortSQL = ""; |
6a488035 | 103 | if ($sort && $sortOrder) { |
86bfa4f6 | 104 | $sortSQL = $sort . ' ' . $sortOrder; |
6a488035 | 105 | } |
1d85d241 | 106 | |
6a488035 TO |
107 | // get the activities related to given case |
108 | $globalGroupInfo = array(); | |
1d85d241 | 109 | |
6a488035 TO |
110 | // get the total row count |
111 | $relGlobalTotalCount = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo, NULL, FALSE, TRUE, NULL, NULL); | |
112 | // limit the rows | |
1d85d241 DL |
113 | $relGlobal = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo, $sortSQL, $showLinks = TRUE, FALSE, $offset, $rowCount); |
114 | ||
6a488035 TO |
115 | $iFilteredTotal = $iTotal = $relGlobalTotalCount; |
116 | $selectorElements = array('sort_name', 'phone', 'email'); | |
1d85d241 | 117 | |
6a488035 TO |
118 | echo CRM_Utils_JSON::encodeDataTableSelector($relGlobal, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); |
119 | CRM_Utils_System::civiExit(); | |
1d85d241 DL |
120 | } |
121 | ||
00be9182 | 122 | public static function getCaseClientRelationships() { |
353ffa53 | 123 | $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer'); |
6a488035 | 124 | $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer'); |
1d85d241 | 125 | |
6a488035 | 126 | $sortMapper = array( |
32864ccf | 127 | 0 => 'relation', |
353ffa53 TO |
128 | 1 => 'name', |
129 | 2 => 'phone', | |
130 | 3 => 'email', | |
6a488035 | 131 | ); |
1d85d241 | 132 | |
353ffa53 TO |
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'; | |
6a488035 | 137 | $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; |
1d85d241 | 138 | |
6a488035 TO |
139 | $params = $_POST; |
140 | if ($sort && $sortOrder) { | |
86bfa4f6 | 141 | $sortSQL = $sort . ' ' . $sortOrder; |
6a488035 TO |
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 | ); | |
1d85d241 | 149 | |
6a488035 | 150 | $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID); |
1d85d241 | 151 | |
6a488035 TO |
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 | } | |
1d85d241 | 160 | |
6a488035 TO |
161 | // sort clientRelationships array using jquery call params |
162 | foreach ($clientRelationships as $key => $row) { | |
353ffa53 | 163 | $sortArray[$key] = $row[$sort]; |
6a488035 | 164 | } |
0e2079a1 CW |
165 | $sort_type = "SORT_" . strtoupper($sortOrder); |
166 | array_multisort($sortArray, constant($sort_type), $clientRelationships); | |
1d85d241 | 167 | |
6a488035 TO |
168 | //limit the rows |
169 | $allClientRelationships = $clientRelationships; | |
170 | $clientRelationships = array_slice($allClientRelationships, $offset, $rowCount, TRUE); | |
1d85d241 | 171 | |
6a488035 | 172 | // after sort we can update username fields to be a url |
22e263ad | 173 | foreach ($clientRelationships as $key => $value) { |
92fcb95f | 174 | $clientRelationships[$key]['name'] = '<a href=' . CRM_Utils_System::url('civicrm/contact/view', |
353ffa53 | 175 | 'action=view&reset=1&cid=' . $clientRelationships[$key]['cid']) . '>' . $clientRelationships[$key]['name'] . '</a>'; |
6a488035 | 176 | } |
1d85d241 | 177 | |
6a488035 TO |
178 | $iFilteredTotal = $iTotal = $params['total'] = count($allClientRelationships); |
179 | $selectorElements = array('relation', 'name', 'phone', 'email'); | |
1d85d241 | 180 | |
6a488035 TO |
181 | echo CRM_Utils_JSON::encodeDataTableSelector($clientRelationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); |
182 | CRM_Utils_System::civiExit(); | |
1d85d241 DL |
183 | } |
184 | ||
185 | ||
00be9182 | 186 | public static function getCaseRoles() { |
353ffa53 | 187 | $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer'); |
6a488035 | 188 | $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer'); |
1d85d241 | 189 | |
6a488035 | 190 | $sortMapper = array( |
32864ccf | 191 | 0 => 'relation', |
353ffa53 TO |
192 | 1 => 'name', |
193 | 2 => 'phone', | |
194 | 3 => 'email', | |
195 | 4 => 'actions', | |
6a488035 | 196 | ); |
1d85d241 | 197 | |
353ffa53 TO |
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'; | |
6a488035 | 202 | $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; |
1d85d241 | 203 | |
6a488035 TO |
204 | $params = $_POST; |
205 | if ($sort && $sortOrder) { | |
86bfa4f6 | 206 | $sortSQL = $sort . ' ' . $sortOrder; |
6a488035 TO |
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(); | |
353ffa53 | 212 | $caseRoles = $xmlProcessor->get($caseTypeName, 'CaseRoles'); |
1d85d241 | 213 | |
6a488035 | 214 | $hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities'); |
1d85d241 | 215 | |
6a488035 TO |
216 | $managerRoleId = $xmlProcessor->getCaseManagerRoleId($caseTypeName); |
217 | if (!empty($managerRoleId)) { | |
218 | $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')'; | |
219 | } | |
1d85d241 | 220 | |
6a488035 TO |
221 | foreach ($caseRelationships as $key => $value) { |
222 | //calculate roles that don't have relationships | |
a7488080 | 223 | if (!empty($caseRoles[$value['relation_type']])) { |
6a488035 TO |
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 | } | |
1d85d241 | 231 | |
6a488035 TO |
232 | $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($caseID); |
233 | ||
234 | // move/transform caseRoles array data to caseRelationships | |
235 | // for sorting and display | |
5b6db2c7 | 236 | // CRM-14466 added cid to the non-client array to avoid php notice |
22e263ad | 237 | foreach ($caseRoles as $id => $value) { |
6a488035 TO |
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; | |
0db6c3e1 TO |
247 | } |
248 | else { | |
22e263ad | 249 | foreach ($value as $clientRole) { |
6a488035 TO |
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) { | |
353ffa53 | 264 | $sortArray[$key] = $row[$sort]; |
6a488035 TO |
265 | } |
266 | ||
0e2079a1 CW |
267 | $sort_type = "SORT_" . strtoupper($sortOrder); |
268 | array_multisort($sortArray, constant($sort_type), $caseRelationships); | |
6a488035 TO |
269 | |
270 | //limit rows display | |
271 | $allCaseRelationships = $caseRelationships; | |
272 | $caseRelationships = array_slice($allCaseRelationships, $offset, $rowCount, TRUE); | |
5b6db2c7 | 273 | |
6a488035 TO |
274 | // set user name, email and edit columns links |
275 | // idx will count number of current row / needed by edit links | |
276 | $idx = 1; | |
c91df8b4 CW |
277 | foreach ($caseRelationships as &$row) { |
278 | // Get rid of the "<br />(Case Manager)" from label | |
279 | list($typeLabel) = explode('<', $row['relation']); | |
6a488035 | 280 | // view user links |
3662628a | 281 | if (!empty($row['cid'])) { |
86bfa4f6 | 282 | $row['name'] = '<a class="view-contact" title="' . ts('View Contact') . '" href=' . CRM_Utils_System::url('civicrm/contact/view', |
353ffa53 | 283 | 'action=view&reset=1&cid=' . $row['cid']) . '>' . $row['name'] . '</a>'; |
5b6db2c7 | 284 | } |
6a488035 | 285 | // email column links/icon |
c91df8b4 | 286 | if ($row['email']) { |
86bfa4f6 | 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>'; |
6a488035 TO |
288 | } |
289 | // edit links | |
3662628a | 290 | $row['actions'] = ''; |
6a488035 | 291 | if ($hasAccessToAllCases) { |
e3756c36 CW |
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; | |
22e263ad | 294 | switch ($row['source']) { |
32864ccf | 295 | case 'caseRel': |
79d7553f | 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') . '">' . | |
52604b19 | 298 | '<span class="icon ui-icon-pencil"></span>' . |
353ffa53 TO |
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') . '">' . | |
92fcb95f | 301 | '<span class="icon delete-icon"></span>' . |
353ffa53 | 302 | '</a>'; |
32864ccf | 303 | break; |
1d85d241 | 304 | |
32864ccf | 305 | case 'caseRoles': |
79d7553f | 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') . '">' . | |
52604b19 | 308 | '<span class="icon ui-icon-pencil"></span>' . |
353ffa53 | 309 | '</a>'; |
32864ccf | 310 | break; |
6a488035 | 311 | } |
6a488035 TO |
312 | } |
313 | $idx++; | |
314 | } | |
315 | $iFilteredTotal = $iTotal = $params['total'] = count($allCaseRelationships); | |
316 | $selectorElements = array('relation', 'name', 'phone', 'email', 'actions'); | |
ffd93213 | 317 | |
6a488035 TO |
318 | echo CRM_Utils_JSON::encodeDataTableSelector($caseRelationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); |
319 | CRM_Utils_System::civiExit(); | |
1d85d241 DL |
320 | } |
321 | ||
00be9182 | 322 | public static function convertToCaseActivity() { |
6a488035 | 323 | $params = array('caseID', 'activityID', 'contactID', 'newSubject', 'targetContactIds', 'mode'); |
ecdef330 | 324 | $vals = array(); |
6a488035 TO |
325 | foreach ($params as $param) { |
326 | $vals[$param] = CRM_Utils_Array::value($param, $_POST); | |
327 | } | |
328 | ||
ecdef330 | 329 | CRM_Utils_JSON::output(self::_convertToCaseActivity($vals)); |
6a488035 TO |
330 | } |
331 | ||
ffd93213 | 332 | /** |
c490a46a | 333 | * @param array $params |
ffd93213 EM |
334 | * |
335 | * @return array | |
336 | */ | |
00be9182 | 337 | public static function _convertToCaseActivity($params) { |
6a488035 TO |
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 | |
7b1ec1c6 | 373 | * then just change the subject. |
374 | */ | |
6a488035 TO |
375 | |
376 | if (in_array($params['mode'], array( | |
353ffa53 | 377 | 'move', |
79d7553f | 378 | 'file', |
353ffa53 | 379 | ))) { |
6a488035 TO |
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( | |
21dfd5f5 | 388 | 1 => $params['caseID'], |
7b1ec1c6 | 389 | )) . ' ' . $otherActivity->subject; |
6a488035 TO |
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 | } | |
f813f78e | 402 | |
e7e657f0 | 403 | $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); |
a24b3694 | 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 | ||
7b1ec1c6 | 408 | $sourceContactID = CRM_Activity_BAO_Activity::getSourceContactID($params['activityID']); |
409 | $src_params = array( | |
410 | 'activity_id' => $mainActivityId, | |
411 | 'contact_id' => $sourceContactID, | |
21dfd5f5 | 412 | 'record_type_id' => $sourceID, |
7b1ec1c6 | 413 | ); |
414 | CRM_Activity_BAO_ActivityContact::create($src_params); | |
415 | ||
6a488035 TO |
416 | foreach ($targetContacts as $key => $value) { |
417 | $targ_params = array( | |
418 | 'activity_id' => $mainActivityId, | |
1d85d241 | 419 | 'contact_id' => $value, |
21dfd5f5 | 420 | 'record_type_id' => $targetID, |
6a488035 | 421 | ); |
1d85d241 | 422 | CRM_Activity_BAO_ActivityContact::create($targ_params); |
6a488035 TO |
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, | |
1d85d241 | 433 | 'contact_id' => $value, |
21dfd5f5 | 434 | 'record_type_id' => $assigneeID, |
6a488035 | 435 | ); |
1d85d241 | 436 | CRM_Activity_BAO_ActivityContact::create($assigneeParams); |
6a488035 TO |
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 | ||
00be9182 | 453 | public static function getContactActivity() { |
6a488035 TO |
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( | |
f3548d18 BS |
458 | 0 => 'activity_type', |
459 | 1 => 'subject', | |
460 | 2 => 'source_contact_name', | |
461 | 3 => '', | |
8c7ca479 | 462 | 4 => '', |
463 | 5 => 'activity_date_time', | |
464 | 6 => 'status_id', | |
6a488035 TO |
465 | ); |
466 | ||
f3548d18 BS |
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; | |
6a488035 TO |
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 | ||
97c7504f | 487 | foreach ($activities as $key => $value) { |
488 | //Check if recurring activity | |
b53cbfbc | 489 | if (!empty($value['is_recurring_activity'])) { |
97c7504f | 490 | if ($key == $value['is_recurring_activity']) { |
92fcb95f | 491 | $activities[$key]['activity_type'] = $activities[$key]['activity_type'] . '<br/><span class="bold">Recurring Activity - (Parent)</span>'; |
97c7504f | 492 | } |
493 | else { | |
92fcb95f | 494 | $activities[$key]['activity_type'] = $activities[$key]['activity_type'] . '<br/><span class="bold">Recurring Activity - (Child)</span>'; |
97c7504f | 495 | } |
496 | } | |
497 | } | |
498 | ||
6a488035 TO |
499 | // store the activity filter preference CRM-11761 |
500 | $session = CRM_Core_Session::singleton(); | |
501 | $userID = $session->get('userID'); | |
502 | if ($userID) { | |
f3548d18 BS |
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 | ); | |
481a74f4 | 514 | if ($cacheKey) { |
f3548d18 BS |
515 | CRM_Core_BAO_Setting::flushCache($cacheKey); |
516 | } | |
517 | ||
518 | $activityFilter = array( | |
32864ccf TO |
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'), | |
f3548d18 BS |
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 | ); | |
6a488035 | 531 | } |
1d85d241 | 532 | |
6a488035 TO |
533 | $iFilteredTotal = $iTotal = $params['total']; |
534 | $selectorElements = array( | |
353ffa53 TO |
535 | 'activity_type', |
536 | 'subject', | |
537 | 'source_contact', | |
538 | 'target_contact', | |
539 | 'assignee_contact', | |
540 | 'activity_date', | |
541 | 'status', | |
542 | 'links', | |
543 | 'class', | |
6a488035 TO |
544 | ); |
545 | ||
546 | echo CRM_Utils_JSON::encodeDataTableSelector($activities, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); | |
547 | CRM_Utils_System::civiExit(); | |
548 | } | |
96025800 | 549 | |
6a488035 | 550 | } |