You are here

function legal_user_update in Legal 7

Same name and namespace in other branches
  1. 8 legal.module \legal_user_update()
  2. 7.2 legal.module \legal_user_update()
  3. 2.0.x legal.module \legal_user_update()

Implements hook_user_update().

File

./legal.module, line 576
Module file for Legal.

Code

function legal_user_update(&$edit, $account, $category) {
  global $user;
  global $language;

  // We only care about the account category.
  if ($category != 'account') {
    return;
  }
  $conditions = legal_get_conditions($language->language);
  if (empty($conditions['conditions'])) {
    return;
  }

  // Record the accepted state before removing legal_accept from $edit.
  $accepted = isset($edit['legal_accept']) ? $edit['legal_accept'] : FALSE;
  $edit['legal_accept'] = NULL;
  $edit['conditions'] = NULL;
  foreach ($conditions['extras'] as $key => $label) {
    $edit[$key] = NULL;
  }
  if ($account->uid == 1 || $account->uid != $user->uid) {
    return;
  }

  // If already accepted skip data entry.
  $previously_accepted = legal_version_check($account->uid, $conditions['version'], $conditions['revision']);
  if ($previously_accepted === TRUE) {
    return;
  }
  if ($accepted) {
    legal_save_accept($conditions['version'], $conditions['revision'], $conditions['language'], $conditions['tc_id'], $account->uid);
  }
}