function uc_addresses_pane_address in Ubercart Addresses 5.2
Same name and namespace in other branches
- 5 uc_addresses_address_pane.inc \uc_addresses_pane_address()
- 6 uc_addresses_address_pane.inc \uc_addresses_pane_address()
Create, edit, process or view the Address pane.
Parameters
$op The name of the operation to perform. One of 'new',: 'add, 'edit', 'process' or 'view'.
$address The address object.:
$form_values If op = 'process', this is an array storing the: values the user entered for the form.
Return value
If $op is 'new', 'add' or 'edit', return a form. If $op is 'process', return an address object. If $op is 'view', return an array of address fields to view.
1 call to uc_addresses_pane_address()
- uc_addresses_user in ./
uc_addresses.module - Implementation of hook_user().
1 string reference to 'uc_addresses_pane_address'
- uc_addresses_address_pane in ./
uc_addresses.module - Implementation of hook_address_pane().
File
- ./
uc_addresses_address_pane.inc, line 29 - This file contains the callbacks for the default address panes and their corresponding helper functions.
Code
function uc_addresses_pane_address($op, $address, $form_values) {
global $user;
switch ($op) {
case 'new':
case 'add':
$description = t('Enter your new address information.');
$form['address'] = array(
'#type' => 'fieldset',
'#title' => t('Add an address'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
if (!$address) {
$address = uc_addresses_blank_address();
}
if (uc_address_field_enabled('first_name')) {
$form['address']['first_name'] = uc_textfield(uc_get_field_name('first_name'), $address->first_name, uc_address_field_required('first_name'));
}
if (uc_address_field_enabled('last_name')) {
$form['address']['last_name'] = uc_textfield(uc_get_field_name('last_name'), $address->last_name, uc_address_field_required('last_name'));
}
if (uc_address_field_enabled('company')) {
$form['address']['company'] = uc_textfield(uc_get_field_name('company'), $address->company, uc_address_field_required('company'), NULL, 64);
}
if (uc_address_field_enabled('street1')) {
$form['address']['street1'] = uc_textfield(uc_get_field_name('street1'), $address->street1, uc_address_field_required('street1'), NULL, 64);
}
if (uc_address_field_enabled('street2')) {
$form['address']['street2'] = uc_textfield(uc_get_field_name('street2'), $address->street2, uc_address_field_required('street2'), NULL, 64);
}
if (uc_address_field_enabled('city')) {
$form['address']['city'] = uc_textfield(uc_get_field_name('city'), $address->city, uc_address_field_required('city'));
}
if (uc_address_field_enabled('country')) {
$form['address']['country'] = uc_country_select(uc_get_field_name('country'), $address->country, NULL, 'name', uc_address_field_required('country'));
}
if (uc_address_field_enabled('zone')) {
$country_id = $address->country;
if ($op == 'add') {
if (isset($_POST['panes'], $_POST['panes']['address'], $_POST['panes']['address']['country'])) {
$country_id = intval($_POST['panes']['address']['country']);
}
}
else {
if (isset($_POST['country'])) {
$country_id = intval($_POST['country']);
}
}
$form['address']['zone'] = uc_zone_select(uc_get_field_name('zone'), $address->zone, NULL, $country_id, 'name', uc_address_field_required('zone'));
}
if (uc_address_field_enabled('postal_code')) {
$form['address']['postal_code'] = uc_textfield(uc_get_field_name('postal_code'), $address->postal_code, uc_address_field_required('postal_code'), NULL, 10, 10);
}
if (uc_address_field_enabled('phone')) {
$form['address']['phone'] = uc_textfield(uc_get_field_name('phone'), $address->phone, uc_address_field_required('phone'), NULL, 32, 16);
}
if ($op == 'add') {
$form['address']['address_name'] = uc_textfield(t('Save as'), $address->address_name, FALSE, t('Enter a name for this address (e.g. Home or Work)'));
$form['address']['save'] = array(
'#type' => 'checkbox',
'#title' => t('Default address'),
'#suffix' => t('Make this address the default address'),
'#default_value' => $address->is_default,
);
}
drupal_add_js(drupal_get_path('module', 'uc_addresses') . '/uc_addresses.js');
//drupal_add_js(drupal_get_path('module', 'uc_store') .'/uc_country_select.js');
return array(
'description' => $description,
'contents' => $form['address'],
'theme' => 'uc_addresses_pane',
);
case 'edit':
if ($address->is_default) {
$description = t('Edit your default address information.');
}
else {
$description = t('Edit your address information.');
}
$form['address'] = array(
'#type' => 'fieldset',
'#title' => t("Edit address information"),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['address']['aid'] = array(
'#type' => 'hidden',
'#value' => $address->aid,
);
if (uc_address_field_enabled('first_name')) {
$form['address']['first_name'] = uc_textfield(uc_get_field_name('first_name'), $address->first_name, uc_address_field_required('first_name'));
}
if (uc_address_field_enabled('last_name')) {
$form['address']['last_name'] = uc_textfield(uc_get_field_name('last_name'), $address->last_name, uc_address_field_required('last_name'));
}
if (uc_address_field_enabled('phone')) {
$form['address']['phone'] = uc_textfield(uc_get_field_name('phone'), $address->phone, uc_address_field_required('phone'), NULL, 32, 16);
}
if (uc_address_field_enabled('company')) {
$form['address']['company'] = uc_textfield(uc_get_field_name('company'), $address->company, uc_address_field_required('company'), NULL, 64);
}
if (uc_address_field_enabled('street1')) {
$form['address']['street1'] = uc_textfield(uc_get_field_name('street1'), $address->street1, uc_address_field_required('street1'), NULL, 64);
}
if (uc_address_field_enabled('street2')) {
$form['address']['street2'] = uc_textfield(uc_get_field_name('street2'), $address->street2, uc_address_field_required('street2'), NULL, 64);
}
if (uc_address_field_enabled('city')) {
$form['address']['city'] = uc_textfield(uc_get_field_name('city'), $address->city, uc_address_field_required('city'));
}
if (uc_address_field_enabled('country')) {
$form['address']['country'] = uc_country_select(uc_get_field_name('country'), $address->country, NULL, 'name', uc_address_field_required('country'));
}
if (uc_address_field_enabled('zone')) {
if (isset($_POST['panes'], $_POST['panes']['address'], $_POST['panes']['address']['country'])) {
$country_id = intval($_POST['panes']['address']['country']);
}
else {
$country_id = $address->country;
}
$form['address']['zone'] = uc_zone_select(uc_get_field_name('zone'), $address->zone, NULL, $country_id, 'name', uc_address_field_required('zone'));
}
if (uc_address_field_enabled('postal_code')) {
$form['address']['postal_code'] = uc_textfield(uc_get_field_name('postal_code'), $address->postal_code, uc_address_field_required('postal_code'), NULL, 10, 10);
}
$form['address']['address_name'] = uc_textfield(t('Save as'), $address->address_name, FALSE, t('Enter a name for this address (e.g. Home or Work)'));
$form['address']['save'] = array(
'#type' => 'checkbox',
'#title' => t('Default address'),
'#suffix' => t('Make this address the default address'),
'#default_value' => $address->is_default,
'#disabled' => $address->is_default,
);
drupal_add_js(drupal_get_path('module', 'uc_store') . '/uc_country_select.js');
return array(
'description' => $description,
'contents' => $form['address'],
'theme' => 'uc_addresses_pane',
);
case 'process':
$address->first_name = $form_values['first_name'];
$address->last_name = $form_values['last_name'];
$address->company = $form_values['company'];
$address->street1 = $form_values['street1'];
$address->street2 = $form_values['street2'];
$address->city = $form_values['city'];
$address->zone = $form_values['zone'];
$address->postal_code = $form_values['postal_code'];
$address->country = $form_values['country'];
$address->phone = $form_values['phone'];
$address->address_name = $form_values['address_name'];
$address->is_default = $form_values['save'];
return TRUE;
case 'view':
$view[] = array(
'title' => t('Address'),
'data' => uc_addresses_address($address),
);
if (uc_address_field_enabled('phone') && !empty($address->phone)) {
$view[] = array(
'title' => t('Phone'),
'data' => check_plain($address->phone),
);
}
return $view;
}
}