You are here

function apply_for_role_mail in Apply for role 7.2

Same name and namespace in other branches
  1. 8 apply_for_role.module \apply_for_role_mail()

Implements hook_mail()

Parameters

$key:

$message:

$params:

File

./apply_for_role.module, line 850
Allows users to apply for roles.

Code

function apply_for_role_mail($key, &$message, $params) {
  switch ($key) {
    case 'admin':
      $subject = variable_get('apply_for_role_email_admin_subject');
      $body = variable_get('apply_for_role_email_admin_body');

      // place user name in body
      $body = str_replace('%USER', $params['user']->name, $body);
      if (count($params['rid']) > 1) {

        // If multiple roles, break out and put in body.
        $roles = array();
        foreach ($params['rid'] as $rid => $role) {

          // loop through all roles
          $role = user_role_load($rid);
          $roles[] = $role->name;
        }
        $roles = implode(', ', $roles);
        $body = str_replace('%ROLE', $roles, $body);
      }
      else {

        // Single role, just place it in the body
        $role = user_role_load(key($params['rid']));
        $body = str_replace('%ROLE', $role->name, $body);
      }
      break;
    case 'approve':
      $subject = variable_get('apply_for_role_approve_email_subject');
      $body = variable_get('apply_for_role_approve_email_body');
      $role = user_role_load($params['rid']);
      $body = str_replace('%URL', $GLOBALS['base_url'] . base_path(), $body);
      $body = str_replace('%ROLE', $role->name, $body);
      break;
    case 'deny':
      $subject = variable_get('apply_for_role_denial_email_subject');
      $body = variable_get('apply_for_role_denial_email_body');
      $role = user_role_load($params['rid']);
      $body = str_replace('%URL', $GLOBALS['base_url'] . base_path(), $body);
      $body = str_replace('%ROLE', $role->name, $body);
      break;
  }
  $data = array(
    'user' => $params['user'],
  );
  $options['language'] = $message['language'];
  user_mail_tokens($variables, $data, $options);
  $langcode = $message['language']->language;
  $message['subject'] = $subject;
  $message['body'][] = $body;
}