You are here

function apply_for_role_user in Apply for role 5

Same name and namespace in other branches
  1. 6 apply_for_role.module \apply_for_role_user()

Implementation of hook_user().

File

./apply_for_role.module, line 612
Allows users to apply for roles.

Code

function apply_for_role_user($op, &$edit, &$user, $category = NULL) {
  switch ($op) {
    case 'register':

      // Admin created accounts aren't processed by the module.
      if (user_access('administer users')) {
        break;
      }
      if (variable_get('apply_for_role_register', 0)) {
        $filter_roles = array();
        foreach (variable_get('users_apply_roles', array()) as $rid => $role) {
          if ($rid > 2) {
            $filter_roles[$rid] = $role;
          }
        }
        if (count($filter_roles)) {
          $form['apply_for_role'] = array(
            '#type' => 'fieldset',
            '#title' => t('Apply for role'),
            '#collapsible' => FALSE,
          );
          if (variable_get('apply_for_role_multiple', 0) == 0 && variable_get('apply_for_role_register', 0) == 1) {
            $filter_roles[0] = t('--');
            ksort($filter_roles);
          }
          $form['apply_for_role']['rid'] = array(
            '#type' => variable_get('apply_for_role_multiple', 0) ? 'checkboxes' : 'select',
            '#title' => variable_get('apply_for_role_multiple', 0) ? t('Select a role or roles') : t('Select a role'),
            '#options' => $filter_roles,
            '#required' => variable_get('apply_for_role_register', 0) == 2 ? TRUE : FALSE,
          );
        }
        return $form;
      }
      break;
    case 'insert':
      if (variable_get('apply_for_role_register', 0) && !empty($edit['rid'])) {
        apply_for_role_process_applications($user->uid, $edit['rid']);
      }
      break;
    case 'delete':
      db_query("DELETE FROM {users_roles_apply} WHERE uid = %d", $user->uid);
      break;
  }
}