You are here

function regcode_user in Registration codes 5.3

Same name and namespace in other branches
  1. 5 regcode.module \regcode_user()
  2. 6.2 regcode.module \regcode_user()
  3. 6 regcode.module \regcode_user()

Act on user account actions.

Parameters

$op: The type of action is being performed.

$edit: The array of form values submitted by the user.

$account: The user object on which the operation is being performed.

$category: The active category of user information being edited.

Return value

This varies depending on the operation.

File

./regcode.module, line 153
The main module file of the registration code module

Code

function regcode_user($op, &$edit, &$account, $category = NULL) {
  $code = trim($edit['regcode_code']);
  $code_required = TRUE;
  if (variable_get('regcode_optional', 0)) {
    $code_required = FALSE;
  }
  if (user_access('bypass registration code entry')) {
    $code_required = FALSE;
  }
  switch ($op) {
    case 'register':

      // Inject the registration code field into the registration form.
      $form['regcode_code'] = array(
        '#type' => 'textfield',
        '#title' => t(variable_get('regcode_fieldtitle', 'Registration Code')),
        '#description' => t(variable_get('regcode_fielddescription', 'Please enter your registration code.')),
        '#required' => $code_required,
      );
      return $form;
      break;
    case 'validate':
      if ($category == 'account' && !$account->uid) {

        // Make sure that the entered code is valid (if option is set)
        if ($code_required) {
          require_once 'regcode_admin.inc.php';
          $code = regcode_get_code($code);
          if (!is_array($code)) {
            form_set_error('regcode_code', t('Invalid !title', array(
              '!title' => variable_get('regcode_fieldtitle', 'registration code'),
            )) . ' - ' . t(regcode_message('VALIDITY_ERROR', $code)));
            watchdog('regcode', t('User entered invalid registration code: ') . ' ' . $edit['regcode_code'] . " ({$code} - " . regcode_message('VALIDITY_ERROR', $code) . ")", WATCHDOG_WARNING);
          }
        }
      }
      break;
    case 'insert':
      require_once 'regcode_admin.inc.php';
      $code = regcode_get_code($code, $account->uid);
      if (is_array($code)) {
        $edit['roles'][$code['rid']] = array();
      }
      break;
  }

  // switch
}