function _webform_submission_user_limit_check in Webform 6.3
Same name and namespace in other branches
- 7.3 includes/webform.submissions.inc \_webform_submission_user_limit_check()
Check if the current user has exceeded the limit on this form.
Parameters
$node: The webform node to be checked.
Return value
Boolean TRUE if the user has exceeded their limit. FALSE otherwise.
2 calls to _webform_submission_user_limit_check()
- webform_client_form_validate in ./
webform.module - webform_node_view in ./
webform.module - Implements hook_node_view().
File
- includes/
webform.submissions.inc, line 770 - This file is loaded when handling submissions, either submitting new, editing, or viewing. It also contains all CRUD functions for submissions.
Code
function _webform_submission_user_limit_check($node) {
global $user;
// Check if submission limiting is enabled.
if ($node->webform['submit_limit'] == '-1') {
return FALSE;
// No check enabled.
}
// Retrieve submission data for this IP address or username from the database.
$query = 'SELECT count(*) ' . 'FROM {webform_submissions} ' . "WHERE (( 0 = %d AND remote_addr = '%s') OR (uid > 0 AND uid = %d)) " . 'AND submitted > %d AND nid = %d AND is_draft = 0';
// Fetch all the entries from the database within the submit interval with this username and IP.
$num_submissions_database = db_result(db_query($query, $user->uid, ip_address(), $user->uid, $node->webform['submit_interval'] != -1 ? time() - $node->webform['submit_interval'] : $node->webform['submit_interval'], $node->nid));
// Double check the submission history from the users machine using cookies.
$num_submissions_cookie = 0;
if ($user->uid == 0 && variable_get('webform_use_cookies', 0)) {
$cookie_name = 'webform-' . $node->nid;
if (isset($_COOKIE[$cookie_name]) && is_array($_COOKIE[$cookie_name])) {
foreach ($_COOKIE[$cookie_name] as $key => $timestamp) {
if ($node->webform['submit_interval'] != -1 && $timestamp <= time() - $node->webform['submit_interval']) {
// Remove the cookie if past the required time interval.
$params = session_get_cookie_params();
setcookie($cookie_name . '[' . $key . ']', '', 0, $params['path'], $params['domain'], $params['secure']);
}
}
// Count the number of submissions recorded in cookies.
$num_submissions_cookie = count($_COOKIE[$cookie_name]);
}
else {
$num_submissions_cookie = 0;
}
}
if ($num_submissions_database >= $node->webform['submit_limit'] || $num_submissions_cookie >= $node->webform['submit_limit']) {
// Limit exceeded.
return TRUE;
}
// Limit not exceeded.
return FALSE;
}