Пример #1
0
 /**
  * Set the default form values
  *
  * @access protected
  *
  * @return array the default array reference
  */
 function setDefaultValues()
 {
     $defaults = array();
     $stateCountryMap = array();
     foreach ($this->_fields as $name => $field) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name'])) {
             CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
         }
         //CRM-5403
         if (substr($name, 0, 14) === 'state_province' || substr($name, 0, 7) === 'country' || substr($name, 0, 6) === 'county') {
             list($fieldName, $index) = CRM_Utils_System::explode('-', $name, 2);
             if (!array_key_exists($index, $stateCountryMap)) {
                 $stateCountryMap[$index] = array();
             }
             $stateCountryMap[$index][$fieldName] = $name;
         }
     }
     // also take care of state country widget
     if (!empty($stateCountryMap)) {
         CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $defaults);
     }
     //set default for country.
     CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $defaults);
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     return $defaults;
 }
/**
 * Grab the button type from a passed button element 'name' by checking for reserved QF button type strings
 *
 * @param $btnName
 *
 * @internal param string $btnId
 *
 * @return string  button type, one of: 'upload', 'next', 'back', 'cancel', 'refresh'
 *                                      'submit', 'done', 'display', 'jump' 'process'
 * @access public
 */
function smarty_modifier_crmBtnType($btnName)
{
    // split the string into 5 or more
    // button name are typically: '_qf_Contact_refresh' OR '_qf_Contact_refresh_dedupe'
    // button type is always the 3rd element
    // note the first _
    $substr = CRM_Utils_System::explode('_', $btnName, 5);
    return $substr[3];
}
Пример #3
0
/**
 * Based on the QF id, give this button a class 'validate' or 'cancel' which will be used by jQuery.validate
 *
 * @param string $btnName
 *
 * @return string
 *
 * @see smarty_modifier_crmBtnType
 * @access public
 */
