$includeState->setButtonAttributes('remove', array('value' => ts('<< Remove')));
$this->addElement('select', 'defaultContactCountry', ts('Default Country'), array('' => ts('- select -')) + $country);
-
- /***Default State/Province***/
- $stateCountryMap = array();
- $stateCountryMap[] = array(
- 'state_province' => 'defaultContactStateProvince',
- 'country' => 'defaultContactCountry',
- );
-
- $countryDefault = isset($this->_submitValues['defaultContactCountry']) ? $this->_submitValues['defaultContactCountry'] : $config->defaultContactCountry;
-
- if ($countryDefault) {
- $selectStateProvinceOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
- }
- else {
- $selectStateProvinceOptions = array('' => ts('- select a country -'));
- }
-
- $i18n->localizeArray($selectStateProvinceOptions, array('context' => 'state_province'));
- asort($selectStateProvinceOptions);
-
- $this->addElement('select', 'defaultContactStateProvince', ts('Default State/Province'), $selectStateProvinceOptions);
-
- // state country js
- CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
-
- $defaults = array();
- CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults);
+ $this->addChainSelect('defaultContactStateProvince', array('label' => ts('Default State/Province')));
// we do this only to initialize currencySymbols, kinda hackish but works!
$config->defaultCurrencySymbol();
}
$this->setDefaults($this->_defaults);
-
- // add in all state country selectors for enabled countries
- CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
}
public function buildQuickForm() {
* @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);
// 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;
}
}
- // initialize the state country map
- CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
-
if ($addCaptcha && !$viewOnly) {
$captcha = CRM_Utils_ReCAPTCHA::singleton();
$captcha->add($this);
);
//build the address block
CRM_Contact_Form_Edit_Address::buildQuickForm($form);
-
- // also fix the state country selector
- CRM_Contact_Form_Edit_Address::fixStateSelect($form,
- 'address[1][country_id]',
- 'address[1][state_province_id]',
- "address[1][county_id]",
- $countryID,
- $stateID
- );
}
/**
$defaults[$name][1]['is_primary'] = TRUE;
}
}
-
- // set defaults for country-state widget
- if (!empty($defaults['address']) && is_array($defaults['address'])) {
- foreach ($defaults['address'] as $blockId => $values) {
- CRM_Contact_Form_Edit_Address::fixStateSelect($this,
- "address[$blockId][country_id]",
- "address[$blockId][state_province_id]",
- "address[$blockId][county_id]",
- CRM_Utils_Array::value('country_id',
- $values, $config->defaultContactCountry
- ),
- CRM_Utils_Array::value('state_province_id',
- $values, $config->defaultContactStateProvince
- )
- );
- }
- }
}
/**
$defaults['address'][1]['state_province_id'] = $config->defaultContactStateProvince;
}
- if (!empty($defaults['address'])) {
- foreach ($defaults['address'] as $key => $value) {
- CRM_Contact_Form_Edit_Address::fixStateSelect($this,
- "address[$key][country_id]",
- "address[$key][state_province_id]",
- "address[$key][county_id]",
- CRM_Utils_Array::value('country_id', $value,
- $config->defaultContactCountry
- ),
- CRM_Utils_Array::value('state_province_id', $value,
- $config->defaultContactStateProvince
- )
- );
- }
- }
}
$defaults = array_merge($defaults, $domainDefaults);
return $defaults;
'city' => array(ts('City'), $attributes['city'], NULL),
'postal_code' => array(ts('Zip / Postal Code'), array_merge($attributes['postal_code'], array('class' => 'crm_postal_code')), NULL),
'postal_code_suffix' => array(ts('Postal Code Suffix'), array('size' => 4, 'maxlength' => 12, 'class' => 'crm_postal_code_suffix'), NULL),
- 'county_id' => array(ts('County'), $attributes['county_id'], NULL),
+ 'country_id' => array(ts('Country'), $attributes['country_id'], 'country'),
'state_province_id' => array(ts('State / Province'), $attributes['state_province_id'], NULL),
- 'country_id' => array(ts('Country'), $attributes['country_id'], NULL),
+ 'county_id' => array(ts('County'), $attributes['county_id'], NULL),
'geo_code_1' => array(ts('Latitude'), array('size' => 9, 'maxlength' => 11), NULL),
'geo_code_2' => array(ts('Longitude'), array('size' => 9, 'maxlength' => 11), NULL),
'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL),
'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL),
);
- $stateCountryMap = array();
foreach ($elements as $name => $v) {
list($title, $attributes, $select) = $v;
}
}
- if (!$attributes) {
- $attributes = $attributes[$name];
- }
-
//build normal select if country is not present in address block
if ($name == 'state_province_id' && !$addressOptions['country']) {
$select = 'stateProvince';
}
if (!$select) {
- if ($name == 'country_id' || $name == 'state_province_id' || $name == 'county_id') {
- if ($name == 'country_id') {
- $stateCountryMap[$blockId]['country'] = "address_{$blockId}_{$name}";
- $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
- }
- elseif ($name == 'state_province_id') {
- $stateCountryMap[$blockId]['state_province'] = "address_{$blockId}_{$name}";
- if ($countryDefault) {
- $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
- }
- else {
- $selectOptions = array('' => ts('- select a country -'));
- }
- }
- elseif ($name == 'county_id') {
- $stateCountryMap[$blockId]['county'] = "address_{$blockId}_{$name}";
- if ($form->getSubmitValue("address[{$blockId}][state_province_id]")) {
- $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::countyForState($form->getSubmitValue("address[{$blockId}][state_province_id]"));
- }
- elseif ($form->getSubmitValue("address[{$blockId}][county_id]")) {
- $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::county();
- }
- else {
- $selectOptions = array('' => ts('- select a state -'));
- }
- }
- $form->addElement('select',
- "address[$blockId][$name]",
- $title,
- $selectOptions
- );
+ if ($name == 'state_province_id' || $name == 'county_id') {
+ $form->addChainSelect("address[$blockId][$name]");
}
else {
if ($name == 'address_name') {
}
}
else {
- if ($name == 'state_province_id') {
- $stateCountryMap[$blockId]['state_province'] = "address_{$blockId}_{$name}";
- }
$form->addElement('select',
"address[$blockId][$name]",
$title,
}
}
- CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
-
$entityId = NULL;
if (!empty($form->_values['address']) && !empty($form->_values['address'][$blockId])) {
$entityId = $form->_values['address'][$blockId]['id'];
return empty($errors) ? TRUE : $errors;
}
- /**
- * @param $form
- * @param $countryElementName
- * @param $stateElementName
- * @param $countyElementName
- * @param $countryDefaultValue
- * @param null $stateDefaultValue
- */
- static function fixStateSelect(&$form,
- $countryElementName,
- $stateElementName,
- $countyElementName,
- $countryDefaultValue,
- $stateDefaultValue = NULL
- ) {
- $countryID = $stateID = NULL;
- if (isset($form->_elementIndex[$countryElementName])) {
- //get the country id to load states -
- //first check for submitted value,
- //then check for user passed value.
- //finally check for element default val.
- $submittedVal = $form->getSubmitValue($countryElementName);
- if ($submittedVal) {
- $countryID = $submittedVal;
- }
- elseif ($countryDefaultValue) {
- $countryID = $countryDefaultValue;
- }
- else {
- $countryID = CRM_Utils_Array::value(0, $form->getElementValue($countryElementName));
- }
- }
- $stateTitle = ts('State/Province');
- if (isset($form->_fields[$stateElementName]['title'])) {
- $stateTitle = $form->_fields[$stateElementName]['title'];
- }
-
- if (isset($form->_elementIndex[$stateElementName])) {
- $submittedValState = $form->getSubmitValue($stateElementName);
- if ($submittedValState) {
- $stateID = $submittedValState;
- }
- elseif ($stateDefaultValue) {
- $stateID = $stateDefaultValue;
- }
- else {
- $stateID = CRM_Utils_Array::value(0, $form->getElementValue($stateElementName));
- }
- }
-
- if (isset($form->_elementIndex[$stateElementName])) {
- if ($countryID) {
- $stateProvinces = CRM_Core_PseudoConstant::stateProvinceForCountry($countryID);
- }
- else {
- $stateProvinces = CRM_Core_PseudoConstant::stateProvince();
- }
-
- $stateSelect = & $form->addElement('select', $stateElementName, $stateTitle,
- array('' => ts('- select -')) + $stateProvinces);
- }
-
- if (isset($form->_elementIndex[$stateElementName]) && isset($form->_elementIndex[$countyElementName])) {
- if ($stateID) {
- $counties = CRM_Core_PseudoConstant::countyForState($stateID);
- }
- else {
- $counties = CRM_Core_PseudoConstant::county();
- }
-
- $form->addElement('select', $countyElementName, ts('County'), array('' => ts('- select -')) + $counties);
- }
-
- // CRM-7296 freeze the select for state if address is shared with household
- // CRM-9070 freeze the select for state if it is view only
- if (isset($form->_fields) && !empty($form->_fields[$stateElementName]) &&
- (!empty($form->_fields[$stateElementName]['is_shared']) || !empty($form->_fields[$stateElementName]['is_view'])) &&
- !empty($stateSelect)
- ) {
- $stateSelect->freeze();
- }
- }
-
/**
* function to set default values for address block
*
$defaults['address'][$this->_locBlockNo] = $address;
}
- $values = $defaults['address'][$this->_locBlockNo];
-
- CRM_Contact_Form_Edit_Address::fixStateSelect($this,
- "address[$this->_locBlockNo][country_id]",
- "address[$this->_locBlockNo][state_province_id]",
- "address[$this->_locBlockNo][county_id]",
- CRM_Utils_Array::value('country_id',
- $values, $config->defaultContactCountry
- ),
- CRM_Utils_Array::value('state_province_id',
- $values, $config->defaultContactStateProvince
- )
- );
-
return $defaults;
}
'street_address' => array(ts('Street Address'), $attributes['street_address'], NULL, NULL),
'city' => array(ts('City'), $attributes['city'], NULL, NULL),
'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], NULL, NULL),
- 'county' => array(ts('County'), $attributes['county_id'], 'county', TRUE),
- 'state_province' => array(ts('State / Province'), $attributes['state_province_id'], 'stateProvince', TRUE),
'country' => array(ts('Country'), $attributes['country_id'], 'country', FALSE),
+ 'state_province' => array(ts('State / Province'), $attributes['state_province_id'], 'stateProvince', TRUE),
+ 'county' => array(ts('County'), $attributes['county_id'], 'county', TRUE),
'address_name' => array(ts('Address Name'), $attributes['address_name'], NULL, NULL),
'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL, NULL),
'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL, NULL),
$parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', $addressOptions, 0);
$form->assign('parseStreetAddress', $parseStreetAddress);
- $stateCountryMap = NULL;
foreach ($elements as $name => $v) {
list($title, $attributes, $select, $multiSelect) = $v;
}
if ($select) {
- $stateCountryMap = array(array(
- 'state_province' => 'state_province',
- 'country' => 'country',
- 'county' => 'county',
- ));
- if ($select == 'stateProvince') {
- if (!empty($formValues['country'])) {
- $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($formValues['country']);
- }
- else {
- //if not setdefault any country
- $selectElements = CRM_Core_PseudoConstant::$select();
- }
- $element = $form->add('select', $name, $title, $selectElements);
- }
- elseif ($select == 'country') {
- $selectElements = array('' => ts('- any -')) + CRM_Core_PseudoConstant::$select();
- $element = $form->add('select', $name, $title, $selectElements);
- }
- elseif ($select == 'county') {
- if ( array_key_exists('state_province', $formValues) && !CRM_Utils_System::isNull($formValues['state_province'])) {
- $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::countyForState($formValues['state_province']);
- }
- else {
- $selectElements = array('' => ts('- any -'));
- }
- $element = $form->add('select', $name, $title, $selectElements);
+ if ($select == 'stateProvince' || $select == 'county') {
+ $element = $form->addChainSelect($name);
}
else {
$selectElements = array('' => ts('- any -')) + CRM_Core_PseudoConstant::$select();
}
}
- CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
-
// extend addresses with proximity search
if (!empty($config->geocodeMethod)) {
$form->addElement('text', 'prox_distance', ts('Find contacts within'), array('class' => 'six'));
}
/**
- * @param $form
+ * @param CRM_Core_Form $form
*/
function buildForm(&$form) {
'postal_code',
ts('Postal Code')
);
- $stateCountryMap = array();
- $stateCountryMap[] = array(
- 'state_province' => 'state_province_id',
- 'country' => 'country_id',
- );
+
$defaults = array();
if ($countryDefault) {
- $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
$defaults['country_id'] = $countryDefault;
}
- else {
- $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince();
- }
- $form->add('select', 'state_province_id', ts('State/Province'), $stateProvince, FALSE, array('class' => 'crm-select2 huge'));
+ $form->addChainSelect('state_province_id');
$country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
- $form->add('select', 'country_id', ts('Country'), $country, TRUE, array('class' => 'crm-select2 huge'));
+ $form->add('select', 'country_id', ts('Country'), $country, TRUE, array('class' => 'crm-select2'));
$group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::nestedGroup();
$form->addElement('select', 'group', ts('Group'), $group, array('class' => 'crm-select2 huge'));
$tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
$form->addElement('select', 'tag', ts('Tag'), $tag, array('class' => 'crm-select2 huge'));
-
- // state country js, CRM-5233
- CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
- CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults);
-
/**
* You can define a custom title for the search form
*/
*/
protected $_preserveDefault = TRUE;
- /**
- * the internal QF names for the state/country/county fields
- */
-
- protected $_stateCountryCountyFields = array();
-
/**
* build all the data structures needed to build the form
*
'household_name',
);
- $stateCountryMap = array();
-
foreach ($this->_contactIds as $contactId) {
$profileFields = $this->_fields;
CRM_Core_BAO_Address::checkContactSharedAddressFields($profileFields, $contactId);
foreach ($profileFields as $name => $field) {
-
- // Link state to country, county to state per location per contact
- list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
- if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
- $stateCountryMap["$index-$contactId"][$prefixName] = "field_{$contactId}_{$field['name']}";
- $this->_stateCountryCountyFields["$index-$contactId"][$prefixName] = "field[{$contactId}][{$field['name']}]";
- }
-
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $contactId);
if (in_array($field['name'], $preserveDefaultsArray)) {
}
}
- CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
-
-
-
$this->assign('fields', $this->_fields);
// don't set the status message when form is submitted.
*
* @access public
*
- * @return void
+ * @return array
*/
function setDefaultValues() {
if (empty($this->_fields)) {
$this->assign('sortName', $sortName);
- // now fix all state country selectors
- CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults, $this->_stateCountryCountyFields);
-
return $defaults;
}
*
* @access public
*
- * @param $form
+ * @param CRM_Core_Form $form
* @param $proxSearch
*
* @return void
$form->add('text', 'prox_postal_code', ts('Postal Code'), NULL, FALSE);
- $defaults = self::setDefaultValues($form);
- if (!empty($defaults['prox_country_id'])) {
- $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($defaults['prox_country_id']);
- }
- else {
- $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince();
- }
- $form->add('select', 'prox_state_province_id', ts('State/Province'), $stateProvince, $proxRequired);
+ $form->addChainSelect('prox_state_province_id', array('required' => $proxRequired));
$country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
$form->add('select', 'prox_country_id', ts('Country'), $country, $proxRequired);
$form->add('select', 'prox_distance_unit', ts('Units'), $proxUnits, $proxRequired);
// prox_distance_unit
- // state country js, CRM-5233
- $stateCountryMap = array();
- $stateCountryMap[] = array(
- 'state_province' => 'prox_state_province_id',
- 'country' => 'prox_country_id',
- );
- CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
- CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
$form->addFormRule(array('CRM_Contact_Form_Task_ProximityCommon', 'formRule'), $form);
}
$billingDefaults = $this->getProfileDefaults('Billing', $this->_contactId);
$defaults = array_merge($defaults, $billingDefaults);
-
- // now fix all state country selectors, set correct state based on country
- CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
}
if (empty($defaults['trxn_date']) && empty($defaults['trxn_date_time'])) {
$billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
$defaults = array_merge($defaults, $billingDefaults);
-
- // now fix all state country selectors, set correct state based on country
- CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
}
if ($this->_id) {
$this->assign('useForMember', $this->get('useForMember'));
- // now fix all state country selectors
- CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
-
$this->setDefaults($defaults);
$this->freeze();
$this->_defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
}
- // now fix all state country selectors
- CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
-
if ($this->_priceSetId) {
if (($this->_useForMember && !empty($this->_currentMemberships)) || $this->_defaultMemTypeId) {
$selectedCurrentMemTypes = array();
$fieldTypes = array_merge($fieldTypes, array('Contribution'));
}
- $stateCountryMap = array();
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(
- 'state_province', 'country', 'county'))) {
- if (!array_key_exists($index, $stateCountryMap)) {
- $stateCountryMap[$index] = array();
- }
-
- $stateCountryMap[$index][$prefixName] = 'onbehalf[' . $name . ']';
-
+ if (in_array($prefixName, array('state_province', 'country', 'county'))) {
if (count($form->_submitValues)) {
$locationTypeId = $field['location_type_id'];
if (!empty($form->_submitValues['onbehalf']["country-{$locationTypeId}"]) &&
}
}
}
- elseif (in_array($prefixName, array(
- 'organization_name', 'email')) && empty($field['is_required'])) {
+ elseif (in_array($prefixName, array('organization_name', 'email')) && empty($field['is_required'])) {
$field['is_required'] = 1;
}
}
}
- if (!empty($stateCountryMap)) {
- CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
-
- // now fix all state country selectors
- CRM_Core_BAO_Address::fixAllStateSelects($form, CRM_Core_DAO::$_nullArray);
- }
-
$form->assign('onBehalfOfFields', $profileFields);
$form->addElement('hidden', 'hidden_onbehalf_profile', 1);
}
}
}
- // now fix all state country selectors
- CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
-
$this->_submitValues = array_merge($this->_submitValues, $defaults);
$this->setDefaults($defaults);
* @access public
*/
function buildCustom($id, $name, $viewOnly = FALSE, $profileContactType = NULL, $fieldTypes = NULL) {
- $stateCountryMap = array();
-
if ($id) {
$contactID = $this->getContactID();
list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
- if (!array_key_exists($index, $stateCountryMap)) {
- $stateCountryMap[$index] = array();
- }
- $stateCountryMap[$index][$prefixName] = $key;
-
if ($prefixName == "state_province") {
if ($profileContactType == 'onbehalf') {
//CRM-11881: Bypass required-ness check for state/province on Contribution Confirm page
$this->assign($name, $fields);
- CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
-
if ($addCaptcha && !$viewOnly) {
$captcha = CRM_Utils_ReCAPTCHA::singleton();
$captcha->add($this);
$this->_defaults = array();
if ($this->_subscriptionDetails->contact_id) {
- $options = array();
$fields = array();
$names = array(
'first_name', 'middle_name', 'last_name', "street_address-{$this->_bltID}", "city-{$this->_bltID}",
}
}
-
$config = CRM_Core_Config::singleton();
// set default country from config if no country set
if (empty($this->_defaults["billing_country_id-{$this->_bltID}"])) {
$this->_defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
}
- // now fix all state country selectors
- CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
-
return $this->_defaults;
}
* @static
*/
static function allEntityAddress(&$entityElements) {
+ $addresses = array();
if (empty($entityElements)) {
return $addresses;
}
ORDER BY civicrm_address.is_primary DESC, civicrm_address.location_type_id DESC, address_id ASC ";
$params = array(1 => array($entityId, 'Integer'));
- $addresses = array();
$dao = CRM_Core_DAO::executeQuery($sql, $params);
$locationCount = 1;
while ($dao->fetch()) {
return $addresses;
}
- /**
- * @param $stateCountryMap
- * @param null $defaults
- */
- static function addStateCountryMap($stateCountryMap, $defaults = NULL) {
- // first fix the statecountry map if needed
- if (empty($stateCountryMap)) {
- return;
- }
-
- $config = CRM_Core_Config::singleton();
- if (!isset($config->stateCountryMap)) {
- $config->stateCountryMap = array();
- }
-
- $config->stateCountryMap = array_merge($config->stateCountryMap, $stateCountryMap);
- }
-
- /**
- * @param $form
- * @param $defaults
- * @param bool $batchFieldNames
- */
- static function fixAllStateSelects(&$form, $defaults, $batchFieldNames = false) {
- $config = CRM_Core_Config::singleton();
- $map = null;
- if (is_array($batchFieldNames)) {
- $map = $batchFieldNames;
- }
- elseif (!empty($config->stateCountryMap)) {
- $map = $config->stateCountryMap;
- }
- if (!empty($map)) {
- foreach ($map as $index => $match) {
- if (array_key_exists('state_province', $match)
- || array_key_exists('country', $match)
- || array_key_exists('county', $match)
- ) {
- $countryElementName = CRM_Utils_Array::value('country', $match);
- $stateProvinceElementName = CRM_Utils_Array::value('state_province', $match);
- $countyElementName = CRM_Utils_Array::value('county', $match);
- CRM_Contact_Form_Edit_Address::fixStateSelect(
- $form,
- $countryElementName,
- $stateProvinceElementName,
- $countyElementName,
- CRM_Utils_Array::value($countryElementName, $defaults),
- CRM_Utils_Array::value($stateProvinceElementName, $defaults)
- );
- }
- else {
- unset($config->stateCountryMap[$index]);
- }
- }
- }
- }
-
/**
* Function to get address sequence
*
$widget = 'Text';
}
- if ($widget == 'Select State/Province' || $widget == 'Select Country') {
- $qf->_stateCountryMap[$widget == 'Select Country' ? 'country' : 'state_province'][] = $elementName;
- }
-
$placeholder = $search ? ts('- any -') : ($useRequired ? ts('- select -') : ts('- none -'));
// FIXME: Why are select state/country separate widget types?
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, $inactiveNeeded, $required);
}
}
- if (!empty($form->_stateCountryMap['state_province']) && !empty($form->_stateCountryMap['country'])) {
- foreach ($form->_stateCountryMap['state_province'] as $key => $value) {
- $stateCountryMap[$key]['state_province'] = $value;
- $stateCountryMap[$key]['country'] = $form->_stateCountryMap['country'][$key];
- }
- CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
- }
}
/**
* @params int $contactID contact id
* @params string $usedFor for building up prefixed fieldname for special cases (e.g. onBehalf, Honor)
*
- * @param $form
+ * @param CRM_Core_Form $form
* @param $field
* @param $mode
* @param null $contactId
$name = $fieldName;
}
+ // CRM-15172 - keep track of all the fields we've processed
+ // This is hackish but we can't always rely on $form->_fields depending on how this is called
+ static $fieldsProcessed = array();
+ $fieldsProcessed[] = $name;
+
if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) {
$deleteExtra = ts('Are you sure you want to delete contact image.');
$deleteURL = array(
);
if (substr($fieldName, 0, 14) === 'state_province') {
- $form->add('select', $name, $title,
- array(
- '' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required
- );
+ $controlField = str_replace('state_province', 'country', $name);
+ if (isset($form->_fields[$controlField]) || in_array($controlField, $fieldsProcessed)) {
+ $form->addChainSelect($name, array('label' => $title, 'required' => $required));
+ }
+ else {
+ $form->add('select', $name, $title,
+ array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required);
+ }
$config = CRM_Core_Config::singleton();
if (!in_array($mode, array(
CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) &&
}
}
elseif (substr($fieldName, 0, 7) === 'country') {
- $form->add('select', $name, $title,
- array(
- '' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required
- );
+ $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required);
$config = CRM_Core_Config::singleton();
if (!in_array($mode, array(
CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) &&
}
elseif (substr($fieldName, 0, 6) === 'county') {
if ($addressOptions['county']) {
- $form->add('select', $name, $title,
- array('' => ts('Choose state first')), $required
- );
+ $form->addChainSelect($name, array('label' => $title, 'required' => $required));
}
}
elseif (substr($fieldName, 0, 9) === 'image_URL') {
'non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) {
$form->addRule($name, ts('Please enter a valid amount.'), 'money');
}
- $stateCountryMap = array();
- if (!empty($form->_stateCountryMap['state_province']) && !empty($form->_stateCountryMap['country'])) {
- foreach ($form->_stateCountryMap['state_province'] as $key => $value) {
- $stateCountryMap[$key]['state_province'] = $value;
- $stateCountryMap[$key]['country'] = $form->_stateCountryMap['country'][$key];
- }
- CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
- }
if ($rule) {
if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) {
$form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule);
);
$form->_paymentFields["billing_state_province_id-{$bltID}"] = array(
- 'htmlType' => 'select',
+ 'htmlType' => 'chainSelect',
'name' => "billing_state_province_id-{$bltID}",
- 'title' => ts('State / Province'),
'cc_field' => TRUE,
- 'attributes' => array(
- '' => ts('- select -')) +
- CRM_Core_PseudoConstant::stateProvince(),
'is_required' => self::checkRequiredStateProvince($form, "billing_country_id-{$bltID}"),
);
if ($form->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) {
self::setCreditCardFields($form);
foreach ($form->_paymentFields as $name => $field) {
- if (isset($field['cc_field']) &&
- $field['cc_field']
- ) {
- $form->add($field['htmlType'],
- $field['name'],
- $field['title'],
- $field['attributes'],
- $useRequired ? $field['is_required'] : FALSE
- );
+ if (!empty($field['cc_field'])) {
+ if ($field['htmlType'] == 'chainSelect') {
+ $form->addChainSelect($field['name'], array('required' => $useRequired && $field['is_required']));
+ }
+ else {
+ $form->add($field['htmlType'],
+ $field['name'],
+ $field['title'],
+ $field['attributes'],
+ $useRequired ? $field['is_required'] : FALSE
+ );
+ }
}
}
'currentDate', TRUE
);
- // also take care of state country widget
- $stateCountryMap = array(
- 1 => array('country' => "billing_country_id-{$form->_bltID}",
- 'state_province' => "billing_state_province_id-{$form->_bltID}",
- ));
- CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
}
if ($form->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) {
$billingDefaults = $form->getProfileDefaults('Billing', $form->_contactId);
$defaults[$form->_pId] = array_merge($defaults[$form->_pId], $billingDefaults);
- // now fix all state country selectors, set correct state based on country
- CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults[$form->_pId]);
-
// // hack to simplify credit card entry for testing
// $defaults[$form->_pId]['credit_card_type'] = 'Visa';
// $defaults[$form->_pId]['credit_card_number'] = '4807731747657838';
$defaults['address'][1]['state_province_id'] = $config->defaultContactStateProvince;
}
- if (!empty($defaults['address'])) {
- foreach ($defaults['address'] as $key => $value) {
- CRM_Contact_Form_Edit_Address::fixStateSelect($this,
- "address[$key][country_id]",
- "address[$key][state_province_id]",
- "address[$key][county_id]",
- CRM_Utils_Array::value('country_id', $value,
- $config->defaultContactCountry
- ),
- CRM_Utils_Array::value('state_province_id', $value)
- );
- }
- }
$defaults['location_option'] = $this->_oldLocBlockId ? 2 : 1;
return $defaults;
* @access public
*/
function buildCustom($id, $name, $viewOnly = FALSE) {
- $stateCountryMap = $fields = array();
-
if ($id) {
$button = substr($this->controller->getButtonName(), -4);
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
$addCaptcha = TRUE;
}
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_Core_BAO_Address::addStateCountryMap($stateCountryMap);
-
if ($addCaptcha && !$viewOnly) {
$captcha = CRM_Utils_ReCAPTCHA::singleton();
$captcha->add($this);
if (array_key_exists('participant_campaign_id', $this->_fields)) {
$defaults['participant_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
}
- CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
return $defaults;
}
}
}
- // now fix all state country selectors
- CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
-
$this->setDefaults($defaults);
$this->freeze();
}
if ($this->_snippet) {
- // now fix all state country selectors
- CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
return $this->_defaults;
}
CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults);
}
- // now fix all state country selectors
- CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
-
// Set default payment processor as default payment_processor radio button value
if (!empty($this->_paymentProcessors)) {
foreach ($this->_paymentProcessors as $pid => $value) {
$billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
$defaults = array_merge($defaults, $billingDefaults);
- // now fix all state country selectors, set correct state based on country
- CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
-
// // hack to simplify credit card entry for testing
// $defaults['credit_card_type'] = 'Visa';
// $defaults['credit_card_number'] = '4807731747657838';
CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $this->_defaults);
}
- $stateCountryMap = array();
//set custom field defaults
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
);
}
}
- 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, $this->_defaults);
- }
}
- // now fix all state country selectors
- CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
return $this->_defaults;
}
protected $_currentUserID = NULL;
protected $_session = NULL;
- public $_stateCountryMap = array();
/**
* pre processing work done here.
*
$addCaptcha = array();
$emailPresent = FALSE;
- // cache the state country fields. based on the results, we could use our javascript solution
- // in create or register mode
- $stateCountryMap = array();
-
// add the form elements
foreach ($this->_fields as $name => $field) {
// make sure that there is enough permission to expose this field
}
list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
- if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
- if (!array_key_exists($index, $stateCountryMap)) {
- $stateCountryMap[$index] = array();
- }
- $stateCountryMap[$index][$prefixName] = $name;
- }
CRM_Core_BAO_UFGroup::buildProfile($this, $field, $this->_mode);
}
}
- // lets do the defaults, so we can use it for the below state country routines
- $this->setDefaultsValues();
-
- // also do state country js
- CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $this->_defaults);
-
$action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, NULL);
if ($this->_mode == self::MODE_CREATE) {
CRM_Core_BAO_CMSUser::buildForm($this, $this->_gid, $emailPresent, $action);
$this->assign('groupId', $this->_gid);
- // now fix all state country selectors
- CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
-
// if view mode pls freeze it with the done button.
if ($this->_action & CRM_Core_Action::VIEW) {
$this->freeze();
}
function addFilters() {
- $options = $filters = array();
+ $filters = array();
$count = 1;
foreach ($this->_filters as $table => $attributes) {
foreach ($attributes as $fieldName => $field) {
case CRM_Report_Form::OP_MULTISELECT:
case CRM_Report_Form::OP_MULTISELECT_SEPARATOR:
// assume a multi-select field
- if (!empty($field['options'])) {
+ if (!empty($field['options']) || $fieldName == 'state_province_id' || $fieldName == 'county_id') {
$element = $this->addElement('select', "{$fieldName}_op", ts('Operator:'), $operations);
if (count($operations) <= 1) {
$element->freeze();
}
- $this->addElement('select', "{$fieldName}_value", NULL, $field['options'], array(
- 'style' => 'min-width:250px',
- 'class' => 'crm-select2',
- 'multiple' => TRUE,
- 'placeholder' => ts('- select -'),
- ));
+ if ($fieldName == 'state_province_id' || $fieldName == 'county_id') {
+ $this->addChainSelect($fieldName . '_value', array('multiple' => TRUE, 'label' => NULL));
+ }
+ else {
+ $this->addElement('select', "{$fieldName}_value", NULL, $field['options'], array(
+ 'style' => 'min-width:250px',
+ 'class' => 'crm-select2',
+ 'multiple' => TRUE,
+ 'placeholder' => ts('- select -'),
+ ));
+ }
}
break;
}
}
}
-
- $stateCountryMap[] = array(
- 'country' => 'country_id_value',
- 'state_province' => 'state_province_id_value',
- 'county' => 'county_id_value'
- );
- CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
-
$this->assign('filters', $filters);
}
*
* @return array address fields for construct clause
*/
- function addAddressFields($groupBy = TRUE, $orderBy = FALSE, $filters = TRUE, $defaults = array(
- 'country_id' => TRUE)) {
+ function addAddressFields($groupBy = TRUE, $orderBy = FALSE, $filters = TRUE, $defaults = array('country_id' => TRUE)) {
$addressFields = array(
'civicrm_address' =>
array(
'type' => CRM_Utils_Type::T_INT,
'operatorType' =>
CRM_Report_Form::OP_MULTISELECT,
- 'options' =>
- CRM_Core_PseudoConstant::country(),
+ 'options' => CRM_Core_PseudoConstant::country(),
),
'state_province_id' => array(
'name' => 'state_province_id',
'title' => ts('State/Province'),
'type' => CRM_Utils_Type::T_INT,
- 'operatorType' =>
- CRM_Report_Form::OP_MULTISELECT,
- 'options' =>
- CRM_Core_PseudoConstant::stateProvince(),
+ 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
+ 'options' => array(),
),
'county_id' => array(
'name' => 'county_id',
'title' => ts('County'),
'type' => CRM_Utils_Type::T_INT,
- 'operatorType' =>
- CRM_Report_Form::OP_MULTISELECT,
- 'options' =>
- CRM_Core_PseudoConstant::county(),
+ 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
+ 'options' => array(),
),
);
}
* - prefix_label Label to give columns from this address table instance
* @return array address columns definition
*/
- function getAddressColumns($options = array()){
- $defaultOptions = array(
+ function getAddressColumns($options = array()) {
+ $options += array(
'prefix' => '',
'prefix_label' => '',
'group_by' => TRUE,
'order_by' => TRUE,
'filters' => TRUE,
- 'defaults' => array(
- ),
+ 'defaults' => array(),
);
- $options = array_merge($defaultOptions,$options);
return $this->addAddressFields(
$options['group_by'],
$options['order_by'],
$options['filters'],
$options['defaults']
);
-
}
/**
public $_drilldownReport = array('contact/detail' => 'Link to Detail Report');
- /**
- *
- */
/**
*
*/
),
),
),
- 'civicrm_address' =>
- array(
- 'dao' => 'CRM_Core_DAO_Address',
- 'grouping' => 'contact-fields',
- 'fields' =>
- array(
- 'street_address' =>
- array('default' => TRUE),
- 'city' =>
- array('default' => TRUE),
- 'postal_code' => NULL,
- 'state_province_id' =>
- array('title' => ts('State/Province'),
- ),
- ),
- 'filters' =>
- array(
- 'country_id' =>
- array('title' => ts('Country'),
- 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
- 'options' => CRM_Core_PseudoConstant::country(),
- ),
- 'state_province_id' =>
- array('title' => ts('State / Province'),
- 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
- 'options' => CRM_Core_PseudoConstant::stateProvince(),
- ),
- ),
- 'order_bys' =>
- array('state_province_id' => array('title' => 'State/Province'),
- 'city' => array('title' => 'City'),
- 'postal_code' => array('title' => 'Postal Code'),
- ),
- ),
- 'civicrm_country' =>
- array(
- 'dao' => 'CRM_Core_DAO_Country',
- 'fields' =>
- array(
- 'name' =>
- array('title' => 'Country', 'default' => TRUE),
- ),
- 'order_bys' =>
- array(
- 'name' =>
- array('title' => 'Country'),
- ),
- 'grouping' => 'contact-fields',
- ),
'civicrm_phone' =>
array(
'dao' => 'CRM_Core_DAO_Phone',
),
'grouping' => 'contact-fields',
),
- );
+ ) + $this->getAddressColumns(array('group_by' => FALSE));
$this->_groupFilter = TRUE;
$this->_tagFilter = TRUE;
*/
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;
}
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
-{include file="CRM/common/stateCountry.tpl"}
-
{if $form.javascript}
{$form.javascript}
{/if}
+++ /dev/null
-{*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM. |
- | |
- | CiviCRM is free software; you can copy, modify, and distribute it |
- | under the terms of the GNU Affero General Public License |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
- | |
- | CiviCRM is distributed in the hope that it will be useful, but |
- | WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
- | See the GNU Affero General Public License for more details. |
- | |
- | You should have received a copy of the GNU Affero General Public |
- | License and the CiviCRM Licensing Exception along |
- | with this program; if not, contact CiviCRM LLC |
- | at info[AT]civicrm[DOT]org. If you have questions about the |
- | GNU Affero General Public License or the licensing of CiviCRM, |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing |
- +--------------------------------------------------------------------+
-*}
-{if $config->stateCountryMap}
-<script type="text/javascript">
- {literal}
- CRM.$(function($) {
- var $form = $('form.{/literal}{$form.formClass}{literal}');
- function chainSelect(e) {
- var info = $(this).data('chainSelect');
- var val = info.target.val();
- var multiple = info.target.attr('multiple');
- var placeholder = $(this).val() ? "{/literal}{ts escape='js'}Loading{/ts}{literal}..." : info.placeholder;
- if (multiple) {
- info.target.html('').prop('disabled', true).crmSelect2({placeholder: placeholder});
- }
- else {
- info.target.html('<option value="">' + placeholder + '</option>').prop('disabled', true).crmSelect2();
- }
- if ($(this).val()) {
- $.getJSON(info.callback, {_value: $(this).val()}, function(data) {
- var options = '';
- function buildOptions(data) {
- $.each(data, function() {
- if (this.children) {
- options += '<optgroup label="' + this.name + '">';
- buildOptions(this.children);
- options += '</optgroup>';
- }
- else if (this.value || !multiple) {
- options += '<option value="' + this.value + '">' + this.name + '</option>';
- }
- else {
- info.target.crmSelect2({placeholder: this.name});
- }
- });
- }
- buildOptions(data);
- info.target.html(options).val(val).prop('disabled', false).trigger('change');
- });
- }
- else {
- info.target.trigger('change');
- }
- }
- function initField(selector, removePlaceholder) {
- var $el = $(selector, $form);
- if (removePlaceholder !== false) {
- $el.removeAttr('placeholder');
- }
- return $el.css('min-width', '20em').crmSelect2();
- }
- {/literal}
- {foreach from=$config->stateCountryMap item=stateCountryMap}
- {if $stateCountryMap.state_province && $stateCountryMap.county}
- $('select[name="{$stateCountryMap.state_province}"], select#{$stateCountryMap.state_province}', $form).data('chainSelect', {ldelim}
- callback: CRM.url('civicrm/ajax/jqCounty'),
- target: initField('select[name="{$stateCountryMap.county}"], #{$stateCountryMap.county}'),
- placeholder: "{ts escape='js'}Choose state first{/ts}"
- {rdelim}).on('change', chainSelect);
- {/if}
- {if $stateCountryMap.country && $stateCountryMap.state_province}
- initField('select[name="{$stateCountryMap.country}"], select#{$stateCountryMap.country}', false).data('chainSelect', {ldelim}
- callback: CRM.url('civicrm/ajax/jqState'),
- target: initField('select[name="{$stateCountryMap.state_province}"], #{$stateCountryMap.state_province}'),
- placeholder: "{ts escape='js'}Choose country first{/ts}"
- {rdelim}).on('change', chainSelect).change();
- {/if}
- {/foreach}
- {literal}
- });
- {/literal}
-</script>
-{/if}