You are here

function invite_form in Invite 7.2

Same name and namespace in other branches
  1. 5.2 invite.module \invite_form()
  2. 5 invite.module \invite_form()
  3. 6.2 invite.module \invite_form()
  4. 7.4 includes/invite.admin.inc \invite_form()

Generate the invite forms.

Parameters

$form_state: A keyed array containing the current state of the form.

$op: The type of form to generate, 'page' or 'block'.

$edit: Previous values when resending an invite.

Return value

A form definition.

3 string references to 'invite_form'
invite_block_view in ./invite.module
Implements hook_block_view().
invite_menu in ./invite.module
Implements hook_menu().
invite_resend in ./invite.pages.inc
Menu callback; resend an expired invite.

File

./invite.module, line 858
Allows your users to send and track invitations to join your site.

Code

function invite_form($form, &$form_state, $op = 'page', $edit = array()) {
  global $user;

  // Show registration links when the form has been submitted using the Show registration link button.
  if (!empty($form_state['invite_show_reg_links'])) {
    $headers = array(
      t('E-mail'),
      t('Registration link'),
    );
    $rows = array();
    foreach ($form_state['invite_processed_invites'] as $invite) {
      $rows[] = array(
        check_plain($invite->email),
        url('invite/accept/' . $invite->reg_code, array(
          'absolute' => TRUE,
        )),
      );
    }
    if ($user->uid && user_access('track invitations')) {
      $reg_link_note = t('You can later view the links in the list of your !link.', array(
        '!link' => l('invites', 'user/' . $user->uid . '/invites/pending'),
      ));
    }
    else {
      $reg_link_note = t('Save the links now, because you will not be able to retrieve them once you leave this page.');
    }
    $form['reg_links'] = array(
      '#type' => 'fieldset',
      '#title' => t('Registration links for invitees'),
      '#description' => format_plural(count($form_state['invite_processed_invites']), 'Below is the registration link for the newly created invitation. Give this link to the invitee - he/she will need it to use the invitation and register.', 'Below are the registration links for the newly created invitations. Give these links to the invitees - they will need them to use their invitations and register.') . ' ' . $reg_link_note,
    );
    $form['reg_links']['links_table'] = array(
      '#markup' => theme('table', array(
        'header' => $headers,
        'rows' => $rows,
        'attributes' => array(
          'id' => 'invite-reg-links',
        ),
      )),
    );

    // Clear the form.
    unset($form_state['input']);
  }
  $form['#op'] = $op;
  if (!is_array($edit)) {
    $edit = (array) $edit;
  }
  $remaining_invites = invite_get_remaining_invites($user);
  if ($remaining_invites == 0) {
    if ($op == 'block') {

      // Hide block.
      $form['#access'] = FALSE;
      return $form;
    }
  }
  $form['reg_code'] = array(
    '#type' => 'value',
    '#value' => $edit ? $edit['reg_code'] : NULL,
  );
  if ($remaining_invites != INVITE_UNLIMITED) {
    $form['remaining_invites'] = array(
      '#type' => 'value',
      '#value' => $remaining_invites,
    );
  }
  switch ($op) {
    case 'page':
    default:
      $form += invite_page_form($remaining_invites, $edit);
      break;
    case 'block':
      $form += invite_block_form($remaining_invites);
      break;
  }
  return $form;
}