function smarty_modifier_crmBtnValidate($btnName)
{
    // split the string into 5 or more
    // button name are typically: '_qf_Contact_refresh' OR '_qf_Contact_refresh_dedupe'
    // button type is always the 3rd element
    // note the first _
    $substr = CRM_Utils_System::explode('_', $btnName, 5);
    if (in_array($substr[3], array('upload', 'next', 'submit', 'done', 'process'))) {
        return 'validate';
    }
    return 'cancel';
}
Пример #4
0
 /**
  * Format profile contact parameters.
  *
  * @param array $params
  * @param $fields
  * @param int $contactID
  * @param int $ufGroupId
  * @param null $ctype
  * @param bool $skipCustom
  *
  * @return array
  */
 public static function formatProfileContactParams(&$params, &$fields, $contactID = NULL, $ufGroupId = NULL, $ctype = NULL, $skipCustom = FALSE)
 {
     $data = $contactDetails = array();
     // get the contact details (hier)
     if ($contactID) {
         list($details, $options) = self::getHierContactDetails($contactID, $fields);
         $contactDetails = $details[$contactID];
         $data['contact_type'] = CRM_Utils_Array::value('contact_type', $contactDetails);
         $data['contact_sub_type'] = CRM_Utils_Array::value('contact_sub_type', $contactDetails);
     } else {
         //we should get contact type only if contact
         if ($ufGroupId) {
             $data['contact_type'] = CRM_Core_BAO_UFField::getProfileType($ufGroupId);
             //special case to handle profile with only contact fields
             if ($data['contact_type'] == 'Contact') {
                 $data['contact_type'] = 'Individual';
             } elseif (CRM_Contact_BAO_ContactType::isaSubType($data['contact_type'])) {
                 $data['contact_type'] = CRM_Contact_BAO_ContactType::getBasicType($data['contact_type']);
             }
         } elseif ($ctype) {
             $data['contact_type'] = $ctype;
         } else {
             $data['contact_type'] = 'Individual';
         }
     }
     //fix contact sub type CRM-5125
     if (array_key_exists('contact_sub_type', $params) && !empty($params['contact_sub_type'])) {
         $data['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, (array) $params['contact_sub_type']) . CRM_Core_DAO::VALUE_SEPARATOR;
     } elseif (array_key_exists('contact_sub_type_hidden', $params) && !empty($params['contact_sub_type_hidden'])) {
         // if profile was used, and had any subtype, we obtain it from there
         $data['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, (array) $params['contact_sub_type_hidden']) . CRM_Core_DAO::VALUE_SEPARATOR;
     }
     if ($ctype == 'Organization') {
         $data['organization_name'] = CRM_Utils_Array::value('organization_name', $contactDetails);
     } elseif ($ctype == 'Household') {
         $data['household_name'] = CRM_Utils_Array::value('household_name', $contactDetails);
     }
     $locationType = array();
     $count = 1;
     if ($contactID) {
         //add contact id
         $data['contact_id'] = $contactID;
         $primaryLocationType = self::getPrimaryLocationType($contactID);
     } else {
         $defaultLocation = CRM_Core_BAO_LocationType::getDefault();
         $defaultLocationId = $defaultLocation->id;
     }
     // get the billing location type
     $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
     $billingLocationTypeId = array_search('Billing', $locationTypes);
     $blocks = array('email', 'phone', 'im', 'openid');
     $multiplFields = array('url');
     // prevent overwritten of formatted array, reset all block from
     // params if it is not in valid format (since import pass valid format)
     foreach ($blocks as $blk) {
         if (array_key_exists($blk, $params) && !is_array($params[$blk])) {
             unset($params[$blk]);
         }
     }
     $primaryPhoneLoc = NULL;
     $session = CRM_Core_Session::singleton();
     foreach ($params as $key => $value) {
         $fieldName = $locTypeId = $typeId = NULL;
         list($fieldName, $locTypeId, $typeId) = CRM_Utils_System::explode('-', $key, 3);
         //store original location type id
         $actualLocTypeId = $locTypeId;
         if ($locTypeId == 'Primary') {
             if ($contactID) {
                 if (in_array($fieldName, $blocks)) {
                     $locTypeId = self::getPrimaryLocationType($contactID, FALSE, $fieldName);
                 } else {
                     $locTypeId = self::getPrimaryLocationType($contactID, FALSE, 'address');
                 }
                 $primaryLocationType = $locTypeId;
             } else {
                 $locTypeId = $defaultLocationId;
             }
         }
         if (is_numeric($locTypeId) && !in_array($fieldName, $multiplFields) && substr($fieldName, 0, 7) != 'custom_') {
             $index = $locTypeId;
             if (is_numeric($typeId)) {
                 $index .= '-' . $typeId;
             }
             if (!in_array($index, $locationType)) {
                 $locationType[$count] = $index;
                 $count++;
             }
             $loc = CRM_Utils_Array::key($index, $locationType);
             $blockName = in_array($fieldName, $blocks) ? $fieldName : 'address';
             $data[$blockName][$loc]['location_type_id'] = $locTypeId;
             //set is_billing true, for location type "Billing"
             if ($locTypeId == $billingLocationTypeId) {
                 $data[$blockName][$loc]['is_billing'] = 1;
             }
             if ($contactID) {
                 //get the primary location type
                 if ($locTypeId == $primaryLocationType) {
                     $data[$blockName][$loc]['is_primary'] = 1;
                 }
             } elseif ($locTypeId == $defaultLocationId) {
                 $data[$blockName][$loc]['is_primary'] = 1;
             }
             if (in_array($fieldName, array('phone'))) {
                 if ($typeId) {
                     $data['phone'][$loc]['phone_type_id'] = $typeId;
                 } else {
                     $data['phone'][$loc]['phone_type_id'] = '';
                 }
                 $data['phone'][$loc]['phone'] = $value;
                 //special case to handle primary phone with different phone types
                 // in this case we make first phone type as primary
                 if (isset($data['phone'][$loc]['is_primary']) && !$primaryPhoneLoc) {
                     $primaryPhoneLoc = $loc;
                 }
                 if ($loc != $primaryPhoneLoc) {
                     unset($data['phone'][$loc]['is_primary']);
                 }
             } elseif ($fieldName == 'phone_ext') {
                 $data['phone'][$loc]['phone_ext'] = $value;
             } elseif ($fieldName == 'email') {
                 $data['email'][$loc]['email'] = $value;
             } elseif ($fieldName == 'im') {
                 if (isset($params[$key . '-provider_id'])) {
                     $data['im'][$loc]['provider_id'] = $params[$key . '-provider_id'];
                 }
                 if (strpos($key, '-provider_id') !== FALSE) {
                     $data['im'][$loc]['provider_id'] = $params[$key];
                 } else {
                     $data['im'][$loc]['name'] = $value;
                 }
             } elseif ($fieldName == 'openid') {
                 $data['openid'][$loc]['openid'] = $value;
             } else {
                 if ($fieldName === 'state_province') {
                     // CRM-3393
                     if (is_numeric($value) && (int) $value >= 1000) {
                         $data['address'][$loc]['state_province_id'] = $value;
                     } elseif (empty($value)) {
                         $data['address'][$loc]['state_province_id'] = '';
                     } else {
                         $data['address'][$loc]['state_province'] = $value;
                     }
                 } elseif ($fieldName === 'country') {
                     // CRM-3393
                     if (is_numeric($value) && (int) $value >= 1000) {
                         $data['address'][$loc]['country_id'] = $value;
                     } elseif (empty($value)) {
                         $data['address'][$loc]['country_id'] = '';
                     } else {
                         $data['address'][$loc]['country'] = $value;
                     }
                 } elseif ($fieldName === 'county') {
                     $data['address'][$loc]['county_id'] = $value;
                 } elseif ($fieldName == 'address_name') {
                     $data['address'][$loc]['name'] = $value;
                 } elseif (substr($fieldName, 0, 14) === 'address_custom') {
                     $data['address'][$loc][substr($fieldName, 8)] = $value;
                 } else {
                     $data['address'][$loc][$fieldName] = $value;
                 }
             }
         } else {
             if (substr($key, 0, 4) === 'url-') {
                 $websiteField = explode('-', $key);
                 $data['website'][$websiteField[1]]['website_type_id'] = $websiteField[1];
                 $data['website'][$websiteField[1]]['url'] = $value;
             } elseif (in_array($key, self::$_greetingTypes, TRUE)) {
                 //save email/postal greeting and addressee values if any, CRM-4575
                 $data[$key . '_id'] = $value;
             } elseif (!$skipCustom && ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key))) {
                 // for autocomplete transfer hidden value instead of label
                 if ($params[$key] && isset($params[$key . '_id'])) {
                     $value = $params[$key . '_id'];
                 }
                 // we need to append time with date
                 if ($params[$key] && isset($params[$key . '_time'])) {
                     $value .= ' ' . $params[$key . '_time'];
                 }
                 // if auth source is not checksum / login && $value is blank, do not proceed - CRM-10128
                 if (($session->get('authSrc') & CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN) == 0 && ($value == '' || !isset($value))) {
                     continue;
                 }
                 $valueId = NULL;
                 if (!empty($params['customRecordValues'])) {
                     if (is_array($params['customRecordValues']) && !empty($params['customRecordValues'])) {
                         foreach ($params['customRecordValues'] as $recId => $customFields) {
                             if (is_array($customFields) && !empty($customFields)) {
                                 foreach ($customFields as $customFieldName) {
                                     if ($customFieldName == $key) {
                                         $valueId = $recId;
                                         break;
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $type = $data['contact_type'];
                 if (!empty($data['contact_sub_type'])) {
                     $type = $data['contact_sub_type'];
                     $type = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($type, CRM_Core_DAO::VALUE_SEPARATOR));
                     // generally a contact even if, has multiple subtypes the parent-type is going to be one only
                     // and since formatCustomField() would be interested in parent type, lets consider only one subtype
                     // as the results going to be same.
                     $type = $type[0];
                 }
                 CRM_Core_BAO_CustomField::formatCustomField($customFieldId, $data['custom'], $value, $type, $valueId, $contactID);
             } elseif ($key == 'edit') {
                 continue;
             } else {
                 if ($key == 'location') {
                     foreach ($value as $locationTypeId => $field) {
                         foreach ($field as $block => $val) {
                             if ($block == 'address' && array_key_exists('address_name', $val)) {
                                 $value[$locationTypeId][$block]['name'] = $value[$locationTypeId][$block]['address_name'];
                             }
                         }
                     }
                 }
                 if ($key == 'phone' && isset($params['phone_ext'])) {
                     $data[$key] = $value;
                     foreach ($value as $cnt => $phoneBlock) {
                         if ($params[$key][$cnt]['location_type_id'] == $params['phone_ext'][$cnt]['location_type_id']) {
                             $data[$key][$cnt]['phone_ext'] = CRM_Utils_Array::retrieveValueRecursive($params['phone_ext'][$cnt], 'phone_ext');
                         }
                     }
                 } elseif (in_array($key, array('nick_name', 'job_title', 'middle_name', 'birth_date', 'gender_id', 'current_employer', 'prefix_id', 'suffix_id')) && ($value == '' || !isset($value)) && ($session->get('authSrc') & CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN) == 0) {
                     // CRM-10128: if auth source is not checksum / login && $value is blank, do not fill $data with empty value
                     // to avoid update with empty values
                     continue;
                 } else {
                     $data[$key] = $value;
                 }
             }
         }
     }
     if (!isset($data['contact_type'])) {
         $data['contact_type'] = 'Individual';
     }
     //set the values for checkboxes (do_not_email, do_not_mail, do_not_trade, do_not_phone)
     $privacy = CRM_Core_SelectValues::privacy();
     foreach ($privacy as $key => $value) {
         if (array_key_exists($key, $fields)) {
             // do not reset values for existing contacts, if fields are added to a profile
             if (array_key_exists($key, $params)) {
                 $data[$key] = $params[$key];
                 if (empty($params[$key])) {
                     $data[$key] = 0;
                 }
             } elseif (!$contactID) {
                 $data[$key] = 0;
             }
         }
     }
     return array($data, $contactDetails);
 }
Пример #5
0
 /**
  * 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;
     }
     // dont 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';
         }
         $dedupeParams = CRM_Dedupe_Finder::formatParams($fields, $ctype);
         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'));
         }
         // for dialog mode we should always use fuzzy rule.
         $ruleType = 'Unsupervised';
         if ($form->_context == 'dialog') {
             $ruleType = 'Supervised';
         }
         $dedupeParams['check_permission'] = FALSE;
         $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $ctype, $ruleType, $exceptions, $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 = '<div class="matching-contacts-found">';
                     $duplicateContactsLinks .= ts('One matching contact was found. ', array('count' => count($contactLinks['rows']), 'plural' => '%count matching contacts were found.<br />'));
                     if ($contactLinks['msg'] == 'view') {
                         $duplicateContactsLinks .= ts('You can View the existing contact.', array('count' => count($contactLinks['rows']), 'plural' => 'You can View the existing contacts.'));
                     } else {
                         $duplicateContactsLinks .= ts('You can View or Edit the existing contact.', array('count' => count($contactLinks['rows']), 'plural' => 'You can View or Edit the existing contacts.'));
                     }
                     $duplicateContactsLinks .= '</div>';
                     $duplicateContactsLinks .= '<table class="matching-contacts-actions">';
                     $row = '';
                     for ($i = 0; $i < count($contactLinks['rows']); $i++) {
                         $row .= '  <tr>   ';
                         $row .= '    <td class="matching-contacts-name"> ';
                         $row .= $contactLinks['rows'][$i]['display_name'];
                         $row .= '    </td>';
                         $row .= '    <td class="matching-contacts-email"> ';
                         $row .= $contactLinks['rows'][$i]['primary_email'];
                         $row .= '    </td>';
                         $row .= '    <td class="action-items"> ';
                         $row .= $contactLinks['rows'][$i]['view'] . ' ';
                         $row .= $contactLinks['rows'][$i]['edit'];
                         $row .= '    </td>';
                         $row .= '  </tr>   ';
                     }
                     $duplicateContactsLinks .= $row . '</table>';
                     $duplicateContactsLinks .= "If you're sure this record is not a duplicate, click the 'Save Matching Contact' button below.";
                     $errors['_qf_default'] = $duplicateContactsLinks;
                     // let smarty know that there are duplicates
                     $template = CRM_Core_Smarty::singleton();
                     $template->assign('isDuplicate', 1);
                 } else {
                     $errors['_qf_default'] = ts('A record already exists with the same information.');
                 }
             }
         }
     }
     foreach ($fields as $key => $value) {
         list($fieldName, $locTypeId, $phoneTypeId) = CRM_Utils_System::explode('-', $key, 3);
         if ($fieldName == 'state_province' && !empty($fields["country-{$locTypeId}"])) {
             // Validate Country - State list
             $countryId = $fields["country-{$locTypeId}"];
             $stateProvinceId = $value;
             if ($stateProvinceId && $countryId) {
                 $stateProvinceDAO = new CRM_Core_DAO_StateProvince();
                 $stateProvinceDAO->id = $stateProvinceId;
                 $stateProvinceDAO->find(TRUE);
                 if ($stateProvinceDAO->country_id != $countryId) {
                     // country mismatch hence display error
                     $stateProvinces = CRM_Core_PseudoConstant::stateProvince();
                     $countries = CRM_Core_PseudoConstant::country();
                     $errors[$key] = "State/Province " . $stateProvinces[$stateProvinceId] . " is not part of " . $countries[$countryId] . ". It belongs to " . $countries[$stateProvinceDAO->country_id] . ".";
                 }
             }
         }
         if ($fieldName == 'county' && $fields["state_province-{$locTypeId}"]) {
             // Validate County - State list
             $stateProvinceId = $fields["state_province-{$locTypeId}"];
             $countyId = $value;
             if ($countyId && $stateProvinceId) {
                 $countyDAO = new CRM_Core_DAO_County();
                 $countyDAO->id = $countyId;
                 $countyDAO->find(TRUE);
                 if ($countyDAO->state_province_id != $stateProvinceId) {
                     // state province mismatch hence display error
                     $stateProvinces = CRM_Core_PseudoConstant::stateProvince();
                     $counties = CRM_Core_PseudoConstant::county();
                     $errors[$key] = "County " . $counties[$countyId] . " is not part of " . $stateProvinces[$stateProvinceId] . ". It belongs to " . $stateProvinces[$countyDAO->state_province_id] . ".";
                 }
             }
         }
     }
     foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
         if ($greetingType = CRM_Utils_Array::value($greeting, $fields)) {
             $customizedValue = CRM_Core_OptionGroup::getValue($greeting, 'Customized', 'name');
             if ($customizedValue == $greetingType && empty($fields[$greeting . '_custom'])) {
                 $errors[$greeting . '_custom'] = ts('Custom  %1 is a required field if %1 is of type Customized.', array(1 => ucwords(str_replace('_', ' ', $greeting))));
             }
         }
     }
     return empty($errors) ? TRUE : $errors;
 }
Пример #6
0
 static function &makeArray($string)
 {
     $string = trim($string);
     $values = explode("\n", $string);
     $result = array();
     foreach ($values as $value) {
         list($n, $v) = CRM_Utils_System::explode('=', $value, 2);
         if (!empty($v)) {
             $result[trim($n)] = trim($v);
         }
     }
     return $result;
 }
Пример #7
0
 /**
  * returns all the rows in the given offset and rowCount
  *
  * @param enum   $action   the action being performed
  * @param int    $offset   the row number to start from
  * @param int    $rowCount the number of rows to return
  * @param string $sort     the sql string that describes the sort order
  * @param enum   $output   what should the result set include (web/email/csv)
  *
  * @return int   the total number of rows for this action
  */
 function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     $config = CRM_Core_Config::singleton();
     if (($output == CRM_Core_Selector_Controller::EXPORT || $output == CRM_Core_Selector_Controller::SCREEN) && $this->_formValues['radio_ts'] == 'ts_sel') {
         $includeContactIds = TRUE;
     } else {
         $includeContactIds = FALSE;
     }
     // note the formvalues were given by CRM_Contact_Form_Search to us
     // and contain the search criteria (parameters)
     // note that the default action is basic
     if ($rowCount) {
         $cacheKey = $this->buildPrevNextCache($sort);
         $result = $this->_query->getCachedContacts($cacheKey, $offset, $rowCount, $includeContactIds);
     } else {
         $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, $includeContactIds);
     }
     // process the result of the query
     $rows = array();
     $permissions = array(CRM_Core_Permission::getPermission());
     if (CRM_Core_Permission::check('delete contacts')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     // mask value to hide map link if there are not lat/long
     $mapMask = $mask & 4095;
     if ($this->_searchContext == 'smog') {
         $gc = CRM_Core_SelectValues::groupContactStatus();
     }
     if ($this->_ufGroupID) {
         $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
         $names = array();
         static $skipFields = array('group', 'tag');
         foreach ($this->_fields as $key => $field) {
             if (!empty($field['in_selector']) && !in_array($key, $skipFields)) {
                 if (strpos($key, '-') !== FALSE) {
                     list($fieldName, $id, $type) = CRM_Utils_System::explode('-', $key, 3);
                     if ($id == 'Primary') {
                         $locationTypeName = 1;
                     } else {
                         $locationTypeName = CRM_Utils_Array::value($id, $locationTypes);
                         if (!$locationTypeName) {
                             continue;
                         }
                     }
                     $locationTypeName = str_replace(' ', '_', $locationTypeName);
                     if (in_array($fieldName, array('phone', 'im', 'email'))) {
                         if ($type) {
                             $names[] = "{$locationTypeName}-{$fieldName}-{$type}";
                         } else {
                             $names[] = "{$locationTypeName}-{$fieldName}";
                         }
                     } else {
                         $names[] = "{$locationTypeName}-{$fieldName}";
                     }
                 } else {
                     $names[] = $field['name'];
                 }
             }
         }
         $names[] = "status";
     } elseif (!empty($this->_returnProperties)) {
         $names = self::makeProperties($this->_returnProperties);
     } else {
         $names = self::$_properties;
     }
     $multipleSelectFields = array('preferred_communication_method' => 1);
     $links = self::links($this->_context, $this->_contextMenu, $this->_key);
     //check explicitly added contact to a Smart Group.
     $groupID = CRM_Utils_Array::key('1', $this->_formValues['group']);
     $pseudoconstants = array();
     // for CRM-3157 purposes
     if (in_array('world_region', $names)) {
         $pseudoconstants['world_region'] = array('dbName' => 'world_region_id', 'values' => CRM_Core_PseudoConstant::worldRegion());
     }
     $seenIDs = array();
     while ($result->fetch()) {
         $row = array();
         $this->_query->convertToPseudoNames($result);
         // the columns we are interested in
         foreach ($names as $property) {
             if ($property == 'status') {
                 continue;
             }
             if ($cfID = CRM_Core_BAO_CustomField::getKeyID($property)) {
                 $row[$property] = CRM_Core_BAO_CustomField::getDisplayValue($result->{$property}, $cfID, $this->_options, $result->contact_id);
             } elseif ($multipleSelectFields && array_key_exists($property, $multipleSelectFields)) {
                 $key = $property;
                 $paramsNew = array($key => $result->{$property});
                 $name = array($key => array('newName' => $key, 'groupName' => $key));
                 CRM_Core_OptionGroup::lookupValues($paramsNew, $name, FALSE);
                 $row[$key] = $paramsNew[$key];
             } elseif (strpos($property, '-im')) {
                 $row[$property] = $result->{$property};
                 if (!empty($result->{$property})) {
                     $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
                     $providerId = $property . "-provider_id";
                     $providerName = $imProviders[$result->{$providerId}];
                     $row[$property] = $result->{$property} . " ({$providerName})";
                 }
             } elseif (in_array($property, array('addressee', 'email_greeting', 'postal_greeting'))) {
                 $greeting = $property . '_display';
                 $row[$property] = $result->{$greeting};
             } elseif (isset($pseudoconstants[$property])) {
                 $row[$property] = CRM_Utils_Array::value($result->{$pseudoconstants[$property]['dbName']}, $pseudoconstants[$property]['values']);
             } elseif (strpos($property, '-url') !== FALSE) {
                 $websiteUrl = '';
                 $websiteKey = 'website-1';
                 $propertyArray = explode('-', $property);
                 $websiteFld = $websiteKey . '-' . array_pop($propertyArray);
                 if (!empty($result->{$websiteFld})) {
                     $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
                     $websiteType = $websiteTypes[$result->{"{$websiteKey}-website_type_id"}];
                     $websiteValue = $result->{$websiteFld};
                     $websiteUrl = "<a href=\"{$websiteValue}\">{$websiteValue}  ({$websiteType})</a>";
                 }
                 $row[$property] = $websiteUrl;
             } else {
                 $row[$property] = isset($result->{$property}) ? $result->{$property} : NULL;
             }
         }
         if (!empty($result->postal_code_suffix)) {
             $row['postal_code'] .= "-" . $result->postal_code_suffix;
         }
         if ($output != CRM_Core_Selector_Controller::EXPORT && $this->_searchContext == 'smog') {
             if (empty($result->status) && $groupID) {
                 $contactID = $result->contact_id;
                 if ($contactID) {
                     $gcParams = array('contact_id' => $contactID, 'group_id' => $groupID);
                     $gcDefaults = array();
                     CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_GroupContact', $gcParams, $gcDefaults);
                     if (empty($gcDefaults)) {
                         $row['status'] = ts('Smart');
                     } else {
                         $row['status'] = $gc[$gcDefaults['status']];
                     }
                 } else {
                     $row['status'] = NULL;
                 }
             } else {
                 $row['status'] = $gc[$result->status];
             }
         }
         if ($output != CRM_Core_Selector_Controller::EXPORT) {
             $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contact_id;
             if (!empty($this->_formValues['deleted_contacts']) && CRM_Core_Permission::check('access deleted contacts')) {
                 $links = array(array('name' => ts('View'), 'url' => 'civicrm/contact/view', 'qs' => 'reset=1&cid=%%id%%', 'class' => 'no-popup', 'title' => ts('View Contact Details')), array('name' => ts('Restore'), 'url' => 'civicrm/contact/view/delete', 'qs' => 'reset=1&cid=%%id%%&restore=1', 'title' => ts('Restore Contact')));
                 if (CRM_Core_Permission::check('delete contacts')) {
                     $links[] = array('name' => ts('Delete Permanently'), 'url' => 'civicrm/contact/view/delete', 'qs' => 'reset=1&cid=%%id%%&skip_undelete=1', 'title' => ts('Permanently Delete Contact'));
                 }
                 $row['action'] = CRM_Core_Action::formLink($links, NULL, array('id' => $result->contact_id), ts('more'), FALSE, 'contact.selector.row', 'Contact', $result->contact_id);
             } elseif (is_numeric(CRM_Utils_Array::value('geo_code_1', $row)) || $config->mapGeoCoding && !empty($row['city']) && CRM_Utils_Array::value('state_province', $row)) {
                 $row['action'] = CRM_Core_Action::formLink($links, $mask, array('id' => $result->contact_id), ts('more'), FALSE, 'contact.selector.row', 'Contact', $result->contact_id);
             } else {
                 $row['action'] = CRM_Core_Action::formLink($links, $mapMask, array('id' => $result->contact_id), ts('more'), FALSE, 'contact.selector.row', 'Contact', $result->contact_id);
             }
             // allow components to add more actions
             CRM_Core_Component::searchAction($row, $result->contact_id);
             $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id);
             $row['contact_type_orig'] = $result->contact_sub_type ? $result->contact_sub_type : $result->contact_type;
             $row['contact_sub_type'] = $result->contact_sub_type ? CRM_Contact_BAO_ContactType::contactTypePairs(FALSE, $result->contact_sub_type, ', ') : $result->contact_sub_type;
             $row['contact_id'] = $result->contact_id;
             $row['sort_name'] = $result->sort_name;
             if (array_key_exists('id', $row)) {
                 $row['id'] = $result->contact_id;
             }
         }
         // Dedupe contacts
         if (in_array($row['contact_id'], $seenIDs) === FALSE) {
             $seenIDs[] = $row['contact_id'];
             $rows[] = $row;
         }
     }
     return $rows;
 }
Пример #8
0
 /**
  *  function to check if an error in custom data
  *  
  *  @param String   $errorMessage   A string containing all the error-fields.
  *  
  *  @access public 
  */
 function isErrorInCustomData($params, &$errorMessage)
 {
     $session =& CRM_Core_Session::singleton();
     $dateType = $session->get("dateTypes");
     //CRM-5125
     //add custom fields for contact sub type
     if (!empty($this->_contactSubType)) {
         $csType = $this->_contactSubType;
     }
     if (CRM_Utils_Array::value('contact_sub_type', $params)) {
         $csType = CRM_Utils_Array::value('contact_sub_type', $params);
     }
     $customFields = CRM_Core_BAO_CustomField::getFields($params['contact_type'], false, false, $csType);
     foreach ($params as $key => $value) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
             /* check if it's a valid custom field id */
             if (!array_key_exists($customFieldID, $customFields)) {
                 self::addToErrorMsg(ts('field ID'), $errorMessage);
             }
             /* validate the data against the CF type */
             if ($value) {
                 if ($customFields[$customFieldID]['data_type'] == 'Date') {
                     if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         $value = $params[$key];
                     } else {
                         self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                     }
                 } else {
                     if ($customFields[$customFieldID]['data_type'] == 'Boolean') {
                         if (CRM_Utils_String::strtoboolstr($value) === false) {
                             self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                         }
                     }
                 }
                 // need not check for label filed import
                 $htmlType = array('CheckBox', 'Multi-Select', 'AdvMulti-Select', 'Select', 'Radio', 'Multi-Select State/Province', 'Multi-Select Country');
                 if (!in_array($customFields[$customFieldID]['html_type'], $htmlType) || $customFields[$customFieldID]['data_type'] == 'Boolean') {
                     $valid = CRM_Core_BAO_CustomValue::typecheck($customFields[$customFieldID]['data_type'], $value);
                     if (!$valid) {
                         self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                     }
                 }
                 // check for values for custom fields for checkboxes and multiselect
                 if ($customFields[$customFieldID]['html_type'] == 'CheckBox' || $customFields[$customFieldID]['html_type'] == 'AdvMulti-Select' || $customFields[$customFieldID]['html_type'] == 'Multi-Select') {
                     $value = trim($value);
                     $value = str_replace('|', ',', $value);
                     $mulValues = explode(',', $value);
                     $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                     foreach ($mulValues as $v1) {
                         if (strlen($v1) == 0) {
                             continue;
                         }
                         $flag = false;
                         foreach ($customOption as $v2) {
                             if (strtolower(trim($v2['label'])) == strtolower(trim($v1)) || strtolower(trim($v2['value'])) == strtolower(trim($v1))) {
                                 $flag = true;
                             }
                         }
                         if (!$flag) {
                             self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                         }
                     }
                 } else {
                     if ($customFields[$customFieldID]['html_type'] == 'Select' || $customFields[$customFieldID]['html_type'] == 'Radio' && $customFields[$customFieldID]['data_type'] != 'Boolean') {
                         $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                         $flag = false;
                         foreach ($customOption as $v2) {
                             if (strtolower(trim($v2['label'])) == strtolower(trim($value)) || strtolower(trim($v2['value'])) == strtolower(trim($value))) {
                                 $flag = true;
                             }
                         }
                         if (!$flag) {
                             self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                         }
                     } else {
                         if ($customFields[$customFieldID]['html_type'] == 'Multi-Select State/Province') {
                             $mulValues = explode(',', $value);
                             foreach ($mulValues as $stateValue) {
                                 if ($stateValue) {
                                     if (self::in_value(trim($stateValue), CRM_Core_PseudoConstant::stateProvinceAbbreviation()) || self::in_value(trim($stateValue), CRM_Core_PseudoConstant::stateProvince())) {
                                         continue;
                                     } else {
                                         self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                                     }
                                 }
                             }
                         } else {
                             if ($customFields[$customFieldID]['html_type'] == 'Multi-Select Country') {
                                 $mulValues = explode(',', $value);
                                 foreach ($mulValues as $countryValue) {
                                     if ($countryValue) {
                                         CRM_Core_PseudoConstant::populate($countryNames, 'CRM_Core_DAO_Country', true, 'name', 'is_active');
                                         CRM_Core_PseudoConstant::populate($countryIsoCodes, 'CRM_Core_DAO_Country', true, 'iso_code');
                                         $config =& CRM_Core_Config::singleton();
                                         $limitCodes = $config->countryLimit();
                                         $error = true;
                                         foreach (array($countryNames, $countryIsoCodes, $limitCodes) as $values) {
                                             if (in_array(trim($countryValue), $values)) {
                                                 $error = false;
                                                 break;
                                             }
                                         }
                                         if ($error) {
                                             self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             if (is_array($params[$key]) && isset($params[$key]["contact_type"])) {
                 //CRM-5125
                 //supporting custom data of related contact subtypes
                 if (array_key_exists($key, $this->_relationships)) {
                     $relation = $key;
                 } else {
                     if (CRM_Utils_Array::key($key, $this->_relationships)) {
                         $relation = CRM_Utils_Array::key($key, $this->_relationships);
                     }
                 }
                 if (!empty($relation)) {
                     list($id, $first, $second) = CRM_Utils_System::explode('_', $relation, 3);
                     $direction = "contact_sub_type_{$second}";
                     require_once 'CRM/Contact/BAO/RelationshipType.php';
                     $relationshipType =& new CRM_Contact_BAO_RelationshipType();
                     $relationshipType->id = $id;
                     if ($relationshipType->find(true)) {
                         if (isset($relationshipType->{$direction})) {
                             $params[$key]['contact_sub_type'] = $relationshipType->{$direction};
                         }
                     }
                     $relationshipType->free();
                 }
                 self::isErrorInCustomData($params[$key], $errorMessage);
             }
         }
     }
 }
Пример #9
0
 /**
  * Make sure the checksum is valid for the passed in contactID.
  *
  * @param int $contactID
  * @param string $inputCheck
  *   Checksum to match against.
  *
  * @return bool
  *   true if valid, else false
  */
 public static function validChecksum($contactID, $inputCheck)
 {
     $input = CRM_Utils_System::explode('_', $inputCheck, 3);
     $inputCS = CRM_Utils_Array::value(0, $input);
     $inputTS = CRM_Utils_Array::value(1, $input);
     $inputLF = CRM_Utils_Array::value(2, $input);
     $check = self::generateChecksum($contactID, $inputTS, $inputLF);
     if ($check != $inputCheck) {
         return FALSE;
     }
     // no life limit for checksum
     if ($inputLF == 'inf') {
         return TRUE;
     }
     // checksum matches so now check timestamp
     $now = time();
     return $inputTS + $inputLF * 60 * 60 >= $now;
 }
Пример #10
0
 /**
  * Add onbehalf/honoree profile fields and native module fields.
  *
  * @param int $id
  * @param CRM_Core_Form $form
  */
 public function buildComponentForm($id, $form)
 {
     if (empty($id)) {
         return;
     }
     $contactID = $this->getContactID();
     foreach (array('soft_credit', 'on_behalf') as $module) {
         if ($module == 'soft_credit') {
             if (empty($form->_values['honoree_profile_id'])) {
                 continue;
             }
             if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_values['honoree_profile_id'], 'is_active')) {
                 CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the selected honoree profile is either disabled or not found.'));
             }
             $profileContactType = CRM_Core_BAO_UFGroup::getContactType($form->_values['honoree_profile_id']);
             $requiredProfileFields = array('Individual' => array('first_name', 'last_name'), 'Organization' => array('organization_name', 'email'), 'Household' => array('household_name', 'email'));
             $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_values['honoree_profile_id'], $requiredProfileFields[$profileContactType]);
             if (!$validProfile) {
                 CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the required fields of the selected honoree profile are disabled or doesn\'t exist.'));
             }
             foreach (array('honor_block_title', 'honor_block_text') as $name) {
                 $form->assign($name, $form->_values[$name]);
             }
             $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
             // radio button for Honor Type
             foreach ($form->_values['soft_credit_types'] as $value) {
                 $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value);
             }
             $form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE);
             $honoreeProfileFields = CRM_Core_BAO_UFGroup::getFields($this->_values['honoree_profile_id'], FALSE, NULL, NULL, NULL, FALSE, NULL, TRUE, NULL, CRM_Core_Permission::CREATE);
             $form->assign('honoreeProfileFields', $honoreeProfileFields);
             // add the form elements
             foreach ($honoreeProfileFields as $name => $field) {
                 // If soft credit type is not chosen then make omit requiredness from honoree profile fields
                 if (count($form->_submitValues) && empty($form->_submitValues['soft_credit_type_id']) && !empty($field['is_required'])) {
                     $field['is_required'] = FALSE;
                 }
                 CRM_Core_BAO_UFGroup::buildProfile($form, $field, CRM_Profile_Form::MODE_CREATE, NULL, FALSE, FALSE, NULL, 'honor');
             }
         } else {
             if (empty($form->_values['onbehalf_profile_id'])) {
                 continue;
             }
             if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_values['onbehalf_profile_id'], 'is_active')) {
                 CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the selected onbehalf profile is either disabled or not found.'));
             }
             $member = CRM_Member_BAO_Membership::getMembershipBlock($form->_id);
             if (empty($member['is_active'])) {
                 $msg = ts('Mixed profile not allowed for on behalf of registration/sign up.');
                 $onBehalfProfile = CRM_Core_BAO_UFGroup::profileGroups($form->_values['onbehalf_profile_id']);
                 foreach (array('Individual', 'Organization', 'Household') as $contactType) {
                     if (in_array($contactType, $onBehalfProfile) && (in_array('Membership', $onBehalfProfile) || in_array('Contribution', $onBehalfProfile))) {
                         CRM_Core_Error::fatal($msg);
                     }
                 }
             }
             if ($contactID) {
                 // retrieve all permissioned organizations of contact $contactID
                 $organizations = CRM_Contact_BAO_Relationship::getPermissionedContacts($contactID, NULL, NULL, 'Organization');
                 if (count($organizations)) {
                     // Related org url - pass checksum if needed
                     $args = array('ufId' => $form->_values['onbehalf_profile_id'], 'cid' => '');
                     if (!empty($_GET['cs'])) {
                         $args = array('ufId' => $form->_values['onbehalf_profile_id'], 'uid' => $this->_contactID, 'cs' => $_GET['cs'], 'cid' => '');
                     }
                     $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE);
                     $form->assign('locDataURL', $locDataURL);
                 }
                 if (count($organizations) > 0) {
                     $form->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $organizations));
                     $orgOptions = array(0 => ts('Select an existing organization'), 1 => ts('Enter a new organization'));
                     $form->addRadio('org_option', ts('options'), $orgOptions);
                     $form->setDefaults(array('org_option' => 0));
                 }
             }
             $form->assign('fieldSetTitle', ts('Organization Details'));
             if (CRM_Utils_Array::value('is_for_organization', $form->_values)) {
                 if ($form->_values['is_for_organization'] == 2) {
                     $form->assign('onBehalfRequired', TRUE);
                 } else {
                     $form->addElement('checkbox', 'is_for_organization', $form->_values['for_organization'], NULL);
                 }
             }
             $profileFields = CRM_Core_BAO_UFGroup::getFields($form->_values['onbehalf_profile_id'], FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
             $form->assign('onBehalfOfFields', $profileFields);
             if (!empty($form->_submitValues['onbehalf'])) {
                 if (!empty($form->_submitValues['onbehalfof_id'])) {
                     $form->assign('submittedOnBehalf', $form->_submitValues['onbehalfof_id']);
                 }
                 $form->assign('submittedOnBehalfInfo', json_encode($form->_submitValues['onbehalf']));
             }
             $fieldTypes = array('Contact', 'Organization');
             $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
             $fieldTypes = array_merge($fieldTypes, $contactSubType);
             foreach ($profileFields as $name => $field) {
                 if (in_array($field['field_type'], $fieldTypes)) {
                     list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
                     if (in_array($prefixName, array('organization_name', 'email')) && empty($field['is_required'])) {
                         $field['is_required'] = 1;
                     }
                     if (count($form->_submitValues) && empty($form->_submitValues['is_for_organization']) && $form->_values['is_for_organization'] == 1 && !empty($field['is_required'])) {
                         $field['is_required'] = FALSE;
                     }
                     CRM_Core_BAO_UFGroup::buildProfile($form, $field, NULL, NULL, FALSE, 'onbehalf', NULL, 'onbehalf');
                 }
             }
         }
     }
 }
