You are here

function _privatemsg_new_preview in Privatemsg 5.3

Same name and namespace in other branches
  1. 5 privatemsg.module \_privatemsg_new_preview()
1 string reference to '_privatemsg_new_preview'
privatemsg_new_form in ./privatemsg.module
Provides a form to write a private message.

File

./privatemsg.module, line 1513

Code

function _privatemsg_new_preview($form, $form_values) {
  if ($form_values['op'] == t('Preview')) {
    $pass = TRUE;
    $recipients = explode(',', $form_values['recipient']);
    foreach ($recipients as $recipient) {
      $recipient = user_load(array(
        'name' => trim($recipient),
      ));
      if (!$recipient->uid) {
        $pass = FALSE;
      }
    }
    if ($pass) {
      global $user;
      $message->subject = $form_values['subject'];
      $message->message = $form_values['privatemsgbody'];
      $message->format = $form_values['format'];
      $message->timestamp = time();
      $message->newmsg = TRUE;
      $message->folder = 1;
      $message->uid = $message->author = $user->uid;
      $message->name = $user->name;
      $message->recipient = implode(', ', $recipients);
      $message->preview = TRUE;

      // Allow other modules to change the message.
      privatemsg_invoke_privatemsg($message, 'view');
      $form['preview'] = array(
        '#prefix' => '<div class="preview">',
        '#value' => theme('privatemsg_view', $message, TRUE),
        '#suffix' => '</div>',
      );
      drupal_set_title(t('Preview message'));
    }
  }
  return $form;
}