You are here

function oa_users_register_external_user_modal in Open Atrium Core 7.2

This is the page callback for "oa_users/add/%ctools_js/%node".

Parameters

bool|FALSE $js:

$group:

Return value

array|mixed

1 string reference to 'oa_users_register_external_user_modal'
oa_users_menu in modules/oa_users/oa_users.module
Implements hook_menu().

File

modules/oa_users/plugins/content_types/oa_users_add_external_user.inc, line 80

Code

function oa_users_register_external_user_modal($js = FALSE, $group = NULL) {
  $group = !empty($group) ? $group : node_load(oa_core_get_space_context());
  if (empty($group) && !node_access('view', $group) || !og_user_access('node', $group->nid, 'add external user')) {
    return;
  }

  // This is kind of hacky but there really isn't a good way to get the underlying page url.
  if ($group->type == OA_SPACE_TYPE) {

    // If it's an oa_space then we know we came from the members page.
    $url = 'node/' . $group->nid . '/members';
  }
  else {
    if ($group->type == OA_TEAM_TYPE || $group->type == OA_GROUP_TYPE) {

      // If it's an oa_team then we came from the team node.
      $url = 'node/' . $group->nid;
    }
  }
  if ($js) {
    ctools_include('ajax');
    ctools_include('modal');
    ctools_modal_add_js();
    $form_state = array(
      'ajax' => TRUE,
      'title' => t('Add external user to ' . $group->title),
    );
    $form_state['#group'] = $group;

    // Build the form for the modal.
    $output = ctools_modal_form_wrapper('oa_users_external_user_form', $form_state);

    // If we don't find the form or it has already been submitted.
    if (empty($output) || $form_state['executed']) {
      $output = array();

      // Give the user something so they know the modal will close and the page will reload.
      // @todo: This would be better if we just added a loader.
      $output[] = ctools_modal_command_display('', '<h2>Processing...</h2>');
      $output[] = ctools_modal_command_loading();
      $output[] = ctools_ajax_command_redirect($url);
    }

    // Render the output and exit.
    print ajax_render($output);
    drupal_exit();
  }
  else {
    return drupal_get_form('oa_users_external_user_form');
  }
}