Пример #11
0
 /**
  * Get values for from and to for date ranges.
  *
  * @param bool $relative
  * @param string $from
  * @param string $to
  * @param string $fromTime
  * @param string $toTime
  *
  * @return array
  */
 public function getFromTo($relative, $from, $to, $fromTime = NULL, $toTime = NULL)
 {
     if (empty($toTime)) {
         $toTime = '235959';
     }
     //FIX ME not working for relative
     if ($relative) {
         list($term, $unit) = CRM_Utils_System::explode('.', $relative, 2);
         $dateRange = CRM_Utils_Date::relativeToAbsolute($term, $unit);
         $from = substr($dateRange['from'], 0, 8);
         //Take only Date Part, Sometime Time part is also present in 'to'
         $to = substr($dateRange['to'], 0, 8);
     }
     $from = CRM_Utils_Date::processDate($from, $fromTime);
     $to = CRM_Utils_Date::processDate($to, $toTime);
     return array($from, $to);
 }
Пример #12
0
 /**
  * Build the petition profile form.
  *
  * @param int $id
  * @param string $name
  * @param bool $viewOnly
  */
 public function buildCustom($id, $name, $viewOnly = FALSE)
 {
     if ($id) {
         $session = CRM_Core_Session::singleton();
         $this->assign("petition", $this->petition);
         //$contactID = $this->_contactId;
         $contactID = NULL;
         $this->assign('contact_id', $this->_contactId);
         $fields = NULL;
         // TODO: contactID is never set (commented above)
         if ($contactID) {
             if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
                 $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
         }
         if ($fields) {
             $this->assign($name, $fields);
             $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 state or country in the profile, create map
                 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;
                 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
                 if ($field['add_captcha'] && !$this->_contactId) {
                     $addCaptcha = TRUE;
                 }
             }
             if ($addCaptcha && !$viewOnly) {
                 $captcha = CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign("isCaptcha", TRUE);
             }
         }
     }
 }
Пример #13
0
 /**
  * Get Menu name
  *
  * @param $value
  * @param $skipMenuItems
  * @return bool|string
  */
 static function getMenuName(&$value, &$skipMenuItems)
 {
     // we need to localise the menu labels (CRM-5456) and don’t
     // want to use ts() as it would throw the ts-extractor off
     $i18n = CRM_Core_I18n::singleton();
     $name = $i18n->crm_translate($value['attributes']['label'], array('context' => 'menu'));
     $url = $value['attributes']['url'];
     $permission = $value['attributes']['permission'];
     $operator = $value['attributes']['operator'];
     $parentID = $value['attributes']['parentID'];
     $navID = $value['attributes']['navID'];
     $active = $value['attributes']['active'];
     $menuName = $value['attributes']['name'];
     $target = CRM_Utils_Array::value('target', $value['attributes']);
     if (in_array($parentID, $skipMenuItems) || !$active) {
         $skipMenuItems[] = $navID;
         return FALSE;
     }
     //we need to check core view/edit or supported acls.
     if (in_array($menuName, array('Search...', 'Contacts'))) {
         if (!CRM_Core_Permission::giveMeAllACLs()) {
             $skipMenuItems[] = $navID;
             return FALSE;
         }
     }
     $config = CRM_Core_Config::singleton();
     $makeLink = FALSE;
     if (isset($url) && $url) {
         if (substr($url, 0, 4) === 'http') {
             $url = $url;
         } else {
             //CRM-7656 --make sure to separate out url path from url params,
             //as we'r going to validate url path across cross-site scripting.
             $urlParam = CRM_Utils_System::explode('&', str_replace('?', '&', $url), 2);
             $url = CRM_Utils_System::url($urlParam[0], $urlParam[1], FALSE, NULL, TRUE);
         }
         $makeLink = TRUE;
     }
     static $allComponents;
     if (!$allComponents) {
         $allComponents = CRM_Core_Component::getNames();
     }
     if (isset($permission) && $permission) {
         $permissions = explode(',', $permission);
         $hasPermission = FALSE;
         foreach ($permissions as $key) {
             $key = trim($key);
             $showItem = TRUE;
             //get the component name from permission.
             $componentName = CRM_Core_Permission::getComponentName($key);
             if ($componentName) {
                 if (!in_array($componentName, $config->enableComponents) || !CRM_Core_Permission::check($key)) {
                     $showItem = FALSE;
                     if ($operator == 'AND') {
                         $skipMenuItems[] = $navID;
                         return $showItem;
                     }
                 } else {
                     $hasPermission = TRUE;
                 }
             } elseif (!CRM_Core_Permission::check($key)) {
                 $showItem = FALSE;
                 if ($operator == 'AND') {
                     $skipMenuItems[] = $navID;
                     return $showItem;
                 }
             } else {
                 $hasPermission = TRUE;
             }
         }
         if (!$showItem && !$hasPermission) {
             $skipMenuItems[] = $navID;
             return FALSE;
         }
     }
     if ($makeLink) {
         if ($target) {
             $name = "<a href=\"{$url}\" target=\"{$target}\">{$name}</a>";
         } else {
             $name = "<a href=\"{$url}\">{$name}</a>";
         }
     }
     return $name;
 }
Пример #14
0
 /**
  * @param $args
  *
  * @return array
  */
 public static function &buildFormValues($args)
 {
     $args = trim($args);
     $values = explode("\n", $args);
     $formValues = array();
     foreach ($values as $value) {
         list($n, $v) = CRM_Utils_System::explode('=', $value, 2);
         if (!empty($v)) {
             $formValues[$n] = $v;
         }
     }
     return $formValues;
 }
