You are here

function regcode_user in Registration codes 6

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

Implementation of hook_user().

3 calls to regcode_user()
regcode_voucher_submit in regcode_voucher/regcode_voucher.module
Submit handler
regcode_voucher_user in regcode_voucher/regcode_voucher.module
Implementation of hook_user().
regcode_voucher_validate in regcode_voucher/regcode_voucher.module
Validate handler

File

./regcode.module, line 134

Code

function regcode_user($op, &$edit, &$account, $category = NULL) {
  $code_optional = variable_get('regcode_optional', FALSE);
  switch ($op) {
    case 'register':
      $form['regcode'] = array(
        '#type' => 'fieldset',
        '#title' => variable_get('regcode_fieldset_title', t('Registration Code')),
      );
      $form['regcode']['regcode_code'] = array(
        '#type' => 'textfield',
        '#title' => variable_get('regcode_field_title', t('Registration Code')),
        '#description' => variable_get('regcode_field_description', t('Please enter your registration code.')),
        '#required' => !$code_optional,
      );
      if (user_access('bypass registration code entry')) {
        $form['regcode']['regcode_code']['#required'] = FALSE;
      }
      return $form;
      break;
    case 'validate':
      if ($category === 'account' && drupal_strlen(trim($edit['regcode_code']))) {
        $code = regcode_get_code($edit['regcode_code']);
        if (!is_array($code)) {
          form_set_error('regcode_code', regcode_message($code));
          watchdog('regcode', 'User entered invalid registration code (@code)', array(
            '@code' => $edit['regcode_code'],
          ), WATCHDOG_WARNING);
        }
      }
      break;
    case 'insert':

      // Use the code
      $regcode = regcode_get_code($edit['regcode_code'], $account->uid);
      watchdog('regcode', 'The registration code %code was used by !user', array(
        '%code' => $edit['regcode_code'],
        '!user' => l($account->name, 'user/' . $account->uid),
      ));

      // Trigger the event
      foreach (module_implements('regcode_used') as $module) {
        $hook = $module . '_regcode_used';
        $hook($edit, $account, $regcode);
      }

      // Notify rules module
      if (is_array($regcode) && module_exists('rules')) {
        rules_invoke_event('regcode_used', $account, $regcode);
      }

      // Nothing to save
      $edit['regcode_code'] = NULL;
      break;
  }
}