/** * Function to build the form * * @return None * @access public */ function buildQuickForm() { parent::buildQuickForm(); if ($this->_action & CRM_CORE_ACTION_DELETE) { return; } $this->applyFilter('__ALL__', 'trim'); $this->add('text', 'subject', ts('Subject'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Meeting', 'subject')); $this->addRule('subject', ts('Please enter a valid subject.'), 'required'); $this->addElement('date', 'scheduled_date_time', ts('Date and Time'), CRM_Core_SelectValues::date('datetime')); $this->addRule('scheduled_date_time', ts('Select a valid date.'), 'qfDate'); $this->addRule('scheduled_date_time', ts('Please select Scheduled Date.'), 'required'); $this->add('select', 'duration_hours', ts('Duration'), CRM_Core_SelectValues::getHours()); $this->add('select', 'duration_minutes', null, CRM_Core_SelectValues::getMinutes()); $this->add('text', 'location', ts('Location'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Meeting', 'location')); $this->add('textarea', 'details', ts('Details'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Meeting', 'details')); $status =& $this->add('select', 'status', ts('Status'), CRM_Core_SelectValues::activityStatus()); $this->addRule('status', ts('Please select status.'), 'required'); $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree('Meeting', $this->_id, 0); CRM_Core_BAO_CustomGroup::buildQuickForm($this, $this->_groupTree, 'showBlocks1', 'hideBlocks1'); }
/** * Pre processing work done here. * * gets session variables for table name, id of entity in table, type of entity and stores them. */ public function preProcess() { $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE); $this->_entityID = CRM_Utils_Request::retrieve('entityID', 'Positive', $this, TRUE); $this->_subTypeID = CRM_Utils_Request::retrieve('subType', 'Positive', $this, TRUE); $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Case', $this, $this->_entityID, $this->_groupID, $this->_subTypeID); // simplified formatted groupTree $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this); // Array contains only one item foreach ($groupTree as $groupValues) { $this->_customTitle = $groupValues['title']; CRM_Utils_System::setTitle(ts('Edit %1', array(1 => $groupValues['title']))); } $this->_defaults = array(); CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $this->_defaults); $this->setDefaults($this->_defaults); CRM_Core_BAO_CustomGroup::buildQuickForm($this, $groupTree); //need to assign custom data type and subtype to the template $this->assign('entityID', $this->_entityID); $this->assign('groupID', $this->_groupID); $this->assign('subType', $this->_subTypeID); $this->assign('contactID', $this->_contactID); }
/** * Build form for address input fields. * * @param CRM_Core_Form $form * @param int $addressBlockCount * The index of the address array (if multiple addresses on a page). * @param bool $sharing * False, if we want to skip the address sharing features. * @param bool $inlineEdit * True when edit used in inline edit. */ public static function buildQuickForm(&$form, $addressBlockCount = NULL, $sharing = TRUE, $inlineEdit = FALSE) { // passing this via the session is AWFUL. we need to fix this if (!$addressBlockCount) { $blockId = $form->get('Address_Block_Count') ? $form->get('Address_Block_Count') : 1; } else { $blockId = $addressBlockCount; } $config = CRM_Core_Config::singleton(); $countryDefault = $config->defaultContactCountry; $form->applyFilter('__ALL__', 'trim'); $js = array(); if (!$inlineEdit) { $js = array('onChange' => 'checkLocation( this.id );', 'placeholder' => NULL); } //make location type required for inline edit $form->addField("address[{$blockId}][location_type_id]", array('entity' => 'address', 'class' => 'eight') + $js, $inlineEdit); if (!$inlineEdit) { $js = array('id' => 'Address_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );'); } $form->addField("address[{$blockId}][is_primary]", array('entity' => 'address', 'label' => ts('Primary location for this contact'), 'text' => ts('Primary location for this contact')) + $js); if (!$inlineEdit) { $js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );'); } $form->addField("address[{$blockId}][is_billing]", array('entity' => 'address', 'label' => ts('Primary location for this contact'), 'text' => ts('Primary location for this contact')) + $js); // hidden element to store master address id $form->addField("address[{$blockId}][master_id]", array('entity' => 'address', 'type' => 'hidden')); $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE); $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address'); $elements = array('address_name', 'street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'country_id', 'state_province_id', 'county_id', 'geo_code_1', 'geo_code_2', 'street_number', 'street_name', 'street_unit'); foreach ($elements as $name) { //Remove id from name, to allow comparison against enabled addressOtions. $nameWithoutID = strpos($name, '_id') !== FALSE ? substr($name, 0, -3) : $name; // Skip fields which are not enabled in the address options. if (empty($addressOptions[$nameWithoutID])) { $continue = TRUE; //Don't skip street parsed fields when parsing is enabled. if (in_array($nameWithoutID, array('street_number', 'street_name', 'street_unit')) && !empty($addressOptions['street_address_parsing'])) { $continue = FALSE; } if ($continue) { continue; } } if ($name == 'address_name') { $name = 'name'; } $params = array('entity' => 'address'); if ($name == 'postal_code_suffix') { $params['label'] = ts('Suffix'); } $form->addField("address[{$blockId}][{$name}]", $params); } $entityId = NULL; if (!empty($form->_values['address']) && !empty($form->_values['address'][$blockId])) { $entityId = $form->_values['address'][$blockId]['id']; } // CRM-11665 geocode override option $geoCode = FALSE; if (!empty($config->geocodeMethod)) { $geoCode = TRUE; $form->addElement('checkbox', "address[{$blockId}][manual_geo_code]", ts('Override automatic geocoding')); } $form->assign('geoCode', $geoCode); // Process any address custom data - $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $form, $entityId); if (isset($groupTree) && is_array($groupTree)) { // use simplified formatted groupTree $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form); // make sure custom fields are added /w element-name in the format - 'address[$blockId][custom-X]' foreach ($groupTree as $id => $group) { foreach ($group['fields'] as $fldId => $field) { $groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name']; $groupTree[$id]['fields'][$fldId]['element_name'] = "address[{$blockId}][{$field['element_name']}]"; } } $defaults = array(); CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults); // since we change element name for address custom data, we need to format the setdefault values $addressDefaults = array(); foreach ($defaults as $key => $val) { if (empty($val)) { continue; } // inorder to set correct defaults for checkbox custom data, we need to converted flat key to array // this works for all types custom data $keyValues = explode('[', str_replace(']', '', $key)); $addressDefaults[$keyValues[0]][$keyValues[1]][$keyValues[2]] = $val; } $form->setDefaults($addressDefaults); // we setting the prefix to 'dnc_' below, so that we don't overwrite smarty's grouptree var. // And we can't set it to 'address_' because we want to set it in a slightly different format. CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, 'dnc_'); // during contact editing : if no address is filled // required custom data must not produce 'required' form rule error // more handling done in formRule func if (!$inlineEdit) { CRM_Contact_Form_Edit_Address::storeRequiredCustomDataInfo($form, $groupTree); } $template = CRM_Core_Smarty::singleton(); $tplGroupTree = $template->get_template_vars('address_groupTree'); $tplGroupTree = empty($tplGroupTree) ? array() : $tplGroupTree; $form->assign('address_groupTree', $tplGroupTree + array($blockId => $groupTree)); // unset the temp smarty var that got created $form->assign('dnc_groupTree', NULL); } // address custom data processing ends .. if ($sharing) { // shared address $form->addElement('checkbox', "address[{$blockId}][use_shared_address]", NULL, ts('Use another contact\'s address')); // Override the default profile links to add address form $profileLinks = CRM_Core_BAO_UFGroup::getCreateLinks(array('new_individual', 'new_organization', 'new_household'), 'shared_address'); $form->addEntityRef("address[{$blockId}][master_contact_id]", ts('Share With'), array('create' => $profileLinks)); } }
/** * @param CRM_Core_Form $form */ public static function buildQuickForm(&$form) { $form->addElement('hidden', 'hidden_custom', 1); $form->addElement('hidden', "hidden_custom_group_count[{$form->_groupID}]", $form->_groupCount); CRM_Core_BAO_CustomGroup::buildQuickForm($form, $form->_groupTree); }
/** * build form for address input fields * * @param object $form - CRM_Core_Form (or subclass) * @param int $addressBlockCount - the index of the address array (if multiple addresses on a page) * @param boolean $sharing - false, if we want to skip the address sharing features * @param boolean $inlineEdit true when edit used in inline edit * * @return void * * @access public * @static */ static function buildQuickForm(&$form, $addressBlockCount = NULL, $sharing = TRUE, $inlineEdit = FALSE) { // passing this via the session is AWFUL. we need to fix this if (!$addressBlockCount) { $blockId = $form->get('Address_Block_Count') ? $form->get('Address_Block_Count') : 1; } else { $blockId = $addressBlockCount; } $config = CRM_Core_Config::singleton(); $countryDefault = $config->defaultContactCountry; $form->applyFilter('__ALL__', 'trim'); $js = array(); if (!$inlineEdit) { $js = array('onChange' => 'checkLocation( this.id );'); } $form->addSelect("address[{$blockId}][location_type_id]", array('entity' => 'address', 'class' => 'eight') + $js); if (!$inlineEdit) { $js = array('id' => 'Address_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );'); } else { //make location type required for inline edit $form->addRule("address[{$blockId}][location_type_id]", ts('%1 is a required field.', array(1 => ts('Location Type'))), 'required'); } $form->addElement('checkbox', "address[{$blockId}][is_primary]", ts('Primary location for this contact'), ts('Primary location for this contact'), $js); if (!$inlineEdit) { $js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );'); } $form->addElement('checkbox', "address[{$blockId}][is_billing]", ts('Billing location for this contact'), ts('Billing location for this contact'), $js); // hidden element to store master address id $form->addElement('hidden', "address[{$blockId}][master_id]"); $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE); $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address'); $elements = array('address_name' => array(ts('Address Name'), $attributes['address_name'], NULL), 'street_address' => array(ts('Street Address'), $attributes['street_address'], NULL), 'supplemental_address_1' => array(ts('Supplemental Address 1'), $attributes['supplemental_address_1'], NULL), 'supplemental_address_2' => array(ts('Supplemental Address 2'), $attributes['supplemental_address_2'], NULL), '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), 'state_province_id' => array(ts('State / Province'), $attributes['state_province_id'], NULL), 'country_id' => array(ts('Country'), $attributes['country_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_name' => array(ts('Street Name'), $attributes['street_name'], NULL), 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL)); $stateCountryMap = array(); foreach ($elements as $name => $v) { list($title, $attributes, $select) = $v; $nameWithoutID = strpos($name, '_id') !== FALSE ? substr($name, 0, -3) : $name; if (empty($addressOptions[$nameWithoutID])) { $continue = TRUE; if (in_array($nameWithoutID, array('street_number', 'street_name', 'street_unit')) && !empty($addressOptions['street_address_parsing'])) { $continue = FALSE; } if ($continue) { continue; } } 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); } else { if ($name == 'address_name') { $name = 'name'; } $form->addElement('text', "address[{$blockId}][{$name}]", $title, $attributes); } } else { if ($name == 'state_province_id') { $stateCountryMap[$blockId]['state_province'] = "address_{$blockId}_{$name}"; } $form->addElement('select', "address[{$blockId}][{$name}]", $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select()); } } CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); $entityId = NULL; if (!empty($form->_values['address']) && !empty($form->_values['address'][$blockId])) { $entityId = $form->_values['address'][$blockId]['id']; } // CRM-11665 geocode override option $geoCode = FALSE; if (!empty($config->geocodeMethod)) { $geoCode = TRUE; $form->addElement('checkbox', "address[{$blockId}][manual_geo_code]", ts('Override automatic geocoding')); } $form->assign('geoCode', $geoCode); // Process any address custom data - $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $form, $entityId); if (isset($groupTree) && is_array($groupTree)) { // use simplified formatted groupTree $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form); // make sure custom fields are added /w element-name in the format - 'address[$blockId][custom-X]' foreach ($groupTree as $id => $group) { foreach ($group['fields'] as $fldId => $field) { $groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name']; $groupTree[$id]['fields'][$fldId]['element_name'] = "address[{$blockId}][{$field['element_name']}]"; } } $defaults = array(); CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults); // since we change element name for address custom data, we need to format the setdefault values $addressDefaults = array(); foreach ($defaults as $key => $val) { if (empty($val)) { continue; } // inorder to set correct defaults for checkbox custom data, we need to converted flat key to array // this works for all types custom data $keyValues = explode('[', str_replace(']', '', $key)); $addressDefaults[$keyValues[0]][$keyValues[1]][$keyValues[2]] = $val; } $form->setDefaults($addressDefaults); // we setting the prefix to 'dnc_' below, so that we don't overwrite smarty's grouptree var. // And we can't set it to 'address_' because we want to set it in a slightly different format. CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, 'dnc_'); // during contact editing : if no address is filled // required custom data must not produce 'required' form rule error // more handling done in formRule func if (!$inlineEdit) { CRM_Contact_Form_Edit_Address::storeRequiredCustomDataInfo($form, $groupTree); } $template = CRM_Core_Smarty::singleton(); $tplGroupTree = $template->get_template_vars('address_groupTree'); $tplGroupTree = empty($tplGroupTree) ? array() : $tplGroupTree; $form->assign('address_groupTree', $tplGroupTree + array($blockId => $groupTree)); // unset the temp smarty var that got created $form->assign('dnc_groupTree', NULL); } // address custom data processing ends .. if ($sharing) { // shared address $form->addElement('checkbox', "address[{$blockId}][use_shared_address]", NULL, ts('Use another contact\'s address')); // get the reserved for address $profileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'shared_address', 'id', 'name'); if (!$profileId) { CRM_Core_Error::fatal(ts('Your install is missing required "Shared Address" profile.')); } CRM_Contact_Form_NewContact::buildQuickForm($form, $blockId, array($profileId)); } }
/** * Function to set variables up before form is built * * @return void * @access public */ function preProcess() { // action $this->_action = CRM_Utils_Request::retrieve('action', $this, false, 'add'); $this->assign('action', $this->_action); $this->_id = CRM_Utils_Request::retrieve('id', $this); if ($this->_action & CRM_CORE_ACTION_DELETE) { return; } // current contribution id if ($this->_id) { require_once 'CRM/Contribute/DAO/FinancialTrxn.php'; $trxn =& new CRM_Contribute_DAO_FinancialTrxn(); $trxn->entity_table = 'civicrm_contribution'; $trxn->entity_id = $this->_id; if ($trxn->find(true)) { $this->_online = true; } } //to get Premium id if ($this->_id) { require_once 'CRM/Contribute/DAO/ContributionProduct.php'; $dao =& new CRM_Contribute_DAO_ContributionProduct(); $dao->contribution_id = $this->_id; if ($dao->find(true)) { $this->_premiumId = $dao->id; } } $this->_contactID = CRM_Utils_Request::retrieve('cid', $this); $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree('Contribution', $this->_id, 0); CRM_Core_BAO_CustomGroup::buildQuickForm($this, $this->_groupTree, 'showBlocks1', 'hideBlocks1'); }
/** * Build quick form. */ public function buildQuickForm() { $this->addElement('hidden', 'hidden_custom', 1); $this->addElement('hidden', "hidden_custom_group_count[{$this->_groupID}]", $this->_groupCount); CRM_Core_BAO_CustomGroup::buildQuickForm($this, $this->_groupTree); }
/** * Function to build the form * * @return None * @access public */ function buildQuickForm() { parent::buildQuickForm(); if ($this->_action & CRM_CORE_ACTION_DELETE) { return; } $activityType = CRM_Core_PseudoConstant::activityType(false); $this->applyFilter('__ALL__', 'trim'); $this->add('select', 'activity_type_id', ts('Activity Type'), array('' => ts('- select activity type -')) + $activityType, array('onChange' => 'activity_get_description( )'), true); $this->addRule('activity_type_id', ts('Select a valid activity.'), 'required'); $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_ActivityType', 'description'), false); $this->add('text', 'subject', ts('Subject'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Activity', 'subject'), true); $this->add('date', 'scheduled_date_time', ts('Date and Time'), CRM_Core_SelectValues::date('datetime'), true); $this->addRule('scheduled_date_time', ts('Select a valid date.'), 'qfDate'); $this->add('select', 'duration_hours', ts('Duration'), CRM_Core_SelectValues::getHours()); $this->add('select', 'duration_minutes', null, CRM_Core_SelectValues::getMinutes()); $this->add('text', 'location', ts('Location'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Activity', 'location')); $this->add('textarea', 'details', ts('Details'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Activity', 'details')); $this->add('select', 'status', ts('Status'), CRM_Core_SelectValues::activityStatus(), true); $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree('Activity', $this->_id, 0); if ($this->_action & CRM_CORE_ACTION_VIEW) { CRM_Core_BAO_CustomGroup::buildViewHTML($this, $this->_groupTree); } else { CRM_Core_BAO_CustomGroup::buildQuickForm($this, $this->_groupTree, 'showBlocks1', 'hideBlocks1'); } }
/** * Function to actually build the form * * @return None * @access public */ function buildQuickForm() { // assign a few constants used by all display elements // we can obsolete this when smarty can access class constans directly $this->assign('locationCount', CRM_CONTACT_FORM_EDIT_LOCATION_BLOCKS + 1); $this->assign('blockCount', CRM_CONTACT_FORM_LOCATION_BLOCKS + 1); $this->assign('contact_type', $this->_contactType); require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_Form_" . $this->_contactType) . ".php"; eval('CRM_Contact_Form_' . $this->_contactType . '::buildQuickForm( $this );'); // add the communications block CRM_Contact_Form_Edit::buildCommunicationBlock($this); /* Entering the compact location engine */ $location =& CRM_Contact_Form_Location::buildLocationBlock($this, CRM_CONTACT_FORM_EDIT_LOCATION_BLOCKS); /* End of locations */ // add note block if ($this->_action & CRM_CORE_ACTION_ADD) { $note =& CRM_Contact_Form_Note::buildNoteBlock($this); } //add tags and groups block $groupTag =& CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_contactId, CRM_CONTACT_FORM_GROUPTAG_ALL); //Custom Group Inline Edit form $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this->_contactId); CRM_Core_BAO_CustomGroup::buildQuickForm($this, $this->_groupTree, 'showBlocks1', 'hideBlocks1'); $config =& CRM_Core_Config::singleton(); CRM_Core_ShowHideBlocks::links($this, 'notes', '', ''); // add the dedupe button $this->addElement('submit', $this->_dedupeButtonName, ts('Check for Matching Contact(s)')); $this->addElement('submit', $this->_duplicateButtonName, ts('Save Duplicate Contact')); $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'subName' => 'view', 'isDefault' => true), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel')))); }
/** * build form for address input fields * * @param object $form - CRM_Core_Form (or subclass) * @param array reference $location - location array * @param int $locationId - location id whose block needs to be built. * @return none * * @access public * @static */ static function buildQuickForm(&$form, $addressBlockCount = null) { // passing this via the session is AWFUL. we need to fix this if (!$addressBlockCount) { $blockId = $form->get('Address_Block_Count') ? $form->get('Address_Block_Count') : 1; } else { $blockId = $addressBlockCount; } $config = CRM_Core_Config::singleton(); $countryDefault = $config->defaultContactCountry; $form->applyFilter('__ALL__', 'trim'); $js = array('onChange' => 'checkLocation( this.id );'); $form->addElement('select', "address[{$blockId}][location_type_id]", ts('Location Type'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::locationType(), $js); $js = array('id' => "Address_" . $blockId . "_IsPrimary", 'onClick' => 'singleSelect( this.id );'); $form->addElement('checkbox', "address[{$blockId}][is_primary]", ts('Primary location for this contact'), ts('Primary location for this contact'), $js); $js = array('id' => "Address_" . $blockId . "_IsBilling", 'onClick' => 'singleSelect( this.id );'); $form->addElement('checkbox', "address[{$blockId}][is_billing]", ts('Billing location for this contact'), ts('Billing location for this contact'), $js); // hidden element to store master address id $form->addElement('hidden', "address[{$blockId}][master_id]"); require_once 'CRM/Core/BAO/Preferences.php'; $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true); $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address'); $elements = array('address_name' => array(ts('Address Name'), $attributes['address_name'], null), 'street_address' => array(ts('Street Address'), $attributes['street_address'], null), 'supplemental_address_1' => array(ts('Addt\'l Address 1'), $attributes['supplemental_address_1'], null), 'supplemental_address_2' => array(ts('Addt\'l Address 2'), $attributes['supplemental_address_2'], null), 'city' => array(ts('City'), $attributes['city'], null), 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], null), 'postal_code_suffix' => array(ts('Postal Code Suffix'), array('size' => 4, 'maxlength' => 12), null), 'county_id' => array(ts('County'), $attributes['county_id'], 'county'), 'state_province_id' => array(ts('State / Province'), $attributes['state_province_id'], null), 'country_id' => array(ts('Country'), $attributes['country_id'], null), 'geo_code_1' => array(ts('Latitude'), array('size' => 9, 'maxlength' => 10), null), 'geo_code_2' => array(ts('Longitude'), array('size' => 9, 'maxlength' => 10), null), 'street_number' => array(ts('Street Number'), $attributes['street_number'], null), 'street_name' => array(ts('Street Name'), $attributes['street_name'], null), 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], null)); $stateCountryMap = array(); foreach ($elements as $name => $v) { list($title, $attributes, $select) = $v; $nameWithoutID = strpos($name, '_id') !== false ? substr($name, 0, -3) : $name; if (!CRM_Utils_Array::value($nameWithoutID, $addressOptions)) { $continue = true; if (in_array($nameWithoutID, array('street_number', 'street_name', 'street_unit')) && CRM_Utils_Array::value('street_address_parsing', $addressOptions)) { $continue = false; } if ($continue) { continue; } } 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') { if ($name == 'country_id') { $stateCountryMap[$blockId]['country'] = "address_{$blockId}_{$name}"; $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(); } else { $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 -')); } } $form->addElement('select', "address[{$blockId}][{$name}]", $title, $selectOptions); } else { if ($name == 'address_name') { $name = "name"; } $form->addElement('text', "address[{$blockId}][{$name}]", $title, $attributes); } } else { $form->addElement('select', "address[{$blockId}][{$name}]", $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select()); } } require_once 'CRM/Core/BAO/Address.php'; require_once 'CRM/Core/BAO/CustomGroup.php'; CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); $entityId = null; if (!empty($form->_values['address'])) { $entityId = $form->_values['address'][$blockId]['id']; } // Process any address custom data - $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $form, $entityId); if (isset($groupTree) && is_array($groupTree)) { // use simplified formatted groupTree $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form); // make sure custom fields are added /w element-name in the format - 'address[$blockId][custom-X]' foreach ($groupTree as $id => $group) { foreach ($group['fields'] as $fldId => $field) { $groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name']; $groupTree[$id]['fields'][$fldId]['element_name'] = "address[{$blockId}][{$field['element_name']}]"; } } $defaults = array(); CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults); // For some of the custom fields like checkboxes, the defaults doesn't populate // in proper format due to the different element-name format - 'address[$blockId][custom-X]'. // Below eval() fixes this issue. $address = array(); foreach ($defaults as $key => $val) { eval("\${$key} = " . (!is_array($val) ? "'{$val}'" : var_export($val, true)) . ";"); } $defaults = array('address' => $address); $form->setDefaults($defaults); // we setting the prefix to 'dnc_' below, so that we don't overwrite smarty's grouptree var. // And we can't set it to 'address_' because we want to set it in a slightly different format. CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, false, 1, "dnc_"); $template =& CRM_Core_Smarty::singleton(); $tplGroupTree = $template->get_template_vars('address_groupTree'); $tplGroupTree = empty($tplGroupTree) ? array() : $tplGroupTree; $form->assign("address_groupTree", $tplGroupTree + array($blockId => $groupTree)); $form->assign("dnc_groupTree", null); // unset the temp smarty var that got created } // address custom data processing ends .. // shared address $form->addElement('checkbox', "address[{$blockId}][use_shared_address]", null, ts('Share Address With')); // get the reserved for address $profileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'shared_address', 'id', 'name'); if (!$profileId) { CRM_Core_Error::fatal(ts('Your install is missing required "Shared Address" profile.')); } require_once 'CRM/Contact/Form/NewContact.php'; CRM_Contact_Form_NewContact::buildQuickForm($form, $blockId, array($profileId)); }
/** * Function to actually build the form * * @return None * @access public */ function buildQuickForm() { if ($this->_action == CRM_CORE_ACTION_DELETE) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Group'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); } else { $this->applyFilter('__ALL__', 'trim'); $this->add('text', 'title', ts('Name:') . ' ', CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title')); $this->addRule('title', ts('Group name is required.'), 'required'); $this->addRule('title', ts('Name already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Group', $this->_id, 'title')); $this->add('text', 'description', ts('Description:') . ' ', CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'description')); $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(), true); $this->addButtons(array(array('type' => 'next', 'name' => $this->_action == CRM_CORE_ACTION_ADD ? ts('Continue') : ts('Save'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree('Group', $this->_id, 0); CRM_Core_BAO_CustomGroup::buildQuickForm($this, $this->_groupTree, 'showBlocks1', 'hideBlocks1'); } }
/** * Function to actually build the form * * @return void * @access public */ function buildQuickForm() { CRM_Core_BAO_CustomGroup::buildQuickForm($this, $this->_groupTree, 'showBlocks', 'hideBlocks'); $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); if ($this->_action & (CRM_CORE_ACTION_VIEW | CRM_CORE_ACTION_BROWSE)) { $this->freeze(); } }