You are here

function uc_addresses_delete_address_confirm in Ubercart Addresses 5.2

Same name and namespace in other branches
  1. 5 uc_addresses.module \uc_addresses_delete_address_confirm()
  2. 6.2 uc_addresses.pages.inc \uc_addresses_delete_address_confirm()
  3. 6 uc_addresses.module \uc_addresses_delete_address_confirm()
  4. 7 uc_addresses.pages.inc \uc_addresses_delete_address_confirm()

Display a confirmation page before deleting an address.

Parameters

$address_user The id of the user who "owns" the address.:

$aid The id of the address to delete.:

1 string reference to 'uc_addresses_delete_address_confirm'
uc_addresses_menu in ./uc_addresses.module
Implementation of hook_menu().

File

./uc_addresses.module, line 1043

Code

function uc_addresses_delete_address_confirm($address_user, $aid) {

  // We returned to this page after the user pressed cancel. Redirect
  // the user back to the address list
  if ($_POST['op'] == t('Cancel')) {

    // TODO: (Tony) This seems draconian
    cache_clear_all();
    drupal_goto('user/' . $address_user . '/addresses/');
  }
  $form = drupal_get_form('uc_addresses_delete_address_confirm_form', $address_user, $aid);

  // If the address doesn't exist, let's get out of here
  $address = _uc_addresses_db_get_address($address_user, $aid);
  if ($address === FALSE) {
    $_SESSION['add_address'] = NULL;
    unset($_SESSION['add_address']);
    drupal_goto('user/' . $address_user . '/addresses/');
  }

  // Address exists. Make sure it's not the default address
  if (_uc_addresses_db_check_if_default($aid)) {
    drupal_set_message(t('You cannot delete your default address'), 'warning');
    drupal_goto('user/' . $address_user . '/addresses');
  }

  // Display a caution
  $help = variable_get('uc_addresses_delete_instructions', t('Are you are sure you want to Delete this address? ' . 'Once deleted, the address cannot be recovered.', array(
    '!delete' => variable_get('uc_addresses_delete_button', t('Delete address')),
  )));
  $panes = _address_pane_list();
  foreach ($panes as $pane) {
    if (variable_get('uc_addresses_pane_' . $pane['id'] . '_enabled', TRUE)) {
      $func = $pane['callback'];
      if (function_exists($func)) {
        $return = $func('view', $address, NULL);
        if (!is_NULL($return)) {
          $data[$pane['title']] = $return;
        }
      }
    }
  }
  $output = theme('uc_addresses_address_delete_confirm', $help, $data, $form);
  return $output;
}