You are here

function select_registration_roles_form_submit in Select registration roles 7

Same name and namespace in other branches
  1. 8 select_registration_roles.module \select_registration_roles_form_submit()

Implements hook_form_submit().

1 string reference to 'select_registration_roles_form_submit'
select_registration_roles_form_user_register_form_alter in ./select_registration_roles.module
Implements hook_form_user_register_form_alter().

File

./select_registration_roles.module, line 104
Admin can select roles that will be display on registration form.

Code

function select_registration_roles_form_submit($form, &$form_state) {
  $select_roles = array_filter($form_state['values']['select_roles']);
  $roles = array();
  $uid = $form_state['user']->uid;
  $username = $form_state['user']->name;
  $account = user_load($uid);
  $all_roles = select_registration_roles_get_all_roles();
  $select_roles = array_intersect_key($all_roles, $select_roles);
  foreach ($select_roles as $role_id => $role_name) {
    $roles[$role_id] = $role_name;
    $approval_roles = array_filter(variable_get('select_registration_roles_admin_approval', $roles));
    if (in_array($role_id, $approval_roles)) {
      $account->status = 0;
      $user_approval[$role_id] = $role_name;
      drupal_get_messages('status', TRUE);
      drupal_set_message(t('Thanks for registering, Account has been blocked until approved by administrator.'));
    }
  }
  $key = array_search($roles, $account->roles);
  if ($key == FALSE) {
    $all_role = $account->roles + $roles;
    user_save($account, array(
      'roles' => $all_role,
    ));
  }

  // Send email notification to administrator.
  if (!empty($user_approval)) {
    $params = array(
      'username' => $username,
      'user_approval' => $user_approval,
    );
    $language = language_default();
    $email = variable_get('site_mail', '');
    drupal_mail('select_registration_roles_with_approval', 'registration', $email, $language, $params);
  }
}