function uc_addresses_list_addresses in Ubercart Addresses 6
Same name and namespace in other branches
- 5.2 uc_addresses.module \uc_addresses_list_addresses()
- 5 uc_addresses.module \uc_addresses_list_addresses()
Generate a list of one or all addresses defined by one user and then theme the list for display.
If the current user can edit the addresses, then provide an edit link for each address.
Parameters
$address_user The user whose address list we want to display.:
$address The address to display or NULL to display all.:
Return value
The themed list (as a string).
1 string reference to 'uc_addresses_list_addresses'
- uc_addresses_menu in ./
uc_addresses.module - Implementation of hook_menu().
File
- ./
uc_addresses.module, line 690
Code
function uc_addresses_list_addresses($address_user, $address = NULL) {
global $user;
$uid = $address_user->uid;
// Save this for later use
$saved_address = $address;
// Determine if the user can view all addresses or just the default address
$can_view_all_addresses = $user->uid == $uid || user_access(UC_ADDRESSES_ACCESS_VIEW_ALL) || user_access(UC_ADDRESSES_ACCESS_ADD_EDIT);
// Flag to determine error message
$allowed_to_view_address = TRUE;
// If they can view all addresses, fetch the addresses
if ($can_view_all_addresses) {
if ($address) {
$addresses = $address;
}
else {
$addresses = _uc_addresses_db_get_address($uid, NULL);
}
}
else {
if ($address) {
if ($address->is_default === FALSE) {
$addresses = FALSE;
$allowed_to_view_address = FALSE;
}
}
else {
$aid = _uc_addresses_get_default_address_id($uid);
if ($aid === NULL) {
// NULL would mean read all addresses
$aid = 0;
}
$addresses = _uc_addresses_db_get_address($uid, $aid);
if (is_object($addresses) && $addresses->is_default === FALSE) {
$addresses = FALSE;
$allowed_to_view_address = FALSE;
}
}
}
$output = '';
// We have multiple addresses
if (is_array($addresses)) {
foreach ($addresses as $address) {
$output .= _uc_addresses_list_one_address($address);
}
}
elseif (is_object($addresses)) {
$output .= _uc_addresses_list_one_address($addresses);
}
else {
// If they asked for all addresses and got nothing, it's because
// there is nothing
if ($saved_address === NULL) {
$output .= t('No addresses have been saved.<br />');
}
elseif ($allowed_to_view_address) {
$output .= t('This address does not exist.<br />');
}
else {
$output .= t('You are not allowed to view this address.<br />');
}
}
// Decide whether to include a link for adding a new address based
// on whether the current user can edit the addresses
if (user_access(UC_ADDRESSES_ACCESS_ADD_EDIT) || $user->uid == $uid) {
$link = l(t('Add a new address'), 'user/' . $uid . '/addresses/add');
$output .= $link;
}
return $output;
}