You are here

function agreement_init in Agreement 7.2

Same name and namespace in other branches
  1. 6.2 agreement.module \agreement_init()
  2. 6 agreement.module \agreement_init()

Implements hook_init().

File

./agreement.module, line 31
Agreement module code - agreement.module.

Code

function agreement_init() {

  // If the user hasn't already agreed, redirect them to the agreement page.
  global $user;

  // Users with the bypass agreement permission are always excluded from any
  // agreement.
  if (!user_access('bypass agreement')) {
    $path = strtolower(drupal_get_path_alias(current_path()));
    $info = agreement_type_get_best_match($user, $path);
    if ($info) {

      // Save intended destination.
      if (!isset($_SESSION['agreement_destination'])) {
        if (preg_match('/^user\\/reset/i', current_path())) {
          $_SESSION['agreement_destination'] = 'change password';
        }
        else {
          $_SESSION['agreement_destination'] = current_path();
        }
      }
      drupal_goto(check_plain($info['path']));
      exit;
    }
  }
}