Exemple #1
0
 /**
  * Function to add the custom fields
  *
  * @return None
  * @access public
  */
 function buildCustom($id, $name, $viewOnly = FALSE, $onBehalf = FALSE, $fieldTypes = NULL)
 {
     $stateCountryMap = array();
     if ($id) {
         $contactID = $this->getContactID();
         // we don't allow conflicting fields to be
         // configured via profile - CRM 2100
         $fieldsToIgnore = array('receive_date' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'net_amount' => 1, 'fee_amount' => 1, 'non_deductible_amount' => 1, 'total_amount' => 1, 'amount_level' => 1, 'contribution_status_id' => 1, 'payment_instrument' => 1, 'check_number' => 1, 'financial_type' => 1);
         $fields = NULL;
         if ($contactID && CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         }
         if ($fields) {
             // unset any email-* fields since we already collect it, CRM-2888
             foreach (array_keys($fields) as $fieldName) {
                 if (substr($fieldName, 0, 6) == 'email-') {
                     unset($fields[$fieldName]);
                 }
             }
             if (array_intersect_key($fields, $fieldsToIgnore)) {
                 $fields = array_diff_key($fields, $fieldsToIgnore);
                 CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'), ts('Warning'), 'alert');
             }
             $fields = array_diff_assoc($fields, $this->_fields);
             CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
             $addCaptcha = FALSE;
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     // ignore file upload fields
                     continue;
                 }
                 list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
                 if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
                     if (!array_key_exists($index, $stateCountryMap)) {
                         $stateCountryMap[$index] = array();
                     }
                     $stateCountryMap[$index][$prefixName] = $key;
                 }
                 if ($onBehalf) {
                     if (!empty($fieldTypes) && in_array($field['field_type'], $fieldTypes)) {
                         CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                         $this->_fields['onbehalf'][$key] = $field;
                     } else {
                         unset($fields[$key]);
                     }
                 } else {
                     CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                     $this->_fields[$key] = $field;
                 }
                 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
                 if ($field['add_captcha'] && !$this->_userID) {
                     $addCaptcha = TRUE;
                 }
             }
             $this->assign($name, $fields);
             CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
             if ($addCaptcha && !$viewOnly) {
                 $captcha = CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign('isCaptcha', TRUE);
             }
         }
     }
 }
