3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
36 * This class contains all contact related functions that are called using AJAX (jQuery)
38 class CRM_Contact_Page_AJAX
{
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).
44 const CHECK_USERNAME_TTL
= 10800; // 3hr; 3*60*60
46 const AUTOCOMPLETE_TTL
= 21600; // 6hr; 6*60*60
49 * Ajax callback for custom fields of type ContactReference
51 * Todo: Migrate contact reference fields to use EntityRef
53 static function contactReference() {
54 $name = CRM_Utils_Array
::value('term', $_GET);
55 $name = CRM_Utils_Type
::escape($name, 'String');
56 $cfID = CRM_Utils_Type
::escape($_GET['id'], 'Positive');
58 // check that this is a valid, active custom field of Contact Reference type
59 $params = array('id' => $cfID);
60 $returnProperties = array('filter', 'data_type', 'is_active');
62 CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_CustomField', $params, $cf, $returnProperties);
63 if (!$cf['id'] ||
!$cf['is_active'] ||
$cf['data_type'] != 'ContactReference') {
64 CRM_Utils_System
::civiExit('error');
67 if (!empty($cf['filter'])) {
68 $filterParams = array();
69 parse_str($cf['filter'], $filterParams);
71 $action = CRM_Utils_Array
::value('action', $filterParams);
73 if (!empty($action) &&
74 !in_array($action, array('get', 'lookup'))
76 CRM_Utils_System
::civiExit('error');
80 $list = array_keys(CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
81 'contact_reference_options'
84 $return = array_unique(array_merge(array('sort_name'), $list));
86 $limit = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'search_autocomplete_count', NULL, 10);
88 $params = array('offset' => 0, 'rowCount' => $limit, 'version' => 3);
89 foreach ($return as $fld) {
90 $params["return.{$fld}"] = 1;
93 if (!empty($action)) {
94 $excludeGet = array('reset', 'key', 'className', 'fnName', 'json', 'reset', 'context', 'timestamp', 'limit', 'id', 's', 'q', 'action');
95 foreach ($_GET as $param => $val) {
97 in_array($param, $excludeGet) ||
98 strpos($param, 'return.') !== FALSE ||
99 strpos($param, 'api.') !== FALSE
103 $params[$param] = $val;
108 $params['sort_name'] = $name;
111 $params['sort'] = 'sort_name';
113 // tell api to skip permission chk. dgg
114 $params['check_permissions'] = 0;
116 // add filter variable to params
117 if (!empty($filterParams)) {
118 $params = array_merge($params, $filterParams);
121 $contact = civicrm_api('Contact', 'Get', $params);
123 if (!empty($contact['is_error'])) {
124 CRM_Utils_System
::civiExit('error');
127 $contactList = array();
128 foreach ($contact['values'] as $value) {
130 foreach ($return as $fld) {
131 if (!empty($value[$fld])) {
132 $view[] = $value[$fld];
135 $contactList[] = array('id' => $value['id'], 'text' => implode(' :: ', $view));
138 CRM_Utils_JSON
::output($contactList);
142 * Function to fetch PCP ID by PCP Supporter sort_name, also displays PCP title and associated Contribution Page title
144 static function getPCPList() {
145 $name = CRM_Utils_Array
::value('term', $_GET);
146 $name = CRM_Utils_Type
::escape($name, 'String');
149 $where = ' AND pcp.page_id = cp.id AND pcp.contact_id = cc.id';
151 $config = CRM_Core_Config
::singleton();
152 if ($config->includeWildCardInName
) {
153 $strSearch = "%$name%";
156 $strSearch = "$name%";
158 $includeEmailFrom = $includeNickName = '';
159 if ($config->includeNickNameInName
) {
160 $includeNickName = " OR nick_name LIKE '$strSearch'";
162 if ($config->includeEmailInName
) {
163 $includeEmailFrom = "LEFT JOIN civicrm_email eml ON ( cc.id = eml.contact_id AND eml.is_primary = 1 )";
164 $whereClause = " WHERE ( email LIKE '$strSearch' OR sort_name LIKE '$strSearch' $includeNickName ) {$where} ";
167 $whereClause = " WHERE ( sort_name LIKE '$strSearch' $includeNickName ) {$where} ";
170 if (!empty($_GET['limit'])) {
171 $limit = CRM_Utils_Type
::escape($_GET['limit'], 'Positive');
174 $select = 'cc.sort_name, pcp.title, cp.title';
178 SELECT pcp.id as id, CONCAT_WS( ' :: ', {$select} ) as data, sort_name
179 FROM civicrm_pcp pcp, civicrm_contribution_page cp, civicrm_contact cc
181 {$whereClause} AND pcp.page_type = 'contribute'
183 SELECT pcp.id as id, CONCAT_WS( ' :: ', {$select} ) as data, sort_name
184 FROM civicrm_pcp pcp, civicrm_event cp, civicrm_contact cc
186 {$whereClause} AND pcp.page_type = 'event'
192 $dao = CRM_Core_DAO
::executeQuery($query);
194 while ($dao->fetch()) {
195 $results[] = array('id' => $dao->id
, 'text' => $dao->data
);
197 CRM_Utils_JSON
::output($results);
200 static function relationship() {
201 $relType = CRM_Utils_Request
::retrieve('rel_type', 'Positive', CRM_Core_DAO
::$_nullObject, TRUE);
202 $relContactID = CRM_Utils_Request
::retrieve('rel_contact', 'Positive', CRM_Core_DAO
::$_nullObject, TRUE);
203 $relationshipID = CRM_Utils_Array
::value('rel_id', $_REQUEST); // this used only to determine add or update mode
204 $caseID = CRM_Utils_Request
::retrieve('case_id', 'Positive', CRM_Core_DAO
::$_nullObject, TRUE);
206 // check if there are multiple clients for this case, if so then we need create
207 // relationship and also activities for each contacts
209 // get case client list
210 $clientList = CRM_Case_BAO_Case
::getCaseClients($caseID);
212 $ret = array('is_error' => 0);
214 foreach($clientList as $sourceContactID) {
215 $relationParams = array(
216 'relationship_type_id' => $relType . '_a_b',
217 'contact_check' => array($relContactID => 1),
219 'case_id' => $caseID,
220 'start_date' => date("Ymd"),
223 $relationIds = array('contact' => $sourceContactID);
225 // check if we are editing/updating existing relationship
226 if ($relationshipID && $relationshipID != 'null') {
227 // here we need to retrieve appropriate relationshipID based on client id and relationship type id
228 $caseRelationships = new CRM_Contact_DAO_Relationship();
229 $caseRelationships->case_id
= $caseID;
230 $caseRelationships->relationship_type_id
= $relType;
231 $caseRelationships->contact_id_a
= $sourceContactID;
232 $caseRelationships->find();
234 while($caseRelationships->fetch()) {
235 $relationIds['relationship'] = $caseRelationships->id
;
236 $relationIds['contactTarget'] = $relContactID;
238 $caseRelationships->free();
241 // create new or update existing relationship
242 $return = CRM_Contact_BAO_Relationship
::create($relationParams, $relationIds);
244 if (!empty($return[4][0])) {
245 $relationshipID = $return[4][0];
247 //create an activity for case role assignment.CRM-4480
248 CRM_Case_BAO_Case
::createCaseRoleActivity($caseID, $relationshipID, $relContactID);
253 '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>.',
254 array(1 => CRM_Utils_System
::url('civicrm/admin/reltype', 'reset=1')))
259 CRM_Utils_JSON
::output($ret);
263 * Function to fetch the custom field help
265 static function customField() {
266 $fieldId = CRM_Utils_Type
::escape($_REQUEST['id'], 'Integer');
267 $params = array('id' => $fieldId);
268 $returnProperties = array('help_pre', 'help_post');
271 CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_CustomField', $params, $values, $returnProperties);
272 CRM_Utils_JSON
::output($values);
275 static function groupTree() {
276 header('Content-Type: application/json');
277 $gids = CRM_Utils_Type
::escape($_GET['gids'], 'String');
278 echo CRM_Contact_BAO_GroupNestingCache
::json($gids);
279 CRM_Utils_System
::civiExit();
283 * Function to delete custom value
286 static function deleteCustomValue() {
287 header('Content-Type: text/plain');
288 $customValueID = CRM_Utils_Type
::escape($_REQUEST['valueID'], 'Positive');
289 $customGroupID = CRM_Utils_Type
::escape($_REQUEST['groupID'], 'Positive');
291 CRM_Core_BAO_CustomValue
::deleteCustomValue($customValueID, $customGroupID);
292 $contactId = CRM_Utils_Array
::value('contactId', $_REQUEST);
294 echo CRM_Contact_BAO_Contact
::getCountComponent('custom_' . $_REQUEST['groupID'], $contactId);
297 // reset the group contact cache for this group
298 CRM_Contact_BAO_GroupContactCache
::remove();
299 CRM_Utils_System
::civiExit();
303 * Function to perform enable / disable actions on record.
306 static function enableDisable() {
307 $op = CRM_Utils_Type
::escape($_REQUEST['op'], 'String');
308 $recordID = CRM_Utils_Type
::escape($_REQUEST['recordID'], 'Positive');
309 $recordBAO = CRM_Utils_Type
::escape($_REQUEST['recordBAO'], 'String');
312 if ($op == 'disable-enable') {
315 elseif ($op == 'enable-disable') {
318 $status = array('status' => 'record-updated-fail');
319 if (isset($isActive)) {
320 // first munge and clean the recordBAO and get rid of any non alpha numeric characters
321 $recordBAO = CRM_Utils_String
::munge($recordBAO);
322 $recordClass = explode('_', $recordBAO);
324 // make sure recordClass is namespaced (we cant check CRM since extensions can also use this)
325 // but it should be at least 3 levels deep
326 if (count($recordClass) >= 3) {
327 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $recordBAO) . ".php");
328 $method = 'setIsActive';
330 if (method_exists($recordBAO, $method)) {
331 $updated = call_user_func_array(array($recordBAO, $method),
332 array($recordID, $isActive)
335 $status = array('status' => 'record-updated-success');
338 // call hook enableDisable
339 CRM_Utils_Hook
::enableDisable($recordBAO, $recordID, $isActive);
342 CRM_Utils_JSON
::output($status);
347 *Function to check the CMS username
350 static public function checkUserName() {
351 $signer = new CRM_Utils_Signer(CRM_Core_Key
::privateKey(), array('for', 'ts'));
353 CRM_Utils_Time
::getTimeRaw() > $_REQUEST['ts'] + self
::CHECK_USERNAME_TTL
354 ||
$_REQUEST['for'] != 'civicrm/ajax/cmsuser'
355 ||
!$signer->validate($_REQUEST['sig'], $_REQUEST)
357 $user = array('name' => 'error');
358 CRM_Utils_JSON
::output($user);
361 $config = CRM_Core_Config
::singleton();
362 $username = trim($_REQUEST['cms_name']);
364 $params = array('name' => $username);
367 $config->userSystem
->checkUserNameEmailExists($params, $errors);
369 if (isset($errors['cms_name']) ||
isset($errors['name'])) {
370 //user name is not availble
371 $user = array('name' => 'no');
372 CRM_Utils_JSON
::output($user);
375 //user name is available
376 $user = array('name' => 'yes');
377 CRM_Utils_JSON
::output($user);
380 // Not reachable: JSON::output() above exits.
381 CRM_Utils_System
::civiExit();
385 * Function to get email address of a contact
387 static function getContactEmail() {
388 if (!empty($_REQUEST['contact_id'])) {
389 $contactID = CRM_Utils_Type
::escape($_REQUEST['contact_id'], 'Positive');
390 if (!CRM_Contact_BAO_Contact_Permission
::allow($contactID, CRM_Core_Permission
::EDIT
)) {
395 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
397 header('Content-Type: text/plain');
403 $noemail = CRM_Utils_Array
::value('noemail', $_GET);
405 $name = CRM_Utils_Array
::value('name', $_GET);
407 $name = CRM_Utils_Type
::escape($name, 'String');
409 $queryString = " cc.sort_name LIKE '%$name%'";
412 $queryString = " ( cc.sort_name LIKE '%$name%' OR ce.email LIKE '%$name%' ) ";
416 $cid = CRM_Utils_Array
::value('cid', $_GET);
418 //check cid for interger
419 $contIDS = explode(',', $cid);
420 foreach ($contIDS as $contID) {
421 CRM_Utils_Type
::escape($contID, 'Integer');
423 $queryString = " cc.id IN ( $cid )";
428 $offset = CRM_Utils_Array
::value('offset', $_GET, 0);
429 $rowCount = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'search_autocomplete_count', NULL, 10);
431 $offset = CRM_Utils_Type
::escape($offset, 'Int');
433 // add acl clause here
434 list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission
::cacheClause('cc');
436 $aclWhere = " AND $aclWhere";
440 SELECT sort_name name, cc.id
441 FROM civicrm_contact cc
443 WHERE cc.is_deceased = 0 AND {$queryString}
445 LIMIT {$offset}, {$rowCount}
448 // send query to hook to be modified if needed
449 CRM_Utils_Hook
::contactListQuery($query,
451 CRM_Utils_Array
::value('context', $_GET),
452 CRM_Utils_Array
::value('cid', $_GET)
455 $dao = CRM_Core_DAO
::executeQuery($query);
456 while ($dao->fetch()) {
459 'text' => $dao->name
,
465 SELECT sort_name name, ce.email, cc.id
466 FROM civicrm_email ce INNER JOIN civicrm_contact cc ON cc.id = ce.contact_id
468 WHERE ce.on_hold = 0 AND cc.is_deceased = 0 AND cc.do_not_email = 0 AND {$queryString}
470 LIMIT {$offset}, {$rowCount}
473 // send query to hook to be modified if needed
474 CRM_Utils_Hook
::contactListQuery($query,
476 CRM_Utils_Array
::value('context', $_GET),
477 CRM_Utils_Array
::value('cid', $_GET)
481 $dao = CRM_Core_DAO
::executeQuery($query);
483 while ($dao->fetch()) {
486 'text' => '"' . $dao->name
. '" <' . $dao->email
. '>',
487 'id' => (CRM_Utils_Array
::value('id', $_GET)) ?
"{$dao->id}::{$dao->email}" : '"' . $dao->name
. '" <' . $dao->email
. '>',
492 CRM_Utils_JSON
::output($result);
496 CRM_Utils_System
::civiExit();
499 static function getContactPhone() {
502 //check for mobile type
503 $phoneTypes = CRM_Core_OptionGroup
::values('phone_type', TRUE, FALSE, FALSE, NULL, 'name');
504 $mobileType = CRM_Utils_Array
::value('Mobile', $phoneTypes);
506 $name = CRM_Utils_Array
::value('name', $_GET);
508 $name = CRM_Utils_Type
::escape($name, 'String');
509 $queryString = " ( cc.sort_name LIKE '%$name%' OR cp.phone LIKE '%$name%' ) ";
512 $cid = CRM_Utils_Array
::value('cid', $_GET);
514 //check cid for interger
515 $contIDS = explode(',', $cid);
516 foreach ($contIDS as $contID) {
517 CRM_Utils_Type
::escape($contID, 'Integer');
519 $queryString = " cc.id IN ( $cid )";
524 $offset = CRM_Utils_Array
::value('offset', $_GET, 0);
525 $rowCount = CRM_Utils_Array
::value('rowcount', $_GET, 20);
527 $offset = CRM_Utils_Type
::escape($offset, 'Int');
528 $rowCount = CRM_Utils_Type
::escape($rowCount, 'Int');
530 // add acl clause here
531 list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission
::cacheClause('cc');
533 $aclWhere = " AND $aclWhere";
537 SELECT sort_name name, cp.phone, cc.id
538 FROM civicrm_phone cp INNER JOIN civicrm_contact cc ON cc.id = cp.contact_id
540 WHERE cc.is_deceased = 0 AND cc.do_not_sms = 0 AND cp.phone_type_id = {$mobileType} AND {$queryString}
542 LIMIT {$offset}, {$rowCount}
545 // send query to hook to be modified if needed
546 CRM_Utils_Hook
::contactListQuery($query,
548 CRM_Utils_Array
::value('context', $_GET),
549 CRM_Utils_Array
::value('cid', $_GET)
552 $dao = CRM_Core_DAO
::executeQuery($query);
554 while ($dao->fetch()) {
556 'text' => '"' . $dao->name
. '" (' . $dao->phone
. ')',
557 'id' => (CRM_Utils_Array
::value('id', $_GET)) ?
"{$dao->id}::{$dao->phone}" : '"' . $dao->name
. '" <' . $dao->phone
. '>',
563 CRM_Utils_JSON
::output($result);
565 CRM_Utils_System
::civiExit();
569 static function buildSubTypes() {
570 $parent = CRM_Utils_Array
::value('parentId', $_REQUEST);
574 $contactType = 'Individual';
578 $contactType = 'Household';
582 $contactType = 'Organization';
586 $subTypes = CRM_Contact_BAO_ContactType
::subTypePairs($contactType, FALSE, NULL);
588 CRM_Utils_JSON
::output($subTypes);
591 static function buildDedupeRules() {
592 $parent = CRM_Utils_Array
::value('parentId', $_REQUEST);
596 $contactType = 'Individual';
600 $contactType = 'Household';
604 $contactType = 'Organization';
608 $dedupeRules = CRM_Dedupe_BAO_RuleGroup
::getByType($contactType);
610 CRM_Utils_JSON
::output($dedupeRules);
614 * Function used for CiviCRM dashboard operations
616 static function dashboard() {
617 $operation = CRM_Utils_Type
::escape($_REQUEST['op'], 'String');
619 switch ($operation) {
620 case 'get_widgets_by_column':
621 // This would normally be coming from either the database (this user's settings) or a default/initial dashboard configuration.
622 // get contact id of logged in user
624 $dashlets = CRM_Core_BAO_Dashboard
::getContactDashlets();
628 $dashletID = CRM_Utils_Type
::escape($_GET['id'], 'Positive');
630 $dashlets = CRM_Core_BAO_Dashboard
::getDashletInfo($dashletID);
634 CRM_Core_BAO_Dashboard
::saveDashletChanges($_REQUEST['columns']);
635 CRM_Utils_System
::civiExit();
636 case 'delete_dashlet':
637 $dashletID = CRM_Utils_Type
::escape($_REQUEST['dashlet_id'], 'Positive');
638 CRM_Core_BAO_Dashboard
::deleteDashlet($dashletID);
639 CRM_Utils_System
::civiExit();
642 CRM_Utils_JSON
::output($dashlets);
646 * Function to retrieve signature based on email id
648 static function getSignature() {
649 $emailID = CRM_Utils_Type
::escape($_REQUEST['emailID'], 'Positive');
650 $query = "SELECT signature_text, signature_html FROM civicrm_email WHERE id = {$emailID}";
651 $dao = CRM_Core_DAO
::executeQuery($query);
653 $signatures = array();
654 while ($dao->fetch()) {
656 'signature_text' => $dao->signature_text
,
657 'signature_html' => $dao->signature_html
,
661 CRM_Utils_JSON
::output($signatures);
665 * Function to process dupes.
668 static function processDupes() {
669 $oper = CRM_Utils_Type
::escape($_REQUEST['op'], 'String');
670 $cid = CRM_Utils_Type
::escape($_REQUEST['cid'], 'Positive');
671 $oid = CRM_Utils_Type
::escape($_REQUEST['oid'], 'Positive');
673 if (!$oper ||
!$cid ||
!$oid) {
677 $exception = new CRM_Dedupe_DAO_Exception();
678 $exception->contact_id1
= $cid;
679 $exception->contact_id2
= $oid;
680 //make sure contact2 > contact1.
682 $exception->contact_id1
= $oid;
683 $exception->contact_id2
= $cid;
685 $exception->find(TRUE);
687 if ($oper == 'dupe-nondupe') {
688 $status = $exception->save();
690 if ($oper == 'nondupe-dupe') {
691 $status = $exception->delete();
694 CRM_Utils_JSON
::output(array('status' => ($status) ?
$oper : $status));
697 static function getDedupes() {
699 $sEcho = CRM_Utils_Type
::escape($_REQUEST['sEcho'], 'Integer');
700 $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type
::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
701 $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type
::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
703 $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type
::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
705 $gid = isset($_REQUEST['gid']) ? CRM_Utils_Type
::escape($_REQUEST['gid'], 'Integer') : 0;
706 $rgid = isset($_REQUEST['rgid']) ? CRM_Utils_Type
::escape($_REQUEST['rgid'], 'Integer') : 0;
709 $contactType = CRM_Core_DAO
::getFieldValue('CRM_Dedupe_DAO_RuleGroup', $rgid, 'contact_type');
712 $cacheKeyString = "merge {$contactType}_{$rgid}_{$gid}";
713 $searchRows = array();
714 $selectorElements = array('src', 'dst', 'weight', 'actions');
717 $join = "LEFT JOIN civicrm_dedupe_exception de ON ( pn.entity_id1 = de.contact_id1 AND
718 pn.entity_id2 = de.contact_id2 )";
719 $where = "de.id IS NULL";
721 $iFilteredTotal = $iTotal = CRM_Core_BAO_PrevNextCache
::getCount($cacheKeyString, $join, $where);
722 $mainContacts = CRM_Core_BAO_PrevNextCache
::retrieve($cacheKeyString, $join, $where, $offset, $rowCount);
724 foreach ($mainContacts as $mainId => $main) {
725 $searchRows[$mainId]['src'] = CRM_Utils_System
::href($main['srcName'], 'civicrm/contact/view', "reset=1&cid={$main['srcID']}");
726 $searchRows[$mainId]['dst'] = CRM_Utils_System
::href($main['dstName'], 'civicrm/contact/view', "reset=1&cid={$main['dstID']}");
727 $searchRows[$mainId]['weight'] = CRM_Utils_Array
::value('weight', $main);
729 if (!empty($main['canMerge'])) {
730 $mergeParams = "reset=1&cid={$main['srcID']}&oid={$main['dstID']}&action=update&rgid={$rgid}";
732 $mergeParams .= "&gid={$gid}";
735 $searchRows[$mainId]['actions'] = CRM_Utils_System
::href(ts('merge'), 'civicrm/contact/merge', $mergeParams);
736 $searchRows[$mainId]['actions'] .= " | <a id='notDuplicate' href='#' onClick=\"processDupes( {$main['srcID']}, {$main['dstID']}, 'dupe-nondupe', 'dupe-listing'); return false;\">" . ts('not a duplicate') . "</a>";
739 $searchRows[$mainId]['actions'] = '<em>' . ts('Insufficient access rights - cannot merge') . '</em>';
743 header('Content-Type: application/json');
744 echo CRM_Utils_JSON
::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
746 CRM_Utils_System
::civiExit();
750 * Function to retrieve a PDF Page Format for the PDF Letter form
752 function pdfFormat() {
753 $formatId = CRM_Utils_Type
::escape($_REQUEST['formatId'], 'Integer');
755 $pdfFormat = CRM_Core_BAO_PdfFormat
::getById($formatId);
757 CRM_Utils_JSON
::output($pdfFormat);
761 * Function to retrieve Paper Size dimensions
763 static function paperSize() {
764 $paperSizeName = CRM_Utils_Type
::escape($_REQUEST['paperSizeName'], 'String');
766 $paperSize = CRM_Core_BAO_PaperSize
::getByName($paperSizeName);
768 CRM_Utils_JSON
::output($paperSize);
771 static function selectUnselectContacts() {
772 $name = CRM_Utils_Array
::value('name', $_REQUEST);
773 $cacheKey = CRM_Utils_Array
::value('qfKey', $_REQUEST);
774 $state = CRM_Utils_Array
::value('state', $_REQUEST, 'checked');
775 $variableType = CRM_Utils_Array
::value('variableType', $_REQUEST, 'single');
777 $actionToPerform = CRM_Utils_Array
::value('action', $_REQUEST, 'select');
779 if ($variableType == 'multiple') {
780 // action post value only works with multiple type variable
782 //multiple names like mark_x_1-mark_x_2 where 1,2 are cids
783 $elements = explode('-', $name);
784 foreach ($elements as $key => $element) {
785 $elements[$key] = self
::_convertToId($element);
787 CRM_Core_BAO_PrevNextCache
::markSelection($cacheKey, $actionToPerform, $elements);
790 CRM_Core_BAO_PrevNextCache
::markSelection($cacheKey, $actionToPerform);
793 elseif ($variableType == 'single') {
794 $cId = self
::_convertToId($name);
795 $action = ($state == 'checked') ?
'select' : 'unselect';
796 CRM_Core_BAO_PrevNextCache
::markSelection($cacheKey, $action, $cId);
798 $contactIds = CRM_Core_BAO_PrevNextCache
::getSelection($cacheKey);
799 $countSelectionCids = count($contactIds[$cacheKey]);
801 $arrRet = array('getCount' => $countSelectionCids);
802 CRM_Utils_JSON
::output($arrRet);
810 static function _convertToId($name) {
811 if (substr($name, 0, CRM_Core_Form
::CB_PREFIX_LEN
) == CRM_Core_Form
::CB_PREFIX
) {
812 $cId = substr($name, CRM_Core_Form
::CB_PREFIX_LEN
);
817 static function getAddressDisplay() {
818 $contactId = CRM_Utils_Array
::value('contact_id', $_REQUEST);
820 $addressVal["error_message"] = "no contact id found";
825 'contact_id' => $contactId,
826 'entity_id' => $contactId,
828 $addressVal = CRM_Core_BAO_Address
::getValues($entityBlock);
831 CRM_Utils_JSON
::output($addressVal);
835 * Function to retrieve contact relationships
837 public static function getContactRelationships() {
838 $contactID = CRM_Utils_Type
::escape($_GET['cid'], 'Integer');
839 $context = CRM_Utils_Type
::escape($_GET['context'], 'String');
841 if (!CRM_Contact_BAO_Contact_Permission
::allow($contactID)) {
842 return CRM_Utils_System
::permissionDenied();
859 $sEcho = CRM_Utils_Type
::escape($_REQUEST['sEcho'], 'Integer');
860 $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type
::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
861 $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type
::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
862 $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array
::value(CRM_Utils_Type
::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
863 $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type
::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
866 if ($sort && $sortOrder) {
867 $params['sortBy'] = $sort . ' ' . $sortOrder;
870 $params['page'] = ($offset / $rowCount) +
1;
871 $params['rp'] = $rowCount;
873 $params['contact_id'] = $contactID;
874 $params['context'] = $context;
876 // get the contact relationships
877 $relationships = CRM_Contact_BAO_Relationship
::getContactRelationshipSelector($params);
879 $iFilteredTotal = $iTotal = $params['total'];
880 $selectorElements = array(
894 header('Content-Type: application/json');
895 echo CRM_Utils_JSON
::encodeDataTableSelector($relationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
896 CRM_Utils_System
::civiExit();