You are here

function webform_protected_downloads_hash_is_valid in Webform Protected Downloads 7

Same name and namespace in other branches
  1. 6 webform_protected_downloads.page.inc \webform_protected_downloads_hash_is_valid()

Check if the given hash is valid

Parameters

string $hash:

Return value

void

1 call to webform_protected_downloads_hash_is_valid()
webform_protected_downloads_download_page in ./webform_protected_downloads.page.inc
Displays the download page

File

./webform_protected_downloads.page.inc, line 125

Code

function webform_protected_downloads_hash_is_valid($hash) {
  $sql = "SELECT    expires, access_type, used\n          FROM      {wpd_access_hashes}\n          LEFT JOIN {webform_submissions} USING(sid)\n          LEFT JOIN {wpd_node_configuration} USING(nid)\n          WHERE     hash = :hash";
  $access = db_query($sql, array(
    ':hash' => $hash,
  ))
    ->fetchObject();

  // no hash found, so access is denied
  if (!$access) {
    return FALSE;
  }

  // for access type "single" we deny access if the hash has already been used
  if ($access->access_type == WEBFORM_PROTECTED_DOWNLOADS_ACCESS_TYPE_SINGLE) {
    return $access->used == 0;
  }
  else {

    // otherwise we grant access if the hash has not yet expired
    return $access->expires == 0 || $access->expires > time();
  }
  return FALSE;
}