View source
<?php
define('SUBUSER_ITEMS_PER_PAGE', 50);
function subuser_ui_access_list_page_callback($account) {
global $user;
$acct_uid = is_object($account) ? $account->uid : $account;
if ($acct_uid) {
if ($user->uid == $acct_uid || user_access('administer users') || user_access('view subusers', $user)) {
return TRUE;
}
}
return FALSE;
}
function subuser_ui_list_page($account) {
$edit_access = FALSE;
$delete_access = FALSE;
$edit_header = array();
$delete_header = array();
$data = array();
$suids = subuser_load_all($account);
if (empty($suids)) {
return t("User doesn't have any subusers.");
}
foreach ($suids as $suid) {
$subuser = user_load($suid);
$values[] = $subuser;
$users_roles = array();
$roles = array_map('check_plain', user_roles(TRUE));
foreach ($subuser->roles as $rid => $user_role) {
$users_roles[] = $roles[$rid];
}
asort($users_roles);
$data['rows'][$subuser->uid] = array(
'name' => array(
'data' => $subuser->name,
'class' => 'name',
),
'mail' => array(
'data' => $subuser->mail,
'class' => 'mail',
),
'roles' => array(
'data' => theme('item_list', array(
'items' => $users_roles,
)),
'class' => 'roles',
),
'access' => array(
'data' => $subuser->access ? t('@time ago', array(
'@time' => format_interval(REQUEST_TIME - $subuser->access),
)) : t('never'),
'class' => 'access',
),
'status' => array(
'data' => $subuser->status ? t('Active') : t('Blocked'),
'class' => 'status',
),
);
if (subuser_access_edit_callback($subuser->uid)) {
$data['rows'][$subuser->uid]['edit'] = array(
'data' => l(t('Edit'), sprintf('user/%s/edit', $subuser->uid)),
'class' => 'edit',
);
$edit_access = TRUE;
}
if (subuser_access_delete_callback($subuser->uid)) {
$data['rows'][$subuser->uid]['delete'] = array(
'data' => l(t('Delete'), sprintf('user/%s/cancel', $subuser->uid)),
'class' => 'delete',
);
$delete_access = TRUE;
}
}
if ($edit_access) {
$edit_header = array(
'data' => t('Edit'),
'class' => 'edit',
);
}
if ($delete_access) {
$delete_header = array(
'data' => t('Delete'),
'class' => 'delete',
);
}
$data['header'] = array(
'name' => array(
'data' => t('Name'),
'class' => 'name',
),
'mail' => array(
'data' => t('Mail'),
'class' => 'mail',
),
'roles' => array(
'data' => t('Roles'),
'class' => 'roles',
),
'access' => array(
'data' => t('Last access'),
'class' => 'access',
),
'status' => array(
'data' => t('Status'),
'class' => 'status',
),
'edit' => $edit_header,
'delete' => $delete_header,
);
$data['per_page'] = SUBUSER_ITEMS_PER_PAGE;
drupal_alter('subuser_ui_data', $data);
$current_page = pager_default_initialize(count($data['rows']), $data['per_page']);
$chunks = array_chunk($data['rows'], $data['per_page'], TRUE);
$table = theme('table', array(
'header' => $data['header'],
'rows' => $chunks[$current_page],
));
$output = theme('subuser_list_item', array(
'content' => $table,
'values' => $values,
));
$output .= theme('pager', array(
'quantity',
count($data['rows']),
));
return $output;
}
function subuser_ui_theme() {
return array(
'subuser_list_item' => array(
'variables' => array(
'content' => NULL,
'values' => NULL,
),
),
);
}
function theme_subuser_list_item($variables) {
return theme('html_tag', array(
'element' => array(
'#tag' => 'div',
'#attributes' => array(
'class' => 'subuser_listing',
),
'#value' => $variables['content'],
),
));
}