Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * |
33 | */ | |
34 | ||
35 | /** | |
36 | * This class contains all contact related functions that are called using AJAX (jQuery) | |
37 | */ | |
38 | class CRM_Contact_Page_AJAX { | |
272081ca TO |
39 | /** |
40 | * When a user chooses a username, CHECK_USERNAME_TTL | |
41 | * is the time window in which they can check usernames | |
42 | * (without reloading the overall form). | |
43 | */ | |
44 | const CHECK_USERNAME_TTL = 10800; // 3hr; 3*60*60 | |
45 | ||
b1dba111 TO |
46 | const AUTOCOMPLETE_TTL = 21600; // 6hr; 6*60*60 |
47 | ||
06508628 | 48 | /** |
06508628 CW |
49 | * Ajax callback for custom fields of type ContactReference |
50 | * | |
51 | * Todo: Migrate contact reference fields to use EntityRef | |
52 | */ | |
00be9182 | 53 | public static function contactReference() { |
06508628 | 54 | $name = CRM_Utils_Array::value('term', $_GET); |
6a488035 TO |
55 | $name = CRM_Utils_Type::escape($name, 'String'); |
56 | $cfID = CRM_Utils_Type::escape($_GET['id'], 'Positive'); | |
57 | ||
58 | // check that this is a valid, active custom field of Contact Reference type | |
06508628 | 59 | $params = array('id' => $cfID); |
6a488035 | 60 | $returnProperties = array('filter', 'data_type', 'is_active'); |
06508628 | 61 | $cf = array(); |
6a488035 | 62 | CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $cf, $returnProperties); |
a4cce21a | 63 | if (!$cf['id'] || !$cf['is_active'] || $cf['data_type'] != 'ContactReference') { |
06508628 | 64 | CRM_Utils_System::civiExit('error'); |
6a488035 TO |
65 | } |
66 | ||
9624538c | 67 | if (!empty($cf['filter'])) { |
6a488035 TO |
68 | $filterParams = array(); |
69 | parse_str($cf['filter'], $filterParams); | |
70 | ||
71 | $action = CRM_Utils_Array::value('action', $filterParams); | |
72 | ||
73 | if (!empty($action) && | |
74 | !in_array($action, array('get', 'lookup')) | |
75 | ) { | |
06508628 | 76 | CRM_Utils_System::civiExit('error'); |
6a488035 TO |
77 | } |
78 | } | |
79 | ||
80 | $list = array_keys(CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, | |
353ffa53 TO |
81 | 'contact_reference_options' |
82 | ), '1'); | |
6a488035 TO |
83 | |
84 | $return = array_unique(array_merge(array('sort_name'), $list)); | |
85 | ||
06508628 | 86 | $limit = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'search_autocomplete_count', NULL, 10); |
6a488035 TO |
87 | |
88 | $params = array('offset' => 0, 'rowCount' => $limit, 'version' => 3); | |
89 | foreach ($return as $fld) { | |
90 | $params["return.{$fld}"] = 1; | |
91 | } | |
92 | ||
93 | if (!empty($action)) { | |
353ffa53 TO |
94 | $excludeGet = array( |
95 | 'reset', | |
96 | 'key', | |
97 | 'className', | |
98 | 'fnName', | |
99 | 'json', | |
100 | 'reset', | |
101 | 'context', | |
102 | 'timestamp', | |
103 | 'limit', | |
104 | 'id', | |
105 | 's', | |
106 | 'q', | |
408b79bf | 107 | 'action', |
353ffa53 | 108 | ); |
6a488035 TO |
109 | foreach ($_GET as $param => $val) { |
110 | if (empty($val) || | |
111 | in_array($param, $excludeGet) || | |
112 | strpos($param, 'return.') !== FALSE || | |
113 | strpos($param, 'api.') !== FALSE | |
114 | ) { | |
115 | continue; | |
116 | } | |
117 | $params[$param] = $val; | |
118 | } | |
119 | } | |
120 | ||
121 | if ($name) { | |
122 | $params['sort_name'] = $name; | |
123 | } | |
124 | ||
125 | $params['sort'] = 'sort_name'; | |
126 | ||
127 | // tell api to skip permission chk. dgg | |
128 | $params['check_permissions'] = 0; | |
129 | ||
130 | // add filter variable to params | |
131 | if (!empty($filterParams)) { | |
132 | $params = array_merge($params, $filterParams); | |
133 | } | |
134 | ||
135 | $contact = civicrm_api('Contact', 'Get', $params); | |
136 | ||
a7488080 | 137 | if (!empty($contact['is_error'])) { |
06508628 | 138 | CRM_Utils_System::civiExit('error'); |
6a488035 TO |
139 | } |
140 | ||
d6408252 | 141 | $contactList = array(); |
6a488035 TO |
142 | foreach ($contact['values'] as $value) { |
143 | $view = array(); | |
144 | foreach ($return as $fld) { | |
a7488080 | 145 | if (!empty($value[$fld])) { |
6a488035 TO |
146 | $view[] = $value[$fld]; |
147 | } | |
148 | } | |
06508628 | 149 | $contactList[] = array('id' => $value['id'], 'text' => implode(' :: ', $view)); |
6a488035 TO |
150 | } |
151 | ||
8be1a839 | 152 | CRM_Utils_JSON::output($contactList); |
6a488035 TO |
153 | } |
154 | ||
155 | /** | |
100fef9d | 156 | * Fetch PCP ID by PCP Supporter sort_name, also displays PCP title and associated Contribution Page title |
6a488035 | 157 | */ |
00be9182 | 158 | public static function getPCPList() { |
7d86179d | 159 | $name = CRM_Utils_Array::value('term', $_GET); |
353ffa53 | 160 | $name = CRM_Utils_Type::escape($name, 'String'); |
8da35492 | 161 | $limit = $max = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'search_autocomplete_count', NULL, 10); |
6a488035 TO |
162 | |
163 | $where = ' AND pcp.page_id = cp.id AND pcp.contact_id = cc.id'; | |
164 | ||
165 | $config = CRM_Core_Config::singleton(); | |
166 | if ($config->includeWildCardInName) { | |
167 | $strSearch = "%$name%"; | |
168 | } | |
169 | else { | |
170 | $strSearch = "$name%"; | |
171 | } | |
172 | $includeEmailFrom = $includeNickName = ''; | |
173 | if ($config->includeNickNameInName) { | |
174 | $includeNickName = " OR nick_name LIKE '$strSearch'"; | |
175 | } | |
176 | if ($config->includeEmailInName) { | |
177 | $includeEmailFrom = "LEFT JOIN civicrm_email eml ON ( cc.id = eml.contact_id AND eml.is_primary = 1 )"; | |
178 | $whereClause = " WHERE ( email LIKE '$strSearch' OR sort_name LIKE '$strSearch' $includeNickName ) {$where} "; | |
179 | } | |
180 | else { | |
181 | $whereClause = " WHERE ( sort_name LIKE '$strSearch' $includeNickName ) {$where} "; | |
182 | } | |
183 | ||
8da35492 | 184 | $offset = $count = 0; |
4feb1cad CW |
185 | if (!empty($_GET['page_num'])) { |
186 | $page = (int) $_GET['page_num']; | |
8da35492 CW |
187 | $offset = $limit * ($page - 1); |
188 | $limit++; | |
6a488035 TO |
189 | } |
190 | ||
191 | $select = 'cc.sort_name, pcp.title, cp.title'; | |
192 | $query = " | |
193 | SELECT id, data | |
194 | FROM ( | |
195 | SELECT pcp.id as id, CONCAT_WS( ' :: ', {$select} ) as data, sort_name | |
196 | FROM civicrm_pcp pcp, civicrm_contribution_page cp, civicrm_contact cc | |
197 | {$includeEmailFrom} | |
900e6829 | 198 | {$whereClause} AND pcp.page_type = 'contribute' |
199 | UNION ALL | |
200 | SELECT pcp.id as id, CONCAT_WS( ' :: ', {$select} ) as data, sort_name | |
201 | FROM civicrm_pcp pcp, civicrm_event cp, civicrm_contact cc | |
202 | {$includeEmailFrom} | |
203 | {$whereClause} AND pcp.page_type = 'event' | |
6a488035 TO |
204 | ) t |
205 | ORDER BY sort_name | |
8da35492 | 206 | LIMIT $offset, $limit |
6a488035 TO |
207 | "; |
208 | ||
209 | $dao = CRM_Core_DAO::executeQuery($query); | |
8da35492 | 210 | $output = array('results' => array(), 'more' => FALSE); |
6a488035 | 211 | while ($dao->fetch()) { |
8da35492 CW |
212 | if (++$count > $max) { |
213 | $output['more'] = TRUE; | |
214 | } | |
215 | else { | |
216 | $output['results'][] = array('id' => $dao->id, 'text' => $dao->data); | |
217 | } | |
6a488035 | 218 | } |
8da35492 | 219 | CRM_Utils_JSON::output($output); |
6a488035 TO |
220 | } |
221 | ||
00be9182 | 222 | public static function relationship() { |
c91df8b4 CW |
223 | $relType = CRM_Utils_Request::retrieve('rel_type', 'Positive', CRM_Core_DAO::$_nullObject, TRUE); |
224 | $relContactID = CRM_Utils_Request::retrieve('rel_contact', 'Positive', CRM_Core_DAO::$_nullObject, TRUE); | |
7fa9167d | 225 | $relationshipID = CRM_Utils_Request::retrieve('rel_id', 'Positive', CRM_Core_DAO::$_nullObject); // this used only to determine add or update mode |
c91df8b4 | 226 | $caseID = CRM_Utils_Request::retrieve('case_id', 'Positive', CRM_Core_DAO::$_nullObject, TRUE); |
6a488035 | 227 | |
14a679f1 KJ |
228 | // check if there are multiple clients for this case, if so then we need create |
229 | // relationship and also activities for each contacts | |
6a488035 | 230 | |
14a679f1 KJ |
231 | // get case client list |
232 | $clientList = CRM_Case_BAO_Case::getCaseClients($caseID); | |
6a488035 | 233 | |
c91df8b4 CW |
234 | $ret = array('is_error' => 0); |
235 | ||
22e263ad | 236 | foreach ($clientList as $sourceContactID) { |
14a679f1 KJ |
237 | $relationParams = array( |
238 | 'relationship_type_id' => $relType . '_a_b', | |
239 | 'contact_check' => array($relContactID => 1), | |
240 | 'is_active' => 1, | |
241 | 'case_id' => $caseID, | |
242 | 'start_date' => date("Ymd"), | |
6a488035 TO |
243 | ); |
244 | ||
14a679f1 KJ |
245 | $relationIds = array('contact' => $sourceContactID); |
246 | ||
247 | // check if we are editing/updating existing relationship | |
248 | if ($relationshipID && $relationshipID != 'null') { | |
249 | // here we need to retrieve appropriate relationshipID based on client id and relationship type id | |
250 | $caseRelationships = new CRM_Contact_DAO_Relationship(); | |
251 | $caseRelationships->case_id = $caseID; | |
252 | $caseRelationships->relationship_type_id = $relType; | |
253 | $caseRelationships->contact_id_a = $sourceContactID; | |
254 | $caseRelationships->find(); | |
255 | ||
22e263ad | 256 | while ($caseRelationships->fetch()) { |
14a679f1 KJ |
257 | $relationIds['relationship'] = $caseRelationships->id; |
258 | $relationIds['contactTarget'] = $relContactID; | |
259 | } | |
260 | $caseRelationships->free(); | |
261 | } | |
262 | ||
263 | // create new or update existing relationship | |
2da59b29 | 264 | $return = CRM_Contact_BAO_Relationship::legacyCreateMultiple($relationParams, $relationIds); |
14a679f1 | 265 | |
a7488080 | 266 | if (!empty($return[4][0])) { |
14a679f1 | 267 | $relationshipID = $return[4][0]; |
14a679f1 KJ |
268 | |
269 | //create an activity for case role assignment.CRM-4480 | |
270 | CRM_Case_BAO_Case::createCaseRoleActivity($caseID, $relationshipID, $relContactID); | |
271 | } | |
c91df8b4 CW |
272 | else { |
273 | $ret = array( | |
274 | 'is_error' => 1, | |
275 | 'error_message' => ts('The relationship type definition for the case role is not valid for the client and / or staff contact types. You can review and edit relationship types at <a href="%1">Administer >> Option Lists >> Relationship Types</a>.', | |
21dfd5f5 | 276 | array(1 => CRM_Utils_System::url('civicrm/admin/reltype', 'reset=1'))), |
c91df8b4 CW |
277 | ); |
278 | } | |
6a488035 | 279 | } |
6a488035 | 280 | |
ecdef330 | 281 | CRM_Utils_JSON::output($ret); |
6a488035 TO |
282 | } |
283 | ||
284 | /** | |
fe482240 | 285 | * Fetch the custom field help. |
6a488035 | 286 | */ |
00be9182 | 287 | public static function customField() { |
353ffa53 TO |
288 | $fieldId = CRM_Utils_Type::escape($_REQUEST['id'], 'Integer'); |
289 | $params = array('id' => $fieldId); | |
6a488035 | 290 | $returnProperties = array('help_pre', 'help_post'); |
353ffa53 | 291 | $values = array(); |
6a488035 TO |
292 | |
293 | CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $values, $returnProperties); | |
ecdef330 | 294 | CRM_Utils_JSON::output($values); |
6a488035 TO |
295 | } |
296 | ||
00be9182 | 297 | public static function groupTree() { |
d42a224c | 298 | CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); |
6a488035 TO |
299 | $gids = CRM_Utils_Type::escape($_GET['gids'], 'String'); |
300 | echo CRM_Contact_BAO_GroupNestingCache::json($gids); | |
301 | CRM_Utils_System::civiExit(); | |
302 | } | |
303 | ||
6a488035 | 304 | /** |
fe482240 | 305 | * Delete custom value. |
6a488035 | 306 | */ |
00be9182 | 307 | public static function deleteCustomValue() { |
d42a224c | 308 | CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain'); |
6a488035 TO |
309 | $customValueID = CRM_Utils_Type::escape($_REQUEST['valueID'], 'Positive'); |
310 | $customGroupID = CRM_Utils_Type::escape($_REQUEST['groupID'], 'Positive'); | |
015bf0da | 311 | $contactId = CRM_Utils_Request::retrieve('contactId', 'Positive', CRM_Core_DAO::$_nullObject); |
6a488035 | 312 | CRM_Core_BAO_CustomValue::deleteCustomValue($customValueID, $customGroupID); |
a4cce21a | 313 | if ($contactId) { |
7fa9167d | 314 | echo CRM_Contact_BAO_Contact::getCountComponent('custom_' . $customGroupID, $contactId); |
6a488035 TO |
315 | } |
316 | ||
317 | // reset the group contact cache for this group | |
318 | CRM_Contact_BAO_GroupContactCache::remove(); | |
319 | CRM_Utils_System::civiExit(); | |
320 | } | |
321 | ||
6a488035 | 322 | /** |
fe482240 | 323 | * check the CMS username. |
ce80b209 | 324 | */ |
6a488035 | 325 | static public function checkUserName() { |
272081ca | 326 | $signer = new CRM_Utils_Signer(CRM_Core_Key::privateKey(), array('for', 'ts')); |
7fa9167d | 327 | $sig = CRM_Utils_Request::retrieve('sig', 'String', CRM_Core_DAO::$_nullObject); |
328 | $for = CRM_Utils_Request::retrieve('for', 'String', CRM_Core_DAO::$_nullObject); | |
272081ca TO |
329 | if ( |
330 | CRM_Utils_Time::getTimeRaw() > $_REQUEST['ts'] + self::CHECK_USERNAME_TTL | |
7fa9167d | 331 | || $for != 'civicrm/ajax/cmsuser' |
332 | || !$signer->validate($sig, $_REQUEST) | |
272081ca TO |
333 | ) { |
334 | $user = array('name' => 'error'); | |
8be1a839 | 335 | CRM_Utils_JSON::output($user); |
272081ca TO |
336 | } |
337 | ||
6a488035 | 338 | $config = CRM_Core_Config::singleton(); |
4c68cf7b | 339 | $username = trim(CRM_Utils_Array::value('cms_name', $_REQUEST)); |
6a488035 TO |
340 | |
341 | $params = array('name' => $username); | |
342 | ||
343 | $errors = array(); | |
344 | $config->userSystem->checkUserNameEmailExists($params, $errors); | |
345 | ||
346 | if (isset($errors['cms_name']) || isset($errors['name'])) { | |
b44e3f84 | 347 | //user name is not available |
6a488035 | 348 | $user = array('name' => 'no'); |
8be1a839 | 349 | CRM_Utils_JSON::output($user); |
6a488035 TO |
350 | } |
351 | else { | |
352 | //user name is available | |
353 | $user = array('name' => 'yes'); | |
8be1a839 | 354 | CRM_Utils_JSON::output($user); |
6a488035 | 355 | } |
8be1a839 TO |
356 | |
357 | // Not reachable: JSON::output() above exits. | |
6a488035 TO |
358 | CRM_Utils_System::civiExit(); |
359 | } | |
360 | ||
361 | /** | |
fe482240 | 362 | * Function to get email address of a contact. |
6a488035 | 363 | */ |
00be9182 | 364 | public static function getContactEmail() { |
a7488080 | 365 | if (!empty($_REQUEST['contact_id'])) { |
6a488035 | 366 | $contactID = CRM_Utils_Type::escape($_REQUEST['contact_id'], 'Positive'); |
8c0ea1d7 TO |
367 | if (!CRM_Contact_BAO_Contact_Permission::allow($contactID, CRM_Core_Permission::EDIT)) { |
368 | return; | |
369 | } | |
6a488035 TO |
370 | list($displayName, |
371 | $userEmail | |
353ffa53 | 372 | ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); |
effdc2d9 | 373 | |
d42a224c | 374 | CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain'); |
6a488035 TO |
375 | if ($userEmail) { |
376 | echo $userEmail; | |
377 | } | |
378 | } | |
379 | else { | |
380 | $noemail = CRM_Utils_Array::value('noemail', $_GET); | |
381 | $queryString = NULL; | |
a4cce21a JM |
382 | $name = CRM_Utils_Array::value('name', $_GET); |
383 | if ($name) { | |
6a488035 TO |
384 | $name = CRM_Utils_Type::escape($name, 'String'); |
385 | if ($noemail) { | |
386 | $queryString = " cc.sort_name LIKE '%$name%'"; | |
387 | } | |
388 | else { | |
389 | $queryString = " ( cc.sort_name LIKE '%$name%' OR ce.email LIKE '%$name%' ) "; | |
390 | } | |
391 | } | |
a4cce21a | 392 | else { |
d75f2f47 EM |
393 | $cid = CRM_Utils_Array::value('cid', $_GET); |
394 | if ($cid) { | |
b44e3f84 | 395 | //check cid for integer |
a4cce21a JM |
396 | $contIDS = explode(',', $cid); |
397 | foreach ($contIDS as $contID) { | |
398 | CRM_Utils_Type::escape($contID, 'Integer'); | |
399 | } | |
400 | $queryString = " cc.id IN ( $cid )"; | |
d75f2f47 | 401 | } |
6a488035 TO |
402 | } |
403 | ||
404 | if ($queryString) { | |
405 | $offset = CRM_Utils_Array::value('offset', $_GET, 0); | |
cac1236c | 406 | $rowCount = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'search_autocomplete_count', NULL, 10); |
6a488035 | 407 | |
bf00d1b6 | 408 | $offset = CRM_Utils_Type::escape($offset, 'Int'); |
bf00d1b6 | 409 | |
6a488035 TO |
410 | // add acl clause here |
411 | list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause('cc'); | |
412 | if ($aclWhere) { | |
413 | $aclWhere = " AND $aclWhere"; | |
414 | } | |
415 | if ($noemail) { | |
416 | $query = " | |
417 | SELECT sort_name name, cc.id | |
418 | FROM civicrm_contact cc | |
419 | {$aclFrom} | |
420 | WHERE cc.is_deceased = 0 AND {$queryString} | |
421 | {$aclWhere} | |
422 | LIMIT {$offset}, {$rowCount} | |
423 | "; | |
424 | ||
425 | // send query to hook to be modified if needed | |
426 | CRM_Utils_Hook::contactListQuery($query, | |
427 | $name, | |
7fa9167d | 428 | CRM_Utils_Request::retrieve('context', 'String', CRM_Core_DAO::$_nullObject), |
429 | CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject) | |
6a488035 TO |
430 | ); |
431 | ||
432 | $dao = CRM_Core_DAO::executeQuery($query); | |
433 | while ($dao->fetch()) { | |
434 | $result[] = array( | |
6a488035 | 435 | 'id' => $dao->id, |
cac1236c | 436 | 'text' => $dao->name, |
6a488035 TO |
437 | ); |
438 | } | |
439 | } | |
440 | else { | |
441 | $query = " | |
442 | SELECT sort_name name, ce.email, cc.id | |
443 | FROM civicrm_email ce INNER JOIN civicrm_contact cc ON cc.id = ce.contact_id | |
444 | {$aclFrom} | |
445 | WHERE ce.on_hold = 0 AND cc.is_deceased = 0 AND cc.do_not_email = 0 AND {$queryString} | |
446 | {$aclWhere} | |
447 | LIMIT {$offset}, {$rowCount} | |
448 | "; | |
449 | ||
450 | // send query to hook to be modified if needed | |
451 | CRM_Utils_Hook::contactListQuery($query, | |
452 | $name, | |
7fa9167d | 453 | CRM_Utils_Request::retrieve('context', 'String', CRM_Core_DAO::$_nullObject), |
015bf0da | 454 | CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject) |
6a488035 TO |
455 | ); |
456 | ||
6a488035 TO |
457 | $dao = CRM_Core_DAO::executeQuery($query); |
458 | ||
459 | while ($dao->fetch()) { | |
ce80b209 | 460 | //working here |
6a488035 | 461 | $result[] = array( |
cac1236c | 462 | 'text' => '"' . $dao->name . '" <' . $dao->email . '>', |
6a488035 TO |
463 | 'id' => (CRM_Utils_Array::value('id', $_GET)) ? "{$dao->id}::{$dao->email}" : '"' . $dao->name . '" <' . $dao->email . '>', |
464 | ); | |
465 | } | |
466 | } | |
6a488035 | 467 | if ($result) { |
8be1a839 | 468 | CRM_Utils_JSON::output($result); |
6a488035 TO |
469 | } |
470 | } | |
471 | } | |
472 | CRM_Utils_System::civiExit(); | |
473 | } | |
474 | ||
00be9182 | 475 | public static function getContactPhone() { |
6a488035 TO |
476 | |
477 | $queryString = NULL; | |
478 | //check for mobile type | |
479 | $phoneTypes = CRM_Core_OptionGroup::values('phone_type', TRUE, FALSE, FALSE, NULL, 'name'); | |
480 | $mobileType = CRM_Utils_Array::value('Mobile', $phoneTypes); | |
481 | ||
a4cce21a JM |
482 | $name = CRM_Utils_Array::value('name', $_GET); |
483 | if ($name) { | |
6a488035 TO |
484 | $name = CRM_Utils_Type::escape($name, 'String'); |
485 | $queryString = " ( cc.sort_name LIKE '%$name%' OR cp.phone LIKE '%$name%' ) "; | |
486 | } | |
a4cce21a | 487 | else { |
d75f2f47 EM |
488 | $cid = CRM_Utils_Array::value('cid', $_GET); |
489 | if ($cid) { | |
b44e3f84 | 490 | //check cid for integer |
a4cce21a JM |
491 | $contIDS = explode(',', $cid); |
492 | foreach ($contIDS as $contID) { | |
493 | CRM_Utils_Type::escape($contID, 'Integer'); | |
494 | } | |
495 | $queryString = " cc.id IN ( $cid )"; | |
6a488035 | 496 | } |
6a488035 TO |
497 | } |
498 | ||
499 | if ($queryString) { | |
500 | $offset = CRM_Utils_Array::value('offset', $_GET, 0); | |
501 | $rowCount = CRM_Utils_Array::value('rowcount', $_GET, 20); | |
502 | ||
bf00d1b6 DL |
503 | $offset = CRM_Utils_Type::escape($offset, 'Int'); |
504 | $rowCount = CRM_Utils_Type::escape($rowCount, 'Int'); | |
505 | ||
6a488035 TO |
506 | // add acl clause here |
507 | list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause('cc'); | |
508 | if ($aclWhere) { | |
509 | $aclWhere = " AND $aclWhere"; | |
510 | } | |
511 | ||
512 | $query = " | |
513 | SELECT sort_name name, cp.phone, cc.id | |
514 | FROM civicrm_phone cp INNER JOIN civicrm_contact cc ON cc.id = cp.contact_id | |
515 | {$aclFrom} | |
516 | WHERE cc.is_deceased = 0 AND cc.do_not_sms = 0 AND cp.phone_type_id = {$mobileType} AND {$queryString} | |
517 | {$aclWhere} | |
518 | LIMIT {$offset}, {$rowCount} | |
519 | "; | |
520 | ||
521 | // send query to hook to be modified if needed | |
522 | CRM_Utils_Hook::contactListQuery($query, | |
523 | $name, | |
7fa9167d | 524 | CRM_Utils_Request::retrieve('context', 'String', CRM_Core_DAO::$_nullObject), |
015bf0da | 525 | CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject) |
6a488035 TO |
526 | ); |
527 | ||
528 | $dao = CRM_Core_DAO::executeQuery($query); | |
529 | ||
530 | while ($dao->fetch()) { | |
531 | $result[] = array( | |
b792e485 | 532 | 'text' => '"' . $dao->name . '" (' . $dao->phone . ')', |
6a488035 TO |
533 | 'id' => (CRM_Utils_Array::value('id', $_GET)) ? "{$dao->id}::{$dao->phone}" : '"' . $dao->name . '" <' . $dao->phone . '>', |
534 | ); | |
535 | } | |
536 | } | |
537 | ||
538 | if ($result) { | |
8be1a839 | 539 | CRM_Utils_JSON::output($result); |
6a488035 TO |
540 | } |
541 | CRM_Utils_System::civiExit(); | |
542 | } | |
543 | ||
544 | ||
00be9182 | 545 | public static function buildSubTypes() { |
7fa9167d | 546 | $parent = CRM_Utils_Request::retrieve('parentId', 'Positive', CRM_Core_DAO::$_nullObject); |
6a488035 TO |
547 | |
548 | switch ($parent) { | |
549 | case 1: | |
550 | $contactType = 'Individual'; | |
551 | break; | |
552 | ||
553 | case 2: | |
554 | $contactType = 'Household'; | |
555 | break; | |
556 | ||
557 | case 4: | |
558 | $contactType = 'Organization'; | |
559 | break; | |
560 | } | |
561 | ||
562 | $subTypes = CRM_Contact_BAO_ContactType::subTypePairs($contactType, FALSE, NULL); | |
563 | asort($subTypes); | |
ecdef330 | 564 | CRM_Utils_JSON::output($subTypes); |
6a488035 TO |
565 | } |
566 | ||
00be9182 | 567 | public static function buildDedupeRules() { |
015bf0da | 568 | $parent = CRM_Utils_Request::retrieve('parentId', 'Positive', CRM_Core_DAO::$_nullObject); |
6a488035 TO |
569 | |
570 | switch ($parent) { | |
571 | case 1: | |
572 | $contactType = 'Individual'; | |
573 | break; | |
574 | ||
575 | case 2: | |
576 | $contactType = 'Household'; | |
577 | break; | |
578 | ||
579 | case 4: | |
580 | $contactType = 'Organization'; | |
581 | break; | |
582 | } | |
583 | ||
584 | $dedupeRules = CRM_Dedupe_BAO_RuleGroup::getByType($contactType); | |
585 | ||
ecdef330 | 586 | CRM_Utils_JSON::output($dedupeRules); |
6a488035 TO |
587 | } |
588 | ||
589 | /** | |
fe482240 | 590 | * Function used for CiviCRM dashboard operations. |
6a488035 | 591 | */ |
00be9182 | 592 | public static function dashboard() { |
6a488035 TO |
593 | $operation = CRM_Utils_Type::escape($_REQUEST['op'], 'String'); |
594 | ||
595 | switch ($operation) { | |
596 | case 'get_widgets_by_column': | |
597 | // This would normally be coming from either the database (this user's settings) or a default/initial dashboard configuration. | |
598 | // get contact id of logged in user | |
599 | ||
600 | $dashlets = CRM_Core_BAO_Dashboard::getContactDashlets(); | |
601 | break; | |
602 | ||
603 | case 'get_widget': | |
604 | $dashletID = CRM_Utils_Type::escape($_GET['id'], 'Positive'); | |
605 | ||
606 | $dashlets = CRM_Core_BAO_Dashboard::getDashletInfo($dashletID); | |
607 | break; | |
608 | ||
609 | case 'save_columns': | |
610 | CRM_Core_BAO_Dashboard::saveDashletChanges($_REQUEST['columns']); | |
611 | CRM_Utils_System::civiExit(); | |
612 | case 'delete_dashlet': | |
613 | $dashletID = CRM_Utils_Type::escape($_REQUEST['dashlet_id'], 'Positive'); | |
614 | CRM_Core_BAO_Dashboard::deleteDashlet($dashletID); | |
615 | CRM_Utils_System::civiExit(); | |
616 | } | |
617 | ||
ecdef330 | 618 | CRM_Utils_JSON::output($dashlets); |
6a488035 TO |
619 | } |
620 | ||
621 | /** | |
fe482240 | 622 | * Retrieve signature based on email id. |
6a488035 | 623 | */ |
00be9182 | 624 | public static function getSignature() { |
6a488035 | 625 | $emailID = CRM_Utils_Type::escape($_REQUEST['emailID'], 'Positive'); |
353ffa53 TO |
626 | $query = "SELECT signature_text, signature_html FROM civicrm_email WHERE id = {$emailID}"; |
627 | $dao = CRM_Core_DAO::executeQuery($query); | |
6a488035 TO |
628 | |
629 | $signatures = array(); | |
630 | while ($dao->fetch()) { | |
631 | $signatures = array( | |
632 | 'signature_text' => $dao->signature_text, | |
633 | 'signature_html' => $dao->signature_html, | |
634 | ); | |
635 | } | |
636 | ||
ecdef330 | 637 | CRM_Utils_JSON::output($signatures); |
6a488035 TO |
638 | } |
639 | ||
640 | /** | |
100fef9d | 641 | * Process dupes. |
6a488035 | 642 | */ |
00be9182 | 643 | public static function processDupes() { |
6a488035 | 644 | $oper = CRM_Utils_Type::escape($_REQUEST['op'], 'String'); |
353ffa53 TO |
645 | $cid = CRM_Utils_Type::escape($_REQUEST['cid'], 'Positive'); |
646 | $oid = CRM_Utils_Type::escape($_REQUEST['oid'], 'Positive'); | |
6a488035 TO |
647 | |
648 | if (!$oper || !$cid || !$oid) { | |
649 | return; | |
650 | } | |
651 | ||
652 | $exception = new CRM_Dedupe_DAO_Exception(); | |
653 | $exception->contact_id1 = $cid; | |
654 | $exception->contact_id2 = $oid; | |
655 | //make sure contact2 > contact1. | |
656 | if ($cid > $oid) { | |
657 | $exception->contact_id1 = $oid; | |
658 | $exception->contact_id2 = $cid; | |
659 | } | |
660 | $exception->find(TRUE); | |
661 | $status = NULL; | |
662 | if ($oper == 'dupe-nondupe') { | |
663 | $status = $exception->save(); | |
664 | } | |
665 | if ($oper == 'nondupe-dupe') { | |
666 | $status = $exception->delete(); | |
667 | } | |
668 | ||
ecdef330 | 669 | CRM_Utils_JSON::output(array('status' => ($status) ? $oper : $status)); |
6a488035 TO |
670 | } |
671 | ||
183ec330 | 672 | /** |
673 | * Retrieve list of duplicate pairs from cache table. | |
674 | */ | |
00be9182 | 675 | public static function getDedupes() { |
63ef778e | 676 | $offset = isset($_REQUEST['start']) ? CRM_Utils_Type::escape($_REQUEST['start'], 'Integer') : 0; |
677 | $rowCount = isset($_REQUEST['length']) ? CRM_Utils_Type::escape($_REQUEST['length'], 'Integer') : 25; | |
6a488035 | 678 | |
63ef778e | 679 | $gid = isset($_REQUEST['gid']) ? CRM_Utils_Type::escape($_REQUEST['gid'], 'Integer') : 0; |
680 | $rgid = isset($_REQUEST['rgid']) ? CRM_Utils_Type::escape($_REQUEST['rgid'], 'Integer') : 0; | |
681 | $selected = isset($_REQUEST['selected']) ? CRM_Utils_Type::escape($_REQUEST['selected'], 'Integer') : 0; | |
682 | if ($rowCount < 0) { | |
683 | $rowCount = 0; | |
684 | } | |
6a488035 TO |
685 | $contactType = ''; |
686 | if ($rgid) { | |
687 | $contactType = CRM_Core_DAO::getFieldValue('CRM_Dedupe_DAO_RuleGroup', $rgid, 'contact_type'); | |
688 | } | |
689 | ||
63ef778e | 690 | $cacheKeyString = "merge {$contactType}_{$rgid}_{$gid}"; |
691 | $searchRows = array(); | |
692 | $selectorElements = array('is_selected', 'is_selected_input', 'src_image', 'src', 'src_email', 'src_street', 'src_postcode', 'dst_image', 'dst', 'dst_email', 'dst_street', 'dst_postcode', 'conflicts', 'weight', 'actions'); | |
6a488035 | 693 | |
63ef778e | 694 | foreach ($_REQUEST['columns'] as $columnInfo) { |
695 | if (!empty($columnInfo['search']['value'])) { | |
696 | ${$columnInfo['data']} = CRM_Utils_Type::escape($columnInfo['search']['value'], 'String'); | |
697 | } | |
698 | } | |
699 | $join = ''; | |
700 | $where = array(); | |
701 | $searchData = CRM_Utils_Array::value('search', $_REQUEST); | |
579ea9bc | 702 | $searchData['value'] = CRM_Utils_Type::escape($searchData['value'], 'String'); |
703 | ||
f931b74c | 704 | if ($src || !empty($searchData['value'])) { |
63ef778e | 705 | $src = $src ? $src : $searchData['value']; |
706 | $where[] = " cc1.display_name LIKE '%{$src}%'"; | |
707 | } | |
708 | if ($dst || !empty($searchData['value'])) { | |
709 | $dst = $dst ? $dst : $searchData['value']; | |
710 | $where[] = " cc2.display_name LIKE '%{$dst}%'"; | |
711 | } | |
712 | if ($src_email || !empty($searchData['value'])) { | |
713 | $src_email = $src_email ? $src_email : $searchData['value']; | |
714 | $where[] = " (ce1.is_primary = 1 AND ce1.email LIKE '%{$src_email}%')"; | |
715 | } | |
716 | if ($dst_email || !empty($searchData['value'])) { | |
717 | $dst_email = $dst_email ? $dst_email : $searchData['value']; | |
718 | $where[] = " (ce2.is_primary = 1 AND ce2.email LIKE '%{$dst_email}%')"; | |
719 | } | |
720 | if ($src_postcode || !empty($searchData['value'])) { | |
721 | $src_postcode = $src_postcode ? $src_postcode : $searchData['value']; | |
722 | $where[] = " (ca1.is_primary = 1 AND ca1.postal_code LIKE '%{$src_postcode}%')"; | |
723 | } | |
724 | if ($dst_postcode || !empty($searchData['value'])) { | |
725 | $dst_postcode = $dst_postcode ? $dst_postcode : $searchData['value']; | |
726 | $where[] = " (ca2.is_primary = 1 AND ca2.postal_code LIKE '%{$dst_postcode}%')"; | |
727 | } | |
728 | if ($src_street || !empty($searchData['value'])) { | |
729 | $src_street = $src_street ? $src_street : $searchData['value']; | |
730 | $where[] = " (ca1.is_primary = 1 AND ca1.street_address LIKE '%{$src_street}%')"; | |
731 | } | |
732 | if ($dst_street || !empty($searchData['value'])) { | |
733 | $dst_street = $dst_street ? $dst_street : $searchData['value']; | |
734 | $where[] = " (ca2.is_primary = 1 AND ca2.street_address LIKE '%{$dst_street}%')"; | |
735 | } | |
736 | if (!empty($searchData['value'])) { | |
f931b74c | 737 | $whereClause = ' ( ' . implode(' OR ', $where) . ' ) '; |
63ef778e | 738 | } |
739 | else { | |
740 | if (!empty($where)) { | |
741 | $whereClause = implode(' AND ', $where); | |
742 | } | |
f931b74c | 743 | } |
63ef778e | 744 | $whereClause .= $whereClause ? ' AND de.id IS NULL' : ' de.id IS NULL'; |
6a488035 | 745 | |
63ef778e | 746 | if ($selected) { |
747 | $whereClause .= ' AND pn.is_selected = 1'; | |
748 | } | |
749 | $join .= " LEFT JOIN civicrm_dedupe_exception de ON ( pn.entity_id1 = de.contact_id1 AND pn.entity_id2 = de.contact_id2 )"; | |
750 | ||
63ef778e | 751 | $select = array( |
f931b74c | 752 | 'cc1.contact_type' => 'src_contact_type', |
753 | 'cc1.display_name' => 'src_display_name', | |
754 | 'cc1.contact_sub_type' => 'src_contact_sub_type', | |
755 | 'cc2.contact_type' => 'dst_contact_type', | |
756 | 'cc2.display_name' => 'dst_display_name', | |
757 | 'cc2.contact_sub_type' => 'dst_contact_sub_type', | |
758 | 'ce1.email' => 'src_email', | |
759 | 'ce2.email' => 'dst_email', | |
760 | 'ca1.postal_code' => 'src_postcode', | |
761 | 'ca2.postal_code' => 'dst_postcode', | |
762 | 'ca1.street_address' => 'src_street', | |
763 | 'ca2.street_address' => 'dst_street', | |
63ef778e | 764 | ); |
765 | ||
f931b74c | 766 | if ($select) { |
63ef778e | 767 | $join .= " INNER JOIN civicrm_contact cc1 ON cc1.id = pn.entity_id1"; |
768 | $join .= " INNER JOIN civicrm_contact cc2 ON cc2.id = pn.entity_id2"; | |
769 | $join .= " LEFT JOIN civicrm_email ce1 ON (ce1.contact_id = pn.entity_id1 AND ce1.is_primary = 1 )"; | |
770 | $join .= " LEFT JOIN civicrm_email ce2 ON (ce2.contact_id = pn.entity_id2 AND ce2.is_primary = 1 )"; | |
771 | $join .= " LEFT JOIN civicrm_address ca1 ON (ca1.contact_id = pn.entity_id1 AND ca1.is_primary = 1 )"; | |
772 | $join .= " LEFT JOIN civicrm_address ca2 ON (ca2.contact_id = pn.entity_id2 AND ca2.is_primary = 1 )"; | |
773 | } | |
774 | $iTotal = CRM_Core_BAO_PrevNextCache::getCount($cacheKeyString, $join, $whereClause); | |
775 | foreach ($_REQUEST['order'] as $orderInfo) { | |
776 | if (!empty($orderInfo['column'])) { | |
777 | $orderColumnNumber = $orderInfo['column']; | |
778 | $dir = $orderInfo['dir']; | |
779 | } | |
780 | } | |
781 | $columnDetails = CRM_Utils_Array::value($orderColumnNumber, $_REQUEST['columns']); | |
f931b74c | 782 | if (!empty($columnDetails)) { |
63ef778e | 783 | switch ($columnDetails['data']) { |
f931b74c | 784 | case 'src': |
785 | $whereClause .= " ORDER BY cc1.display_name {$dir}"; | |
786 | break; | |
787 | ||
788 | case 'src_email': | |
789 | $whereClause .= " ORDER BY ce1.email {$dir}"; | |
790 | break; | |
791 | ||
792 | case 'src_street': | |
793 | $whereClause .= " ORDER BY ca1.street_address {$dir}"; | |
794 | break; | |
795 | ||
796 | case 'src_postcode': | |
797 | $whereClause .= " ORDER BY ca1.postal_code {$dir}"; | |
798 | break; | |
799 | ||
800 | case 'dst': | |
801 | $whereClause .= " ORDER BY cc2.display_name {$dir}"; | |
802 | break; | |
803 | ||
804 | case 'dst_email': | |
805 | $whereClause .= " ORDER BY ce2.email {$dir}"; | |
806 | break; | |
807 | ||
808 | case 'dst_street': | |
809 | $whereClause .= " ORDER BY ca2.street_address {$dir}"; | |
810 | break; | |
811 | ||
812 | case 'dst_postcode': | |
813 | $whereClause .= " ORDER BY ca2.postal_code {$dir}"; | |
814 | break; | |
815 | ||
816 | default: | |
817 | break; | |
63ef778e | 818 | } |
819 | } | |
6a488035 | 820 | |
63ef778e | 821 | $dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $whereClause, $offset, $rowCount, $select); |
822 | $iFilteredTotal = CRM_Core_DAO::singleValueQuery("SELECT FOUND_ROWS()"); | |
6a488035 | 823 | |
63ef778e | 824 | $count = 0; |
825 | foreach ($dupePairs as $key => $pairInfo) { | |
826 | $pair =& $pairInfo['data']; | |
827 | $srcContactSubType = CRM_Utils_Array::value('src_contact_sub_type', $pairInfo); | |
828 | $dstContactSubType = CRM_Utils_Array::value('dst_contact_sub_type', $pairInfo); | |
829 | $srcTypeImage = CRM_Contact_BAO_Contact_Utils::getImage($srcContactSubType ? | |
830 | $srcContactSubType : $pairInfo['src_contact_type'], | |
831 | FALSE, | |
fd630ef9 | 832 | $pairInfo['entity_id1'] |
63ef778e | 833 | ); |
834 | $dstTypeImage = CRM_Contact_BAO_Contact_Utils::getImage($dstContactSubType ? | |
835 | $dstContactSubType : $pairInfo['dst_contact_type'], | |
836 | FALSE, | |
fd630ef9 | 837 | $pairInfo['entity_id2'] |
63ef778e | 838 | ); |
6a488035 | 839 | |
63ef778e | 840 | $searchRows[$count]['is_selected'] = $pairInfo['is_selected']; |
841 | $searchRows[$count]['is_selected_input'] = "<input type='checkbox' class='crm-dedupe-select' name='pnid_{$pairInfo['prevnext_id']}' value='{$pairInfo['is_selected']}' onclick='toggleDedupeSelect(this)'>"; | |
842 | $searchRows[$count]['src_image'] = $srcTypeImage; | |
fd630ef9 | 843 | $searchRows[$count]['src'] = CRM_Utils_System::href($pair['srcName'], 'civicrm/contact/view', "reset=1&cid={$pairInfo['entity_id1']}"); |
63ef778e | 844 | $searchRows[$count]['src_email'] = CRM_Utils_Array::value('src_email', $pairInfo); |
845 | $searchRows[$count]['src_street'] = CRM_Utils_Array::value('src_street', $pairInfo); | |
846 | $searchRows[$count]['src_postcode'] = CRM_Utils_Array::value('src_postcode', $pairInfo); | |
847 | $searchRows[$count]['dst_image'] = $dstTypeImage; | |
fd630ef9 | 848 | $searchRows[$count]['dst'] = CRM_Utils_System::href($pair['dstName'], 'civicrm/contact/view', "reset=1&cid={$pairInfo['entity_id2']}"); |
63ef778e | 849 | $searchRows[$count]['dst_email'] = CRM_Utils_Array::value('dst_email', $pairInfo); |
850 | $searchRows[$count]['dst_street'] = CRM_Utils_Array::value('dst_street', $pairInfo); | |
851 | $searchRows[$count]['dst_postcode'] = CRM_Utils_Array::value('dst_postcode', $pairInfo); | |
da3afd4a | 852 | $searchRows[$count]['conflicts'] = str_replace("',", "',<br/>", CRM_Utils_Array::value('conflicts', $pair)); |
63ef778e | 853 | $searchRows[$count]['weight'] = CRM_Utils_Array::value('weight', $pair); |
854 | ||
fd630ef9 | 855 | if (!empty($pairInfo['data']['canMerge'])) { |
856 | $mergeParams = "reset=1&cid={$pairInfo['entity_id1']}&oid={$pairInfo['entity_id2']}&action=update&rgid={$rgid}"; | |
6a488035 TO |
857 | if ($gid) { |
858 | $mergeParams .= "&gid={$gid}"; | |
859 | } | |
860 | ||
fd630ef9 | 861 | $searchRows[$count]['actions'] = "<a class='crm-dedupe-flip' href='#' data-pnid={$pairInfo['prevnext_id']}>" . ts('flip') . "</a> | "; |
da3afd4a | 862 | $searchRows[$count]['actions'] .= CRM_Utils_System::href(ts('merge'), 'civicrm/contact/merge', $mergeParams); |
fd630ef9 | 863 | $searchRows[$count]['actions'] .= " | <a id='notDuplicate' href='#' onClick=\"processDupes( {$pairInfo['entity_id1']}, {$pairInfo['entity_id2']}, 'dupe-nondupe', 'dupe-listing'); return false;\">" . ts('not a duplicate') . "</a>"; |
6a488035 TO |
864 | } |
865 | else { | |
63ef778e | 866 | $searchRows[$count]['actions'] = '<em>' . ts('Insufficient access rights - cannot merge') . '</em>'; |
6a488035 | 867 | } |
63ef778e | 868 | $count++; |
6a488035 TO |
869 | } |
870 | ||
22b232f3 | 871 | $dupePairs = array( |
872 | 'data' => $searchRows, | |
873 | 'recordsTotal' => $iTotal, | |
874 | 'recordsFiltered' => $iFilteredTotal, | |
875 | ); | |
876 | CRM_Utils_JSON::output($dupePairs); | |
6a488035 TO |
877 | } |
878 | ||
879 | /** | |
fe482240 | 880 | * Retrieve a PDF Page Format for the PDF Letter form. |
6a488035 | 881 | */ |
00be9182 | 882 | public function pdfFormat() { |
6a488035 TO |
883 | $formatId = CRM_Utils_Type::escape($_REQUEST['formatId'], 'Integer'); |
884 | ||
885 | $pdfFormat = CRM_Core_BAO_PdfFormat::getById($formatId); | |
886 | ||
ecdef330 | 887 | CRM_Utils_JSON::output($pdfFormat); |
6a488035 TO |
888 | } |
889 | ||
890 | /** | |
fe482240 | 891 | * Retrieve Paper Size dimensions. |
6a488035 | 892 | */ |
00be9182 | 893 | public static function paperSize() { |
6a488035 TO |
894 | $paperSizeName = CRM_Utils_Type::escape($_REQUEST['paperSizeName'], 'String'); |
895 | ||
896 | $paperSize = CRM_Core_BAO_PaperSize::getByName($paperSizeName); | |
897 | ||
ecdef330 | 898 | CRM_Utils_JSON::output($paperSize); |
6a488035 TO |
899 | } |
900 | ||
183ec330 | 901 | /** |
902 | * Swap contacts in a dupe pair i.e main with duplicate contact. | |
903 | */ | |
f931b74c | 904 | public static function flipDupePairs($prevNextId = NULL) { |
fd630ef9 | 905 | if (!$prevNextId) { |
906 | $prevNextId = $_REQUEST['pnid']; | |
907 | } | |
908 | $query = " | |
909 | UPDATE civicrm_prevnext_cache cpc | |
910 | INNER JOIN civicrm_prevnext_cache old on cpc.id = old.id | |
911 | SET cpc.entity_id1 = cpc.entity_id2, cpc.entity_id2 = old.entity_id1 "; | |
912 | if (is_array($prevNextId) && !CRM_Utils_Array::crmIsEmptyArray($prevNextId)) { | |
913 | $prevNextId = implode(', ', $prevNextId); | |
914 | $prevNextId = CRM_Utils_Type::escape($prevNextId, 'String'); | |
915 | $query .= "WHERE cpc.id IN ({$prevNextId}) AND cpc.is_selected = 1"; | |
f931b74c | 916 | } |
917 | else { | |
fd630ef9 | 918 | $prevNextId = CRM_Utils_Type::escape($prevNextId, 'Positive'); |
919 | $query .= "WHERE cpc.id = $prevNextId"; | |
920 | } | |
921 | CRM_Core_DAO::executeQuery($query); | |
922 | CRM_Utils_JSON::output(); | |
923 | } | |
924 | ||
aeb97cc1 CW |
925 | /** |
926 | * Used to store selected contacts across multiple pages in advanced search. | |
927 | */ | |
00be9182 | 928 | public static function selectUnselectContacts() { |
353ffa53 TO |
929 | $name = CRM_Utils_Array::value('name', $_REQUEST); |
930 | $cacheKey = CRM_Utils_Array::value('qfKey', $_REQUEST); | |
931 | $state = CRM_Utils_Array::value('state', $_REQUEST, 'checked'); | |
6a488035 TO |
932 | $variableType = CRM_Utils_Array::value('variableType', $_REQUEST, 'single'); |
933 | ||
934 | $actionToPerform = CRM_Utils_Array::value('action', $_REQUEST, 'select'); | |
935 | ||
936 | if ($variableType == 'multiple') { | |
937 | // action post value only works with multiple type variable | |
938 | if ($name) { | |
939 | //multiple names like mark_x_1-mark_x_2 where 1,2 are cids | |
940 | $elements = explode('-', $name); | |
941 | foreach ($elements as $key => $element) { | |
942 | $elements[$key] = self::_convertToId($element); | |
943 | } | |
944 | CRM_Core_BAO_PrevNextCache::markSelection($cacheKey, $actionToPerform, $elements); | |
945 | } | |
946 | else { | |
947 | CRM_Core_BAO_PrevNextCache::markSelection($cacheKey, $actionToPerform); | |
948 | } | |
949 | } | |
950 | elseif ($variableType == 'single') { | |
951 | $cId = self::_convertToId($name); | |
952 | $action = ($state == 'checked') ? 'select' : 'unselect'; | |
953 | CRM_Core_BAO_PrevNextCache::markSelection($cacheKey, $action, $cId); | |
954 | } | |
955 | $contactIds = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey); | |
956 | $countSelectionCids = count($contactIds[$cacheKey]); | |
957 | ||
958 | $arrRet = array('getCount' => $countSelectionCids); | |
ecdef330 | 959 | CRM_Utils_JSON::output($arrRet); |
6a488035 TO |
960 | } |
961 | ||
4319322b | 962 | /** |
100fef9d | 963 | * @param string $name |
4319322b EM |
964 | * |
965 | * @return string | |
966 | */ | |
00be9182 | 967 | public static function _convertToId($name) { |
6a488035 TO |
968 | if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { |
969 | $cId = substr($name, CRM_Core_Form::CB_PREFIX_LEN); | |
970 | } | |
971 | return $cId; | |
972 | } | |
973 | ||
00be9182 | 974 | public static function getAddressDisplay() { |
7fa9167d | 975 | $contactId = CRM_Utils_Request::retrieve('contact_id', 'Positive', CRM_Core_DAO::$_nullObject); |
6a488035 TO |
976 | if (!$contactId) { |
977 | $addressVal["error_message"] = "no contact id found"; | |
978 | } | |
979 | else { | |
408b79bf | 980 | $entityBlock = array( |
981 | 'contact_id' => $contactId, | |
982 | 'entity_id' => $contactId, | |
983 | ); | |
6a488035 TO |
984 | $addressVal = CRM_Core_BAO_Address::getValues($entityBlock); |
985 | } | |
986 | ||
ecdef330 | 987 | CRM_Utils_JSON::output($addressVal); |
6a488035 | 988 | } |
40458f6c | 989 | |
183ec330 | 990 | /** |
991 | * Mark dupe pairs as selected from un-selected state or vice-versa, in dupe cache table. | |
992 | */ | |
f931b74c | 993 | public static function toggleDedupeSelect() { |
63ef778e | 994 | $rgid = CRM_Utils_Type::escape($_REQUEST['rgid'], 'Integer'); |
995 | $gid = CRM_Utils_Type::escape($_REQUEST['gid'], 'Integer'); | |
996 | $pnid = $_REQUEST['pnid']; | |
997 | $isSelected = CRM_Utils_Type::escape($_REQUEST['is_selected'], 'Boolean'); | |
998 | ||
999 | $contactType = CRM_Core_DAO::getFieldValue('CRM_Dedupe_DAO_RuleGroup', $rgid, 'contact_type'); | |
1000 | $cacheKeyString = "merge $contactType"; | |
1001 | $cacheKeyString .= $rgid ? "_{$rgid}" : '_0'; | |
1002 | $cacheKeyString .= $gid ? "_{$gid}" : '_0'; | |
1003 | ||
1004 | $params = array( | |
1005 | 1 => array($isSelected, 'Boolean'), | |
f931b74c | 1006 | 3 => array("$cacheKeyString%", 'String'), // using % to address rows with conflicts as well |
63ef778e | 1007 | ); |
1008 | ||
1009 | //check pnid is_array or integer | |
1010 | $whereClause = NULL; | |
1011 | if (is_array($pnid) && !CRM_Utils_Array::crmIsEmptyArray($pnid)) { | |
1012 | $pnid = implode(', ', $pnid); | |
1013 | $pnid = CRM_Utils_Type::escape($pnid, 'String'); | |
1014 | $whereClause = " id IN ( {$pnid} ) "; | |
1015 | } | |
1016 | else { | |
1017 | $pnid = CRM_Utils_Type::escape($pnid, 'Integer'); | |
1018 | $whereClause = " id = %2"; | |
1019 | $params[2] = array($pnid, 'Integer'); | |
1020 | } | |
1021 | ||
1022 | $sql = "UPDATE civicrm_prevnext_cache SET is_selected = %1 WHERE {$whereClause} AND cacheKey LIKE %3"; | |
1023 | CRM_Core_DAO::executeQuery($sql, $params); | |
1024 | ||
1025 | CRM_Utils_System::civiExit(); | |
1026 | } | |
1027 | ||
40458f6c | 1028 | /** |
fe482240 | 1029 | * Retrieve contact relationships. |
40458f6c | 1030 | */ |
1031 | public static function getContactRelationships() { | |
1032 | $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer'); | |
1033 | $context = CRM_Utils_Type::escape($_GET['context'], 'String'); | |
7d12de7f | 1034 | $relationship_type_id = CRM_Utils_Type::escape(CRM_Utils_Array::value('relationship_type_id', $_GET), 'Integer', FALSE); |
40458f6c | 1035 | |
b0266403 CW |
1036 | if (!CRM_Contact_BAO_Contact_Permission::allow($contactID)) { |
1037 | return CRM_Utils_System::permissionDenied(); | |
1038 | } | |
1039 | ||
7d12de7f JL |
1040 | $sortMapper = array(); |
1041 | foreach ($_GET['columns'] as $key => $value) { | |
1042 | $sortMapper[$key] = $value['data']; | |
1043 | }; | |
40458f6c | 1044 | |
7d12de7f JL |
1045 | $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0; |
1046 | $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 25; | |
1047 | $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL; | |
1048 | $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc'; | |
40458f6c | 1049 | |
7d12de7f | 1050 | $params = $_GET; |
40458f6c | 1051 | if ($sort && $sortOrder) { |
1052 | $params['sortBy'] = $sort . ' ' . $sortOrder; | |
1053 | } | |
1054 | ||
1055 | $params['page'] = ($offset / $rowCount) + 1; | |
1056 | $params['rp'] = $rowCount; | |
1057 | ||
1058 | $params['contact_id'] = $contactID; | |
1059 | $params['context'] = $context; | |
4c5f31d0 | 1060 | if ($relationship_type_id) { |
cdee9432 TM |
1061 | $params['relationship_type_id'] = $relationship_type_id; |
1062 | } | |
40458f6c | 1063 | |
1064 | // get the contact relationships | |
1065 | $relationships = CRM_Contact_BAO_Relationship::getContactRelationshipSelector($params); | |
1066 | ||
7d12de7f | 1067 | CRM_Utils_JSON::output($relationships); |
40458f6c | 1068 | } |
96025800 | 1069 | |
6a488035 | 1070 | } |