You are here

function privatemsg_limits_form_privatemsg_list_alter in Privatemsg 7

Same name and namespace in other branches
  1. 6.2 privatemsg_limits/privatemsg_limits.module \privatemsg_limits_form_privatemsg_list_alter()
  2. 7.2 privatemsg_limits/privatemsg_limits.module \privatemsg_limits_form_privatemsg_list_alter()

Implements hook_form_FORM_ID_alter().

Displays a limit info in the message listing.

File

privatemsg_limits/privatemsg_limits.module, line 164
Privatemsg Quota module

Code

function privatemsg_limits_form_privatemsg_list_alter(&$form, &$form_state) {
  global $user;
  $limit = _privatemsg_limits_get_amount('receive_amount', $form['account']['#value']);
  if ($limit > 0) {
    $used = _privatemsg_limits_get_received($form['account']['#value']);
    if ($used < $limit) {
      $percent = round($used / $limit * 100);
    }
    else {
      $percent = 100;
      if ($user->uid == $form['account']['#value']->uid) {
        if (variable_get('privatemsg_limits_receive_object', 'message') == 'message') {
          $error = t("Your message mailbox is currently full. You are allowed a maximum of %limit messages in your mailbox at one time. You won't be able to send or receive new messages until you delete some existing ones.", array(
            '%limit' => $limit,
          ));
        }
        else {
          $error = t("Your message mailbox is currently full. You are allowed a maximum of %limit conversations in your mailbox at one time. You won't be able to start or receive new conversations until you delete some existing ones.", array(
            '%limit' => $limit,
          ));
        }
      }
      else {
        if (variable_get('privatemsg_limits_receive_object', 'message') == 'message') {
          $error = t("This message mailbox is currently full. !user is allowed a maximum of %limit messages in his mailbox at one time. !user won't be able to send or receive new messages until you delete some existing ones.", array(
            '%limit' => $limit,
            '!user' => theme('username', array(
              'account' => $form['account']['#value'],
            )),
          ));
        }
        else {
          $error = t("This message mailbox is currently full. !user is allowed a maximum of %limit conversations in his mailbox at one time. !user won't be able to start or receive new conversations until you delete some existing ones.", array(
            '%limit' => $limit,
            '!user' => theme('username', array(
              'account' => $form['account']['#value'],
            )),
          ));
        }
      }
      drupal_set_message($error, 'error');
    }
    if (variable_get('privatemsg_limits_receive_object', 'message') == 'message') {
      $message = format_plural($used, 'You are currently using %percent% (@count message) of your %limit messages limit.', 'You are currently using %percent% (@count messages) of your %limit messages limit.', array(
        '%percent' => $percent,
        '%used' => $used,
        '%limit' => $limit,
      ));
    }
    else {
      $message = format_plural($used, 'You are currently using %percent% (@count conversation) of your %limit conversations limit.', 'You are currently using %percent% (@count conversations) of your %limit conversations limit.', array(
        '%percent' => $percent,
        '%used' => $used,
        '%limit' => $limit,
      ));
    }
    $form['limit'] = array(
      '#markup' => $message,
      '#weight' => 15,
    );
  }
}