3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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
51 public static function getContactList() {
52 // if context is 'customfield'
53 if (CRM_Utils_Array
::value('context', $_GET) == 'customfield') {
54 return self
::contactReference();
57 $params = array('version' => 3, 'check_permissions' => TRUE);
60 // FIXME: param keys don't match input keys, using this array to translate
63 'fieldName' => 'field_name',
64 'tableName' => 'table_name',
65 'context' => 'context',
67 'contact_sub_type' => 'contact_sub_type',
68 'contact_type' => 'contact_type',
70 foreach ($whitelist as $key => $param) {
71 if (!empty($_GET[$key])) {
72 $params[$param] = $_GET[$key];
76 //CRM-10687: Allow quicksearch by multiple fields
77 if (!empty($params['field_name'])) {
78 if ($params['field_name'] == 'phone_numeric') {
79 $params['name'] = preg_replace('/[^\d]/', '', $params['name']);
81 if (!$params['name']) {
82 CRM_Utils_System
::civiExit();
95 foreach ($whitelist as $key) {
96 if (!empty($_GET[$key]) && is_numeric($_GET[$key])) {
97 $params[$key] = $_GET[$key];
101 $result = civicrm_api('Contact', 'getquick', $params);
102 CRM_Core_Page_AJAX
::autocompleteResults(CRM_Utils_Array
::value('values', $result), 'data');
106 * Ajax callback for custom fields of type ContactReference.
108 * Todo: Migrate contact reference fields to use EntityRef
110 public static function contactReference() {
111 $name = CRM_Utils_Array
::value('term', $_GET);
112 $name = CRM_Utils_Type
::escape($name, 'String');
113 $cfID = CRM_Utils_Type
::escape($_GET['id'], 'Positive');
115 // check that this is a valid, active custom field of Contact Reference type
116 $params = array('id' => $cfID);
117 $returnProperties = array('filter', 'data_type', 'is_active');
119 CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_CustomField', $params, $cf, $returnProperties);
120 if (!$cf['id'] ||
!$cf['is_active'] ||
$cf['data_type'] != 'ContactReference') {
121 CRM_Utils_System
::civiExit('error');
124 if (!empty($cf['filter'])) {
125 $filterParams = array();
126 parse_str($cf['filter'], $filterParams);
128 $action = CRM_Utils_Array
::value('action', $filterParams);
130 if (!empty($action) &&
131 !in_array($action, array('get', 'lookup'))
133 CRM_Utils_System
::civiExit('error');
137 $list = array_keys(CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
138 'contact_reference_options'
141 $return = array_unique(array_merge(array('sort_name'), $list));
143 $limit = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'search_autocomplete_count', NULL, 10);
145 $params = array('offset' => 0, 'rowCount' => $limit, 'version' => 3);
146 foreach ($return as $fld) {
147 $params["return.{$fld}"] = 1;
150 if (!empty($action)) {
166 foreach ($_GET as $param => $val) {
168 in_array($param, $excludeGet) ||
169 strpos($param, 'return.') !== FALSE ||
170 strpos($param, 'api.') !== FALSE
174 $params[$param] = $val;
179 $params['sort_name'] = $name;
182 $params['sort'] = 'sort_name';
184 // tell api to skip permission chk. dgg
185 $params['check_permissions'] = 0;
187 // add filter variable to params
188 if (!empty($filterParams)) {
189 $params = array_merge($params, $filterParams);
192 $contact = civicrm_api('Contact', 'Get', $params);
194 if (!empty($contact['is_error'])) {
195 CRM_Utils_System
::civiExit('error');
198 $contactList = array();
199 foreach ($contact['values'] as $value) {
201 foreach ($return as $fld) {
202 if (!empty($value[$fld])) {
203 $view[] = $value[$fld];
206 $contactList[] = array('id' => $value['id'], 'text' => implode(' :: ', $view));
209 CRM_Utils_System
::civiExit(json_encode($contactList));
213 * Fetch PCP ID by PCP Supporter sort_name, also displays PCP title and associated Contribution Page title
215 public static function getPCPList() {
216 $name = CRM_Utils_Array
::value('term', $_GET);
217 $name = CRM_Utils_Type
::escape($name, 'String');
220 $where = ' AND pcp.page_id = cp.id AND pcp.contact_id = cc.id';
222 $config = CRM_Core_Config
::singleton();
223 if ($config->includeWildCardInName
) {
224 $strSearch = "%$name%";
227 $strSearch = "$name%";
229 $includeEmailFrom = $includeNickName = '';
230 if ($config->includeNickNameInName
) {
231 $includeNickName = " OR nick_name LIKE '$strSearch'";
233 if ($config->includeEmailInName
) {
234 $includeEmailFrom = "LEFT JOIN civicrm_email eml ON ( cc.id = eml.contact_id AND eml.is_primary = 1 )";
235 $whereClause = " WHERE ( email LIKE '$strSearch' OR sort_name LIKE '$strSearch' $includeNickName ) {$where} ";
238 $whereClause = " WHERE ( sort_name LIKE '$strSearch' $includeNickName ) {$where} ";
241 if (!empty($_GET['limit'])) {
242 $limit = CRM_Utils_Type
::escape($_GET['limit'], 'Positive');
245 $select = 'cc.sort_name, pcp.title, cp.title';
249 SELECT pcp.id as id, CONCAT_WS( ' :: ', {$select} ) as data, sort_name
250 FROM civicrm_pcp pcp, civicrm_contribution_page cp, civicrm_contact cc
252 {$whereClause} AND pcp.page_type = 'contribute'
254 SELECT pcp.id as id, CONCAT_WS( ' :: ', {$select} ) as data, sort_name
255 FROM civicrm_pcp pcp, civicrm_event cp, civicrm_contact cc
257 {$whereClause} AND pcp.page_type = 'event'
263 $dao = CRM_Core_DAO
::executeQuery($query);
265 while ($dao->fetch()) {
266 $results[] = array('id' => $dao->id
, 'text' => $dao->data
);
268 CRM_Utils_JSON
::output($results);
271 public static function relationship() {
272 $relType = CRM_Utils_Request
::retrieve('rel_type', 'Positive', CRM_Core_DAO
::$_nullObject, TRUE);
273 $relContactID = CRM_Utils_Request
::retrieve('rel_contact', 'Positive', CRM_Core_DAO
::$_nullObject, TRUE);
274 $relationshipID = CRM_Utils_Array
::value('rel_id', $_REQUEST); // this used only to determine add or update mode
275 $caseID = CRM_Utils_Request
::retrieve('case_id', 'Positive', CRM_Core_DAO
::$_nullObject, TRUE);
277 // check if there are multiple clients for this case, if so then we need create
278 // relationship and also activities for each contacts
280 // get case client list
281 $clientList = CRM_Case_BAO_Case
::getCaseClients($caseID);
283 $ret = array('is_error' => 0);
285 foreach ($clientList as $sourceContactID) {
286 $relationParams = array(
287 'relationship_type_id' => $relType . '_a_b',
288 'contact_check' => array($relContactID => 1),
290 'case_id' => $caseID,
291 'start_date' => date("Ymd"),
294 $relationIds = array('contact' => $sourceContactID);
296 // check if we are editing/updating existing relationship
297 if ($relationshipID && $relationshipID != 'null') {
298 // here we need to retrieve appropriate relationshipID based on client id and relationship type id
299 $caseRelationships = new CRM_Contact_DAO_Relationship();
300 $caseRelationships->case_id
= $caseID;
301 $caseRelationships->relationship_type_id
= $relType;
302 $caseRelationships->contact_id_a
= $sourceContactID;
303 $caseRelationships->find();
305 while ($caseRelationships->fetch()) {
306 $relationIds['relationship'] = $caseRelationships->id
;
307 $relationIds['contactTarget'] = $relContactID;
309 $caseRelationships->free();
312 // create new or update existing relationship
313 $return = CRM_Contact_BAO_Relationship
::createMultiple($relationParams, $relationIds);
315 if (!empty($return[4][0])) {
316 $relationshipID = $return[4][0];
318 //create an activity for case role assignment.CRM-4480
319 CRM_Case_BAO_Case
::createCaseRoleActivity($caseID, $relationshipID, $relContactID);
324 '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>.',
325 array(1 => CRM_Utils_System
::url('civicrm/admin/reltype', 'reset=1'))),
330 CRM_Utils_JSON
::output($ret);
334 * Fetch the custom field help.
336 public static function customField() {
337 $fieldId = CRM_Utils_Type
::escape($_REQUEST['id'], 'Integer');
338 $params = array('id' => $fieldId);
339 $returnProperties = array('help_pre', 'help_post');
342 CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_CustomField', $params, $values, $returnProperties);
343 CRM_Utils_JSON
::output($values);
346 public static function groupTree() {
347 $gids = CRM_Utils_Type
::escape($_GET['gids'], 'String');
348 echo CRM_Contact_BAO_GroupNestingCache
::json($gids);
349 CRM_Utils_System
::civiExit();
354 * Old quicksearch function. No longer used in core.
355 * @todo: Remove this function and associated menu entry in CiviCRM 5
357 public static function search() {
359 $name = CRM_Utils_Array
::value('name', $_GET, '');
360 if (!array_key_exists('name', $_GET)) {
361 $name = CRM_Utils_Array
::value('s', $_GET) . '%';
364 $name = CRM_Utils_Type
::escape($name, 'String');
366 if (!empty($_GET['id'])) {
368 if (is_numeric($_GET['id'])) {
369 $id = CRM_Utils_Type
::escape($_GET['id'], 'Integer');
370 $whereIdClause = " AND civicrm_contact.id = {$id}";
378 if ($name ||
isset($id)) {
381 //contact's based of relationhip type
383 if (isset($_GET['rel'])) {
384 $relation = explode('_', $_GET['rel']);
385 $relType = CRM_Utils_Type
::escape($relation[0], 'Integer');
386 $rel = CRM_Utils_Type
::escape($relation[2], 'String');
389 //shared household info
391 if (isset($_GET['sh'])) {
392 $shared = CRM_Utils_Type
::escape($_GET['sh'], 'Integer');
394 $contactType = 'Household';
395 $cName = 'household_name';
398 $contactType = 'Organization';
399 $cName = 'organization_name';
403 // contacts of type household
404 $hh = $addStreet = $addCity = NULL;
405 if (isset($_GET['hh'])) {
406 $hh = CRM_Utils_Type
::escape($_GET['hh'], 'Integer');
410 $organization = $street = $city = NULL;
411 if (isset($_GET['org'])) {
412 $organization = CRM_Utils_Type
::escape($_GET['org'], 'Integer');
415 if (isset($_GET['org']) ||
isset($_GET['hh'])) {
417 $splitName = explode(' :: ', $name);
419 $contactName = trim(CRM_Utils_Array
::value('0', $splitName));
420 $street = trim(CRM_Utils_Array
::value('1', $splitName));
421 $city = trim(CRM_Utils_Array
::value('2', $splitName));
424 $contactName = $name;
428 $addStreet = "AND civicrm_address.street_address LIKE '$street%'";
431 $addCity = "AND civicrm_address.city LIKE '$city%'";
438 SELECT CONCAT_WS(' :: ',sort_name,LEFT(street_address,25),city) 'sort_name',
439 civicrm_contact.id 'id'
441 LEFT JOIN civicrm_address ON ( civicrm_contact.id = civicrm_address.contact_id
442 AND civicrm_address.is_primary=1
444 WHERE civicrm_contact.contact_type='Organization' AND organization_name LIKE '%$contactName%'
445 {$addStreet} {$addCity} {$whereIdClause}
446 ORDER BY organization_name ";
450 SELECT CONCAT_WS(':::' , sort_name, supplemental_address_1, sp.abbreviation, postal_code, cc.name )'sort_name' , civicrm_contact.id 'id' , civicrm_contact.display_name 'disp' FROM civicrm_contact LEFT JOIN civicrm_address ON (civicrm_contact.id =civicrm_address.contact_id AND civicrm_address.is_primary =1 )LEFT JOIN civicrm_state_province sp ON (civicrm_address.state_province_id =sp.id )LEFT JOIN civicrm_country cc ON (civicrm_address.country_id =cc.id )WHERE civicrm_contact.contact_type ='{$contactType}' AND {$cName} LIKE '%$name%' {$whereIdClause} ORDER BY {$cName} ";
454 SELECT CONCAT_WS(' :: ' , sort_name, LEFT(street_address,25),city) 'sort_name' , location_type_id 'location_type_id', is_primary 'is_primary', is_billing 'is_billing', civicrm_contact.id 'id'
456 LEFT JOIN civicrm_address ON (civicrm_contact.id =civicrm_address.contact_id AND civicrm_address.is_primary =1 )
457 WHERE civicrm_contact.contact_type ='Household'
458 AND household_name LIKE '%$contactName%' {$addStreet} {$addCity} {$whereIdClause} ORDER BY household_name ";
461 if (!empty($_GET['case'])) {
463 SELECT distinct(c.id), c.sort_name
464 FROM civicrm_contact c
465 LEFT JOIN civicrm_relationship ON civicrm_relationship.contact_id_{$rel} = c.id
466 WHERE c.sort_name LIKE '%$name%'
467 AND civicrm_relationship.relationship_type_id = $relType
477 WHERE sort_name LIKE '%$name'
479 ORDER BY sort_name ";
483 if (isset($_GET['limit'])) {
484 $limit = CRM_Utils_Type
::escape($_GET['limit'], 'Positive');
487 $query .= " LIMIT 0,{$limit}";
489 $dao = CRM_Core_DAO
::executeQuery($query);
492 while ($dao->fetch()) {
493 echo $dao->sort_name
;
494 CRM_Utils_System
::civiExit();
498 while ($dao->fetch()) {
501 'name' => addslashes($dao->sort_name
),
506 echo $elements = "$dao->sort_name|$dao->id|$dao->location_type_id|$dao->is_primary|$dao->is_billing\n";
509 //for adding new household address / organization
510 if (empty($elements) && !$json && ($hh ||
$organization)) {
511 echo CRM_Utils_Array
::value('s', $_GET);
516 if (isset($_GET['sh'])) {
518 CRM_Utils_System
::civiExit();
521 if (empty($elements)) {
522 $name = str_replace('%', '', $name);
530 echo json_encode($elements);
532 CRM_Utils_System
::civiExit();
536 * Delete custom value.
538 public static function deleteCustomValue() {
539 $customValueID = CRM_Utils_Type
::escape($_REQUEST['valueID'], 'Positive');
540 $customGroupID = CRM_Utils_Type
::escape($_REQUEST['groupID'], 'Positive');
542 CRM_Core_BAO_CustomValue
::deleteCustomValue($customValueID, $customGroupID);
543 $contactId = CRM_Utils_Array
::value('contactId', $_REQUEST);
545 echo CRM_Contact_BAO_Contact
::getCountComponent('custom_' . $_REQUEST['groupID'], $contactId);
548 // reset the group contact cache for this group
549 CRM_Contact_BAO_GroupContactCache
::remove();
550 CRM_Utils_System
::civiExit();
554 * check the CMS username.
556 static public function checkUserName() {
557 $signer = new CRM_Utils_Signer(CRM_Core_Key
::privateKey(), array('for', 'ts'));
559 CRM_Utils_Time
::getTimeRaw() > $_REQUEST['ts'] + self
::CHECK_USERNAME_TTL
560 ||
$_REQUEST['for'] != 'civicrm/ajax/cmsuser'
561 ||
!$signer->validate($_REQUEST['sig'], $_REQUEST)
563 $user = array('name' => 'error');
564 echo json_encode($user);
565 CRM_Utils_System
::civiExit();
568 $config = CRM_Core_Config
::singleton();
569 $username = trim($_REQUEST['cms_name']);
571 $params = array('name' => $username);
574 $config->userSystem
->checkUserNameEmailExists($params, $errors);
576 if (isset($errors['cms_name']) ||
isset($errors['name'])) {
577 //user name is not availble
578 $user = array('name' => 'no');
579 echo json_encode($user);
582 //user name is available
583 $user = array('name' => 'yes');
584 echo json_encode($user);
586 CRM_Utils_System
::civiExit();
590 * Function to get email address of a contact.
592 public static function getContactEmail() {
593 if (!empty($_REQUEST['contact_id'])) {
594 $contactID = CRM_Utils_Type
::escape($_REQUEST['contact_id'], 'Positive');
595 if (!CRM_Contact_BAO_Contact_Permission
::allow($contactID, CRM_Core_Permission
::EDIT
)) {
600 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
606 $noemail = CRM_Utils_Array
::value('noemail', $_GET);
608 $name = CRM_Utils_Array
::value('name', $_GET);
610 $name = CRM_Utils_Type
::escape($name, 'String');
612 $queryString = " cc.sort_name LIKE '%$name%'";
615 $queryString = " ( cc.sort_name LIKE '%$name%' OR ce.email LIKE '%$name%' ) ";
619 $cid = CRM_Utils_Array
::value('cid', $_GET);
621 //check cid for interger
622 $contIDS = explode(',', $cid);
623 foreach ($contIDS as $contID) {
624 CRM_Utils_Type
::escape($contID, 'Integer');
626 $queryString = " cc.id IN ( $cid )";
631 $offset = CRM_Utils_Array
::value('offset', $_GET, 0);
632 $rowCount = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'search_autocomplete_count', NULL, 10);
634 $offset = CRM_Utils_Type
::escape($offset, 'Int');
636 // add acl clause here
637 list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission
::cacheClause('cc');
639 $aclWhere = " AND $aclWhere";
643 SELECT sort_name name, cc.id
644 FROM civicrm_contact cc
646 WHERE cc.is_deceased = 0 AND {$queryString}
648 LIMIT {$offset}, {$rowCount}
651 // send query to hook to be modified if needed
652 CRM_Utils_Hook
::contactListQuery($query,
654 CRM_Utils_Array
::value('context', $_GET),
655 CRM_Utils_Array
::value('cid', $_GET)
658 $dao = CRM_Core_DAO
::executeQuery($query);
659 while ($dao->fetch()) {
662 'text' => $dao->name
,
668 SELECT sort_name name, ce.email, cc.id
669 FROM civicrm_email ce INNER JOIN civicrm_contact cc ON cc.id = ce.contact_id
671 WHERE ce.on_hold = 0 AND cc.is_deceased = 0 AND cc.do_not_email = 0 AND {$queryString}
673 LIMIT {$offset}, {$rowCount}
676 // send query to hook to be modified if needed
677 CRM_Utils_Hook
::contactListQuery($query,
679 CRM_Utils_Array
::value('context', $_GET),
680 CRM_Utils_Array
::value('cid', $_GET)
683 $dao = CRM_Core_DAO
::executeQuery($query);
685 while ($dao->fetch()) {
688 'text' => '"' . $dao->name
. '" <' . $dao->email
. '>',
689 'id' => (CRM_Utils_Array
::value('id', $_GET)) ?
"{$dao->id}::{$dao->email}" : '"' . $dao->name
. '" <' . $dao->email
. '>',
694 echo json_encode($result);
698 CRM_Utils_System
::civiExit();
701 public static function getContactPhone() {
704 //check for mobile type
705 $phoneTypes = CRM_Core_OptionGroup
::values('phone_type', TRUE, FALSE, FALSE, NULL, 'name');
706 $mobileType = CRM_Utils_Array
::value('Mobile', $phoneTypes);
708 $name = CRM_Utils_Array
::value('name', $_GET);
710 $name = CRM_Utils_Type
::escape($name, 'String');
711 $queryString = " ( cc.sort_name LIKE '%$name%' OR cp.phone LIKE '%$name%' ) ";
714 $cid = CRM_Utils_Array
::value('cid', $_GET);
716 //check cid for interger
717 $contIDS = explode(',', $cid);
718 foreach ($contIDS as $contID) {
719 CRM_Utils_Type
::escape($contID, 'Integer');
721 $queryString = " cc.id IN ( $cid )";
726 $offset = CRM_Utils_Array
::value('offset', $_GET, 0);
727 $rowCount = CRM_Utils_Array
::value('rowcount', $_GET, 20);
729 $offset = CRM_Utils_Type
::escape($offset, 'Int');
730 $rowCount = CRM_Utils_Type
::escape($rowCount, 'Int');
732 // add acl clause here
733 list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission
::cacheClause('cc');
735 $aclWhere = " AND $aclWhere";
739 SELECT sort_name name, cp.phone, cc.id
740 FROM civicrm_phone cp INNER JOIN civicrm_contact cc ON cc.id = cp.contact_id
742 WHERE cc.is_deceased = 0 AND cc.do_not_sms = 0 AND cp.phone_type_id = {$mobileType} AND {$queryString}
744 LIMIT {$offset}, {$rowCount}
747 // send query to hook to be modified if needed
748 CRM_Utils_Hook
::contactListQuery($query,
750 CRM_Utils_Array
::value('context', $_GET),
751 CRM_Utils_Array
::value('cid', $_GET)
754 $dao = CRM_Core_DAO
::executeQuery($query);
756 while ($dao->fetch()) {
758 'text' => '"' . $dao->name
. '" (' . $dao->phone
. ')',
759 'id' => (CRM_Utils_Array
::value('id', $_GET)) ?
"{$dao->id}::{$dao->phone}" : '"' . $dao->name
. '" <' . $dao->phone
. '>',
765 echo json_encode($result);
767 CRM_Utils_System
::civiExit();
771 public static function buildSubTypes() {
772 $parent = CRM_Utils_Array
::value('parentId', $_REQUEST);
776 $contactType = 'Individual';
780 $contactType = 'Household';
784 $contactType = 'Organization';
788 $subTypes = CRM_Contact_BAO_ContactType
::subTypePairs($contactType, FALSE, NULL);
790 CRM_Utils_JSON
::output($subTypes);
793 public static function buildDedupeRules() {
794 $parent = CRM_Utils_Array
::value('parentId', $_REQUEST);
798 $contactType = 'Individual';
802 $contactType = 'Household';
806 $contactType = 'Organization';
810 $dedupeRules = CRM_Dedupe_BAO_RuleGroup
::getByType($contactType);
812 CRM_Utils_JSON
::output($dedupeRules);
816 * Function used for CiviCRM dashboard operations.
818 public static function dashboard() {
819 $operation = CRM_Utils_Type
::escape($_REQUEST['op'], 'String');
821 switch ($operation) {
822 case 'get_widgets_by_column':
823 // This would normally be coming from either the database (this user's settings) or a default/initial dashboard configuration.
824 // get contact id of logged in user
826 $dashlets = CRM_Core_BAO_Dashboard
::getContactDashlets();
830 $dashletID = CRM_Utils_Type
::escape($_GET['id'], 'Positive');
832 $dashlets = CRM_Core_BAO_Dashboard
::getDashletInfo($dashletID);
836 CRM_Core_BAO_Dashboard
::saveDashletChanges($_REQUEST['columns']);
837 CRM_Utils_System
::civiExit();
838 case 'delete_dashlet':
839 $dashletID = CRM_Utils_Type
::escape($_REQUEST['dashlet_id'], 'Positive');
840 CRM_Core_BAO_Dashboard
::deleteDashlet($dashletID);
841 CRM_Utils_System
::civiExit();
844 CRM_Utils_JSON
::output($dashlets);
848 * Retrieve signature based on email id.
850 public static function getSignature() {
851 $emailID = CRM_Utils_Type
::escape($_REQUEST['emailID'], 'Positive');
852 $query = "SELECT signature_text, signature_html FROM civicrm_email WHERE id = {$emailID}";
853 $dao = CRM_Core_DAO
::executeQuery($query);
855 $signatures = array();
856 while ($dao->fetch()) {
858 'signature_text' => $dao->signature_text
,
859 'signature_html' => $dao->signature_html
,
863 CRM_Utils_JSON
::output($signatures);
869 public static function processDupes() {
870 $oper = CRM_Utils_Type
::escape($_REQUEST['op'], 'String');
871 $cid = CRM_Utils_Type
::escape($_REQUEST['cid'], 'Positive');
872 $oid = CRM_Utils_Type
::escape($_REQUEST['oid'], 'Positive');
874 if (!$oper ||
!$cid ||
!$oid) {
878 $exception = new CRM_Dedupe_DAO_Exception();
879 $exception->contact_id1
= $cid;
880 $exception->contact_id2
= $oid;
881 //make sure contact2 > contact1.
883 $exception->contact_id1
= $oid;
884 $exception->contact_id2
= $cid;
886 $exception->find(TRUE);
888 if ($oper == 'dupe-nondupe') {
889 $status = $exception->save();
891 if ($oper == 'nondupe-dupe') {
892 $status = $exception->delete();
895 CRM_Utils_JSON
::output(array('status' => ($status) ?
$oper : $status));
898 public static function getDedupes() {
900 $sEcho = CRM_Utils_Type
::escape($_REQUEST['sEcho'], 'Integer');
901 $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type
::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
902 $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type
::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
904 $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type
::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
906 $gid = isset($_REQUEST['gid']) ? CRM_Utils_Type
::escape($_REQUEST['gid'], 'Integer') : 0;
907 $rgid = isset($_REQUEST['rgid']) ? CRM_Utils_Type
::escape($_REQUEST['rgid'], 'Integer') : 0;
910 $contactType = CRM_Core_DAO
::getFieldValue('CRM_Dedupe_DAO_RuleGroup', $rgid, 'contact_type');
913 $cacheKeyString = "merge {$contactType}_{$rgid}_{$gid}";
914 $searchRows = array();
915 $selectorElements = array('src', 'dst', 'weight', 'actions');
917 $join = "LEFT JOIN civicrm_dedupe_exception de ON ( pn.entity_id1 = de.contact_id1 AND
918 pn.entity_id2 = de.contact_id2 )";
919 $where = "de.id IS NULL";
921 $iFilteredTotal = $iTotal = CRM_Core_BAO_PrevNextCache
::getCount($cacheKeyString, $join, $where);
922 $mainContacts = CRM_Core_BAO_PrevNextCache
::retrieve($cacheKeyString, $join, $where, $offset, $rowCount);
924 foreach ($mainContacts as $mainId => $main) {
925 $searchRows[$mainId]['src'] = CRM_Utils_System
::href($main['srcName'], 'civicrm/contact/view', "reset=1&cid={$main['srcID']}");
926 $searchRows[$mainId]['dst'] = CRM_Utils_System
::href($main['dstName'], 'civicrm/contact/view', "reset=1&cid={$main['dstID']}");
927 $searchRows[$mainId]['weight'] = CRM_Utils_Array
::value('weight', $main);
929 if (!empty($main['canMerge'])) {
930 $mergeParams = "reset=1&cid={$main['srcID']}&oid={$main['dstID']}&action=update&rgid={$rgid}";
932 $mergeParams .= "&gid={$gid}";
935 $searchRows[$mainId]['actions'] = '<a class="action-item crm-hover-button" href="' . CRM_Utils_System
::url('civicrm/contact/merge', $mergeParams) . '">' . ts('merge') . '</a>';
936 $searchRows[$mainId]['actions'] .= "<a class='action-item crm-hover-button crm-notDuplicate' href='#' onClick=\"processDupes( {$main['srcID']}, {$main['dstID']}, 'dupe-nondupe', 'dupe-listing'); return false;\">" . ts('not a duplicate') . "</a>";
939 $searchRows[$mainId]['actions'] = '<em>' . ts('Insufficient access rights - cannot merge') . '</em>';
943 echo CRM_Utils_JSON
::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
945 CRM_Utils_System
::civiExit();
949 * Retrieve a PDF Page Format for the PDF Letter form.
951 public function pdfFormat() {
952 $formatId = CRM_Utils_Type
::escape($_REQUEST['formatId'], 'Integer');
954 $pdfFormat = CRM_Core_BAO_PdfFormat
::getById($formatId);
956 CRM_Utils_JSON
::output($pdfFormat);
960 * Retrieve Paper Size dimensions.
962 public static function paperSize() {
963 $paperSizeName = CRM_Utils_Type
::escape($_REQUEST['paperSizeName'], 'String');
965 $paperSize = CRM_Core_BAO_PaperSize
::getByName($paperSizeName);
967 CRM_Utils_JSON
::output($paperSize);
971 * Used to store selected contacts across multiple pages in advanced search.
973 public static function selectUnselectContacts() {
974 $name = CRM_Utils_Array
::value('name', $_REQUEST);
975 $cacheKey = CRM_Utils_Array
::value('qfKey', $_REQUEST);
976 $state = CRM_Utils_Array
::value('state', $_REQUEST, 'checked');
977 $variableType = CRM_Utils_Array
::value('variableType', $_REQUEST, 'single');
979 $actionToPerform = CRM_Utils_Array
::value('action', $_REQUEST, 'select');
981 if ($variableType == 'multiple') {
982 // action post value only works with multiple type variable
984 //multiple names like mark_x_1-mark_x_2 where 1,2 are cids
985 $elements = explode('-', $name);
986 foreach ($elements as $key => $element) {
987 $elements[$key] = self
::_convertToId($element);
989 CRM_Core_BAO_PrevNextCache
::markSelection($cacheKey, $actionToPerform, $elements);
992 CRM_Core_BAO_PrevNextCache
::markSelection($cacheKey, $actionToPerform);
995 elseif ($variableType == 'single') {
996 $cId = self
::_convertToId($name);
997 $action = ($state == 'checked') ?
'select' : 'unselect';
998 CRM_Core_BAO_PrevNextCache
::markSelection($cacheKey, $action, $cId);
1000 $contactIds = CRM_Core_BAO_PrevNextCache
::getSelection($cacheKey);
1001 $countSelectionCids = count($contactIds[$cacheKey]);
1003 $arrRet = array('getCount' => $countSelectionCids);
1004 CRM_Utils_JSON
::output($arrRet);
1008 * @param string $name
1012 public static function _convertToId($name) {
1013 if (substr($name, 0, CRM_Core_Form
::CB_PREFIX_LEN
) == CRM_Core_Form
::CB_PREFIX
) {
1014 $cId = substr($name, CRM_Core_Form
::CB_PREFIX_LEN
);
1019 public static function getAddressDisplay() {
1020 $contactId = CRM_Utils_Array
::value('contact_id', $_REQUEST);
1022 $addressVal["error_message"] = "no contact id found";
1025 $entityBlock = array(
1026 'contact_id' => $contactId,
1027 'entity_id' => $contactId,
1029 $addressVal = CRM_Core_BAO_Address
::getValues($entityBlock);
1032 CRM_Utils_JSON
::output($addressVal);
1036 * Retrieve contact relationships.
1038 public static function getContactRelationships() {
1039 $contactID = CRM_Utils_Type
::escape($_GET['cid'], 'Integer');
1040 $context = CRM_Utils_Type
::escape($_GET['context'], 'String');
1042 if (!CRM_Contact_BAO_Contact_Permission
::allow($contactID)) {
1043 return CRM_Utils_System
::permissionDenied();
1046 $sortMapper = array(
1060 $sEcho = CRM_Utils_Type
::escape($_REQUEST['sEcho'], 'Integer');
1061 $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type
::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
1062 $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type
::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
1063 $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array
::value(CRM_Utils_Type
::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
1064 $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type
::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
1067 if ($sort && $sortOrder) {
1068 $params['sortBy'] = $sort . ' ' . $sortOrder;
1071 $params['page'] = ($offset / $rowCount) +
1;
1072 $params['rp'] = $rowCount;
1074 $params['contact_id'] = $contactID;
1075 $params['context'] = $context;
1077 // get the contact relationships
1078 $relationships = CRM_Contact_BAO_Relationship
::getContactRelationshipSelector($params);
1080 $iFilteredTotal = $iTotal = $params['total'];
1081 $selectorElements = array(
1095 echo CRM_Utils_JSON
::encodeDataTableSelector($relationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
1096 CRM_Utils_System
::civiExit();