autoassignrole_user

Versions
6
autoassignrole_user($op, &$edit, &$account, $category = NULL)

Implementation of hook_user().

Code

contributions/autoassignrole/autoassignrole.module, line 152

<?php
function autoassignrole_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'insert':
      // If this is an administrator creating the account only use auto_assign if
      // allowed by auto_admin_active
      if (arg(0) == 'admin' && _autoassignrole_get_settings('auto_admin_active') == 0) {
        return;
      }
      $rolenames = user_roles();
      if (_autoassignrole_get_settings('user_active') == 1) {
        $roles = array();
        $user_roles = _autoassignrole_get_settings('user_roles');
        if (is_array($edit['user_roles'])) {
          foreach ($edit['user_roles'] as $k => $v) {
            if ($v != 0 && in_array($k, $user_roles, TRUE)) {
              $roles[$k] = $v;
            }
          }
          $edit['roles'] = $roles;
        }
        elseif ($edit['user_roles'] != '') {
          $edit['roles'] = array($edit['user_roles'] => $edit['user_roles']);
        }
      }
      if ($rid = autoassignrole_get_active_path_rid()) {
        $edit['roles'][$rid] = $rolenames[$rid];
      }
      if (_autoassignrole_get_settings('auto_active') == 1) {
        $auto_roles = _autoassignrole_get_settings('auto_roles');
        foreach ($auto_roles as $k => $v) {
          $edit['roles'][$k] = $rolenames[$k];
        }
      }
      $account = user_load(array("uid" => $account->uid));
    break;
    case 'register':
      if (_autoassignrole_get_settings('user_active') == 1) {
        $roles = user_roles(TRUE);
        $user_roles = _autoassignrole_get_settings('user_roles');
        $path_roles = db_query("SELECT rid from {autoassignrole_page}");
        while ($path_role = db_fetch_object($path_roles)) {
          unset($roles[$path_role->rid]);
        }
        foreach ($roles as $k => $r) {
          if (!in_array($k, $user_roles, TRUE)) {
            unset($roles[$k]);
          }
        }
        if (count($roles)) {
         $form['autoassignrole_user'] = array(
           '#type' => 'fieldset',
           '#title' => _autoassignrole_get_settings('user_fieldset_title'),
           '#collapsible' => FALSE,
           '#collapsed' => FALSE,
         );
         if (_autoassignrole_get_settings('user_sort') == "SORT_ASC") {
           uasort($roles, '_autoassignrole_array_asc');
         }
         else {
           uasort($roles, '_autoassignrole_array_desc');
         }

         if (!$edit || !array_key_exists('user_roles', $edit)) {
           $edit['user_roles'] = array();
         }
         if (_autoassignrole_get_settings('user_selection') == 0) {
           $form['autoassignrole_user']['user_roles'] = array(
             '#type' => 'radios',
             '#title' => t(_autoassignrole_get_settings('user_title')),
             '#options' => $roles,
             '#description' => t(_autoassignrole_get_settings('user_description')),
           );
         }
         if (_autoassignrole_get_settings('user_selection') == 1) {
           $form['autoassignrole_user']['user_roles'] = array(
             '#type' => 'select',
             '#title' => t(_autoassignrole_get_settings('user_title')),
             '#default_value' => '',
             '#description' => t(_autoassignrole_get_settings('user_description')),
           );

           if (_autoassignrole_get_settings('user_multiple')) {
             $form['autoassignrole_user']['user_roles']['#multiple'] = TRUE;
             unset($form['autoassignrole_user']['user_roles']['#default_value']);
           }
           else {
             $roles[''] = '';
           }
           $form['autoassignrole_user']['user_roles']['#options'] = $roles;
         }
         if (_autoassignrole_get_settings('user_selection') == 2) {
           $form['autoassignrole_user']['user_roles'] = array(
             '#type' => 'checkboxes',
             '#title' => t(_autoassignrole_get_settings('user_title')),
             '#default_value' => $edit['user_roles'],
             '#options' => $roles,
             '#description' => _autoassignrole_get_settings('user_description'),
           );
         }
         if (_autoassignrole_get_settings('user_required')) {
           $form['autoassignrole_user']['user_roles']['#required'] = TRUE;
         }
         return $form;
        }
      }
    break;
  }
}
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters (without spaces) shown in the image.