You are here

function uc_addresses_user in Ubercart Addresses 5.2

Same name and namespace in other branches
  1. 5 uc_addresses.module \uc_addresses_user()
  2. 6.2 uc_addresses.module \uc_addresses_user()
  3. 6 uc_addresses.module \uc_addresses_user()

Implementation of hook_user().

Parameters

$op An integer representing the action being performed.:

$edit An array of form values submitted by the user.:

$account The user on which the operation is being performed.:

$category The active category of user information being edited.:

File

./uc_addresses.module, line 189

Code

function uc_addresses_user($op, &$edit, &$account, $category = NULL) {
  global $user;
  switch ($op) {
    case 'view':

      // When viewing the basic user information, all we do is add a
      // nice little message for the account holder, so that's all we
      // need to check
      if ($user->uid == $account->uid) {
        $items = array();
        $items['addresses'] = array(
          'value' => l(t('Click here to manage your addresses.'), 'user/' . $account->uid . '/addresses'),
          'class' => 'member',
        );
        return array(
          t('Addresses') => $items,
        );
      }
      else {
        return NULL;
      }
    case 'register':

      // For registration, we may want the user to enter his default
      // address
      if (variable_get('uc_addresses_require_address', TRUE)) {
        $form = uc_addresses_pane_address('new', NULL, $edit);
        $form = array(
          $form['contents'],
        );

        // Modify to what we need
        $form[0]['#title'] = t('Address');

        // Rename the fieldset
        return $form;
      }
    case 'insert':

      // We're about to add the user to the database, so get the address
      // info and add it to the address table
      $address = (object) $edit;
      $address->is_default = 0;
      _uc_addresses_db_add_address($address);
      return;
    case 'delete':

      // We're deleting the user, so delete all his/her addresses as
      // well
      db_query("DELETE FROM {uc_addresses} WHERE uid = %d", $account->uid);
      db_query("DELETE FROM {uc_addresses_defaults} WHERE uid = %d", $account->uid);
      return;
  }
}