You are here

function og_ui_og_user_operations in Organic groups 7

Implement hook_og_user_operations().

File

og_ui/og_ui.module, line 517
Organic groups UI.

Code

function og_ui_og_user_operations($form = array(), $form_state = array()) {
  $gid = $form_state['group']->gid;
  $operations = array(
    'unblock' => array(
      'label' => t('Approve membership of the selected users'),
      'callback' => 'og_ui_user_operations_approve',
    ),
    'deny' => array(
      'label' => t('Deny membership from the selected users'),
      'callback' => 'og_ui_user_operations_deny',
    ),
    'block' => array(
      'label' => t('Block membership from the selected users'),
      'callback' => 'og_ui_user_operations_block',
    ),
  );
  if (og_user_access($gid, 'administer group')) {
    $roles = og_roles($gid);
    $add_roles = array();
    foreach ($roles as $rid => $name) {
      if (!in_array($name, array(
        OG_ANONYMOUS_ROLE,
        OG_AUTHENTICATED_ROLE,
      ))) {
        $add_roles['add_role-' . $rid] = strip_tags($name);
      }
    }
    $remove_roles = array();
    foreach ($roles as $rid => $name) {
      if (!in_array($name, array(
        OG_ANONYMOUS_ROLE,
        OG_AUTHENTICATED_ROLE,
      ))) {
        $remove_roles['remove_role-' . $rid] = strip_tags($name);
      }
    }
    if ($add_roles) {
      $role_operations = array(
        t('Add a role to the selected users') => array(
          'label' => $add_roles,
        ),
        t('Remove a role from the selected users') => array(
          'label' => $remove_roles,
        ),
      );
      $operations += $role_operations;
    }
  }

  // If the form has been posted, we need to insert the proper data for
  // role editing if necessary.
  if (!empty($form_state['submitted'])) {
    $operation_rid = explode('-', $form_state['values']['operation']);
    $operation = $operation_rid[0];
    if ($operation == 'add_role' || $operation == 'remove_role') {
      $rid = $operation_rid[1];
      if (og_user_access($gid, 'administer group')) {
        $operations[$form_state['values']['operation']] = array(
          'callback' => 'og_ui_user_multiple_role_edit',
          'callback arguments' => array(
            $operation,
            $rid,
          ),
        );
      }
      else {
        watchdog('security', 'Detected malicious attempt to alter protected user fields.', array(), WATCHDOG_WARNING);
        return;
      }
    }
  }
  return $operations;
}