You are here

function privatemsg_view_form in Privatemsg 5.3

Same name and namespace in other branches
  1. 5 privatemsg.module \privatemsg_view_form()

Add the action form to the view message screen.

1 string reference to 'privatemsg_view_form'
theme_privatemsg_view in ./privatemsg.module
Returns content to view a private message.

File

./privatemsg.module, line 1850

Code

function privatemsg_view_form($message) {
  global $user;
  $form['pm_id'] = array(
    '#type' => 'hidden',
    '#value' => $message->id,
  );
  $form['pm_fid'] = array(
    '#type' => 'hidden',
    '#value' => $message->folder,
  );
  $form['author'] = array(
    '#type' => 'value',
    '#value' => $message->author,
  );
  $form['js_bypass'] = array(
    '#type' => 'hidden',
    '#value' => 0,
  );
  $form['actions'] = array(
    '#type' => 'fieldset',
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#attributes' => array(
      'class' => 'container-inline',
    ),
  );
  $form['actions']['text'] = array(
    '#value' => '<div><strong>' . t('With this message:') . '</strong> </div>',
  );
  if ($user->uid == $message->recipient) {
    $form['actions']['reply'] = array(
      '#type' => 'submit',
      '#value' => t('Reply'),
      '#attributes' => array(
        'class' => 'pm-spacer',
      ),
    );
  }
  $del = variable_get('privatemsg_actions_loc', '1');
  if ($del == '1') {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
      '#prefix' => ' &nbsp; &nbsp;',
      '#attributes' => array(
        'class' => 'pm-add-delete pm-spacer',
      ),
    );
  }
  $folders = privatemsg_load_folders($user->uid);
  if (user_access('create new folder')) {
    $extra_folders = array();
    foreach ($folders as $folder) {

      // Do not display the recycle bin in the move to folder drop down as the
      // delete button is already available. Similarly, avoid displaying
      // the sent items folder as it is for internal use only.
      if ($folder['fid'] != PRIVATEMSG_FOLDER_SENT && $folder['fid'] != PRIVATEMSG_FOLDER_RECYCLE_BIN && $folder['fid'] != $message->folder) {
        $extra_folders[$folder['fid']] = $folder['name'];
      }
    }
    $extra_folders['new'] = t('New folder...');
    if ($user->uid == $message->recipient) {
      $form['actions']['folder'] = array(
        '#type' => 'select',
        '#options' => $extra_folders,
        '#attributes' => array(
          'class' => 'pm-spacer',
        ),
      );
      $form['actions']['extra_folders'] = array(
        '#type' => 'value',
        '#value' => $extra_folders,
      );
      $form['actions']['move_messages'] = array(
        '#type' => 'submit',
        '#value' => t('Move to folder'),
      );
    }
  }
  if ($del == '2') {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
      '#prefix' => ' &nbsp; &nbsp;',
      '#attributes' => array(
        'class' => 'pm-add-delete pm-spacer',
      ),
    );
  }

  // only add the JS once, otherwise we get dupllicated JS confirm messages on thread views
  static $count = 0;
  if ($count == 0) {
    $js = array(
      'deleteMessage' => t('Are you sure you want to delete this message?'),
    );
    drupal_add_js(drupal_get_path('module', 'privatemsg') . '/privatemsg.js');
    drupal_add_js(array(
      'privatemsg' => $js,
    ), 'setting');
    ++$count;
  }
  return $form;
}