You are here

function uc_addresses_pane_address in Ubercart Addresses 5

Same name and namespace in other branches
  1. 5.2 uc_addresses_address_pane.inc \uc_addresses_pane_address()
  2. 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'.

$arg1 The address object.:

$arg2 If op = 'process', $arg2 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, $arg1, $arg2) {
  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 (uc_address_field_enabled('first_name')) {
        $form['address']['first_name'] = uc_textfield(uc_get_field_name('first_name'), $arg1->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'), $arg1->last_name, uc_address_field_required('last_name'));
      }
      if (uc_address_field_enabled('company')) {
        $form['address']['company'] = uc_textfield(uc_get_field_name('company'), $arg1->company, uc_address_field_required('company'), NULL, 64);
      }
      if (uc_address_field_enabled('street1')) {
        $form['address']['street1'] = uc_textfield(uc_get_field_name('street1'), $arg1->street1, uc_address_field_required('street1'), NULL, 64);
      }
      if (uc_address_field_enabled('street2')) {
        $form['address']['street2'] = uc_textfield(uc_get_field_name('street2'), $arg1->street2, uc_address_field_required('street2'), NULL, 64);
      }
      if (uc_address_field_enabled('city')) {
        $form['address']['city'] = uc_textfield(uc_get_field_name('city'), $arg1->city, uc_address_field_required('city'));
      }
      if (uc_address_field_enabled('country')) {
        $form['address']['country'] = uc_country_select(uc_get_field_name('country'), $arg1->country, NULL, 'name', uc_address_field_required('country'));
      }
      if (uc_address_field_enabled('zone')) {
        $country_id = $arg1->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'), $arg1->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'), $arg1->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'), $arg1->phone, uc_address_field_required('phone'), NULL, 32, 16);
      }
      if ($op == 'add') {
        $form['address']['address_name'] = uc_textfield(t('Save as'), $arg1->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' => $arg1->is_default,
        );
      }
      return array(
        'description' => $description,
        'contents' => $form['address'],
        'theme' => 'addresses_pane',
      );
    case 'edit':
      if ($arg1->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' => $arg1->aid,
      );
      if (uc_address_field_enabled('first_name')) {
        $form['address']['first_name'] = uc_textfield(uc_get_field_name('first_name'), $arg1->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'), $arg1->last_name, uc_address_field_required('last_name'));
      }
      if (uc_address_field_enabled('phone')) {
        $form['address']['phone'] = uc_textfield(uc_get_field_name('phone'), $arg1->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'), $arg1->company, uc_address_field_required('company'), NULL, 64);
      }
      if (uc_address_field_enabled('street1')) {
        $form['address']['street1'] = uc_textfield(uc_get_field_name('street1'), $arg1->street1, uc_address_field_required('street1'), NULL, 64);
      }
      if (uc_address_field_enabled('street2')) {
        $form['address']['street2'] = uc_textfield(uc_get_field_name('street2'), $arg1->street2, uc_address_field_required('street2'), NULL, 64);
      }
      if (uc_address_field_enabled('city')) {
        $form['address']['city'] = uc_textfield(uc_get_field_name('city'), $arg1->city, uc_address_field_required('city'));
      }
      if (uc_address_field_enabled('country')) {
        $form['address']['country'] = uc_country_select(uc_get_field_name('country'), $arg1->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 = $arg1->country;
        }
        $form['address']['zone'] = uc_zone_select(uc_get_field_name('zone'), $arg1->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'), $arg1->postal_code, uc_address_field_required('postal_code'), NULL, 10, 10);
      }
      $form['address']['address_name'] = uc_textfield(t('Save as'), $arg1->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' => $arg1->is_default,
        '#disabled' => $arg1->is_default,
      );
      return array(
        'description' => $description,
        'contents' => $form['address'],
        'theme' => 'addresses_pane',
      );
    case 'process':
      $arg1->aid = $arg2['aid'];
      $arg1->first_name = $arg2['first_name'];
      $arg1->last_name = $arg2['last_name'];
      $arg1->company = $arg2['company'];
      $arg1->street1 = $arg2['street1'];
      $arg1->street2 = $arg2['street2'];
      $arg1->city = $arg2['city'];
      $arg1->zone = $arg2['zone'];
      $arg1->postal_code = $arg2['postal_code'];
      $arg1->country = $arg2['country'];
      $arg1->phone = $arg2['phone'];
      $arg1->address_name = $arg2['address_name'];
      $arg1->is_default = $arg2['save'];
      return TRUE;
    case 'view':
      $view[] = array(
        'title' => t('Address'),
        'data' => uc_addresses_address($arg1),
      );
      if (uc_address_field_enabled('phone') && !empty($arg1->phone)) {
        $view[] = array(
          'title' => t('Phone'),
          'data' => check_plain($arg1->phone),
        );
      }
      return $view;
  }
}