Пример #15
0
 /**
  * Function to set profile defaults
  *
  * @params int     $contactId      contact id
  * @params array   $fields         associative array of fields
  * @params array   $defaults       defaults array
  * @params boolean $singleProfile  true for single profile else false(batch update)
  * @params int     $componentId    id for specific components like contribute, event etc
  *
  * @return null
  * @static
  * @access public
  */
 static function setProfileDefaults($contactId, &$fields, &$defaults, $singleProfile = true, $componentId = null, $component = null)
 {
     if (!$componentId) {
         //get the contact details
         require_once 'CRM/Contact/BAO/Contact.php';
         list($contactDetails, $options) = CRM_Contact_BAO_Contact::getHierContactDetails($contactId, $fields);
         $details = $contactDetails[$contactId];
         require_once 'CRM/Contact/Form/Edit/TagsAndGroups.php';
         //start of code to set the default values
         foreach ($fields as $name => $field) {
             //set the field name depending upon the profile mode(single/batch)
             if ($singleProfile) {
                 $fldName = $name;
             } else {
                 $fldName = "field[{$contactId}][{$name}]";
             }
             if ($name == 'group') {
                 CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, $fldName);
             }
             if ($name == 'tag') {
                 CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::TAG, $fldName);
             }
             if (CRM_Utils_Array::value($name, $details) || isset($details[$name])) {
                 //to handle custom data (checkbox) to be written
                 // to handle gender / suffix / prefix / greeting_type
                 if ($name == 'gender') {
                     $defaults[$fldName] = $details['gender_id'];
                 } else {
                     if ($name == 'individual_prefix') {
                         $defaults[$fldName] = $details['individual_prefix_id'];
                     } else {
                         if ($name == 'individual_suffix') {
                             $defaults[$fldName] = $details['individual_suffix_id'];
                         } else {
                             if ($name == 'birth_date' || $name == 'deceased_date') {
                                 list($defaults[$fldName]) = CRM_Utils_Date::setDateDefaults($details[$name], 'birth');
                             } else {
                                 if ($name == 'email_greeting') {
                                     $defaults[$fldName] = $details['email_greeting_id'];
                                     $defaults['email_greeting_custom'] = $details['email_greeting_custom'];
                                 } else {
                                     if ($name == 'postal_greeting') {
                                         $defaults[$fldName] = $details['postal_greeting_id'];
                                         $defaults['postal_greeting_custom'] = $details['postal_greeting_custom'];
                                     } else {
                                         if ($name == 'addressee') {
                                             $defaults[$fldName] = $details['addressee_id'];
                                             $defaults['addressee_custom'] = $details['addressee_custom'];
                                         } else {
                                             if ($name == 'preferred_communication_method') {
                                                 $v = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details[$name]);
                                                 foreach ($v as $item) {
                                                     if ($item) {
                                                         $defaults[$fldName . "[{$item}]"] = 1;
                                                     }
                                                 }
                                             } else {
                                                 if ($name == 'world_region') {
                                                     $defaults[$fldName] = $details['worldregion_id'];
                                                 } else {
                                                     if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($name)) {
                                                         //fix for custom fields
                                                         $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('Individual', $values));
                                                         // hack to add custom data for components
                                                         $components = array("Contribution", "Participant", "Membership");
                                                         foreach ($components as $value) {
                                                             $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFieldsForImport($value));
                                                         }
                                                         switch ($customFields[$customFieldId]['html_type']) {
                                                             case 'Multi-Select State/Province':
                                                             case 'Multi-Select Country':
                                                             case 'AdvMulti-Select':
                                                             case 'Multi-Select':
                                                                 $v = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details[$name]);
                                                                 foreach ($v as $item) {
                                                                     if ($item) {
                                                                         $defaults[$fldName][$item] = $item;
                                                                     }
                                                                 }
                                                                 break;
                                                             case 'CheckBox':
                                                                 $v = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details[$name]);
                                                                 foreach ($v as $item) {
                                                                     if ($item) {
                                                                         $defaults[$fldName][$item] = 1;
                                                                         // seems like we need this for QF style checkboxes in profile where its multiindexed
                                                                         // CRM-2969
                                                                         $defaults["{$fldName}[{$item}]"] = 1;
                                                                     }
                                                                 }
                                                                 break;
                                                             case 'Autocomplete-Select':
                                                                 if ($customFields[$customFieldId]['data_type'] == "ContactReference") {
                                                                     require_once 'CRM/Contact/BAO/Contact.php';
                                                                     if (is_numeric($details[$name])) {
                                                                         $defaults[$fldName . '_id'] = $details[$name];
                                                                         $defaults[$fldName] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $details[$name], 'sort_name');
                                                                     }
                                                                 } else {
                                                                     $label = CRM_Core_BAO_CustomOption::getOptionLabel($customFieldId, $details[$name]);
                                                                     $defaults[$fldName . '_id'] = $details[$name];
                                                                     $defaults[$fldName] = $label;
                                                                 }
                                                                 break;
                                                             case 'Select Date':
                                                                 list($defaults[$fldName], $defaults[substr($fldName, 0, -1) . '_time]']) = CRM_Utils_Date::setDateDefaults($details[$name]);
                                                                 break;
                                                             default:
                                                                 $defaults[$fldName] = $details[$name];
                                                                 break;
                                                         }
                                                     } else {
                                                         $defaults[$fldName] = $details[$name];
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             } else {
                 list($fieldName, $locTypeId, $phoneTypeId) = CRM_Utils_System::explode('-', $name, 3);
                 if (is_array($details)) {
                     foreach ($details as $key => $value) {
                         // when we fixed CRM-5319 - get primary loc
                         // type as per loc field and removed below code.
                         if ($locTypeId == 'Primary') {
                             $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactId);
                         }
                         if (is_numeric($locTypeId)) {
                             //fixed for CRM-665
                             if ($locTypeId == CRM_Utils_Array::value('location_type_id', $value)) {
                                 if (CRM_Utils_Array::value($fieldName, $value)) {
                                     //to handle stateprovince and country
                                     if ($fieldName == 'state_province') {
                                         $defaults[$fldName] = $value['state_province_id'];
                                     } else {
                                         if ($fieldName == 'county') {
                                             $defaults[$fldName] = $value['county_id'];
                                         } else {
                                             if ($fieldName == 'country') {
                                                 $defaults[$fldName] = $value['country_id'];
                                                 if (!isset($value['country_id']) || !$value['country_id']) {
                                                     $config =& CRM_Core_Config::singleton();
                                                     if ($config->defaultContactCountry) {
                                                         $defaults[$fldName] = $config->defaultContactCountry;
                                                     }
                                                 }
                                             } else {
                                                 if ($fieldName == 'phone') {
                                                     if ($phoneTypeId) {
                                                         if ($value['phone'][$phoneTypeId]) {
                                                             $defaults[$fldName] = $value['phone'][$phoneTypeId];
                                                         }
                                                     } else {
                                                         $defaults[$fldName] = $value['phone'];
                                                     }
                                                 } else {
                                                     if ($fieldName == 'email') {
                                                         //adding the first email (currently we don't support multiple emails of same location type)
                                                         $defaults[$fldName] = $value['email'];
                                                     } else {
                                                         if ($fieldName == 'im') {
                                                             //adding the first im (currently we don't support multiple ims of same location type)
                                                             $defaults[$fldName] = $value['im'];
                                                             $defaults[$fldName . "-provider_id"] = $value['im_provider_id'];
                                                         } else {
                                                             $defaults[$fldName] = $value[$fieldName];
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (CRM_Core_Permission::access('Quest', false)) {
             require_once 'CRM/Quest/BAO/Student.php';
             // Checking whether the database contains quest_student table.
             // Now there are two different schemas for core and quest.
             // So if only core schema in use then withought following check gets the DB error.
             $student = new CRM_Quest_BAO_Student();
             $tableStudent = $student->getTableName();
             if ($tableStudent) {
                 //set student defaults
                 CRM_Quest_BAO_Student::retrieve($details, $studentDefaults, $ids);
                 $studentFields = array('educational_interest', 'college_type', 'college_interest', 'test_tutoring');
                 foreach ($studentFields as $fld) {
                     if ($studentDefaults[$fld]) {
                         $values = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $studentDefaults[$fld]);
                     }
                     $studentDefaults[$fld] = array();
                     if (is_array($values)) {
                         foreach ($values as $v) {
                             $studentDefaults[$fld][$v] = 1;
                         }
                     }
                 }
                 foreach ($fields as $name => $field) {
                     $fldName = "field[{$contactId}][{$name}]";
                     if (array_key_exists($name, $studentDefaults)) {
                         $defaults[$fldName] = $studentDefaults[$name];
                     }
                 }
             }
         }
     }
     //Handling Contribution Part of the batch profile
     if (CRM_Core_Permission::access('CiviContribute') && $component == 'Contribute') {
         self::setComponentDefaults($fields, $componentId, $component, $defaults);
     }
     //Handling Event Participation Part of the batch profile
     if (CRM_Core_Permission::access('CiviEvent') && $component == 'Event') {
         self::setComponentDefaults($fields, $componentId, $component, $defaults);
     }
     //Handling membership Part of the batch profile
     if (CRM_Core_Permission::access('CiviMember') && $component == 'Membership') {
         self::setComponentDefaults($fields, $componentId, $component, $defaults);
     }
 }
Пример #16
0
 /**
  * Function to build the petition profile form
  *
  * @return void
  * @access public
  */
 function buildCustom($id, $name, $viewOnly = FALSE)
 {
     // create state country map array to hold selectors
     $stateCountryMap = array();
     if ($id) {
         $session = CRM_Core_Session::singleton();
         $this->assign("petition", $this->petition);
         //$contactID = $this->_contactId;
         $contactID = NULL;
         $this->assign('contact_id', $this->_contactId);
         $fields = NULL;
         // TODO: contactID is never set (commented above)
         if ($contactID) {
             if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
                 $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
         }
         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] );
                 }
             }
             */
             $this->assign($name, $fields);
             $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 state or country in the profile, create map
                 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;
                 }
                 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->_contactId) {
                     $addCaptcha = TRUE;
                 }
             }
             // initialize the state country map
             CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
             if ($addCaptcha && !$viewOnly) {
                 $captcha = CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign("isCaptcha", TRUE);
             }
         }
     }
 }
Пример #17
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->getName());
     if (!$this->_contactID && isset($params['cms_create_account'])) {
         foreach ($params as $key => $value) {
             if (substr($key, 0, 5) == 'email' && !empty($value)) {
                 list($fieldName, $locTypeId) = CRM_Utils_System::explode('-', $key, 2);
                 $isPrimary = 0;
                 if ($locTypeId == 'Primary') {
                     $locTypeDefault = CRM_Core_BAO_LocationType::getDefault();
                     $locTypeId = NULL;
                     if ($locTypeDefault) {
                         $locTypeId = $locTypeDefault->id;
                     }
                     $isPrimary = 1;
                 }
                 $params['email'] = array();
                 $params['email'][1]['email'] = $value;
                 $params['email'][1]['location_type_id'] = $locTypeId;
                 $params['email'][1]['is_primary'] = $isPrimary;
             }
         }
     }
     $dedupeParams = CRM_Dedupe_Finder::formatParams($params, 'Individual');
     $dedupeParams['check_permission'] = FALSE;
     $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual', 'Unsupervised');
     if ($ids) {
         $this->_contactID = $ids['0'];
     }
     $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $this->_fields, $this->_contactID);
     $this->set('contactID', $contactID);
     if (!empty($params['email'])) {
         $params['email'] = $params['email'][1]['email'];
     }
     CRM_Contribute_BAO_Contribution_Utils::createCMSUser($params, $contactID, 'email');
 }
Пример #18
0
 /**
  * Check if an error in custom data.
  *
  * @param array $params
  * @param string $errorMessage
  *   A string containing all the error-fields.
  *
  * @param null $csType
  * @param null $relationships
  */
 public static function isErrorInCustomData($params, &$errorMessage, $csType = NULL, $relationships = NULL)
 {
     $session = CRM_Core_Session::singleton();
     $dateType = $session->get("dateTypes");
     if (!empty($params['contact_sub_type'])) {
         $csType = CRM_Utils_Array::value('contact_sub_type', $params);
     }
     if (empty($params['contact_type'])) {
         $params['contact_type'] = 'Individual';
     }
     $customFields = CRM_Core_BAO_CustomField::getFields($params['contact_type'], FALSE, FALSE, $csType);
     $addressCustomFields = CRM_Core_BAO_CustomField::getFields('Address');
     $customFields = $customFields + $addressCustomFields;
     foreach ($params as $key => $value) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
             /* check if it's a valid custom field id */
             if (!array_key_exists($customFieldID, $customFields)) {
                 self::addToErrorMsg(ts('field ID'), $errorMessage);
             }
             // validate null values for required custom fields of type boolean
             if (!empty($customFields[$customFieldID]['is_required']) && (empty($params['custom_' . $customFieldID]) && !is_numeric($params['custom_' . $customFieldID])) && $customFields[$customFieldID]['data_type'] == 'Boolean') {
                 self::addToErrorMsg($customFields[$customFieldID]['label'] . '::' . $customFields[$customFieldID]['groupTitle'], $errorMessage);
             }
             //For address custom fields, we do get actual custom field value as an inner array of
             //values so need to modify
             if (array_key_exists($customFieldID, $addressCustomFields)) {
                 $value = $value[0][$key];
             }
             /* validate the data against the CF type */
             if ($value) {
                 if ($customFields[$customFieldID]['data_type'] == 'Date') {
                     if (array_key_exists($customFieldID, $addressCustomFields) && CRM_Utils_Date::convertToDefaultDate($params[$key][0], $dateType, $key)) {
                         $value = $params[$key][0][$key];
                     } elseif (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         $value = $params[$key];
                     } else {
                         self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                     }
                 } elseif ($customFields[$customFieldID]['data_type'] == 'Boolean') {
                     if (CRM_Utils_String::strtoboolstr($value) === FALSE) {
                         self::addToErrorMsg($customFields[$customFieldID]['label'] . '::' . $customFields[$customFieldID]['groupTitle'], $errorMessage);
                     }
                 }
                 // need not check for label filed import
                 $htmlType = array('CheckBox', 'Multi-Select', 'AdvMulti-Select', 'Select', 'Radio', 'Multi-Select State/Province', 'Multi-Select Country');
                 if (!in_array($customFields[$customFieldID]['html_type'], $htmlType) || $customFields[$customFieldID]['data_type'] == 'Boolean' || $customFields[$customFieldID]['data_type'] == 'ContactReference') {
                     $valid = CRM_Core_BAO_CustomValue::typecheck($customFields[$customFieldID]['data_type'], $value);
                     if (!$valid) {
                         self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                     }
                 }
                 // check for values for custom fields for checkboxes and multiselect
                 if ($customFields[$customFieldID]['html_type'] == 'CheckBox' || $customFields[$customFieldID]['html_type'] == 'AdvMulti-Select' || $customFields[$customFieldID]['html_type'] == 'Multi-Select') {
                     $value = trim($value);
                     $value = str_replace('|', ',', $value);
                     $mulValues = explode(',', $value);
                     $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
                     foreach ($mulValues as $v1) {
                         if (strlen($v1) == 0) {
                             continue;
                         }
                         $flag = FALSE;
                         foreach ($customOption as $v2) {
                             if (strtolower(trim($v2['label'])) == strtolower(trim($v1)) || strtolower(trim($v2['value'])) == strtolower(trim($v1))) {
                                 $flag = TRUE;
                             }
                         }
                         if (!$flag) {
                             self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                         }
                     }
                 } elseif ($customFields[$customFieldID]['html_type'] == 'Select' || $customFields[$customFieldID]['html_type'] == 'Radio' && $customFields[$customFieldID]['data_type'] != 'Boolean') {
                     $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
                     $flag = FALSE;
                     foreach ($customOption as $v2) {
                         if (strtolower(trim($v2['label'])) == strtolower(trim($value)) || strtolower(trim($v2['value'])) == strtolower(trim($value))) {
                             $flag = TRUE;
                         }
                     }
                     if (!$flag) {
                         self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                     }
                 } elseif ($customFields[$customFieldID]['html_type'] == 'Multi-Select State/Province') {
                     $mulValues = explode(',', $value);
                     foreach ($mulValues as $stateValue) {
                         if ($stateValue) {
                             if (self::in_value(trim($stateValue), CRM_Core_PseudoConstant::stateProvinceAbbreviation()) || self::in_value(trim($stateValue), CRM_Core_PseudoConstant::stateProvince())) {
                                 continue;
                             } else {
                                 self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                             }
                         }
                     }
                 } elseif ($customFields[$customFieldID]['html_type'] == 'Multi-Select Country') {
                     $mulValues = explode(',', $value);
                     foreach ($mulValues as $countryValue) {
                         if ($countryValue) {
                             CRM_Core_PseudoConstant::populate($countryNames, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active');
                             CRM_Core_PseudoConstant::populate($countryIsoCodes, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
                             $config = CRM_Core_Config::singleton();
                             $limitCodes = $config->countryLimit();
                             $error = TRUE;
                             foreach (array($countryNames, $countryIsoCodes, $limitCodes) as $values) {
                                 if (in_array(trim($countryValue), $values)) {
                                     $error = FALSE;
                                     break;
                                 }
                             }
                             if ($error) {
                                 self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
                             }
                         }
                     }
                 }
             }
         } elseif (is_array($params[$key]) && isset($params[$key]["contact_type"])) {
             //CRM-5125
             //supporting custom data of related contact subtypes
             $relation = NULL;
             if ($relationships) {
                 if (array_key_exists($key, $relationships)) {
                     $relation = $key;
                 } elseif (CRM_Utils_Array::key($key, $relationships)) {
                     $relation = CRM_Utils_Array::key($key, $relationships);
                 }
             }
             if (!empty($relation)) {
                 list($id, $first, $second) = CRM_Utils_System::explode('_', $relation, 3);
                 $direction = "contact_sub_type_{$second}";
                 $relationshipType = new CRM_Contact_BAO_RelationshipType();
                 $relationshipType->id = $id;
                 if ($relationshipType->find(TRUE)) {
                     if (isset($relationshipType->{$direction})) {
                         $params[$key]['contact_sub_type'] = $relationshipType->{$direction};
                     }
                 }
                 $relationshipType->free();
             }
             self::isErrorInCustomData($params[$key], $errorMessage, $csType, $relationships);
         }
     }
 }
Пример #19
0
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Contact_BAO_RelationshipType::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected Relationship type has been deleted.'));
     } else {
         $params = array();
         $ids = array();
         // store the submitted values in an array
         $params = $this->exportValues();
         $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false);
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $ids['relationshipType'] = $this->_id;
         }
         $cTypeA = CRM_Utils_System::explode(CRM_Core_DAO::VALUE_SEPARATOR, $params['contact_types_a'], 2);
         $cTypeB = CRM_Utils_System::explode(CRM_Core_DAO::VALUE_SEPARATOR, $params['contact_types_b'], 2);
         $params['contact_type_a'] = $cTypeA[0];
         $params['contact_type_b'] = $cTypeB[0];
         $params['contact_sub_type_a'] = $cTypeA[1] ? $cTypeA[1] : 'NULL';
         $params['contact_sub_type_b'] = $cTypeB[1] ? $cTypeB[1] : 'NULL';
         CRM_Contact_BAO_RelationshipType::add($params, $ids);
         CRM_Core_Session::setStatus(ts('The Relationship Type has been saved.'));
     }
 }