Exemple #2
0
 /**
  * Add the custom fields.
  *
  * @param int $id
  * @param string $name
  * @param bool $viewOnly
  */
 public function buildCustom($id, $name, $viewOnly = FALSE)
 {
     if ($id) {
         $button = substr($this->controller->getButtonName(), -4);
         $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
         $session = CRM_Core_Session::singleton();
         $contactID = $session->get('userID');
         // we don't allow conflicting fields to be
         // configured via profile
         $fieldsToIgnore = array('participant_fee_amount' => 1, 'participant_fee_level' => 1);
         if ($contactID) {
             //FIX CRM-9653
             if (is_array($id)) {
                 $fields = array();
                 foreach ($id as $profileID) {
                     $field = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, 'field_name', TRUE);
                     $fields = array_merge($fields, $field);
                 }
             } else {
                 if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
                     $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, 'field_name', TRUE);
                 }
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, 'field_name', TRUE);
         }
         if (array_intersect_key($fields, $fieldsToIgnore)) {
             $fields = array_diff_key($fields, $fieldsToIgnore);
             CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'));
         }
         $addCaptcha = FALSE;
         if (!empty($this->_fields)) {
             $fields = @array_diff_assoc($fields, $this->_fields);
         }
         if (empty($this->_params[0]['additional_participants']) && is_null($cid)) {
             CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
         }
         $this->assign($name, $fields);
         if (is_array($fields)) {
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     // ignore file upload fields
                     continue;
                 }
                 //make the field optional if primary participant
                 //have been skip the additional participant.
                 if ($button == 'skip') {
                     $field['is_required'] = FALSE;
                 } elseif ($field['add_captcha'] && !$contactID) {
                     // only add captcha for first page
                     $addCaptcha = TRUE;
                 }
                 list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
                 CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                 $this->_fields[$key] = $field;
             }
         }
         if ($addCaptcha && !$viewOnly) {
             $captcha = CRM_Utils_ReCAPTCHA::singleton();
             $captcha->add($this);
             $this->assign('isCaptcha', TRUE);
         }
     }
 }
 /**
  * Function to add the custom fields
  *
  * @param $id
  * @param $name
  * @param bool $viewOnly
  * @param null $profileContactType
  * @param null $fieldTypes
  *
  * @return void
  * @access public
  */
 function buildCustom($id, $name, $viewOnly = FALSE, $profileContactType = NULL, $fieldTypes = NULL)
 {
     if ($id) {
         $contactID = $this->getContactID();
         // we don't allow conflicting fields to be
         // configured via profile - CRM 2100
         $fieldsToIgnore = array('receive_date' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'net_amount' => 1, 'fee_amount' => 1, 'non_deductible_amount' => 1, 'total_amount' => 1, 'amount_level' => 1, 'contribution_status_id' => 1, 'payment_instrument' => 1, 'check_number' => 1, 'financial_type' => 1);
         $fields = NULL;
         if ($contactID && CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         }
         if ($fields) {
             // unset any email-* fields since we already collect it, CRM-2888
             foreach (array_keys($fields) as $fieldName) {
                 if (substr($fieldName, 0, 6) == 'email-' && $profileContactType != 'honor') {
                     unset($fields[$fieldName]);
                 }
             }
             if (array_intersect_key($fields, $fieldsToIgnore)) {
                 $fields = array_diff_key($fields, $fieldsToIgnore);
                 CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'), ts('Warning'), 'alert');
             }
             $fields = array_diff_assoc($fields, $this->_fields);
             CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
             $addCaptcha = FALSE;
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     // ignore file upload fields
                     continue;
                 }
                 if ($profileContactType) {
                     //Since we are showing honoree name separately so we are removing it from honoree profile just for display
                     $honoreeNamefields = array('prefix_id', 'first_name', 'last_name', 'suffix_id', 'organization_name', 'household_name');
                     if ($profileContactType == 'honor' && in_array($field['name'], $honoreeNamefields)) {
                         unset($fields[$field['name']]);
                         continue;
                     }
                     if (!empty($fieldTypes) && in_array($field['field_type'], $fieldTypes)) {
                         CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE, $profileContactType);
                         $this->_fields[$profileContactType][$key] = $field;
                     } else {
                         unset($fields[$key]);
                     }
                 } else {
                     CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                     $this->_fields[$key] = $field;
                 }
                 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
                 if ($field['add_captcha'] && !$this->_userID) {
                     $addCaptcha = TRUE;
                 }
             }
             $this->assign($name, $fields);
             if ($addCaptcha && !$viewOnly) {
                 $captcha = CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign('isCaptcha', TRUE);
             }
         }
     }
 }
