3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
37 * form helper class for address section
39 class CRM_Contact_Form_Inline_Address
extends CRM_Contact_Form_Inline
{
47 * Do we want to parse street address.
49 public $_parseStreetAddress;
52 * store address values
67 * Since we are using same class / code to generate multiple instances
68 * of address block, we need to generate unique form name for each,
69 * hence calling parent contructor
71 function __construct() {
72 $locBlockNo = CRM_Utils_Request
::retrieve('locno', 'Positive', CRM_Core_DAO
::$_nullObject, TRUE, NULL, $_REQUEST);
73 $name = "Address_{$locBlockNo}";
75 parent
::__construct(null, CRM_Core_Action
::NONE
, 'post', $name);
81 public function preProcess() {
84 $this->_locBlockNo
= CRM_Utils_Request
::retrieve('locno', 'Positive', $this, TRUE, NULL, $_REQUEST);
85 $this->assign('blockId', $this->_locBlockNo
);
87 $addressSequence = CRM_Core_BAO_Address
::addressSequence();
88 $this->assign('addressSequence', $addressSequence);
90 $this->_values
= array();
91 $this->_addressId
= CRM_Utils_Request
::retrieve('aid', 'Positive', $this, FALSE, NULL, $_REQUEST);
93 $this->_action
= CRM_Core_Action
::ADD
;
94 if ($this->_addressId
) {
95 $params = array('id' => $this->_addressId
);
96 $address = CRM_Core_BAO_Address
::getValues($params, FALSE, 'id');
97 $this->_values
['address'][$this->_locBlockNo
] = array_pop($address);
98 $this->_action
= CRM_Core_Action
::UPDATE
;
101 $this->_addressId
= 0;
104 $this->assign('action', $this->_action
);
105 $this->assign('addressId', $this->_addressId
);
107 // parse street address, CRM-5450
108 $this->_parseStreetAddress
= $this->get('parseStreetAddress');
109 if (!isset($this->_parseStreetAddress
)) {
110 $addressOptions = CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
113 $this->_parseStreetAddress
= FALSE;
114 if (CRM_Utils_Array
::value('street_address', $addressOptions) &&
115 CRM_Utils_Array
::value('street_address_parsing', $addressOptions)
117 $this->_parseStreetAddress
= TRUE;
119 $this->set('parseStreetAddress', $this->_parseStreetAddress
);
121 $this->assign('parseStreetAddress', $this->_parseStreetAddress
);
125 * build the form elements for an address object
130 public function buildQuickForm() {
131 parent
::buildQuickForm();
132 CRM_Contact_Form_Edit_Address
::buildQuickForm($this, $this->_locBlockNo
, TRUE, TRUE);
136 * set defaults for the form
141 public function setDefaultValues() {
142 $defaults = $this->_values
;
144 $config = CRM_Core_Config
::singleton();
145 //set address block defaults
146 if (CRM_Utils_Array
::value('address', $defaults)) {
147 CRM_Contact_Form_Edit_Address
::setDefaultValues($defaults, $this);
150 // get the default location type
151 $locationType = CRM_Core_BAO_LocationType
::getDefault();
153 if ($this->_locBlockNo
== 1) {
154 $address['is_primary'] = TRUE;
155 $address['location_type_id'] = $locationType->id
;
158 $address['country_id'] = $config->defaultContactCountry
;
159 $defaults['address'][$this->_locBlockNo
] = $address;
162 $values = $defaults['address'][$this->_locBlockNo
];
164 CRM_Contact_Form_Edit_Address
::fixStateSelect($this,
165 "address[$this->_locBlockNo][country_id]",
166 "address[$this->_locBlockNo][state_province_id]",
167 "address[$this->_locBlockNo][county_id]",
168 CRM_Utils_Array
::value('country_id',
169 $values, $config->defaultContactCountry
171 CRM_Utils_Array
::value('state_province_id',
172 $values, $config->defaultContactStateProvince
185 public function postProcess() {
186 $params = $this->exportValues();
188 // Process / save address
189 $params['contact_id'] = $this->_contactId
;
190 $params['updateBlankLocInfo'] = TRUE;
192 // process shared contact address.
193 CRM_Contact_BAO_Contact_Utils
::processSharedAddress($params['address']);
195 if ($this->_parseStreetAddress
) {
196 CRM_Contact_Form_Contact
::parseAddress($params);
199 if ($this->_addressId
> 0) {
200 $params['address'][$this->_locBlockNo
]['id'] = $this->_addressId
;
203 // save address changes
204 $address = CRM_Core_BAO_Address
::create($params, TRUE);
207 $this->response(array('addressId' => $address[0]->id
));