Пример #20
0
 /**
  * Process the mapped fields and map it into the uploaded file
  * preview the file and extract some summary statistics
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues('MapField');
     //reload the mapfield if load mapping is pressed
     if (!empty($params['savedMapping'])) {
         $this->set('savedMapping', $params['savedMapping']);
         $this->controller->resetPage($this->_name);
         return;
     }
     $mapperKeys = array();
     $mapper = array();
     $mapperKeys = $this->controller->exportValue($this->_name, 'mapper');
     $mapperKeysMain = array();
     $mapperLocType = array();
     $mapperPhoneType = array();
     $mapperImProvider = array();
     $locations = array();
     $phoneTypes = CRM_Core_PseudoConstant::phoneType();
     $imProviders = CRM_Core_PseudoConstant::IMProvider();
     for ($i = 0; $i < $this->_columnCount; $i++) {
         $mapper[$i] = $this->_mapperFields[$mapperKeys[$i][0]];
         $mapperKeysMain[$i] = $mapperKeys[$i][0];
         if (isset($mapperKeys[$i][1]) && is_numeric($mapperKeys[$i][1])) {
             $mapperLocType[$i] = $mapperKeys[$i][1];
         } else {
             $mapperLocType[$i] = null;
         }
         $locations[$i] = isset($mapperLocType[$i]) ? $this->_location_types[$mapperLocType[$i]] : null;
         // to store phone_type id and provider id seperately, CRM-3140
         if (CRM_Utils_Array::value($i, $mapperKeysMain) == 'phone') {
             $mapperPhoneType[$i] = $phoneTypes[$mapperKeys[$i][2]];
             $mapperImProvider[$i] = null;
         } else {
             if (CRM_Utils_Array::value($i, $mapperKeysMain) == 'im') {
                 $mapperImProvider[$i] = $imProviders[$mapperKeys[$i][2]];
                 $mapperPhoneType[$i] = null;
             } else {
                 $mapperPhoneType[$i] = null;
                 $mapperImProvider[$i] = null;
             }
         }
         //relationship info
         if (isset($mapperKeys[$i]) && isset($mapperKeys[$i][0])) {
             list($id, $first, $second) = CRM_Utils_System::explode('_', $mapperKeys[$i][0], 3);
         } else {
             list($id, $first, $second) = array(null, null, null);
         }
         if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') {
             $related[$i] = $this->_mapperFields[$mapperKeys[$i][0]];
             $relatedContactLocType[$i] = isset($mapperKeys[$i][1]) ? $this->_location_types[$mapperKeys[$i][2]] : null;
             //$relatedContactPhoneType[$i] = !is_numeric($mapperKeys[$i][2]) ? $mapperKeys[$i][3] : null;
             // to store phoneType id and provider id seperately for ralated contact, CRM-3140
             if (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'phone') {
                 $relatedContactPhoneType[$i] = isset($mapperKeys[$i][3]) ? $phoneTypes[$mapperKeys[$i][3]] : null;
                 $relatedContactImProvider[$i] = null;
             } else {
                 if (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'im') {
                     $relatedContactImProvider[$i] = isset($mapperKeys[$i][3]) ? $imProviders[$mapperKeys[$i][3]] : null;
                     $relatedContactPhoneType[$i] = null;
                 }
             }
             $relationType =& new CRM_Contact_DAO_RelationshipType();
             $relationType->id = $id;
             $relationType->find(true);
             eval('$relatedContactType[$i] = $relationType->contact_type_' . $second . ';');
             $relatedContactDetails[$i] = $this->_formattedFieldNames[$relatedContactType[$i]][$mapperKeys[$i][1]];
         } else {
             $related[$i] = null;
             $relatedContactType[$i] = null;
             $relatedContactDetails[$i] = null;
             $relatedContactLocType[$i] = null;
             $relatedContactPhoneType[$i] = null;
             $relatedContactImProvider[$i] = null;
         }
     }
     $this->set('mapper', $mapper);
     $this->set('locations', $locations);
     $this->set('phones', $mapperPhoneType);
     $this->set('ims', $mapperImProvider);
     $this->set('columnNames', $this->_columnNames);
     //relationship info
     $this->set('related', $related);
     $this->set('relatedContactType', $relatedContactType);
     $this->set('relatedContactDetails', $relatedContactDetails);
     $this->set('relatedContactLocType', $relatedContactLocType);
     $this->set('relatedContactPhoneType', $relatedContactPhoneType);
     $this->set('relatedContactImProvider', $relatedContactImProvider);
     // store mapping Id to display it in the preview page
     $this->set('loadMappingId', CRM_Utils_Array::value('mappingId', $params));
     //Updating Mapping Records
     if (CRM_Utils_Array::value('updateMapping', $params)) {
         $locationTypes =& CRM_Core_PseudoConstant::locationType();
         $mappingFields =& new CRM_Core_DAO_MappingField();
         $mappingFields->mapping_id = $params['mappingId'];
         $mappingFields->find();
         $mappingFieldsId = array();
         while ($mappingFields->fetch()) {
             if ($mappingFields->id) {
                 $mappingFieldsId[$mappingFields->column_number] = $mappingFields->id;
             }
         }
         for ($i = 0; $i < $this->_columnCount; $i++) {
             $updateMappingFields =& new CRM_Core_DAO_MappingField();
             $updateMappingFields->id = $mappingFieldsId[$i];
             $updateMappingFields->mapping_id = $params['mappingId'];
             $updateMappingFields->column_number = $i;
             list($id, $first, $second) = explode('_', $mapperKeys[$i][0]);
             if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') {
                 $updateMappingFields->relationship_type_id = $id;
                 $updateMappingFields->relationship_direction = "{$first}_{$second}";
                 $updateMappingFields->name = ucwords(str_replace("_", " ", $mapperKeys[$i][1]));
                 $updateMappingFields->location_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : null;
                 // get phoneType id and provider id separately
                 // before updating mappingFields of phone and IM for related contact, CRM-3140
                 if (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'phone') {
                     $updateMappingFields->phone_type_id = isset($mapperKeys[$i][3]) ? $mapperKeys[$i][3] : null;
                 } else {
                     if (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'im') {
                         $updateMappingFields->im_provider_id = isset($mapperKeys[$i][3]) ? $mapperKeys[$i][3] : null;
                     }
                 }
             } else {
                 $updateMappingFields->name = $mapper[$i];
                 $updateMappingFields->relationship_type_id = null;
                 $location = array_keys($locationTypes, $locations[$i]);
                 $updateMappingFields->location_type_id = isset($location) ? $location[0] : null;
                 // to store phoneType id and provider id seperately
                 // before updating mappingFields for phone and IM, CRM-3140
                 if (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'phone') {
                     $updateMappingFields->phone_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : null;
                 } else {
                     if (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'im') {
                         $updateMappingFields->im_provider_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : null;
                     }
                 }
             }
             $updateMappingFields->save();
         }
     }
     //Saving Mapping Details and Records
     if (CRM_Utils_Array::value('saveMapping', $params)) {
         $mappingParams = array('name' => $params['saveMappingName'], 'description' => $params['saveMappingDesc'], 'mapping_type_id' => CRM_Core_OptionGroup::getValue('mapping_type', 'Import Contact', 'name'));
         $saveMapping = CRM_Core_BAO_Mapping::add($mappingParams);
         $locationTypes =& CRM_Core_PseudoConstant::locationType();
         $contactType = $this->get('contactType');
         switch ($contactType) {
             case CRM_Import_Parser::CONTACT_INDIVIDUAL:
                 $cType = 'Individual';
                 break;
             case CRM_Import_Parser::CONTACT_HOUSEHOLD:
                 $cType = 'Household';
                 break;
             case CRM_Import_Parser::CONTACT_ORGANIZATION:
                 $cType = 'Organization';
         }
         for ($i = 0; $i < $this->_columnCount; $i++) {
             $saveMappingFields =& new CRM_Core_DAO_MappingField();
             $saveMappingFields->mapping_id = $saveMapping->id;
             $saveMappingFields->contact_type = $cType;
             $saveMappingFields->column_number = $i;
             list($id, $first, $second) = explode('_', $mapperKeys[$i][0]);
             if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') {
                 $saveMappingFields->name = ucwords(str_replace("_", " ", $mapperKeys[$i][1]));
                 $saveMappingFields->relationship_type_id = $id;
                 $saveMappingFields->relationship_direction = "{$first}_{$second}";
                 // to get phoneType id and provider id seperately
                 // before saving mappingFields of phone and IM for related contact, CRM-3140
                 if (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'phone') {
                     $saveMappingFields->phone_type_id = isset($mapperKeys[$i][3]) ? $mapperKeys[$i][3] : null;
                 } else {
                     if (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'im') {
                         $saveMappingFields->im_provider_id = isset($mapperKeys[$i][3]) ? $mapperKeys[$i][3] : null;
                     }
                 }
                 $saveMappingFields->location_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : null;
             } else {
                 $saveMappingFields->name = $mapper[$i];
                 $location_id = array_keys($locationTypes, $locations[$i]);
                 $saveMappingFields->location_type_id = isset($location_id[0]) ? $location_id[0] : null;
                 // to get phoneType id and provider id seperately
                 // before saving mappingFields of phone and IM, CRM-3140
                 if (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'phone') {
                     $saveMappingFields->phone_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : null;
                 } else {
                     if (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'im') {
                         $saveMappingFields->im_provider_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : null;
                     }
                 }
                 $saveMappingFields->relationship_type_id = null;
             }
             $saveMappingFields->save();
         }
         $this->set('savedMapping', $saveMappingFields->mapping_id);
     }
     $parser =& new CRM_Import_Parser_Contact($mapperKeysMain, $mapperLocType, $mapperPhoneType, $mapperImProvider, $related, $relatedContactType, $relatedContactDetails, $relatedContactLocType, $relatedContactPhoneType, $relatedContactImProvider);
     $primaryKeyName = $this->get('primaryKeyName');
     $statusFieldName = $this->get('statusFieldName');
     $parser->run($this->_importTableName, $mapper, CRM_Import_Parser::MODE_PREVIEW, $this->get('contactType'), $primaryKeyName, $statusFieldName, $this->_onDuplicate, null, null, false, CRM_Import_Parser::DEFAULT_TIMEOUT, $this->get('contactSubType'));
     // add all the necessary variables to the form
     $parser->set($this);
 }
Пример #21
0
 /**
  * Function to build the array for display the profile fields
  *
  * @param array $params key value.
  * @param int $gid profile Id
  * @param array $groupTitle Profile Group Title.
  * @param array $values formatted array of key value
  *
  * @param array $profileFields
  *
  * @return void
  * @access public
  * @static
  */
 static function displayProfile(&$params, $gid, &$groupTitle, &$values, &$profileFields = array())
 {
     if ($gid) {
         $config = CRM_Core_Config::singleton();
         $session = CRM_Core_Session::singleton();
         $contactID = $session->get('userID');
         if ($contactID) {
             if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $contactID)) {
                 $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::VIEW);
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::ADD);
         }
         foreach ($fields as $v) {
             if (!empty($v['groupTitle'])) {
                 $groupTitle['groupTitle'] = $v['groupTitle'];
                 break;
             }
         }
         $customVal = '';
         $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
         //start of code to set the default values
         foreach ($fields as $name => $field) {
             $skip = FALSE;
             // skip fields that should not be displayed separately
             if ($field['skipDisplay']) {
                 continue;
             }
             $index = $field['title'];
             if ($name === 'organization_name') {
                 $values[$index] = $params[$name];
             }
             if ('state_province' == substr($name, 0, 14)) {
                 if ($params[$name]) {
                     $values[$index] = CRM_Core_PseudoConstant::stateProvince($params[$name]);
                 } else {
                     $values[$index] = '';
                 }
             } elseif ('date' == substr($name, -4)) {
                 $values[$index] = CRM_Utils_Date::customFormat(CRM_Utils_Date::processDate($params[$name]), $config->dateformatFull);
             } elseif ('country' == substr($name, 0, 7)) {
                 if ($params[$name]) {
                     $values[$index] = CRM_Core_PseudoConstant::country($params[$name]);
                 } else {
                     $values[$index] = '';
                 }
             } elseif ('county' == substr($name, 0, 6)) {
                 if ($params[$name]) {
                     $values[$index] = CRM_Core_PseudoConstant::county($params[$name]);
                 } else {
                     $values[$index] = '';
                 }
             } elseif (in_array(substr($name, 0, -3), array('gender', 'prefix', 'suffix', 'communication_style'))) {
                 $values[$index] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', $name, $params[$name]);
             } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting'))) {
                 $filterCondition = array('greeting_type' => $name);
                 $greeting = CRM_Core_PseudoConstant::greeting($filterCondition);
                 $values[$index] = $greeting[$params[$name]];
             } elseif ($name === 'preferred_communication_method') {
                 $communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
                 $compref = array();
                 $pref = $params[$name];
                 if (is_array($pref)) {
                     foreach ($pref as $k => $v) {
                         if ($v) {
                             $compref[] = $communicationFields[$k];
                         }
                     }
                 }
                 $values[$index] = implode(',', $compref);
             } elseif ($name == 'contact_sub_type') {
                 $values[$index] = implode(', ', $params[$name]);
             } elseif ($name == 'group') {
                 $groups = CRM_Contact_BAO_GroupContact::getGroupList();
                 $title = array();
                 foreach ($params[$name] as $gId => $dontCare) {
                     if ($dontCare) {
                         $title[] = $groups[$gId];
                     }
                 }
                 $values[$index] = implode(', ', $title);
             } elseif ($name == 'tag') {
                 $entityTags = $params[$name];
                 $allTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
                 $title = array();
                 if (is_array($entityTags)) {
                     foreach ($entityTags as $tagId => $dontCare) {
                         $title[] = $allTags[$tagId];
                     }
                 }
                 $values[$index] = implode(', ', $title);
             } elseif ('participant_role_id' == $name or 'participant_role' == $name) {
                 $roles = CRM_Event_PseudoConstant::participantRole();
                 $values[$index] = $roles[$params[$name]];
             } elseif ('participant_status_id' == $name or 'participant_status' == $name) {
                 $status = CRM_Event_PseudoConstant::participantStatus();
                 $values[$index] = $status[$params[$name]];
             } elseif (substr($name, -11) == 'campaign_id') {
                 $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($params[$name]);
                 $values[$index] = CRM_Utils_Array::value($params[$name], $campaigns);
             } elseif (strpos($name, '-') !== FALSE) {
                 list($fieldName, $id) = CRM_Utils_System::explode('-', $name, 2);
                 $detailName = str_replace(' ', '_', $name);
                 if (in_array($fieldName, array('state_province', 'country', 'county'))) {
                     $values[$index] = $params[$detailName];
                     $idx = $detailName . '_id';
                     $values[$index] = $params[$idx];
                 } elseif ($fieldName == 'im') {
                     $providerName = NULL;
                     if ($providerId = $detailName . '-provider_id') {
                         $providerName = CRM_Utils_Array::value($params[$providerId], $imProviders);
                     }
                     if ($providerName) {
                         $values[$index] = $params[$detailName] . " (" . $providerName . ")";
                     } else {
                         $values[$index] = $params[$detailName];
                     }
                 } elseif ($fieldName == 'phone') {
                     $phoneExtField = str_replace('phone', 'phone_ext', $detailName);
                     if (isset($params[$phoneExtField])) {
                         $values[$index] = $params[$detailName] . " (" . $params[$phoneExtField] . ")";
                     } else {
                         $values[$index] = $params[$detailName];
                     }
                 } else {
                     $values[$index] = $params[$detailName];
                 }
             } else {
                 if (substr($name, 0, 7) === 'do_not_' or substr($name, 0, 3) === 'is_') {
                     if ($params[$name]) {
                         $values[$index] = '[ x ]';
                     }
                 } else {
                     if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                         $query = "\nSELECT html_type, data_type\nFROM   civicrm_custom_field\nWHERE  id = {$cfID}\n";
                         $dao = CRM_Core_DAO::executeQuery($query);
                         $dao->fetch();
                         $htmlType = $dao->html_type;
                         if ($htmlType == 'File') {
                             $values[$index] = $params[$index];
                         } else {
                             if ($dao->data_type == 'Int' || $dao->data_type == 'Boolean') {
                                 $v = $params[$name];
                                 if (!CRM_Utils_System::isNull($v)) {
                                     $customVal = (int) $v;
                                 }
                             } elseif ($dao->data_type == 'Float') {
                                 $customVal = (double) $params[$name];
                             } elseif ($dao->data_type == 'Date') {
                                 //@todo note the currently we are using default date time formatting. Since you can select/set
                                 // different date and time format specific to custom field we should consider fixing this
                                 // sometime in the future
                                 $customVal = $displayValue = CRM_Utils_Date::customFormat(CRM_Utils_Date::processDate($params[$name]), $config->dateformatFull);
                                 if (!empty($params[$name . '_time'])) {
                                     $customVal = $displayValue = CRM_Utils_Date::customFormat(CRM_Utils_Date::processDate($params[$name], $params[$name . '_time']), $config->dateformatDatetime);
                                 }
                                 $skip = TRUE;
                             } else {
                                 $customVal = $params[$name];
                             }
                             //take the custom field options
                             $returnProperties = array($name => 1);
                             $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields);
                             $options =& $query->_options;
                             if (!$skip) {
                                 $displayValue = CRM_Core_BAO_CustomField::getDisplayValue($customVal, $cfID, $options);
                             }
                             //Hack since we dont have function to check empty.
                             //FIXME in 2.3 using crmIsEmptyArray()
                             $customValue = TRUE;
                             if (is_array($customVal) && is_array($displayValue)) {
                                 $customValue = array_diff($customVal, $displayValue);
                             }
                             //use difference of arrays
                             if (empty($customValue) || !$customValue) {
                                 $values[$index] = '';
                             } else {
                                 $values[$index] = $displayValue;
                             }
                         }
                     } elseif ($name == 'home_URL' && !empty($params[$name])) {
                         $url = CRM_Utils_System::fixURL($params[$name]);
                         $values[$index] = "<a href=\"{$url}\">{$params[$name]}</a>";
                     } elseif (in_array($name, array('birth_date', 'deceased_date', 'participant_register_date'))) {
                         $values[$index] = CRM_Utils_Date::customFormat(CRM_Utils_Date::format($params[$name]));
                     } else {
                         $values[$index] = $params[$name];
                     }
                 }
             }
             $profileFields[$name] = $field;
         }
     }
 }