Exemple #4
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     $ufGroupId = $this->get('ufGroupId');
     if (!$ufGroupId) {
         CRM_Core_Error::fatal('ufGroupId is missing');
     }
     $this->_title = ts('Update multiple contacts') . ' - ' . CRM_Core_BAO_UFGroup::getTitle($ufGroupId);
     CRM_Utils_System::setTitle($this->_title);
     $this->addDefaultButtons(ts('Save'));
     $this->_fields = CRM_Core_BAO_UFGroup::getFields($ufGroupId, FALSE, CRM_Core_Action::VIEW);
     // remove file type field and then limit fields
     $suppressFields = FALSE;
     $removehtmlTypes = array('File', 'Autocomplete-Select');
     foreach ($this->_fields as $name => $field) {
         if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name) && in_array($this->_fields[$name]['html_type'], $removehtmlTypes)) {
             $suppressFields = TRUE;
             unset($this->_fields[$name]);
         }
     }
     //FIX ME: phone ext field is added at the end and it gets removed because of below code
     //$this->_fields = array_slice($this->_fields, 0, $this->_maxFields);
     $this->addButtons(array(array('type' => 'submit', 'name' => ts('Update Contact(s)'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->assign('profileTitle', $this->_title);
     $this->assign('componentIds', $this->_contactIds);
     // if below fields are missing we should not reset sort name / display name
     // CRM-6794
     $preserveDefaultsArray = array('first_name', 'last_name', 'middle_name', 'organization_name', 'prefix_id', 'suffix_id', 'household_name');
     foreach ($this->_contactIds as $contactId) {
         $profileFields = $this->_fields;
         CRM_Core_BAO_Address::checkContactSharedAddressFields($profileFields, $contactId);
         foreach ($profileFields as $name => $field) {
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $contactId);
             if (in_array($field['name'], $preserveDefaultsArray)) {
                 $this->_preserveDefault = FALSE;
             }
         }
     }
     $this->assign('fields', $this->_fields);
     // don't set the status message when form is submitted.
     $buttonName = $this->controller->getButtonName('submit');
     if ($suppressFields && $buttonName != '_qf_BatchUpdateProfile_next') {
         CRM_Core_Session::setStatus(ts("File or Autocomplete-Select type field(s) in the selected profile are not supported for Update multiple contacts."), ts('Some Fields Excluded'), 'info');
     }
     $this->addDefaultButtons(ts('Update Contacts'));
     $this->addFormRule(array('CRM_Contact_Form_Task_Batch', 'formRule'));
 }
Exemple #5
0
 /**
  * Build the form object.
  *
  * @return void
  */
 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 visibile:
         // 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) {
         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'));
     }
 }
 /**
  * Function to add the custom fields
  *
  * @return void
  * @access public
  */
 function buildCustom($id, $name, $viewOnly = FALSE, $profileContactType = NULL, $fieldTypes = NULL)
 {
     $stateCountryMap = array();
     if ($id) {
         $contactID = $this->getContactID();
         // we don't allow conflicting fields to be
         // configured via profile - CRM 2100
         $fieldsToIgnore = array('receive_date' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'net_amount' => 1, 'fee_amount' => 1, 'non_deductible_amount' => 1, 'total_amount' => 1, 'amount_level' => 1, 'contribution_status_id' => 1, 'payment_instrument' => 1, 'check_number' => 1, 'financial_type' => 1);
         $fields = NULL;
         if ($contactID && CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         }
         if ($fields) {
             // unset any email-* fields since we already collect it, CRM-2888
             foreach (array_keys($fields) as $fieldName) {
                 if (substr($fieldName, 0, 6) == 'email-') {
                     unset($fields[$fieldName]);
                 }
             }
             if (array_intersect_key($fields, $fieldsToIgnore)) {
                 $fields = array_diff_key($fields, $fieldsToIgnore);
                 CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'), ts('Warning'), 'alert');
             }
             $fields = array_diff_assoc($fields, $this->_fields);
             CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
             $addCaptcha = FALSE;
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     // ignore file upload fields
                     continue;
                 }
                 list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
                 if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
                     if (!array_key_exists($index, $stateCountryMap)) {
                         $stateCountryMap[$index] = array();
                     }
                     $stateCountryMap[$index][$prefixName] = $key;
                     if ($prefixName == "state_province") {
                         if ($profileContactType == 'onbehalf') {
                             //CRM-11881: Bypass required-ness check for state/province on Contribution Confirm page
                             //as already done during Contribution registration via onBehalf's quickForm
                             $field['is_required'] = FALSE;
                         } else {
                             if (count($this->_submitValues)) {
                                 $locationTypeId = $field['location_type_id'];
                                 if (array_key_exists("country-{$locationTypeId}", $fields) && array_key_exists("state_province-{$locationTypeId}", $fields) && !empty($this->_submitValues["country-{$locationTypeId}"])) {
                                     $field['is_required'] = CRM_Core_Payment_Form::checkRequiredStateProvince($this, "country-{$locationTypeId}");
                                 }
                             }
                         }
                     }
                 }
                 if ($profileContactType) {
                     //Since we are showing honoree name separately so we are removing it from honoree profile just for display
                     $honoreeNamefields = array('prefix_id', 'first_name', 'last_name', 'suffix_id', 'organization_name', 'household_name');
                     if ($profileContactType == 'honor' && in_array($field['name'], $honoreeNamefields)) {
                         unset($fields[$field['name']]);
                         continue;
                     }
                     if (!empty($fieldTypes) && in_array($field['field_type'], $fieldTypes)) {
                         CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE, $profileContactType);
                         $this->_fields[$profileContactType][$key] = $field;
                     } else {
                         unset($fields[$key]);
                     }
                 } else {
                     CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                     $this->_fields[$key] = $field;
                 }
                 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
                 if ($field['add_captcha'] && !$this->_userID) {
                     $addCaptcha = TRUE;
                 }
             }
             $this->assign($name, $fields);
             CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
             if ($addCaptcha && !$viewOnly) {
                 $captcha = CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign('isCaptcha', TRUE);
             }
         }
     }
 }
 /**
  * Add the custom fields.
  *
  * @param int $id
  * @param string $name
  * @param bool $viewOnly
  * @param null $profileContactType
  * @param array $fieldTypes
  */
 public function buildCustom($id, $name, $viewOnly = FALSE, $profileContactType = NULL, $fieldTypes = NULL)
 {
     if ($id) {
         $contactID = $this->getContactID();
         // we don't allow conflicting fields to be
         // configured via profile - CRM 2100
         $fieldsToIgnore = array('receive_date' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'net_amount' => 1, 'fee_amount' => 1, 'non_deductible_amount' => 1, 'total_amount' => 1, 'amount_level' => 1, 'contribution_status_id' => 1, 'payment_instrument' => 1, 'check_number' => 1, 'financial_type' => 1);
         $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         if ($fields) {
             // unset any email-* fields since we already collect it, CRM-2888
             foreach (array_keys($fields) as $fieldName) {
                 if (substr($fieldName, 0, 6) == 'email-' && !in_array($profileContactType, array('honor', 'onbehalf'))) {
                     unset($fields[$fieldName]);
                 }
             }
             if (array_intersect_key($fields, $fieldsToIgnore)) {
                 $fields = array_diff_key($fields, $fieldsToIgnore);
                 CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'), ts('Warning'), 'alert');
             }
             //remove common fields only if profile is not configured for onbehalf/honor
             if (!in_array($profileContactType, array('honor', 'onbehalf'))) {
                 $fields = array_diff_assoc($fields, $this->_fields);
             }
             CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
             $addCaptcha = FALSE;
             // fetch file preview when not submitted yet, like in online contribution Confirm and ThankYou page
             $viewOnlyFileValues = empty($profileContactType) ? array() : array($profileContactType => array());
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     //retrieve file value from submitted values on basis of $profileContactType
                     $fileValue = CRM_Utils_Array::value($key, $this->_params);
                     if (!empty($profileContactType) && !empty($this->_params[$profileContactType])) {
                         $fileValue = CRM_Utils_Array::value($key, $this->_params[$profileContactType]);
                     }
                     if ($fileValue) {
                         $path = CRM_Utils_Array::value('name', $fileValue);
                         $fileType = CRM_Utils_Array::value('type', $fileValue);
                         $fileValue = CRM_Utils_File::getFileURL($path, $fileType);
                     }
                     // format custom file value fetched from submitted value
                     if ($profileContactType) {
                         $viewOnlyFileValues[$profileContactType][$key] = $fileValue;
                     } else {
                         $viewOnlyFileValues[$key] = $fileValue;
                     }
                 }
                 if ($profileContactType) {
                     //Since we are showing honoree name separately so we are removing it from honoree profile just for display
                     if ($profileContactType == 'honor') {
                         $honoreeNamefields = array('prefix_id', 'first_name', 'last_name', 'suffix_id', 'organization_name', 'household_name');
                         if (in_array($field['name'], $honoreeNamefields)) {
                             unset($fields[$field['name']]);
                             continue;
                         }
                     }
                     if (!empty($fieldTypes) && in_array($field['field_type'], $fieldTypes)) {
                         CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE, $profileContactType);
                         $this->_fields[$profileContactType][$key] = $field;
                     } else {
                         unset($fields[$key]);
                     }
                 } else {
                     CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                     $this->_fields[$key] = $field;
                 }
                 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
                 if ($field['add_captcha'] && !$this->_userID) {
                     $addCaptcha = TRUE;
                 }
             }
             $this->assign($name, $fields);
             if ($profileContactType && count($viewOnlyFileValues[$profileContactType])) {
                 $this->assign('viewOnlyPrefixFileValues', $viewOnlyFileValues);
             } elseif (count($viewOnlyFileValues)) {
                 $this->assign('viewOnlyFileValues', $viewOnlyFileValues);
             }
             if ($addCaptcha && !$viewOnly) {
                 $captcha = CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign('isCaptcha', TRUE);
             }
         }
     }
 }