/** * returns the list of fields that can be exported * * @access public * return array * @static */ static function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields = self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['sdd_creditor'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } self::$_export = array_merge(self::$_export, CRM_Core_DAO_Country::export(true)); } return self::$_export; }
/** * @return array */ public function setDefaultValues() { $defaults = parent::setDefaultValues(); $config = CRM_Core_Config::singleton(); $default_country = new CRM_Core_DAO_Country(); $default_country->iso_code = $config->defaultContactCountry(); $default_country->find(TRUE); $defaults["billing_country_id-{$this->_bltID}"] = $default_country->id; if (self::getContactID() && !self::is_administrator()) { $params = array('id' => self::getContactID()); $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults); foreach ($contact->email as $email) { if ($email['is_billing']) { $defaults["billing_contact_email"] = $email['email']; } } if (empty($defaults['billing_contact_email'])) { foreach ($contact->email as $email) { if ($email['is_primary']) { $defaults["billing_contact_email"] = $email['email']; } } } $defaults["billing_first_name"] = $contact->first_name; $defaults["billing_middle_name"] = $contact->middle_name; $defaults["billing_last_name"] = $contact->last_name; $billing_address = CRM_Event_Cart_BAO_MerParticipant::billing_address_from_contact($contact); if ($billing_address != NULL) { $defaults["billing_street_address-{$this->_bltID}"] = $billing_address['street_address']; $defaults["billing_city-{$this->_bltID}"] = $billing_address['city']; $defaults["billing_postal_code-{$this->_bltID}"] = $billing_address['postal_code']; $defaults["billing_state_province_id-{$this->_bltID}"] = $billing_address['state_province_id']; $defaults["billing_country_id-{$this->_bltID}"] = $billing_address['country_id']; } } $defaults["source"] = $this->description; return $defaults; }
/** * Format the address params to have reasonable values. * * @param array $params * (reference ) an assoc array of name/value pairs. */ public static function fixAddress(&$params) { if (!empty($params['billing_street_address'])) { //Check address is coming from online contribution / registration page //Fixed :CRM-5076 $billing = array('street_address' => 'billing_street_address', 'city' => 'billing_city', 'postal_code' => 'billing_postal_code', 'state_province' => 'billing_state_province', 'state_province_id' => 'billing_state_province_id', 'country' => 'billing_country', 'country_id' => 'billing_country_id'); foreach ($billing as $key => $val) { if ($value = CRM_Utils_Array::value($val, $params)) { if (!empty($params[$key])) { unset($params[$val]); } else { //add new key and removed old $params[$key] = $value; unset($params[$val]); } } } } /* Split the zip and +4, if it's in US format */ if (!empty($params['postal_code']) && preg_match('/^(\\d{4,5})[+-](\\d{4})$/', $params['postal_code'], $match)) { $params['postal_code'] = $match[1]; $params['postal_code_suffix'] = $match[2]; } // add country id if not set if ((!isset($params['country_id']) || !is_numeric($params['country_id'])) && isset($params['country'])) { $country = new CRM_Core_DAO_Country(); $country->name = $params['country']; if (!$country->find(TRUE)) { $country->name = NULL; $country->iso_code = $params['country']; $country->find(TRUE); } $params['country_id'] = $country->id; } // add state_id if state is set if ((!isset($params['state_province_id']) || !is_numeric($params['state_province_id'])) && isset($params['state_province'])) { if (!empty($params['state_province'])) { $state_province = new CRM_Core_DAO_StateProvince(); $state_province->name = $params['state_province']; // add country id if present if (!empty($params['country_id'])) { $state_province->country_id = $params['country_id']; } if (!$state_province->find(TRUE)) { unset($state_province->name); $state_province->abbreviation = $params['state_province']; $state_province->find(TRUE); } $params['state_province_id'] = $state_province->id; if (empty($params['country_id'])) { // set this here since we have it $params['country_id'] = $state_province->country_id; } } else { $params['state_province_id'] = 'null'; } } // add county id if county is set // CRM-7837 if ((!isset($params['county_id']) || !is_numeric($params['county_id'])) && isset($params['county']) && !empty($params['county'])) { $county = new CRM_Core_DAO_County(); $county->name = $params['county']; if (isset($params['state_province_id'])) { $county->state_province_id = $params['state_province_id']; } if ($county->find(TRUE)) { $params['county_id'] = $county->id; } } // currently copy values populates empty fields with the string "null" // and hence need to check for the string null if (isset($params['state_province_id']) && is_numeric($params['state_province_id']) && (!isset($params['country_id']) || empty($params['country_id']))) { // since state id present and country id not present, hence lets populate it // jira issue http://issues.civicrm.org/jira/browse/CRM-56 $params['country_id'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_StateProvince', $params['state_province_id'], 'country_id'); } //special check to ignore non numeric values if they are not //detected by formRule(sometimes happens due to internet latency), also allow user to unselect state/country if (isset($params['state_province_id'])) { if (empty($params['state_province_id'])) { $params['state_province_id'] = 'null'; } elseif (!is_numeric($params['state_province_id']) || (int) $params['state_province_id'] < 1000) { // CRM-3393 ( the hacky 1000 check) $params['state_province_id'] = 'null'; } } if (isset($params['country_id'])) { if (empty($params['country_id'])) { $params['country_id'] = 'null'; } elseif (!is_numeric($params['country_id']) || (int) $params['country_id'] < 1000) { // CRM-3393 ( the hacky 1000 check) $params['country_id'] = 'null'; } } // add state and country names from the ids if (isset($params['state_province_id']) && is_numeric($params['state_province_id'])) { $params['state_province'] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($params['state_province_id']); } if (isset($params['country_id']) && is_numeric($params['country_id'])) { $params['country'] = CRM_Core_PseudoConstant::country($params['country_id']); } $config = CRM_Core_Config::singleton(); $asp = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::ADDRESS_STANDARDIZATION_PREFERENCES_NAME, 'address_standardization_provider'); // clean up the address via USPS web services if enabled if ($asp === 'USPS' && $params['country_id'] == 1228) { CRM_Utils_Address_USPS::checkAddress($params); // do street parsing again if enabled, since street address might have changed $parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options'), FALSE); if ($parseStreetAddress && !empty($params['street_address'])) { foreach (array('street_number', 'street_name', 'street_unit', 'street_number_suffix') as $fld) { unset($params[$fld]); } // main parse string. $parseString = CRM_Utils_Array::value('street_address', $params); $parsedFields = CRM_Core_BAO_Address::parseStreetAddress($parseString); // merge parse address in to main address block. $params = array_merge($params, $parsedFields); } } // add latitude and longitude and format address if needed if (!empty($config->geocodeMethod) && $config->geocodeMethod != 'CRM_Utils_Geocode_OpenStreetMaps' && empty($params['manual_geo_code'])) { $class = $config->geocodeMethod; $class::format($params); } }
/** * returns the list of fields that can be exported * * @access public * return array */ function &export($prefix = false) { if (!$GLOBALS['_CRM_CORE_DAO_ADDRESS']['_export']) { $GLOBALS['_CRM_CORE_DAO_ADDRESS']['_export'] = array(); $fields =& CRM_Core_DAO_Address::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { $GLOBALS['_CRM_CORE_DAO_ADDRESS']['_export']['address'] =& $fields[$name]; } else { $GLOBALS['_CRM_CORE_DAO_ADDRESS']['_export'][$name] =& $fields[$name]; } } } $GLOBALS['_CRM_CORE_DAO_ADDRESS']['_export'] = array_merge($GLOBALS['_CRM_CORE_DAO_ADDRESS']['_export'], CRM_Core_DAO_StateProvince::export(true)); $GLOBALS['_CRM_CORE_DAO_ADDRESS']['_export'] = array_merge($GLOBALS['_CRM_CORE_DAO_ADDRESS']['_export'], CRM_Core_DAO_Country::export(true)); } return $GLOBALS['_CRM_CORE_DAO_ADDRESS']['_export']; }
/** * returns the list of fields that can be exported * * @access public * return array * @static */ static function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields = self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['country'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }
/** * returns the list of fields that can be exported * * @access public * return array */ function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields =& self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['address'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } self::$_export = array_merge(self::$_export, CRM_Core_DAO_County::export(true)); self::$_export = array_merge(self::$_export, CRM_Core_DAO_StateProvince::export(true)); self::$_export = array_merge(self::$_export, CRM_Core_DAO_Country::export(true)); } return self::$_export; }
/** * returns the list of fields that can be exported * * @access public * return array */ function &export($prefix = false) { if (!$GLOBALS['_CRM_CORE_DAO_COUNTRY']['_export']) { $GLOBALS['_CRM_CORE_DAO_COUNTRY']['_export'] = array(); $fields =& CRM_Core_DAO_Country::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { $GLOBALS['_CRM_CORE_DAO_COUNTRY']['_export']['country'] =& $fields[$name]; } else { $GLOBALS['_CRM_CORE_DAO_COUNTRY']['_export'][$name] =& $fields[$name]; } } } } return $GLOBALS['_CRM_CORE_DAO_COUNTRY']['_export']; }
/** * format the address params to have reasonable values * * @param array $params (reference ) an assoc array of name/value pairs * * @return void * @access public * @static */ static function fixAddress(&$params) { if (CRM_Utils_Array::value('billing_street_address', $params)) { //Check address is comming from online contribution / registration page //Fixed :CRM-5076 $billing = array('street_address' => 'billing_street_address', 'city' => 'billing_city', 'postal_code' => 'billing_postal_code', 'state_province' => 'billing_state_province', 'state_province_id' => 'billing_state_province_id', 'country' => 'billing_country', 'country_id' => 'billing_country_id'); foreach ($billing as $key => $val) { if ($value = CRM_Utils_Array::value($val, $params)) { if (CRM_Utils_Array::value($key, $params)) { unset($params[$val]); } else { //add new key and removed old $params[$key] = $value; unset($params[$val]); } } } } /* Split the zip and +4, if it's in US format */ if (CRM_Utils_Array::value('postal_code', $params) && preg_match('/^(\\d{4,5})[+-](\\d{4})$/', $params['postal_code'], $match)) { $params['postal_code'] = $match[1]; $params['postal_code_suffix'] = $match[2]; } // add country id if not set if ((!isset($params['country_id']) || !is_numeric($params['country_id'])) && isset($params['country'])) { $country = new CRM_Core_DAO_Country(); $country->name = $params['country']; if (!$country->find(true)) { $country->name = null; $country->iso_code = $params['country']; $country->find(true); } $params['country_id'] = $country->id; } // add state_id if state is set if ((!isset($params['state_province_id']) || !is_numeric($params['state_province_id'])) && isset($params['state_province'])) { if (!empty($params['state_province'])) { $state_province = new CRM_Core_DAO_StateProvince(); $state_province->name = $params['state_province']; // add country id if present if (isset($params['country_id'])) { $state_province->country_id = $params['country_id']; } if (!$state_province->find(true)) { $state_province->name = null; $state_province->abbreviation = $params['state_province']; $state_province->find(true); } $params['state_province_id'] = $state_province->id; } else { $params['state_province_id'] = 'null'; } } // currently copy values populates empty fields with the string "null" // and hence need to check for the string null if (isset($params['state_province_id']) && is_numeric($params['state_province_id']) && (!isset($params['country_id']) || empty($params['country_id']))) { // since state id present and country id not present, hence lets populate it // jira issue http://issues.civicrm.org/jira/browse/CRM-56 $params['country_id'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_StateProvince', $params['state_province_id'], 'country_id'); } //special check to ignore non numeric values if they are not //detected by formRule(sometimes happens due to internet latency), also allow user to unselect state/country if (isset($params['state_province_id'])) { if (!trim($params['state_province_id'])) { $params['state_province_id'] = 'null'; } else { if (!is_numeric($params['state_province_id']) || (int) $params['state_province_id'] < 1000) { // CRM-3393 ( the hacky 1000 check) $params['state_province_id'] = 'null'; } } } if (isset($params['country_id'])) { if (!trim($params['country_id'])) { $params['country_id'] = 'null'; } else { if (!is_numeric($params['country_id']) || (int) $params['country_id'] < 1000) { // CRM-3393 ( the hacky 1000 check) $params['country_id'] = 'null'; } } } // add state and country names from the ids if (isset($params['state_province_id']) && is_numeric($params['state_province_id'])) { $params['state_province'] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($params['state_province_id']); } if (isset($params['country_id']) && is_numeric($params['country_id'])) { $params['country'] = CRM_Core_PseudoConstant::country($params['country_id']); } $config = CRM_Core_Config::singleton(); require_once 'CRM/Core/BAO/Preferences.php'; $asp = CRM_Core_BAO_Preferences::value('address_standardization_provider'); // clean up the address via USPS web services if enabled if ($asp === 'USPS') { require_once 'CRM/Utils/Address/USPS.php'; CRM_Utils_Address_USPS::checkAddress($params); } // add latitude and longitude and format address if needed if (!empty($config->geocodeMethod)) { require_once str_replace('_', DIRECTORY_SEPARATOR, $config->geocodeMethod) . '.php'; eval($config->geocodeMethod . '::format( $params );'); } }