Пример #22
0
/**
 * Use this API to get existing custom values for an entity.
 *
 * @param array $params
 *   Array specifying the entity_id.
 *   Optionally include entity_type param, i.e. 'entity_type' => 'Activity'
 *   If no entity_type is supplied, it will be determined based on the fields you request.
 *   If no entity_type is supplied and no fields are specified, 'Contact' will be assumed.
 *   Optionally include the desired custom data to be fetched (or else all custom data for this entity will be returned)
 *   Example: 'entity_id' => 123, 'return.custom_6' => 1, 'return.custom_33' => 1
 *   If you do not know the ID, you may use group name : field name, for example 'return.foo_stuff:my_field' => 1
 *
 * @throws API_Exception
 * @return array
 */
function civicrm_api3_custom_value_get($params)
{
    $getParams = array('entityID' => $params['entity_id'], 'entityType' => CRM_Utils_Array::value('entity_table', $params, ''));
    if (strstr($getParams['entityType'], 'civicrm_')) {
        $getParams['entityType'] = ucfirst(substr($getParams['entityType'], 8));
    }
    unset($params['entity_id'], $params['entity_table']);
    foreach ($params as $id => $param) {
        if ($param && substr($id, 0, 6) == 'return') {
            $id = substr($id, 7);
            list($c, $i) = CRM_Utils_System::explode('_', $id, 2);
            if ($c == 'custom' && is_numeric($i)) {
                $names['custom_' . $i] = 'custom_' . $i;
                $id = $i;
            } else {
                // Lookup names if ID was not supplied
                list($group, $field) = CRM_Utils_System::explode(':', $id, 2);
                $id = CRM_Core_BAO_CustomField::getCustomFieldID($field, $group);
                if (!$id) {
                    continue;
                }
                $names['custom_' . $id] = 'custom_' . $i;
            }
            $getParams['custom_' . $id] = 1;
        }
    }
    $result = CRM_Core_BAO_CustomValueTable::getValues($getParams);
    if ($result['is_error']) {
        if ($result['error_message'] == "No values found for the specified entity ID and custom field(s).") {
            $values = array();
            return civicrm_api3_create_success($values, $params, 'CustomValue');
        } else {
            throw new API_Exception($result['error_message']);
        }
    } else {
        $entity_id = $result['entityID'];
        unset($result['is_error'], $result['entityID']);
        // Convert multi-value strings to arrays
        $sp = CRM_Core_DAO::VALUE_SEPARATOR;
        foreach ($result as $id => $value) {
            if (strpos($value, $sp) !== FALSE) {
                $value = explode($sp, trim($value, $sp));
            }
            $idArray = explode('_', $id);
            if ($idArray[0] != 'custom') {
                continue;
            }
            $fieldNumber = $idArray[1];
            $customFieldInfo = CRM_Core_BAO_CustomField::getNameFromID($fieldNumber);
            $info = array_pop($customFieldInfo);
            // id is the index for returned results
            if (empty($idArray[2])) {
                $n = 0;
                $id = $fieldNumber;
            } else {
                $n = $idArray[2];
                $id = $fieldNumber . "." . $idArray[2];
            }
            if (!empty($params['format.field_names'])) {
                $id = $info['field_name'];
            } else {
                $id = $fieldNumber;
            }
            $values[$id]['entity_id'] = $getParams['entityID'];
            if (!empty($getParams['entityType'])) {
                $values[$id]['entity_table'] = $getParams['entityType'];
            }
            //set 'latest' -useful for multi fields but set for single for consistency
            $values[$id]['latest'] = $value;
            $values[$id]['id'] = $id;
            $values[$id][$n] = $value;
        }
        return civicrm_api3_create_success($values, $params, 'CustomValue');
    }
}
Пример #23
0
 /**
  * Process the mapped fields and map it into the uploaded file.
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues('MapField');
     //reload the mapfield if load mapping is pressed
     if (!empty($params['savedMapping'])) {
         $this->set('savedMapping', $params['savedMapping']);
         $this->controller->resetPage($this->_name);
         return;
     }
     $mapper = array();
     $mapperKeys = array();
     $mapperKeys = $this->controller->exportValue($this->_name, 'mapper');
     $mapperKeysMain = array();
     $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
     $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
     $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
     $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     //these mapper params need to set key as array and val as null.
     $mapperParams = array('related' => 'relatedVal', 'locations' => 'locationsVal', 'mapperLocType' => 'mapperLocTypeVal', 'mapperPhoneType' => 'mapperPhoneTypeVal', 'mapperImProvider' => 'mapperImProviderVal', 'mapperWebsiteType' => 'mapperWebsiteTypeVal', 'relatedContactType' => 'relatedContactTypeVal', 'relatedContactDetails' => 'relatedContactDetailsVal', 'relatedContactLocType' => 'relatedContactLocTypeVal', 'relatedContactPhoneType' => 'relatedContactPhoneTypeVal', 'relatedContactImProvider' => 'relatedContactImProviderVal', 'relatedContactWebsiteType' => 'relatedContactWebsiteTypeVal');
     //set respective mapper params to array.
     foreach (array_keys($mapperParams) as $mapperParam) {
         ${$mapperParam} = array();
     }
     for ($i = 0; $i < $this->_columnCount; $i++) {
         //set respective mapper value to null
         foreach (array_values($mapperParams) as $mapperParam) {
             ${$mapperParam} = NULL;
         }
         $fldName = CRM_Utils_Array::value(0, $mapperKeys[$i]);
         $selOne = CRM_Utils_Array::value(1, $mapperKeys[$i]);
         $selTwo = CRM_Utils_Array::value(2, $mapperKeys[$i]);
         $selThree = CRM_Utils_Array::value(3, $mapperKeys[$i]);
         $mapper[$i] = $this->_mapperFields[$mapperKeys[$i][0]];
         $mapperKeysMain[$i] = $fldName;
         //need to differentiate non location elements.
         if ($selOne && is_numeric($selOne)) {
             if ($fldName == 'url') {
                 $mapperWebsiteTypeVal = $websiteTypes[$selOne];
             } else {
                 $locationsVal = $locationTypes[$selOne];
                 $mapperLocTypeVal = $selOne;
                 if ($selTwo && is_numeric($selTwo)) {
                     if ($fldName == 'phone') {
                         $mapperPhoneTypeVal = $phoneTypes[$selTwo];
                     } elseif ($fldName == 'im') {
                         $mapperImProviderVal = $imProviders[$selTwo];
                     }
                 }
             }
         }
         //relationship contact mapper info.
         list($id, $first, $second) = CRM_Utils_System::explode('_', $fldName, 3);
         if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') {
             $relatedVal = $this->_mapperFields[$fldName];
             if ($selOne) {
                 if ($selOne == 'url') {
                     $relatedContactWebsiteTypeVal = $websiteTypes[$selTwo];
                 } else {
                     $relatedContactLocTypeVal = CRM_Utils_Array::value($selTwo, $locationTypes);
                     if ($selThree) {
                         if ($selOne == 'phone') {
                             $relatedContactPhoneTypeVal = $phoneTypes[$selThree];
                         } elseif ($selOne == 'im') {
                             $relatedContactImProviderVal = $imProviders[$selThree];
                         }
                     }
                 }
                 //get the related contact type.
                 $relationType = new CRM_Contact_DAO_RelationshipType();
                 $relationType->id = $id;
                 $relationType->find(TRUE);
                 $relatedContactTypeVal = $relationType->{"contact_type_{$second}"};
                 $relatedContactDetailsVal = $this->_formattedFieldNames[$relatedContactTypeVal][$selOne];
             }
         }
         //set the respective mapper param array values.
         foreach ($mapperParams as $mapperParamKey => $mapperParamVal) {
             ${$mapperParamKey}[$i] = ${$mapperParamVal};
         }
     }
     $this->set('columnNames', $this->_columnNames);
     //set main contact properties.
     $properties = array('ims' => 'mapperImProvider', 'mapper' => 'mapper', 'phones' => 'mapperPhoneType', 'websites' => 'mapperWebsiteType', 'locations' => 'locations');
     foreach ($properties as $propertyName => $propertyVal) {
         $this->set($propertyName, ${$propertyVal});
     }
     //set related contact propeties.
     $relProperties = array('related', 'relatedContactType', 'relatedContactDetails', 'relatedContactLocType', 'relatedContactPhoneType', 'relatedContactImProvider', 'relatedContactWebsiteType');
     foreach ($relProperties as $relProperty) {
         $this->set($relProperty, ${$relProperty});
     }
     // store mapping Id to display it in the preview page
     $this->set('loadMappingId', CRM_Utils_Array::value('mappingId', $params));
     //Updating Mapping Records
     if (!empty($params['updateMapping'])) {
         $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
         $mappingFields = new CRM_Core_DAO_MappingField();
         $mappingFields->mapping_id = $params['mappingId'];
         $mappingFields->find();
         $mappingFieldsId = array();
         while ($mappingFields->fetch()) {
             if ($mappingFields->id) {
                 $mappingFieldsId[$mappingFields->column_number] = $mappingFields->id;
             }
         }
         for ($i = 0; $i < $this->_columnCount; $i++) {
             $updateMappingFields = new CRM_Core_DAO_MappingField();
             $updateMappingFields->id = CRM_Utils_Array::value($i, $mappingFieldsId);
             $updateMappingFields->mapping_id = $params['mappingId'];
             $updateMappingFields->column_number = $i;
             $mapperKeyParts = explode('_', $mapperKeys[$i][0], 3);
             $id = isset($mapperKeyParts[0]) ? $mapperKeyParts[0] : NULL;
             $first = isset($mapperKeyParts[1]) ? $mapperKeyParts[1] : NULL;
             $second = isset($mapperKeyParts[2]) ? $mapperKeyParts[2] : NULL;
             if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') {
                 $updateMappingFields->relationship_type_id = $id;
                 $updateMappingFields->relationship_direction = "{$first}_{$second}";
                 $updateMappingFields->name = ucwords(str_replace("_", " ", $mapperKeys[$i][1]));
                 // get phoneType id and provider id separately
                 // before updating mappingFields of phone and IM for related contact, CRM-3140
                 if (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'url') {
                     $updateMappingFields->website_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : NULL;
                 } else {
                     if (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'phone') {
                         $updateMappingFields->phone_type_id = isset($mapperKeys[$i][3]) ? $mapperKeys[$i][3] : NULL;
                     } elseif (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'im') {
                         $updateMappingFields->im_provider_id = isset($mapperKeys[$i][3]) ? $mapperKeys[$i][3] : NULL;
                     }
                     $updateMappingFields->location_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : NULL;
                 }
             } else {
                 $updateMappingFields->name = $mapper[$i];
                 $updateMappingFields->relationship_type_id = 'NULL';
                 $updateMappingFields->relationship_type_direction = 'NULL';
                 // to store phoneType id and provider id separately
                 // before updating mappingFields for phone and IM, CRM-3140
                 if (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'url') {
                     $updateMappingFields->website_type_id = isset($mapperKeys[$i][1]) ? $mapperKeys[$i][1] : NULL;
                 } else {
                     if (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'phone') {
                         $updateMappingFields->phone_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : NULL;
                     } elseif (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'im') {
                         $updateMappingFields->im_provider_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : NULL;
                     }
                     $location = array_keys($locationTypes, $locations[$i]);
                     $updateMappingFields->location_type_id = isset($location) && isset($location[0]) ? $location[0] : NULL;
                 }
             }
             $updateMappingFields->save();
         }
     }
     //Saving Mapping Details and Records
     if (!empty($params['saveMapping'])) {
         $mappingParams = array('name' => $params['saveMappingName'], 'description' => $params['saveMappingDesc'], 'mapping_type_id' => CRM_Core_OptionGroup::getValue('mapping_type', 'Import Contact', 'name'));
         $saveMapping = CRM_Core_BAO_Mapping::add($mappingParams);
         $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
         $contactType = $this->get('contactType');
         switch ($contactType) {
             case CRM_Import_Parser::CONTACT_INDIVIDUAL:
                 $cType = 'Individual';
                 break;
             case CRM_Import_Parser::CONTACT_HOUSEHOLD:
                 $cType = 'Household';
                 break;
             case CRM_Import_Parser::CONTACT_ORGANIZATION:
                 $cType = 'Organization';
         }
         for ($i = 0; $i < $this->_columnCount; $i++) {
             $saveMappingFields = new CRM_Core_DAO_MappingField();
             $saveMappingFields->mapping_id = $saveMapping->id;
             $saveMappingFields->contact_type = $cType;
             $saveMappingFields->column_number = $i;
             $mapperKeyParts = explode('_', $mapperKeys[$i][0], 3);
             $id = isset($mapperKeyParts[0]) ? $mapperKeyParts[0] : NULL;
             $first = isset($mapperKeyParts[1]) ? $mapperKeyParts[1] : NULL;
             $second = isset($mapperKeyParts[2]) ? $mapperKeyParts[2] : NULL;
             if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') {
                 $saveMappingFields->name = ucwords(str_replace("_", " ", $mapperKeys[$i][1]));
                 $saveMappingFields->relationship_type_id = $id;
                 $saveMappingFields->relationship_direction = "{$first}_{$second}";
                 // to get phoneType id and provider id separately
                 // before saving mappingFields of phone and IM for related contact, CRM-3140
                 if (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'url') {
                     $saveMappingFields->website_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : NULL;
                 } else {
                     if (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'phone') {
                         $saveMappingFields->phone_type_id = isset($mapperKeys[$i][3]) ? $mapperKeys[$i][3] : NULL;
                     } elseif (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'im') {
                         $saveMappingFields->im_provider_id = isset($mapperKeys[$i][3]) ? $mapperKeys[$i][3] : NULL;
                     }
                     $saveMappingFields->location_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : NULL;
                 }
             } else {
                 $saveMappingFields->name = $mapper[$i];
                 $location_id = array_keys($locationTypes, $locations[$i]);
                 // to get phoneType id and provider id separately
                 // before saving mappingFields of phone and IM, CRM-3140
                 if (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'url') {
                     $saveMappingFields->website_type_id = isset($mapperKeys[$i][1]) ? $mapperKeys[$i][1] : NULL;
                 } else {
                     if (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'phone') {
                         $saveMappingFields->phone_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : NULL;
                     } elseif (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'im') {
                         $saveMappingFields->im_provider_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : NULL;
                     }
                     $saveMappingFields->location_type_id = isset($location_id[0]) ? $location_id[0] : NULL;
                 }
                 $saveMappingFields->relationship_type_id = NULL;
             }
             $saveMappingFields->save();
         }
         $this->set('savedMapping', $saveMappingFields->mapping_id);
     }
     $parser = new CRM_Contact_Import_Parser_Contact($mapperKeysMain, $mapperLocType, $mapperPhoneType, $mapperImProvider, $related, $relatedContactType, $relatedContactDetails, $relatedContactLocType, $relatedContactPhoneType, $relatedContactImProvider, $mapperWebsiteType, $relatedContactWebsiteType);
     $primaryKeyName = $this->get('primaryKeyName');
     $statusFieldName = $this->get('statusFieldName');
     $parser->run($this->_importTableName, $mapper, CRM_Import_Parser::MODE_PREVIEW, $this->get('contactType'), $primaryKeyName, $statusFieldName, $this->_onDuplicate, NULL, NULL, FALSE, CRM_Contact_Import_Parser::DEFAULT_TIMEOUT, $this->get('contactSubType'), $this->get('dedupe'));
     // add all the necessary variables to the form
     $parser->set($this);
 }
Пример #24
0
 function where()
 {
     $whereClauses = $havingClauses = array();
     foreach ($this->_columns as $tableName => $table) {
         if (array_key_exists('filters', $table)) {
             foreach ($table['filters'] as $fieldName => $field) {
                 $clause = null;
                 if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
                     $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
                     $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
                     $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
                     $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
                 } else {
                     $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
                     if ($op) {
                         if ($tableName == 'civicrm_relationship_type' && ($fieldName == 'contact_type_a' || $fieldName == 'contact_type_b')) {
                             $cTypes = CRM_Utils_Array::value("{$fieldName}_value", $this->_params);
                             $contactTypes = $contactSubTypes = array();
                             if (!empty($cTypes)) {
                                 foreach ($cTypes as $ctype) {
                                     $getTypes = CRM_Utils_System::explode('_', $ctype, 2);
                                     if ($getTypes[1] && !in_array($getTypes[1], $contactSubTypes)) {
                                         $contactSubTypes[] = $getTypes[1];
                                     } elseif ($getTypes[0] && !in_array($getTypes[0], $contactTypes)) {
                                         $contactTypes[] = $getTypes[0];
                                     }
                                 }
                             }
                             if (!empty($contactTypes)) {
                                 $clause = $this->whereClause($field, $op, $contactTypes, CRM_Utils_Array::value("{$fieldName}_min", $this->_params), CRM_Utils_Array::value("{$fieldName}_max", $this->_params));
                             }
                             if (!empty($contactSubTypes)) {
                                 if ($fieldName == 'contact_type_a') {
                                     $field['name'] = 'contact_sub_type_a';
                                 } else {
                                     $field['name'] = 'contact_sub_type_b';
                                 }
                                 $field['dbAlias'] = $field['alias'] . '.' . $field['name'];
                                 $subTypeClause = $this->whereClause($field, $op, $contactSubTypes, CRM_Utils_Array::value("{$fieldName}_min", $this->_params), CRM_Utils_Array::value("{$fieldName}_max", $this->_params));
                                 if ($clause) {
                                     $clause = '(' . $clause . ' OR ' . $subTypeClause . ')';
                                 } else {
                                     $clause = $subTypeClause;
                                 }
                             }
                         } else {
                             $clause = $this->whereClause($field, $op, CRM_Utils_Array::value("{$fieldName}_value", $this->_params), CRM_Utils_Array::value("{$fieldName}_min", $this->_params), CRM_Utils_Array::value("{$fieldName}_max", $this->_params));
                         }
                     }
                 }
                 if (!empty($clause)) {
                     if (CRM_Utils_Array::value('having', $field)) {
                         $havingClauses[] = $clause;
                     } else {
                         $whereClauses[] = $clause;
                     }
                 }
             }
         }
     }
     if (empty($whereClauses)) {
         $this->_where = 'WHERE ( 1 ) ';
         $this->_having = '';
     } else {
         $this->_where = 'WHERE ' . implode(' AND ', $whereClauses);
     }
     if ($this->_aclWhere) {
         $this->_where .= " AND {$this->_aclWhere} ";
     }
     if (!empty($havingClauses)) {
         // use this clause to construct group by clause.
         $this->_having = 'HAVING ' . implode(' AND ', $havingClauses);
     }
 }
Пример #25
0
 /**  
  * Function to build the array for display the profile fields
  *  
  * @param array $params key value. 
  * @param int $gid profile Id
  * @param array $groupTitle Profile Group Title.
  * @param array $values formatted array of key value
  *
  * @return None  
  * @access public  
  */
 function displayProfile(&$params, $gid, &$groupTitle, &$values)
 {
     if ($gid) {
         require_once 'CRM/Core/BAO/UFGroup.php';
         require_once 'CRM/Profile/Form.php';
         require_once 'CRM/Event/PseudoConstant.php';
         $session = CRM_Core_Session::singleton();
         $contactID = $session->get('userID');
         if ($contactID) {
             if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $contactID)) {
                 $fields = CRM_Core_BAO_UFGroup::getFields($gid, false, CRM_Core_Action::VIEW);
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($gid, false, CRM_Core_Action::ADD);
         }
         if (is_array($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]);
                 }
             }
         }
         foreach ($fields as $v) {
             if (CRM_Utils_Array::value('groupTitle', $v)) {
                 $groupTitle['groupTitle'] = $v["groupTitle"];
                 break;
             }
         }
         $config = CRM_Core_Config::singleton();
         require_once 'CRM/Core/PseudoConstant.php';
         $locationTypes = $imProviders = array();
         $locationTypes = CRM_Core_PseudoConstant::locationType();
         $imProviders = CRM_Core_PseudoConstant::IMProvider();
         //start of code to set the default values
         foreach ($fields as $name => $field) {
             $index = $field['title'];
             $customFieldName = null;
             if ($name === 'organization_name') {
                 $values[$index] = $params[$name];
             }
             if ('state_province' == substr($name, 0, 14)) {
                 if ($params[$name]) {
                     $values[$index] = CRM_Core_PseudoConstant::stateProvince($params[$name]);
                 } else {
                     $values[$index] = '';
                 }
             } else {
                 if ('country' == substr($name, 0, 7)) {
                     if ($params[$name]) {
                         $values[$index] = CRM_Core_PseudoConstant::country($params[$name]);
                     } else {
                         $values[$index] = '';
                     }
                 } else {
                     if ('county' == substr($name, 0, 6)) {
                         if ($params[$name]) {
                             $values[$index] = CRM_Core_PseudoConstant::county($params[$name]);
                         } else {
                             $values[$index] = '';
                         }
                     } else {
                         if ('gender' == substr($name, 0, 6)) {
                             $gender = CRM_Core_PseudoConstant::gender();
                             $values[$index] = $gender[$params[$name]];
                         } else {
                             if ('individual_prefix' == substr($name, 0, 17)) {
                                 $prefix = CRM_Core_PseudoConstant::individualPrefix();
                                 $values[$index] = $prefix[$params[$name]];
                             } else {
                                 if ('individual_suffix' == substr($name, 0, 17)) {
                                     $suffix = CRM_Core_PseudoConstant::individualSuffix();
                                     $values[$index] = $suffix[$params[$name]];
                                 } else {
                                     if (in_array($name, array('addressee', 'email_greeting', 'postal_greeting'))) {
                                         $filterCondition = array('greeting_type' => $name);
                                         $greeting =& CRM_Core_PseudoConstant::greeting($filterCondition);
                                         $values[$index] = $greeting[$params[$name]];
                                     } else {
                                         if ($name === 'preferred_communication_method') {
                                             $communicationFields = CRM_Core_PseudoConstant::pcm();
                                             $pref = array();
                                             $compref = array();
                                             $pref = $params[$name];
                                             if (is_array($pref)) {
                                                 foreach ($pref as $k => $v) {
                                                     if ($v) {
                                                         $compref[] = $communicationFields[$k];
                                                     }
                                                 }
                                             }
                                             $values[$index] = implode(",", $compref);
                                         } else {
                                             if ($name == 'group') {
                                                 require_once 'CRM/Contact/BAO/GroupContact.php';
                                                 $groups = CRM_Contact_BAO_GroupContact::getGroupList();
                                                 $title = array();
                                                 foreach ($params[$name] as $gId => $dontCare) {
                                                     if ($dontCare) {
                                                         $title[] = $groups[$gId];
                                                     }
                                                 }
                                                 $values[$index] = implode(', ', $title);
                                             } else {
                                                 if ($name == 'tag') {
                                                     require_once 'CRM/Core/BAO/EntityTag.php';
                                                     $entityTags = $params[$name];
                                                     $allTags =& CRM_Core_PseudoConstant::tag();
                                                     $title = array();
                                                     if (is_array($entityTags)) {
                                                         foreach ($entityTags as $tagId => $dontCare) {
                                                             $title[] = $allTags[$tagId];
                                                         }
                                                     }
                                                     $values[$index] = implode(', ', $title);
                                                 } else {
                                                     if ('participant_role_id' == $name) {
                                                         $roles = CRM_Event_PseudoConstant::participantRole();
                                                         $values[$index] = $roles[$params[$name]];
                                                     } else {
                                                         if ('participant_status_id' == $name) {
                                                             $status = CRM_Event_PseudoConstant::participantStatus();
                                                             $values[$index] = $status[$params[$name]];
                                                         } else {
                                                             if (strpos($name, '-') !== false) {
                                                                 list($fieldName, $id) = CRM_Utils_System::explode('-', $name, 2);
                                                                 $detailName = str_replace(' ', '_', $name);
                                                                 if (in_array($fieldName, array('state_province', 'country', 'county'))) {
                                                                     $values[$index] = $params[$detailName];
                                                                     $idx = $detailName . '_id';
                                                                     $values[$index] = $params[$idx];
                                                                 } else {
                                                                     if ($fieldName == 'im') {
                                                                         $providerName = null;
                                                                         if ($providerId = $detailName . '-provider_id') {
                                                                             $providerName = CRM_Utils_Array::value($params[$providerId], $imProviders);
                                                                         }
                                                                         if ($providerName) {
                                                                             $values[$index] = $params[$detailName] . " (" . $providerName . ")";
                                                                         } else {
                                                                             $values[$index] = $params[$detailName];
                                                                         }
                                                                     } else {
                                                                         $values[$index] = $params[$detailName];
                                                                     }
                                                                 }
                                                             } else {
                                                                 if (substr($name, 0, 7) === 'do_not_' or substr($name, 0, 3) === 'is_') {
                                                                     if ($params[$name]) {
                                                                         $values[$index] = '[ x ]';
                                                                     }
                                                                 } else {
                                                                     require_once 'CRM/Core/BAO/CustomField.php';
                                                                     if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                                                                         $query = "\nSELECT html_type, data_type\nFROM   civicrm_custom_field\nWHERE  id = {$cfID}\n";
                                                                         $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
                                                                         $dao->fetch();
                                                                         $htmlType = $dao->html_type;
                                                                         $dataType = $dao->data_type;
                                                                         if ($htmlType == 'File') {
                                                                             //$fileURL = CRM_Core_BAO_CustomField::getFileURL( $contactID, $cfID );
                                                                             //$params[$index] = $values[$index] = $fileURL['file_url'];
                                                                             $values[$index] = $params[$index];
                                                                         } else {
                                                                             if ($dao->data_type == 'Int' || $dao->data_type == 'Boolean') {
                                                                                 $customVal = (int) $params[$name];
                                                                             } else {
                                                                                 if ($dao->data_type == 'Float') {
                                                                                     $customVal = (double) $params[$name];
                                                                                 } else {
                                                                                     if ($dao->data_type == 'Date') {
                                                                                         $date = CRM_Utils_Date::format($params[$name], null, 'invalidDate');
                                                                                         if ($date != 'invalidDate') {
                                                                                             $customVal = $date;
                                                                                         }
                                                                                     } else {
                                                                                         $customVal = $params[$name];
                                                                                     }
                                                                                 }
                                                                             }
                                                                             //take the custom field options
                                                                             $returnProperties = array($name => 1);
                                                                             require_once 'CRM/Contact/BAO/Query.php';
                                                                             $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields);
                                                                             $options =& $query->_options;
                                                                             $displayValue = CRM_Core_BAO_CustomField::getDisplayValue($customVal, $cfID, $options);
                                                                             //Hack since we dont have function to check empty.
                                                                             //FIXME in 2.3 using crmIsEmptyArray()
                                                                             $customValue = true;
                                                                             if (is_array($customVal) && is_array($displayValue)) {
                                                                                 $customValue = array_diff($customVal, $displayValue);
                                                                             }
                                                                             //use difference of arrays
                                                                             if (empty($customValue) || !$customValue) {
                                                                                 $values[$index] = '';
                                                                             } else {
                                                                                 $values[$index] = $displayValue;
                                                                             }
                                                                             if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $cfID, 'is_search_range')) {
                                                                                 $customFieldName = "{$name}_from";
                                                                             }
                                                                         }
                                                                     } else {
                                                                         if ($name == 'home_URL' && !empty($params[$name])) {
                                                                             $url = CRM_Utils_System::fixURL($params[$name]);
                                                                             $values[$index] = "<a href=\"{$url}\">{$params[$name]}</a>";
                                                                         } else {
                                                                             if (in_array($name, array('birth_date', 'deceased_date', 'participant_register_date'))) {
                                                                                 require_once 'CRM/Utils/Date.php';
                                                                                 $values[$index] = CRM_Utils_Date::customFormat(CRM_Utils_Date::format($params[$name]));
                                                                             } else {
                                                                                 $values[$index] = $params[$name];
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 function getFromTo($relative, $from, $to, $fromtime = NULL, $totime = NULL)
 {
     if (empty($totime)) {
         $totime = '235959';
     }
     //FIX ME not working for relative
     if ($relative) {
         list($term, $unit) = CRM_Utils_System::explode('.', $relative, 2);
         $dateRange = CRM_Utils_Date::relativeToAbsolute($term, $unit);
         $from = substr($dateRange['from'], 0, 8);
         //Take only Date Part, Sometime Time part is also present in 'to'
         $to = substr($dateRange['to'], 0, 8);
     }
     $from = CRM_Utils_Date::processDate($from, $fromtime);
     $to = CRM_Utils_Date::processDate($to, $totime);
     $report_type = CRM_Utils_Array::value("teamsinger_retention_report_type_value", $this->_params);
     if ($report_type == 'have_renewed' && !$this->_runQuery) {
         $this->_runQuery = TRUE;
         $original_from = new DateTime($from);
         $original_from->add(new DateInterval('P1Y'));
         $from = $original_from->format('YmdHis');
         $original_to = new DateTime($to);
         $original_to->add(new DateInterval('P1Y'));
         $to = $original_to->format('YmdHis');
     }
     return array($from, $to);
 }
Пример #27
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);
             }
         }
     }
 }
Пример #28
0
 /**
  * Set profile defaults.
  *
  * @param int $contactId
  *   Contact id.
  * @param array $fields
  *   Associative array of fields.
  * @param array $defaults
  *   Defaults array.
  * @param bool $singleProfile
  *   True for single profile else false(batch update).
  * @param int $componentId
  *   Id for specific components like contribute, event etc.
  * @param null $component
  */
 public static function setProfileDefaults($contactId, &$fields, &$defaults, $singleProfile = TRUE, $componentId = NULL, $component = NULL)
 {
     if (!$componentId) {
         //get the contact details
         list($contactDetails, $options) = CRM_Contact_BAO_Contact::getHierContactDetails($contactId, $fields);
         $details = CRM_Utils_Array::value($contactId, $contactDetails);
         $multipleFields = array('website' => 'url');
         //start of code to set the default values
         foreach ($fields as $name => $field) {
             // skip pseudo fields
             if (substr($name, 0, 9) == 'phone_ext') {
                 continue;
             }
             //set the field name depending upon the profile mode(single/batch)
             if ($singleProfile) {
                 $fldName = $name;
             } else {
                 $fldName = "field[{$contactId}][{$name}]";
             }
             if ($name == 'group') {
                 CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, $fldName);
             }
             if ($name == 'tag') {
                 CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::TAG, $fldName);
             }
             if (!empty($details[$name]) || isset($details[$name])) {
                 //to handle custom data (checkbox) to be written
                 // to handle birth/deceased date, greeting_type and few other fields
                 if ($name == 'birth_date' || $name == 'deceased_date') {
                     list($defaults[$fldName]) = CRM_Utils_Date::setDateDefaults($details[$name], 'birth');
                 } elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)) {
                     $defaults[$fldName] = $details[$name . '_id'];
                     $defaults[$name . '_custom'] = $details[$name . '_custom'];
                 } elseif ($name == 'preferred_communication_method') {
                     $v = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details[$name]);
                     foreach ($v as $item) {
                         if ($item) {
                             $defaults[$fldName . "[{$item}]"] = 1;
                         }
                     }
                 } elseif ($name == 'contact_sub_type') {
                     $defaults[$fldName] = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($details[$name], CRM_Core_DAO::VALUE_SEPARATOR));
                 } elseif ($name == 'world_region') {
                     $defaults[$fldName] = $details['worldregion_id'];
                 } elseif ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($name)) {
                     //fix for custom fields
                     $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $details));
                     // hack to add custom data for components
                     $components = array('Contribution', 'Participant', 'Membership', 'Activity');
                     foreach ($components as $value) {
                         $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFieldsForImport($value));
                     }
                     switch ($customFields[$customFieldId]['html_type']) {
                         case 'Multi-Select State/Province':
                         case 'Multi-Select Country':
                         case 'AdvMulti-Select':
                         case 'Multi-Select':
                             $v = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details[$name]);
                             foreach ($v as $item) {
                                 if ($item) {
                                     $defaults[$fldName][$item] = $item;
                                 }
                             }
                             break;
                         case 'CheckBox':
                             $v = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details[$name]);
                             foreach ($v as $item) {
                                 if ($item) {
                                     $defaults[$fldName][$item] = 1;
                                     // seems like we need this for QF style checkboxes in profile where its multiindexed
                                     // CRM-2969
                                     $defaults["{$fldName}[{$item}]"] = 1;
                                 }
                             }
                             break;
                         case 'Select Date':
                             // CRM-6681, set defult values according to date and time format (if any).
                             $dateFormat = NULL;
                             if (!empty($customFields[$customFieldId]['date_format'])) {
                                 $dateFormat = $customFields[$customFieldId]['date_format'];
                             }
                             if (empty($customFields[$customFieldId]['time_format'])) {
                                 list($defaults[$fldName]) = CRM_Utils_Date::setDateDefaults($details[$name], NULL, $dateFormat);
                             } else {
                                 $timeElement = $fldName . '_time';
                                 if (substr($fldName, -1) == ']') {
                                     $timeElement = substr($fldName, 0, -1) . '_time]';
                                 }
                                 list($defaults[$fldName], $defaults[$timeElement]) = CRM_Utils_Date::setDateDefaults($details[$name], NULL, $dateFormat, $customFields[$customFieldId]['time_format']);
                             }
                             break;
                         default:
                             $defaults[$fldName] = $details[$name];
                             break;
                     }
                 } else {
                     $defaults[$fldName] = $details[$name];
                 }
             } else {
                 $blocks = array('email', 'phone', 'im', 'openid');
                 list($fieldName, $locTypeId, $phoneTypeId) = CRM_Utils_System::explode('-', $name, 3);
                 if (!in_array($fieldName, $multipleFields)) {
                     if (is_array($details)) {
                         foreach ($details as $key => $value) {
                             // when we fixed CRM-5319 - get primary loc
                             // type as per loc field and removed below code.
                             $primaryLocationType = FALSE;
                             if ($locTypeId == 'Primary') {
                                 if (is_array($value) && array_key_exists($fieldName, $value)) {
                                     $primaryLocationType = TRUE;
                                     if (in_array($fieldName, $blocks)) {
                                         $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactId, FALSE, $fieldName);
                                     } else {
                                         $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactId, FALSE, 'address');
                                     }
                                 }
                             }
                             // fixed for CRM-665
                             if (is_numeric($locTypeId)) {
                                 if ($primaryLocationType || $locTypeId == CRM_Utils_Array::value('location_type_id', $value)) {
                                     if (!empty($value[$fieldName])) {
                                         //to handle stateprovince and country
                                         if ($fieldName == 'state_province') {
                                             $defaults[$fldName] = $value['state_province_id'];
                                         } elseif ($fieldName == 'county') {
                                             $defaults[$fldName] = $value['county_id'];
                                         } elseif ($fieldName == 'country') {
                                             if (!isset($value['country_id']) || !$value['country_id']) {
                                                 $config = CRM_Core_Config::singleton();
                                                 if ($config->defaultContactCountry) {
                                                     $defaults[$fldName] = $config->defaultContactCountry;
                                                 }
                                             } else {
                                                 $defaults[$fldName] = $value['country_id'];
                                             }
                                         } elseif ($fieldName == 'phone') {
                                             if ($phoneTypeId) {
                                                 if (isset($value['phone'][$phoneTypeId])) {
                                                     $defaults[$fldName] = $value['phone'][$phoneTypeId];
                                                 }
                                                 if (isset($value['phone_ext'][$phoneTypeId])) {
                                                     $defaults[str_replace('phone', 'phone_ext', $fldName)] = $value['phone_ext'][$phoneTypeId];
                                                 }
                                             } else {
                                                 $phoneDefault = CRM_Utils_Array::value('phone', $value);
                                                 // CRM-9216
                                                 if (!is_array($phoneDefault)) {
                                                     $defaults[$fldName] = $phoneDefault;
                                                 }
                                             }
                                         } elseif ($fieldName == 'email') {
                                             //adding the first email (currently we don't support multiple emails of same location type)
                                             $defaults[$fldName] = $value['email'];
                                         } elseif ($fieldName == 'im') {
                                             //adding the first im (currently we don't support multiple ims of same location type)
                                             $defaults[$fldName] = $value['im'];
                                             $defaults[$fldName . '-provider_id'] = $value['im_provider_id'];
                                         } else {
                                             $defaults[$fldName] = $value[$fieldName];
                                         }
                                     } elseif (substr($fieldName, 0, 14) === 'address_custom' && CRM_Utils_Array::value(substr($fieldName, 8), $value)) {
                                         $defaults[$fldName] = $value[substr($fieldName, 8)];
                                     }
                                 }
                             }
                         }
                     }
                 } else {
                     if (is_array($details)) {
                         if ($fieldName === 'url' && !empty($details['website']) && !empty($details['website'][$locTypeId])) {
                             $defaults[$fldName] = CRM_Utils_Array::value('url', $details['website'][$locTypeId]);
                         }
                     }
                 }
             }
         }
     }
     //Handling Contribution Part of the batch profile
     if (CRM_Core_Permission::access('CiviContribute') && $component == 'Contribute') {
         self::setComponentDefaults($fields, $componentId, $component, $defaults);
     }
     //Handling Event Participation Part of the batch profile
     if (CRM_Core_Permission::access('CiviEvent') && $component == 'Event') {
         self::setComponentDefaults($fields, $componentId, $component, $defaults);
     }
     //Handling membership Part of the batch profile
     if (CRM_Core_Permission::access('CiviMember') && $component == 'Membership') {
         self::setComponentDefaults($fields, $componentId, $component, $defaults);
     }
     //Handling Activity Part of the batch profile
     if ($component == 'Activity') {
         self::setComponentDefaults($fields, $componentId, $component, $defaults);
     }
 }
