<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.4 |
+ | CiviCRM version 4.5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
* $Id$
*
*/
* @param boolean $sharing - false, if we want to skip the address sharing features
* @param boolean $inlineEdit true when edit used in inline edit
*
- * @return none
+ * @return void
*
* @access public
* @static
$form->applyFilter('__ALL__', 'trim');
$js = array();
- if ( !$inlineEdit ) {
- $js = array('onChange' => 'checkLocation( this.id );');
+ if (!$inlineEdit) {
+ $js = array('onChange' => 'checkLocation( this.id );', 'placeholder' => NULL);
}
- $form->addElement('select',
- "address[$blockId][location_type_id]",
- ts('Location Type'),
- array(
- '' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'),
- $js
- );
+ //make location type required for inline edit
+ $form->addSelect("address[$blockId][location_type_id]", array('entity' => 'address', 'class' => 'eight') + $js, $inlineEdit);
- 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');
+ if (!$inlineEdit) {
+ $js = array('id' => 'Address_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );');
}
$form->addElement(
$js
);
- if ( !$inlineEdit ) {
- $js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );');
+ if (!$inlineEdit) {
+ $js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );');
}
$form->addElement(
list($title, $attributes, $select) = $v;
$nameWithoutID = strpos($name, '_id') !== FALSE ? substr($name, 0, -3) : $name;
- if (!CRM_Utils_Array::value($nameWithoutID, $addressOptions)) {
+ if (empty($addressOptions[$nameWithoutID])) {
$continue = TRUE;
if (in_array($nameWithoutID, array(
- 'street_number', 'street_name', 'street_unit')) &&
- CRM_Utils_Array::value('street_address_parsing', $addressOptions)
- ) {
+ 'street_number', 'street_name', 'street_unit')) && !empty($addressOptions['street_address_parsing'])) {
$continue = FALSE;
}
if ($continue) {
$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 a state -')) + CRM_Core_PseudoConstant::county();
+ $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::county();
}
else {
$selectOptions = array('' => ts('- select a state -'));
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
$entityId = NULL;
- if (!empty($form->_values['address']) && CRM_Utils_Array::value($blockId, $form->_values['address'])) {
+ if (!empty($form->_values['address']) && !empty($form->_values['address'][$blockId])) {
$entityId = $form->_values['address'][$blockId]['id'];
}
// 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));
+ // 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));
}
}
}
// check for state/county match if not report error to user.
- if (CRM_Utils_Array::value('address', $fields) && is_array($fields['address'])) {
+ if (!empty($fields['address']) && is_array($fields['address'])) {
foreach ($fields['address'] as $instance => $addressValues) {
if (CRM_Utils_System::isNull($addressValues)) {
}
}
- if (CRM_Utils_Array::value('use_shared_address', $addressValues) && !CRM_Utils_Array::value('master_id', $addressValues)) {
+ if (!empty($addressValues['use_shared_address']) && empty($addressValues['master_id'])) {
$errors["address[$instance][use_shared_address]"] = ts('Please select valid shared contact or a contact with valid address.');
}
}
$counties = CRM_Core_PseudoConstant::countyForState($stateID);
}
else {
- $counties = CRM_Core_PseudoConstant::country();
+ $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) &&
- CRM_Utils_Array::value($stateElementName, $form->_fields) &&
- (CRM_Utils_Array::value('is_shared', $form->_fields[$stateElementName]) ||
- CRM_Utils_Array::value('is_view', $form->_fields[$stateElementName]))
+ if (isset($form->_fields) && !empty($form->_fields[$stateElementName]) &&
+ (!empty($form->_fields[$stateElementName]['is_shared']) || !empty($form->_fields[$stateElementName]['is_view']))
) {
$stateSelect->freeze();
}
$shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']);
foreach ($defaults['address'] as $key => $addressValue) {
- if (CRM_Utils_Array::value('master_id', $addressValue) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) {
+ if (!empty($addressValue['master_id']) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) {
$sharedAddresses[$key]['shared_address_display'] = array(
'address' => $addressValue['display'],
'name' => $shareAddressContactNames[$addressValue['master_id']]['name'],
//hack to handle show/hide address fields.
$parsedAddress = array();
- if ($form->_contactId &&
- CRM_Utils_Array::value('address', $_POST)
- && is_array($_POST['address'])
+ if ($form->_contactId && !empty($_POST['address']) && is_array($_POST['address'])
) {
foreach ($_POST['address'] as $cnt => $values) {
$showField = 'streetAddress';
foreach (array('street_number', 'street_name', 'street_unit') as $fld) {
- if (CRM_Utils_Array::value($fld, $values)) {
+ if (!empty($values[$fld])) {
$showField = 'addressElements';
break;
}
$form->_addressRequireOmission = rtrim($requireOmission, ',');
}
}
-}
\ No newline at end of file
+}