You are here

function user_external_invite_pending_invites_form_submit in User External Invite 1.0.x

Same name and namespace in other branches
  1. 7.2 user_external_invite.module \user_external_invite_pending_invites_form_submit()
  2. 7 user_external_invite.module \user_external_invite_pending_invites_form_submit()

Submit callback for user_external_invite_pending_invites_form().

Parameters

array $form: The form being used to edit the node.

array $form_state: The form state array.

File

./user_external_invite.module, line 237
Invites a user to site when connecting via external protocol e.g. LDAP.

Code

function user_external_invite_pending_invites_form_submit(&$form, &$form_state) {

  // If the user has confirmed the form operation, proceed.
  if (isset($form_state['storage']['confirm'])) {

    // Define variable.
    $table_options = $form_state['storage']['form']['table']['#options'];
    $selected_options = $form_state['storage']['form_state']['input']['table'];
    $operation = $form_state['storage']['form_state']['values']['select'];
    $message = $form_state['storage']['form_state']['values']['resend_message'];
    $ids = array();

    // Loop through selected rows and match with invite IDs.
    foreach ($selected_options as $key => $option) {
      if ($option != NULL) {
        $ids[] = $table_options[$key]['id'];
      }
    }

    // If no IDs passed then return with error message.
    if (empty($ids)) {
      drupal_set_message(t('No invites selected for operation. Please select desired invites and try again.'), 'error');
      return;
    }

    // Pass IDs into corresponding callback function.
    switch ($operation) {
      case 'cancel':
        user_external_invite_cancel_invites($ids);
        break;
      case 'resend':

        // Adding additional message to send to invitees.
        user_external_invite_resend_invites($ids, $message);

        // Set message to user about successful resent invites.
        // @todo Handle this better for possible errors. We're assuming invites were sent.
        $num_invites = count($ids);
        $plural_invites = $num_invites > 1 ? 'invites' : 'invite';
        drupal_set_message(t('Successfully resent :number user :invites.', array(
          ':number' => $num_invites,
          ':invites' => $plural_invites,
        )));
        break;
      default:
        break;
    }
  }
  else {
    $form_state['storage']['form_state'] = $form_state;
    $form_state['storage']['form'] = $form;

    // This will cause the form to be rebuilt
    // returning to the confirm part of the form.
    $form_state['storage']['confirm'] = TRUE;
    $form_state['rebuild'] = TRUE;
  }
}