'unknown'); /** * The group id that we are passing in url. * * @var int */ public $_grid; /** * Name of button for saving matching contacts. * @var */ protected $_duplicateButtonName; /** * The title of the category we are editing. * * @var string */ protected $_title; /** * The fields needed to build this form. * * @var array */ public $_fields; /** * store contact details. * * @var array */ protected $_contact; /** * Do we allow updates of the contact. * * @var int */ public $_isUpdateDupe = 0; /** * Dedupe using a specific rule (CRM-6131). * Not currently exposed in profile settings, but can be set in a buildForm hook. */ public $_ruleGroupID = NULL; public $_isAddCaptcha = FALSE; protected $_isPermissionedChecksum = FALSE; /** * THe context from which we came from, allows us to go there if redirect not set. * * @var string */ protected $_context; /** * THe contact type for registration case. * * @var string */ protected $_ctype = NULL; /** * Store profile ids if multiple profile ids are passed using comma separated. * Currently lets implement this functionality only for dialog mode. */ protected $_profileIds = array(); /** * Contact profile having activity fields? * * @var string */ protected $_isContactActivityProfile = FALSE; /** * Activity Id connected to the profile. * * @var string */ protected $_activityId = NULL; protected $_multiRecordFields = NULL; protected $_recordId = NULL; /** * Action for multi record profile (create/edit/delete). * * @var string */ protected $_multiRecord = NULL; protected $_multiRecordProfile = FALSE; protected $_recordExists = TRUE; protected $_customGroupTitle = NULL; protected $_deleteButtonName = NULL; protected $_customGroupId = NULL; protected $_currentUserID = NULL; protected $_session = NULL; /** * Explicitly declare the entity api name. */ public function getDefaultEntity() { return 'Profile'; } /** * Pre processing work done here. * * gets session variables for table name, id of entity in table, type of entity and stores them. */ public function preProcess() { $this->_id = $this->get('id'); $this->_profileIds = $this->get('profileIds'); $this->_grid = CRM_Utils_Request::retrieve('grid', 'Integer', $this); $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); //unset from session when $_GET doesn't have it //except when the form is submitted if (empty($_POST)) { if (!array_key_exists('multiRecord', $_GET)) { $this->set('multiRecord', NULL); } if (!array_key_exists('recordId', $_GET)) { $this->set('recordId', NULL); } } $this->_session = CRM_Core_Session::singleton(); $this->_currentUserID = $this->_session->get('userID'); if ($this->_mode == self::MODE_EDIT) { //specifies the action being done on a multi record field $multiRecordAction = CRM_Utils_Request::retrieve('multiRecord', 'String', $this); $this->_multiRecord = (!is_numeric($multiRecordAction)) ? CRM_Core_Action::resolve($multiRecordAction) : $multiRecordAction; if ($this->_multiRecord) { $this->set('multiRecord', $this->_multiRecord); } if ($this->_multiRecord && !in_array($this->_multiRecord, array(CRM_Core_Action::UPDATE, CRM_Core_Action::ADD, CRM_Core_Action::DELETE)) ) { CRM_Core_Error::fatal(ts('Proper action not specified for this custom value record profile')); } } $this->_duplicateButtonName = $this->getButtonName('upload', 'duplicate'); $gids = explode(',', CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0)); if ((count($gids) > 1) && !$this->_profileIds && empty($this->_profileIds)) { if (!empty($gids)) { foreach ($gids as $pfId) { $this->_profileIds[] = CRM_Utils_Type::escape($pfId, 'Positive'); } } // check if we are rendering mixed profiles if (CRM_Core_BAO_UFGroup::checkForMixProfiles($this->_profileIds)) { CRM_Core_Error::fatal(ts('You cannot combine profiles of multiple types.')); } // for now consider 1'st profile as primary profile and validate it // i.e check for profile type etc. // FIX ME: validations for other than primary $this->_gid = $this->_profileIds[0]; $this->set('gid', $this->_gid); $this->set('profileIds', $this->_profileIds); } if (!$this->_gid) { $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE, 0); $this->set('gid', $this->_gid); } $this->_activityId = CRM_Utils_Request::retrieve('aid', 'Positive', $this, FALSE, 0, 'GET'); if (is_numeric($this->_activityId)) { $latestRevisionId = CRM_Activity_BAO_Activity::getLatestActivityId($this->_activityId); if ($latestRevisionId) { $this->_activityId = $latestRevisionId; } } $this->_isContactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($this->_gid); //get values for ufGroupName, captcha and dupe update. if ($this->_gid) { $dao = new CRM_Core_DAO_UFGroup(); $dao->id = $this->_gid; if ($dao->find(TRUE)) { $this->_isUpdateDupe = $dao->is_update_dupe; $this->_isAddCaptcha = $dao->add_captcha; $this->_ufGroup = (array) $dao; } $dao->free(); if (!CRM_Utils_Array::value('is_active', $this->_ufGroup)) { CRM_Core_Error::fatal(ts('The requested profile (gid=%1) is inactive or does not exist.', array( 1 => $this->_gid, ))); } } $this->assign('ufGroupName', $this->_ufGroup['name']); $gids = empty($this->_profileIds) ? $this->_gid : $this->_profileIds; // if we don't have a gid use the default, else just use that specific gid if (($this->_mode == self::MODE_REGISTER || $this->_mode == self::MODE_CREATE) && !$this->_gid) { $this->_ctype = CRM_Utils_Request::retrieve('ctype', 'String', $this, FALSE, 'Individual', 'REQUEST'); $this->_fields = CRM_Core_BAO_UFGroup::getRegistrationFields($this->_action, $this->_mode, $this->_ctype); } elseif ($this->_mode == self::MODE_SEARCH) { $this->_fields = CRM_Core_BAO_UFGroup::getListingFields($this->_action, CRM_Core_BAO_UFGroup::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup::LISTINGS_VISIBILITY, FALSE, $gids, TRUE, NULL, $this->_skipPermission, CRM_Core_Permission::SEARCH ); } else { $this->_fields = CRM_Core_BAO_UFGroup::getFields($gids, FALSE, NULL, NULL, NULL, FALSE, NULL, $this->_skipPermission, NULL, ($this->_action == CRM_Core_Action::ADD) ? CRM_Core_Permission::CREATE : CRM_Core_Permission::EDIT ); $multiRecordFieldListing = FALSE; //using selector for listing of multi-record fields if ($this->_mode == self::MODE_EDIT && $this->_gid) { CRM_Core_BAO_UFGroup::shiftMultiRecordFields($this->_fields, $this->_multiRecordFields); if ($this->_multiRecord) { if ($this->_multiRecord != CRM_Core_Action::ADD) { $this->_recordId = CRM_Utils_Request::retrieve('recordId', 'Positive', $this); } else { $this->_recordId = NULL; $this->set('recordId', NULL); } //record id is necessary for _multiRecord view and update/edit action if (!$this->_recordId && ($this->_multiRecord == CRM_Core_Action::UPDATE || $this->_multiRecord == CRM_Core_Action::DELETE) ) { CRM_Core_Error::fatal(ts('The requested Profile (gid=%1) requires record id while performing this action', array(1 => $this->_gid) )); } elseif (empty($this->_multiRecordFields)) { CRM_Core_Error::fatal(ts('No Multi-Record Fields configured for this profile (gid=%1)', array(1 => $this->_gid) )); } $fieldId = CRM_Core_BAO_CustomField::getKeyID(key($this->_multiRecordFields)); $customGroupDetails = CRM_Core_BAO_CustomGroup::getGroupTitles(array($fieldId)); $this->_customGroupTitle = $customGroupDetails[$fieldId]['groupTitle']; $this->_customGroupId = $customGroupDetails[$fieldId]['groupID']; if ($this->_multiRecord == CRM_Core_Action::UPDATE || $this->_multiRecord == CRM_Core_Action::DELETE) { //record exists check foreach ($this->_multiRecordFields as $key => $field) { $fieldIds[] = CRM_Core_BAO_CustomField::getKeyID($key); } $getValues = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_id, NULL, $fieldIds, TRUE); if (array_key_exists($this->_recordId, $getValues)) { $this->_recordExists = TRUE; } else { $this->_recordExists = FALSE; if ($this->_multiRecord & CRM_Core_Action::UPDATE) { CRM_Core_Session::setStatus(ts('Note: The record %1 doesnot exists. Upon save a new record will be create', array(1 => $this->_recordId)), ts('Record doesnot exist'), 'alert'); } } } if ($this->_multiRecord & CRM_Core_Action::ADD) { $this->_maxRecordLimit = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($customGroupDetails[$fieldId]['groupID'], $this->_id); if ($this->_maxRecordLimit) { CRM_Core_Session::setStatus(ts('You cannot add a new record as maximum allowed limit is reached'), ts('Sorry'), 'error'); } } } elseif (!empty($this->_multiRecordFields) && (!$this->_multiRecord || !in_array($this->_multiRecord, array( CRM_Core_Action::DELETE, CRM_Core_Action::UPDATE, ))) ) { CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js', 1, 'html-header'); //multi-record listing page $multiRecordFieldListing = TRUE; $page = new CRM_Profile_Page_MultipleRecordFieldsListing(); $cs = $this->get('cs'); $page->set('pageCheckSum', $cs); $page->set('contactId', $this->_id); $page->set('profileId', $this->_gid); $page->set('action', CRM_Core_Action::BROWSE); $page->set('multiRecordFieldListing', $multiRecordFieldListing); $page->run(); } } $this->assign('multiRecordFieldListing', $multiRecordFieldListing); // is profile double-opt in? if (!empty($this->_fields['group']) && CRM_Core_BAO_UFGroup::isProfileDoubleOptin() ) { $emailField = FALSE; foreach ($this->_fields as $name => $values) { if (substr($name, 0, 6) == 'email-') { $emailField = TRUE; } } if (!$emailField) { $status = ts("Email field should be included in profile if you want to use Group(s) when Profile double-opt in process is enabled."); $this->_session->setStatus($status); } } //transferring all the multi-record custom fields in _fields if ($this->_multiRecord && !empty($this->_multiRecordFields)) { $this->_fields = $this->_multiRecordFields; $this->_multiRecordProfile = TRUE; } elseif ($this->_multiRecord && empty($this->_multiRecordFields)) { CRM_Core_Session::setStatus(ts('This feature is not currently available.'), ts('Sorry'), 'error'); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm', 'reset=1')); } } if (!is_array($this->_fields)) { CRM_Core_Session::setStatus(ts('This feature is not currently available.'), ts('Sorry'), 'error'); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm', 'reset=1')); } } /** * Set default values for the form. Note that in edit/view mode * the default values are retrieved from the database * */ public function setDefaultsValues() { $this->_defaults = array(); if ($this->_multiRecordProfile && ($this->_multiRecord == CRM_Core_Action::DELETE)) { return; } if ($this->_mode != self::MODE_SEARCH) { // set default values for country / state to start with CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $this->_defaults); } if ($this->_id && !$this->_multiRecordProfile) { if ($this->_isContactActivityProfile) { $contactFields = $activityFields = array(); foreach ($this->_fields as $fieldName => $field) { if (CRM_Utils_Array::value('field_type', $field) == 'Activity') { $activityFields[$fieldName] = $field; } else { $contactFields[$fieldName] = $field; } } CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $contactFields, $this->_defaults, TRUE); if ($this->_activityId) { CRM_Core_BAO_UFGroup::setComponentDefaults($activityFields, $this->_activityId, 'Activity', $this->_defaults, TRUE); } } else { CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $this->_fields, $this->_defaults, TRUE); } } //set custom field defaults if ($this->_multiRecordProfile) { foreach ($this->_multiRecordFields as $key => $field) { $fieldIds[] = CRM_Core_BAO_CustomField::getKeyID($key); } $defaultValues = array(); if ($this->_multiRecord && $this->_multiRecord == CRM_Core_Action::UPDATE) { $defaultValues = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_id, NULL, $fieldIds, TRUE); if ($this->_recordExists == TRUE) { $defaultValues = $defaultValues[$this->_recordId]; } else { $defaultValues = NULL; } } if (!empty($defaultValues)) { foreach ($defaultValues as $key => $value) { $name = "custom_{$key}"; $htmlType = $this->_multiRecordFields[$name]['html_type']; if ($htmlType != 'File') { if (isset($value)) { CRM_Core_BAO_CustomField::setProfileDefaults($key, $name, $this->_defaults, $this->_id, $this->_mode, $value ); } else { $this->_defaults[$name] = ""; } } if ($htmlType == 'File') { $entityId = $this->_id; if (CRM_Utils_Array::value('field_type', $field) == 'Activity' && $this->_activityId ) { $entityId = $this->_activityId; } $url = ''; if (isset($value)) { $url = CRM_Core_BAO_CustomField::getFileURL($entityId, $key, $value); } if ($url) { $customFiles[$name]['displayURL'] = ts("Attached File") . ": {$url['file_url']}"; $deleteExtra = ts("Are you sure you want to delete attached file?"); $fileId = $url['file_id']; $deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid=$entityId&fid={$key}&action=delete" ); $text = ts("Delete Attached File"); $customFiles[$field['name']]['deleteURL'] = "$text"; // also delete the required rule that we've set on the form element $this->removeFileRequiredRules($name); } } } } } else { foreach ($this->_fields as $name => $field) { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) { $htmlType = $field['html_type']; if ((!isset($this->_defaults[$name]) || $htmlType == 'File') && (CRM_Utils_Array::value('field_type', $field) != 'Activity') ) { CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_id, $this->_mode ); } if ($htmlType == 'File') { $entityId = $this->_id; if (CRM_Utils_Array::value('field_type', $field) == 'Activity' && $this->_activityId) { $entityId = $this->_activityId; } $url = CRM_Core_BAO_CustomField::getFileURL($entityId, $customFieldID); if ($url) { $customFiles[$field['name']]['displayURL'] = ts("Attached File") . ": {$url['file_url']}"; $deleteExtra = ts("Are you sure you want to delete attached file?"); $fileId = $url['file_id']; $deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid=$entityId&fid={$customFieldID}&action=delete" ); $text = ts("Delete Attached File"); $customFiles[$field['name']]['deleteURL'] = "$text"; // also delete the required rule that we've set on the form element $this->removeFileRequiredRules($field['name']); } } } } } if (isset($customFiles)) { $this->assign('customFiles', $customFiles); } if ($this->_multiRecordProfile) { $this->setDefaults($this->_defaults); return; } if (!empty($this->_defaults['image_URL'])) { $this->assign("imageURL", CRM_Utils_File::getImageURL($this->_defaults['image_URL'])); $this->removeFileRequiredRules('image_URL'); } if (array_key_exists('contact_sub_type', $this->_defaults) && !empty($this->_defaults['contact_sub_type']) ) { $this->_defaults['contact_sub_type'] = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($this->_defaults['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR) ); } $this->setDefaults($this->_defaults); } /** * Build the form object. * */ public function buildQuickForm() { $this->add('hidden', 'gid', $this->_gid); switch ($this->_mode) { case self::MODE_CREATE: case self::MODE_EDIT: case self::MODE_REGISTER: CRM_Utils_Hook::buildProfile($this->_ufGroup['name']); break; case self::MODE_SEARCH: CRM_Utils_Hook::searchProfile($this->_ufGroup['name']); break; default: } //lets have single status message, CRM-4363 $return = FALSE; $statusMessage = NULL; if (($this->_multiRecord & CRM_Core_Action::ADD) && $this->_maxRecordLimit) { return; } if (($this->_multiRecord & CRM_Core_Action::DELETE)) { if (!$this->_recordExists) { CRM_Core_Session::setStatus(ts('The record %1 doesnot exists', array(1 => $this->_recordId)), ts('Record doesnot exists'), 'alert'); } else { $this->assign('deleteRecord', TRUE); } return; } CRM_Core_BAO_Address::checkContactSharedAddressFields($this->_fields, $this->_id); // we should not allow component and mix profiles in search mode if ($this->_mode != self::MODE_REGISTER) { //check for mix profile fields (eg: individual + other contact type) if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) { if (($this->_mode & self::MODE_EDIT) && $this->_isContactActivityProfile) { $errors = self::validateContactActivityProfile($this->_activityId, $this->_id, $this->_gid); if (!empty($errors)) { $statusMessage = array_pop($errors); $return = TRUE; } } else { $statusMessage = ts('Profile search, view and edit are not supported for Profiles which include fields for more than one record type.'); $return = TRUE; } } $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid); if ($this->_id) { $contactTypes = CRM_Contact_BAO_Contact::getContactTypes($this->_id); $contactType = $contactTypes[0]; array_shift($contactTypes); $contactSubtypes = $contactTypes; $profileSubType = FALSE; if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $profileSubType = $profileType; $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } if ( ($profileType != 'Contact' && !$this->_isContactActivityProfile) && (($profileSubType && !empty($contactSubtypes) && (!in_array($profileSubType, $contactSubtypes))) || ($profileType != $contactType)) ) { $return = TRUE; if (!$statusMessage) { $statusMessage = ts("This profile is configured for contact type '%1'. It cannot be used to edit contacts of other types.", array(1 => $profileSubType ? $profileSubType : $profileType)); } } } if ( in_array( $profileType, array("Membership", "Participant", "Contribution") ) ) { $return = TRUE; if (!$statusMessage) { $statusMessage = ts('Profile is not configured for the selected action.'); } } } //lets have single status message, $this->assign('statusMessage', $statusMessage); if ($return) { return FALSE; } $this->assign('id', $this->_id); $this->assign('mode', $this->_mode); $this->assign('action', $this->_action); $this->assign('fields', $this->_fields); $this->assign('fieldset', (isset($this->_fieldset)) ? $this->_fieldset : ""); // should we restrict what we display $admin = TRUE; if ($this->_mode == self::MODE_EDIT) { $admin = FALSE; // show all fields that are visible: // if we are a admin OR the same user OR acl-user with access to the profile // or we have checksum access to this contact (i.e. the user without a login) - CRM-5909 if ( CRM_Core_Permission::check('administer users') || $this->_id == $this->_currentUserID || $this->_isPermissionedChecksum || in_array( $this->_gid, CRM_ACL_API::group( CRM_Core_Permission::EDIT, NULL, 'civicrm_uf_group', CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id') ) ) ) { $admin = TRUE; } } // if false, user is not logged-in. $anonUser = FALSE; if (!$this->_currentUserID) { $defaultLocationType = CRM_Core_BAO_LocationType::getDefault(); $primaryLocationType = $defaultLocationType->id; $anonUser = TRUE; } $this->assign('anonUser', $anonUser); $addCaptcha = array(); $emailPresent = FALSE; // add the form elements foreach ($this->_fields as $name => $field) { // make sure that there is enough permission to expose this field if (!$admin && $field['visibility'] == 'User and User Admin Only') { unset($this->_fields[$name]); continue; } // since the CMS manages the email field, suppress the email display if in // register mode which occur within the CMS form if ($this->_mode == self::MODE_REGISTER && substr($name, 0, 5) == 'email') { unset($this->_fields[$name]); continue; } list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2); CRM_Core_BAO_UFGroup::buildProfile($this, $field, $this->_mode); if ($field['add_to_group_id']) { $addToGroupId = $field['add_to_group_id']; } //build array for captcha if ($field['add_captcha']) { $addCaptcha[$field['group_id']] = $field['add_captcha']; } if (($name == 'email-Primary') || ($name == 'email-' . isset($primaryLocationType) ? $primaryLocationType : "")) { $emailPresent = TRUE; $this->_mail = $name; } } // add captcha only for create mode. if ($this->_mode == self::MODE_CREATE) { // suppress captcha for logged in users only if ($this->_currentUserID) { $this->_isAddCaptcha = FALSE; } elseif (!$this->_isAddCaptcha && !empty($addCaptcha)) { $this->_isAddCaptcha = TRUE; } if ($this->_gid) { $dao = new CRM_Core_DAO_UFGroup(); $dao->id = $this->_gid; $dao->addSelect(); $dao->addSelect('is_update_dupe'); if ($dao->find(TRUE)) { if ($dao->is_update_dupe) { $this->_isUpdateDupe = $dao->is_update_dupe; } } } } else { $this->_isAddCaptcha = FALSE; } //finally add captcha to form. if ($this->_isAddCaptcha) { $captcha = CRM_Utils_ReCAPTCHA::singleton(); $captcha->add($this); } $this->assign("isCaptcha", $this->_isAddCaptcha); if ($this->_mode != self::MODE_SEARCH) { if (isset($addToGroupId)) { $this->_ufGroup['add_to_group_id'] = $addToGroupId; } } //let's do set defaults for the profile $this->setDefaultsValues(); $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, NULL); if ($this->_mode == self::MODE_CREATE || $this->_mode == self::MODE_EDIT) { CRM_Core_BAO_CMSUser::buildForm($this, $this->_gid, $emailPresent, $action); } else { $this->assign('showCMS', FALSE); } $this->assign('groupId', $this->_gid); // if view mode pls freeze it with the done button. if ($this->_action & CRM_Core_Action::VIEW) { $this->freeze(); } if ($this->_context == 'dialog') { $this->addElement( 'submit', $this->_duplicateButtonName, ts('Save Matching Contact') ); } } /** * Validate profile and provided activity Id. * * @param int $activityId * @param int $contactId * @param int $gid * * @return array */ public static function validateContactActivityProfile($activityId, $contactId, $gid) { $errors = array(); if (!$activityId) { $errors[] = 'Profile is using one or more activity fields, and is missing the activity Id (aid) in the URL.'; return $errors; } $activityDetails = array(); $activityParams = array('id' => $activityId); CRM_Activity_BAO_Activity::retrieve($activityParams, $activityDetails); if (empty($activityDetails)) { $errors[] = 'Invalid Activity Id (aid).'; return $errors; } $profileActivityTypes = CRM_Core_BAO_UFGroup::groupTypeValues($gid, 'Activity'); if ((!empty($profileActivityTypes['Activity']) && !in_array($activityDetails['activity_type_id'], $profileActivityTypes['Activity']) ) || (!in_array($contactId, $activityDetails['assignee_contact']) && !in_array($contactId, $activityDetails['target_contact']) ) ) { $errors[] = 'This activity cannot be edited or viewed via this profile.'; } return $errors; } /** * Global form rule. * * @param array $fields * The input form values. * @param array $files * The uploaded files if any. * @param CRM_Core_Form $form * The form object. * * @return bool|array * true if no errors, else array of errors */ public static function formRule($fields, $files, $form) { CRM_Utils_Hook::validateProfile($form->_ufGroup['name']); $errors = array(); // if no values, return if (empty($fields)) { return TRUE; } $register = NULL; // hack we use a -1 in options to indicate that its registration if ($form->_id) { $form->_isUpdateDupe = 1; } if ($form->_mode == CRM_Profile_Form::MODE_REGISTER) { $register = TRUE; } // don't check for duplicates during registration validation: CRM-375 if (!$register && empty($fields['_qf_Edit_upload_duplicate'])) { // fix for CRM-3240 if (!empty($fields['email-Primary'])) { $fields['email'] = CRM_Utils_Array::value('email-Primary', $fields); } // fix for CRM-6141 if (!empty($fields['phone-Primary-1']) && empty($fields['phone-Primary'])) { $fields['phone-Primary'] = $fields['phone-Primary-1']; } $ctype = CRM_Core_BAO_UFGroup::getContactType($form->_gid); // If all profile fields is of Contact Type then consider // profile is of Individual type(default). if (!$ctype) { $ctype = 'Individual'; } if ($form->_mode == CRM_Profile_Form::MODE_CREATE) { // fix for CRM-2888 $exceptions = array(); } else { // for edit mode we need to allow our own record to be a dupe match! $exceptions = array($form->_session->get('userID')); } $ids = CRM_Contact_BAO_Contact::getDuplicateContacts( $fields, $ctype, ($form->_context === 'dialog' ? 'Supervised' : 'Unsupervised'), $exceptions, FALSE, $form->_ruleGroupID ); if ($ids) { if ($form->_isUpdateDupe == 2) { CRM_Core_Session::setStatus(ts('Note: this contact may be a duplicate of an existing record.'), ts('Possible Duplicate Detected'), 'alert'); } elseif ($form->_isUpdateDupe == 1) { if (!$form->_id) { $form->_id = $ids[0]; } } else { if ($form->_context == 'dialog') { $contactLinks = CRM_Contact_BAO_Contact_Utils::formatContactIDSToLinks($ids, TRUE, TRUE); $duplicateContactsLinks = '
'; $row .= $contactLinks['rows'][$i]['display_name']; $row .= ' | '; $row .= ''; $row .= $contactLinks['rows'][$i]['primary_email']; $row .= ' | '; $row .= ''; $row .= $contactLinks['rows'][$i]['view'] . ' '; $row .= $contactLinks['rows'][$i]['edit']; $row .= ' | '; $row .= '