You are here

function _webform_ajax_perm in Webform Ajax 6

The access callback for hook_menu item 'webform_ajax/%/%'.

Parameters

$nid: the node id of the current webform.:

Return value

TRUE if user has access to use this webform, FALSE if not.

1 string reference to '_webform_ajax_perm'
webform_ajax_menu in ./webform_ajax.module
Implementation of hook_menu().

File

./webform_ajax.module, line 29
Makes webform pages load by AJAX instead of causing a full page refresh.

Code

function _webform_ajax_perm($nid = NULL) {
  if (!$nid) {
    return FALSE;
  }
  $node = node_load($nid);
  global $user;
  $enabled = TRUE;

  // Check if the user's role can submit this webform.
  if (variable_get('webform_submission_access_control', 1)) {
    $allowed_roles = array();
    foreach ($node->webform['roles'] as $rid) {
      $allowed_roles[$rid] = isset($user->roles[$rid]) ? TRUE : FALSE;
    }
    if (array_search(TRUE, $allowed_roles) === FALSE && $user->uid != 1) {
      $enabled = FALSE;
    }
  }

  // Check if the user can add another submission.
  if ($node->webform['submit_limit'] != -1) {

    // -1: Submissions are never throttled.
    module_load_include('inc', 'webform', 'includes/webform.submissions');

    // Disable the form if the limit is exceeded and page cache is not active.
    if (($limit_exceeded = _webform_submission_limit_check($node)) && ($user->uid != 0 || variable_get('cache', CACHE_DISABLED) == CACHE_DISABLED)) {
      $enabled = FALSE;
    }
  }

  // If editing a submission, load the submission object
  $sid = $_POST['details']['sid'];
  if ($sid) {
    $submission = webform_menu_submission_load($sid, $nid);
    $enabled = $enabled && webform_submission_access($node, $submission, 'edit');
  }
  return $enabled;
}