/** * set defaults for the form * * @return void * @access public */ public function setDefaultValues() { $defaults = $this->_values; $config = CRM_Core_Config::singleton(); //set address block defaults if (CRM_Utils_Array::value('address', $defaults)) { CRM_Contact_Form_Edit_Address::setDefaultValues($defaults, $this); } else { // get the default location type $locationType = CRM_Core_BAO_LocationType::getDefault(); if ($this->_locBlockNo == 1) { $address['is_primary'] = TRUE; $address['location_type_id'] = $locationType->id; } $address['country_id'] = $config->defaultContactCountry; $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)); return $defaults; }
function blockSetDefaults(&$defaults) { $locationTypeKeys = array_filter(array_keys(CRM_Core_PseudoConstant::locationType()), 'is_int'); sort($locationTypeKeys); // get the default location type require_once 'CRM/Core/BAO/LocationType.php'; $locationType = CRM_Core_BAO_LocationType::getDefault(); // unset primary location type $primaryLocationTypeIdKey = CRM_Utils_Array::key($locationType->id, $locationTypeKeys); unset($locationTypeKeys[$primaryLocationTypeIdKey]); // reset the array sequence $locationTypeKeys = array_values($locationTypeKeys); // get default phone and im provider id. require_once 'CRM/Core/OptionGroup.php'; $defPhoneTypeId = key(CRM_Core_OptionGroup::values('phone_type', false, false, false, ' AND is_default = 1')); $defIMProviderId = key(CRM_Core_OptionGroup::values('instant_messenger_service', false, false, false, ' AND is_default = 1')); $allBlocks = $this->_blocks; if (array_key_exists('Address', $this->_editOptions)) { $allBlocks['Address'] = $this->_editOptions['Address']; } $config =& CRM_Core_Config::singleton(); foreach ($allBlocks as $blockName => $label) { $name = strtolower($blockName); if (array_key_exists($name, $defaults) && !CRM_Utils_System::isNull($defaults[$name])) { continue; } for ($instance = 1; $instance <= $this->get($blockName . "_Block_Count"); $instance++) { //set location to primary for first one. if ($instance == 1) { $defaults[$name][$instance]['is_primary'] = true; $defaults[$name][$instance]['location_type_id'] = $locationType->id; } else { $locTypeId = isset($locationTypeKeys[$instance - 1]) ? $locationTypeKeys[$instance - 1] : $locationType->id; $defaults[$name][$instance]['location_type_id'] = $locTypeId; } //set default country if ($name == 'address' && $config->defaultContactCountry) { $defaults[$name][$instance]['country_id'] = $config->defaultContactCountry; } //set default phone type. if ($name == 'phone' && $defPhoneTypeId) { $defaults[$name][$instance]['phone_type_id'] = $defPhoneTypeId; } //set default im provider. if ($name == 'im' && $defIMProviderId) { $defaults[$name][$instance]['provider_id'] = $defIMProviderId; } } } // set defaults for country-state widget if (CRM_Utils_Array::value('address', $defaults) && is_array($defaults['address'])) { require_once 'CRM/Contact/Form/Edit/Address.php'; foreach ($defaults['address'] as $blockId => $values) { CRM_Contact_Form_Edit_Address::fixStateSelect($this, "address[{$blockId}][country_id]", "address[{$blockId}][state_province_id]", CRM_Utils_Array::value('country_id', $values, $config->defaultContactCountry)); } } }
/** * Function to build form for related contacts / on behalf of organization. * * @param $form object invoking Object * @param $contactType string contact type * @param $title string fieldset title * @param $maxLocationBlocks int number of location blocks * * @static * */ static function buildOnBehalfForm(&$form, $contactType = 'Individual', $countryID = null, $stateID = null, $title = 'Contact Information', $contactEditMode = false, $maxLocationBlocks = 1) { if ($title == 'Contact Information') { $title = ts('Contact Information'); } require_once 'CRM/Contact/Form/Location.php'; $config = CRM_Core_Config::singleton(); $form->assign('contact_type', $contactType); $form->assign('fieldSetTitle', $title); $form->assign('contactEditMode', $contactEditMode); $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact'); switch ($contactType) { case 'Organization': $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); if ($contactID) { require_once 'CRM/Contact/BAO/Relationship.php'; $employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($contactID); } if (!$contactEditMode && $contactID && count($employers) >= 1) { $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', "cid=", false, null, false); $form->assign('locDataURL', $locDataURL); $dataURL = CRM_Utils_System::url('civicrm/ajax/employer', "cid=" . $contactID, false, null, false); $form->assign('employerDataURL', $dataURL); $form->add('text', 'organization_id', ts('Select an existing related Organization OR Enter a new one')); $form->add('hidden', 'onbehalfof_id', '', array('id' => 'onbehalfof_id')); $orgOptions = array('0' => ts('Create new organization'), '1' => ts('Select existing organization')); $orgOptionExtra = array('onclick' => "showHideByValue('org_option','true','select_org','table-row','radio',true);showHideByValue('org_option','true','create_org','table-row','radio',false);"); $form->addRadio('org_option', ts('options'), $orgOptions, $orgOptionExtra); $form->assign('relatedOrganizationFound', true); } $isRequired = false; if (CRM_Utils_Array::value('is_for_organization', $form->_values) == 2) { $isRequired = true; } $form->add('text', 'organization_name', ts('Organization Name'), $attributes['organization_name'], $isRequired); break; case 'Household': $form->add('text', 'household_name', ts('Household Name'), $attributes['household_name']); break; default: // individual $form->addElement('select', 'prefix_id', ts('Prefix'), array('' => ts('- prefix -')) + CRM_Core_PseudoConstant::individualPrefix()); $form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']); $form->addElement('text', 'middle_name', ts('Middle Name'), $attributes['middle_name']); $form->addElement('text', 'last_name', ts('Last Name'), $attributes['last_name']); $form->addElement('select', 'suffix_id', ts('Suffix'), array('' => ts('- suffix -')) + CRM_Core_PseudoConstant::individualSuffix()); } $addressSequence = $config->addressSequence(); $form->assign('addressSequence', array_fill_keys($addressSequence, 1)); //Primary Phone $form->addElement('text', "phone[1][phone]", ts('Primary Phone'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone')); //Primary Email $form->addElement('text', "email[1][email]", ts('Primary Email'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', 'email')); //build the address block require_once 'CRM/Contact/Form/Edit/Address.php'; 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]", $countryID); }
function setDefaultValues() { require_once 'CRM/Core/BAO/Domain.php'; $defaults = array(); $params = array(); $locParams = array(); if (isset($this->_id)) { $params['id'] = $this->_id; CRM_Core_BAO_Domain::retrieve($params, $domainDefaults); //get the default domain from email address. fix CRM-3552 require_once 'CRM/Utils/Mail.php'; require_once 'CRM/Core/OptionValue.php'; $optionValues = array(); $grpParams['name'] = 'from_email_address'; CRM_Core_OptionValue::getValues($grpParams, $optionValues); foreach ($optionValues as $Id => $value) { if ($value['is_default'] && $value['is_active']) { $this->_fromEmailId = $Id; $domainDefaults['email_name'] = CRM_Utils_Array::value(1, explode('"', $value['label'])); $domainDefaults['email_address'] = CRM_Utils_Mail::pluckEmailFromHeader($value['label']); break; } } unset($params['id']); $locParams = $params + array('entity_id' => $this->_id, 'entity_table' => 'civicrm_domain'); require_once 'CRM/Core/BAO/Location.php'; $defaults = CRM_Core_BAO_Location::getValues($locParams); $config = CRM_Core_Config::singleton(); if (!isset($defaults['address'][1]['country_id'])) { $defaults['address'][1]['country_id'] = $config->defaultContactCountry; } 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]", CRM_Utils_Array::value('country_id', $value, $config->defaultContactCountry)); } } } $defaults = array_merge($defaults, $domainDefaults); return $defaults; }
/** * This function sets the default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues() { $defaults = $this->_values; if (CRM_Utils_Array::value('loc_block_id', $defaults)) { $defaults['loc_event_id'] = $defaults['loc_block_id']; $countLocUsed = CRM_Event_BAO_Event::countEventsUsingLocBlockId($defaults['loc_block_id']); if ($countLocUsed > 1) { $this->assign('locUsed', true); } } require_once 'CRM/Contact/Form/Edit/Address.php'; if (!empty($defaults['address'])) { $config = CRM_Core_Config::singleton(); foreach ($defaults['address'] as $key => $value) { CRM_Contact_Form_Edit_Address::fixStateSelect($this, "address[{$key}][country_id]", "address[{$key}][state_province_id]", CRM_Utils_Array::value('country_id', CRM_Utils_Array::value('address', $defaults), $config->defaultContactCountry)); } } $defaults['location_option'] = $this->_oldLocBlockId ? 2 : 1; return $defaults; }
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]); } } } }
static function fixAllStateSelects(&$form, &$defaults) { $config = CRM_Core_Config::singleton(); if (!empty($config->stateCountryMap)) { foreach ($config->stateCountryMap as $index => $match) { if (array_key_exists('state_province', $match) && array_key_exists('country', $match)) { CRM_Contact_Form_Edit_Address::fixStateSelect($form, $match['country'], $match['state_province'], CRM_Utils_Array::value('county', $match), CRM_Utils_Array::value($match['country'], $defaults), CRM_Utils_Array::value($match['state_province'], $defaults)); } else { unset($config->stateCountryMap[$index]); } } } }
/** * do the set default related to location type id, * primary location, default country * */ function blockSetDefaults(&$defaults) { $locationTypeKeys = array_filter(array_keys(CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id')), 'is_int'); sort($locationTypeKeys); // get the default location type $locationType = CRM_Core_BAO_LocationType::getDefault(); // unset primary location type $primaryLocationTypeIdKey = CRM_Utils_Array::key($locationType->id, $locationTypeKeys); unset($locationTypeKeys[$primaryLocationTypeIdKey]); // reset the array sequence $locationTypeKeys = array_values($locationTypeKeys); // get default phone and im provider id. $defPhoneTypeId = key(CRM_Core_OptionGroup::values('phone_type', FALSE, FALSE, FALSE, ' AND is_default = 1')); $defIMProviderId = key(CRM_Core_OptionGroup::values('instant_messenger_service', FALSE, FALSE, FALSE, ' AND is_default = 1')); $allBlocks = $this->_blocks; if (array_key_exists('Address', $this->_editOptions)) { $allBlocks['Address'] = $this->_editOptions['Address']; } $config = CRM_Core_Config::singleton(); foreach ($allBlocks as $blockName => $label) { $name = strtolower($blockName); $hasPrimary = $updateMode = FALSE; // user is in update mode. if (array_key_exists($name, $defaults) && !CRM_Utils_System::isNull($defaults[$name])) { $updateMode = TRUE; } for ($instance = 1; $instance <= $this->get($blockName . '_Block_Count'); $instance++) { // make we require one primary block, CRM-5505 if ($updateMode) { if (!$hasPrimary) { $hasPrimary = CRM_Utils_Array::value('is_primary', CRM_Utils_Array::value($instance, $defaults[$name])); } continue; } //set location to primary for first one. if ($instance == 1) { $hasPrimary = TRUE; $defaults[$name][$instance]['is_primary'] = TRUE; $defaults[$name][$instance]['location_type_id'] = $locationType->id; } else { $locTypeId = isset($locationTypeKeys[$instance - 1]) ? $locationTypeKeys[$instance - 1] : $locationType->id; $defaults[$name][$instance]['location_type_id'] = $locTypeId; } //set default country if ($name == 'address' && $config->defaultContactCountry) { $defaults[$name][$instance]['country_id'] = $config->defaultContactCountry; } //set default state/province if ($name == 'address' && $config->defaultContactStateProvince) { $defaults[$name][$instance]['state_province_id'] = $config->defaultContactStateProvince; } //set default phone type. if ($name == 'phone' && $defPhoneTypeId) { $defaults[$name][$instance]['phone_type_id'] = $defPhoneTypeId; } //set default im provider. if ($name == 'im' && $defIMProviderId) { $defaults[$name][$instance]['provider_id'] = $defIMProviderId; } } if (!$hasPrimary) { $defaults[$name][1]['is_primary'] = TRUE; } } // set defaults for country-state widget if (CRM_Utils_Array::value('address', $defaults) && 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)); } } }
/** * This function sets the default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * @access public * * @return None */ function setDefaultValues() { $defaults = $this->_values; if (CRM_Utils_Array::value('loc_block_id', $defaults)) { $defaults['loc_event_id'] = $defaults['loc_block_id']; $countLocUsed = CRM_Event_BAO_Event::countEventsUsingLocBlockId($defaults['loc_block_id']); if ($countLocUsed > 1) { $this->assign('locUsed', TRUE); } } $config = CRM_Core_Config::singleton(); if (!isset($defaults['address'][1]['country_id'])) { $defaults['address'][1]['country_id'] = $config->defaultContactCountry; } if (!isset($defaults['address'][1]['state_province_id'])) { $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; }