You are here

function theme_webform_view_messages in Webform 6.3

Same name and namespace in other branches
  1. 5.2 webform.module \theme_webform_view_messages()
  2. 6.2 webform.module \theme_webform_view_messages()
  3. 7.4 webform.module \theme_webform_view_messages()
  4. 7.3 webform.module \theme_webform_view_messages()

Display a message to a user if they are not allowed to fill out a form.

Parameters

$node: The webform node object.

$teaser: If this webform is being displayed as the teaser view of the node.

$page: If this webform node is being viewed as the main content of the page.

$submission_count: The number of submissions this user has already submitted. Not calculated for anonymous users.

$user_limit_exceeded: Boolean value if the submission limit for this user has been exceeded.

$total_limit_exceeded: Boolean value if the total submission limit has been exceeded.

$allowed_roles: A list of user roles that are allowed to submit this webform.

$closed: Boolean value if submissions are closed.

$cached: Whether the page contents are being cached. Messages that are user-specific should not be shown when the page is cached, otherwise the message may be shown to other users. Some messages should always be shown even if the page is cached, such as "Submissions for this form are closed", because they apply to all users equally.

2 theme calls to theme_webform_view_messages()
webform_client_form_validate in ./webform.module
webform_node_view in ./webform.module
Implements hook_node_view().

File

./webform.module, line 1482

Code

function theme_webform_view_messages($node, $teaser, $page, $submission_count, $user_limit_exceeded, $total_limit_exceeded, $allowed_roles, $closed, $cached) {
  global $user;
  $type = 'status';
  if ($closed) {
    $message = t('Submissions for this form are closed.');
  }
  elseif (array_search(TRUE, $allowed_roles) === FALSE && $user->uid != 1) {
    if (empty($allowed_roles)) {

      // No roles are allowed to submit the form.
      $message = t('Submissions for this form are closed.');
    }
    elseif (isset($allowed_roles[2])) {

      // The "authenticated user" role is allowed to submit and the user is currently logged-out.
      $login = url('user/login', array(
        'query' => drupal_get_destination(),
      ));
      $register = url('user/register', array(
        'query' => drupal_get_destination(),
      ));
      if (variable_get('user_register', 1) == 0) {
        $message = t('You must <a href="!login">login</a> to view this form.', array(
          '!login' => $login,
        ));
      }
      else {
        $message = t('You must <a href="!login">login</a> or <a href="!register">register</a> to view this form.', array(
          '!login' => $login,
          '!register' => $register,
        ));
      }
    }
    else {

      // The user must be some other role to submit.
      $message = t('You do not have permission to view this form.');
      $type = 'error';
    }
  }
  elseif ($user_limit_exceeded && !$cached) {
    if ($node->webform['submit_interval'] == -1 && $node->webform['submit_limit'] > 1) {
      $message = t('You have submitted this form the maximum number of times (@count).', array(
        '@count' => $node->webform['submit_limit'],
      ));
    }
    elseif ($node->webform['submit_interval'] == -1 && $node->webform['submit_limit'] == 1) {
      $message = t('You have already submitted this form.');
    }
    else {
      $message = t('You may not submit another entry at this time.');
    }
    $type = 'error';
  }
  elseif ($total_limit_exceeded && !$cached) {
    if ($node->webform['total_submit_interval'] == -1 && $node->webform['total_submit_limit'] > 1) {
      $message = t('This form has received the maximum number of entries.');
    }
    else {
      $message = t('You may not submit another entry at this time.');
    }
  }

  // If the user has submitted before, give them a link to their submissions.
  if ($submission_count > 0 && $node->webform['submit_notice'] == 1 && !$cached) {
    if (empty($message)) {
      $message = t('You have already submitted this form.') . ' ' . t('<a href="!url">View your previous submissions</a>.', array(
        '!url' => url('node/' . $node->nid . '/submissions'),
      ));
    }
    else {
      $message .= ' ' . t('<a href="!url">View your previous submissions</a>.', array(
        '!url' => url('node/' . $node->nid . '/submissions'),
      ));
    }
  }
  if ($page && isset($message)) {
    drupal_set_message($message, $type, FALSE);
  }
}