Пример #29
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);
         }
     }
 }
Пример #30
0
 /**
  * Add fields to $profileAddressFields as appropriate.
  * profileAddressFields is assigned to the template to tell it
  * what fields are in the profile address
  * that potentially should be copied to the Billing fields
  * we want to give precedence to
  *   1) Billing &
  *   2) then Primary designated as 'Primary
  *   3) location_type is primary
  *   4) if none of these apply then it just uses the first one
  *
  *   as this will be used to
  * transfer profile address data to billing fields
  * http://issues.civicrm.org/jira/browse/CRM-5869
  *
  * @param string $key
  *   Field key - e.g. street_address-Primary, first_name.
  * @param array $profileAddressFields
  *   Array of profile fields that relate to address fields.
  * @param array $profileFilter
  *   Filter to apply to profile fields - expected usage is to only fill based on.
  *   the bottom profile per CRM-13726
  *
  * @return bool
  *   Can the address block be hidden safe in the knowledge all fields are elsewhere collected (see CRM-15118)
  */
 public static function assignAddressField($key, &$profileAddressFields, $profileFilter)
 {
     $billing_id = CRM_Core_BAO_LocationType::getBilling();
     list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
     $profileFields = civicrm_api3('uf_field', 'get', array_merge($profileFilter, array('is_active' => 1, 'return' => 'field_name, is_required', 'options' => array('limit' => 0))));
     //check for valid fields ( fields that are present in billing block )
     $validBillingFields = array('first_name', 'middle_name', 'last_name', 'street_address', 'supplemental_address_1', 'city', 'state_province', 'postal_code', 'country');
     $requiredBillingFields = array_diff($validBillingFields, array('middle_name', 'supplemental_address_1'));
     $validProfileFields = array();
     $requiredProfileFields = array();
     foreach ($profileFields['values'] as $field) {
         if (in_array($field['field_name'], $validBillingFields)) {
             $validProfileFields[] = $field['field_name'];
         }
         if ($field['is_required']) {
             $requiredProfileFields[] = $field['field_name'];
         }
     }
     if (!in_array($prefixName, $validProfileFields)) {
         return FALSE;
     }
     if (!empty($index) && (!CRM_Utils_array::value($prefixName, $profileAddressFields) || $index == $billing_id || $index == 'Primary' && $profileAddressFields[$prefixName] != $billing_id || $index == CRM_Core_BAO_LocationType::getDefault()->id && $profileAddressFields[$prefixName] != $billing_id && $profileAddressFields[$prefixName] != 'Primary')) {
         $profileAddressFields[$prefixName] = $index;
     }
     $potentiallyMissingRequiredFields = array_diff($requiredBillingFields, $requiredProfileFields);
     CRM_Core_Resources::singleton()->addSetting(array('billing' => array('billingProfileIsHideable' => empty($potentiallyMissingRequiredFields))));
 }