function user_external_invite_pending_invites_form in User External Invite 7.2
Same name and namespace in other branches
- 7 user_external_invite.module \user_external_invite_pending_invites_form()
- 1.0.x user_external_invite.module \user_external_invite_pending_invites_form()
Build table showing pending invites.
2 string references to 'user_external_invite_pending_invites_form'
- user_external_invite_menu in ./
user_external_invite.module - Implements hook_menu().
- user_external_invite_operations_page in ./
user_external_invite.module - Page callback for admin/people/invite/operations.
File
- ./
user_external_invite.module, line 109 - Invites a user to site when connecting via external protocol e.g. LDAP.
Code
function user_external_invite_pending_invites_form($form, &$form_state) {
$form = array();
$headers = array(
'id' => t('ID'),
'mail' => t('Email'),
'role' => t('Role'),
'expire' => t('Expires'),
'inviter' => t('Inviter'),
'status' => t('Status'),
);
$rids = variable_get('user_external_invite_roles', NULL);
if (!empty($rids)) {
foreach ($rids as $rid) {
$roles[$rid] = _user_external_invite_role_name_from_rid($rid);
}
}
$pending = _user_external_invite_pending_invites(NULL);
$rows = array();
while ($r = $pending
->fetchObject()) {
$inviter = user_load($r->uid);
$rows[] = array(
'id' => $r->id,
'mail' => $r->mail,
'role' => $roles[$r->rid],
'expire' => format_date($r->expire, 'short'),
'inviter' => $inviter->mail,
'status' => $r->status,
);
}
// Determine whether or not to display confirm form message.
if (!isset($form_state['storage']['confirm'])) {
// Add operations only if rows are present.
if (!empty($rows)) {
// Add container for operations functionality.
$form['operations'] = array(
'#type' => 'fieldset',
'#title' => 'Operations',
);
// Add select list for choosing operations.
$select_options = array(
'cancel' => 'Cancel Invites',
'resend' => 'Resend Invites',
);
$form['operations']['select'] = array(
'#type' => 'select',
'#options' => $select_options,
'#default_value' => $select_options['cancel'],
);
$form['operations']['resend_message'] = array(
'#type' => 'textarea',
'#title' => t('Custom Message'),
'#cols' => 40,
'#rows' => 5,
'#description' => t('Message sent to users being re-invited. The rest of the email will include the "Invitation Email Template" text.'),
'#states' => array(
'visible' => array(
':input[name="select"]' => array(
'value' => 'resend',
),
),
),
);
// Add submit button for operations.
$form['operations']['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
$form['table'] = array(
'#type' => 'tableselect',
'#header' => $headers,
'#options' => $rows,
'#suffix' => empty($rows) ? 'No pending invites.' : '',
'#weight' => 10,
);
$form['pager'] = array(
'#theme' => 'pager',
'#weight' => 11,
);
}
else {
drupal_set_message(t('No invites available.'), 'status');
}
return $form;
}
else {
// Get operation being performed for message to user.
$operation = $form_state['values']['select'];
// Count the number of invites for user message.
$num_invites = 0;
foreach ($form_state['input']['table'] as $value) {
if ($value != NULL) {
$num_invites += 1;
}
}
// Determine if there are multiple invites for message display.
$plural = $num_invites > 1 ? 'invites' : 'invite';
// Need to pass current path and message variables to
// confirm_form() function.
$path = current_path();
return confirm_form($form, 'Do you really want to ' . $operation . ' invites?', $path, $description = 'By proceeding you will ' . $operation . ' ' . $num_invites . ' ' . $plural . '. This action can not be undone.', 'Proceed', 'Cancel');
}
}