Skip to content
privatemsg.module 21.8 KiB
Newer Older
Marco Molinari's avatar
Marco Molinari committed
// $Id$

/**
 * Implementation of hook_help().
 */
function privatemsg_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('Allows private messages between users.');
Marco Molinari's avatar
Marco Molinari committed
}

/**
 * Implementation of hook_link().
 */
function privatemsg_link($type, $arg) {
Tom Dobes's avatar
Tom Dobes committed
  if (user_access('access private messages') && ($type == 'node' || $type == 'comment') && variable_get("privatemsg_link_$type", 0) && (isset($GLOBALS['user']->privatemsg_allow) ? $GLOBALS['user']->privatemsg_allow : 1)) {
    if (user_access('access private messages', $arg) && $arg->privatemsg_allow) {
Tom Dobes's avatar
Tom Dobes committed
      return array(l(t('write to author'), "privatemsg/msgto/$arg->uid"));
/**
 * Implementation of hook_menu().
 */
Tom Dobes's avatar
Tom Dobes committed
function privatemsg_menu($may_cache) {
James Walker's avatar
James Walker committed
  $items = array();
  global $user;
Tom Dobes's avatar
Tom Dobes committed

  if (!$may_cache) {
Tom Dobes's avatar
Tom Dobes committed
    $items[] = array('path' => 'privatemsg',
                     'title' => t('view inbox') . ' ('. (int)_privatemsg_get_new_messages() .')',
                     'callback' => 'privatemsg_page',
                     'access' => user_access('access private messages'),
                     'type' => (isset($user->privatemsg_allow) ? $user->privatemsg_allow : 1) ? MENU_DYNAMIC_ITEM : MENU_CALLBACK);
Tom Dobes's avatar
Tom Dobes committed
  }
James Walker's avatar
James Walker committed
  return $items;
}

/**
 * Implementation of hook_user().
 */
function privatemsg_user($type, $edit, &$user, $category = NULL) {
  switch ($type) {
    case 'view':
Tom Dobes's avatar
Tom Dobes committed
      if (user_access('access private messages') && (isset($user->privatemsg_allow) ? $user->privatemsg_allow : 1)) {
        return array(t('History') => form_item(t('Private messages'), l(t('send private message'), "privatemsg/msgto/$user->uid")));
      }
      else if ($GLOBALS['user']->uid) {
        return;
      }
      else if (isset($user->privatemsg_allow) ? $user->privatemsg_allow : 1) {
        if (variable_get('user_register', 1)) {
          return array(t('History') => form_item(t('Private messages'), t('<a href="%login">login</a> or <a href="%register">register</a> to send private messages to this user', array('%login' => url('user/login'), '%register' => url('user/register')))));
          return array(t('History') => form_item(t('Private messages'), t('<a href="%login">login</a> to send private messages to this user', array('%login' => url('user/login')))));
      }
    case 'form':
      if (user_access('access private messages') && $category == 'account') {
        $output = form_checkbox(t('Allow private messages'), 'privatemsg_allow', 1, isset($edit->privatemsg_allow) ? $edit->privatemsg_allow : (isset($user->privatemsg_allow) ? $user->privatemsg_allow : 1), t('Check this box to allow users to send you private messages.'));
        $output .= form_checkbox(t('Receive daily e-mail for unread messages'), 'privatemsg_mailalert', 1, isset($edit->privatemsg_mailalert) ? $edit->privatemsg_mailalert : (isset($user->privatemsg_mailalert) ? $user->privatemsg_mailalert : 1), t('Check this box to receive e-mail notification for unread messages. Only one e-mail will be sent per day.'));
        return array(array('title' => t('Private message settings'), 'data' => $output));
Marco Molinari's avatar
Marco Molinari committed
  }
Kjartan Mannes's avatar
Kjartan Mannes committed
}
/**
 * Implementation of hook_settings().
 */
Matt Westgate's avatar
Matt Westgate committed
function privatemsg_settings() {
Tom Dobes's avatar
Tom Dobes committed
  $rate = drupal_map_assoc(array(5, 10, 15, 20, 30, 60), 'format_interval');
  $output .= form_select(t('Private messaging max rate'), 'privatemsg_max_rate', variable_get('privatemsg_max_rate', 15), $rate, t('Max submit rate for private messaging. To prevent abuse.'));
  $output .= form_select(t('Sent message status'), 'privatemsg_sent_status', variable_get('privatemsg_sent_status', 1), array(t('Disabled'), t('Enabled')), t('If enabled users can see whether a message has been read or not.'));
  $number = drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100));
Tom Dobes's avatar
Tom Dobes committed
  $output .= form_select(t('Messages per page'), 'privatemsg_per_page', variable_get('privatemsg_per_page', 10), $number, t('The maximum number of messages displayed per page; links to browse messages automatically appear.'));
Tom Dobes's avatar
Tom Dobes committed
  $group = form_checkbox(t('Display link with posts'), 'privatemsg_link_node', 1, variable_get('privatemsg_link_node', 0), t('Provide a link to send private messages to users with posts they start.'));
  $group .= form_checkbox(t('Display link with comments'), 'privatemsg_link_comment', 1, variable_get('privatemsg_link_comment', 0), t('Provide a link to send private messages to users with their comments.'));
  $output .= form_group(t('"Write to author" links'), $group);
/**
 * Implementation of hook_perm().
 */
Marco Molinari's avatar
Marco Molinari committed
function privatemsg_perm() {
Tom Dobes's avatar
Tom Dobes committed
  return array('access private messages');
Marco Molinari's avatar
Marco Molinari committed
}
/**
 * Implementation of hook_cron().
 */
Marco Molinari's avatar
Marco Molinari committed
function privatemsg_cron() {
  // perform these actions just once per day
Tom Dobes's avatar
Tom Dobes committed
  if (variable_get('privatemsg_last_cron', 0) < (time() - 3600*24)) {
Marco Molinari's avatar
Marco Molinari committed
    _privatemsg_prune();
    _privatemsg_mailalert();
Tom Dobes's avatar
Tom Dobes committed
    variable_set('privatemsg_last_cron', time());
Marco Molinari's avatar
Marco Molinari committed
function _privatemsg_prune() {
  // move deleted message older than 1 month to archive table, and optimize table
  $result = db_query("SELECT * FROM {privatemsg} WHERE author_del = 1 AND recipient_del = 1 AND timestamp < '%d'", (time() - 3600*24*30));
Marco Molinari's avatar
Marco Molinari committed
  while ($message = db_fetch_object($result)) {
    db_query("INSERT INTO {privatemsg_archive} (id, author, recipient, subject, message, timestamp, hostname, format, folder) VALUES ('%d', '%d', '%d', '%s', '%s', '%d', '%s', '%d', '%d')", $message->id, $message->author, $message->recipient, $message->subject, $message->message, $message->timestamp, $message->hostname, $message->format, $message->folder);
    db_query("DELETE FROM {privatemsg} WHERE id = '%d'", $message->id);
Marco Molinari's avatar
Marco Molinari committed
  }
Marco Molinari's avatar
Marco Molinari committed
  // this is MySQL-specific
  if ($GLOBALS['db_type'] == 'mysql') {
    db_query("OPTIMIZE TABLE {privatemsg}");
  }
Marco Molinari's avatar
Marco Molinari committed
}
Marco Molinari's avatar
Marco Molinari committed
function _privatemsg_mailalert() {
Tom Dobes's avatar
Tom Dobes committed
  global $locale;
  $initial_locale = $locale;
  if (function_exists('locale')) {
    $languages = locale_supported_languages();
    $languages = $languages['name'];
  }

  $from = variable_get('site_mail', ini_get('sendmail_from'));
  $result = db_query('SELECT COUNT(*) AS c, recipient FROM {privatemsg} WHERE newmsg = 1 AND recipient_del = 0 GROUP BY recipient');
Marco Molinari's avatar
Marco Molinari committed
  while ($alert = db_fetch_object($result)) {
Tom Dobes's avatar
Tom Dobes committed
    $user = user_load(array('uid' => $alert->recipient));

    if ((isset($user->privatemsg_allow) ? $user->privatemsg_allow : 1) && (isset($user->privatemsg_mailalert) ? $user->privatemsg_mailalert : 1)) {
Tom Dobes's avatar
Tom Dobes committed
      // use each user's individual locale
      if (function_exists('locale') && $languages[$user->language]) {
        $locale = $user->language;
      }

      $subject = t('New private messages at %site.', array('%site' => variable_get('site_name', 'drupal')));
      $message = t('Hi %name,
This is an automatic reminder from the site %site. You have %new unread private messages.

To read your messages, follow this link:
%link1

If you don\'t want to receive these email again, change your preferences here:
%link2', array('%name' => $user->name, '%site' => variable_get('site_name', 'drupal'), '%new' => $alert->c, '%link1' => url('privatemsg', NULL, NULL, 1), '%link2' => url('user/'. $user->uid .'/edit', NULL, NULL, 1)));
Tom Dobes's avatar
Tom Dobes committed

      user_mail($user->mail, $subject, $message, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");
Tom Dobes's avatar
Tom Dobes committed

      // revert to previous (site default) locale
      $locale = $initial_locale;
Marco Molinari's avatar
Marco Molinari committed
    }
  }
Marco Molinari's avatar
Marco Molinari committed
function privatemsg_page() {
  global $user;
  $breadcrumb = NULL;
  $op = $_POST["op"];
  $edit = $_POST["edit"];
  $recipient = $_POST["recipient"];
  $msg = $_POST["msg"];
  if (empty($op)) {
Marco Molinari's avatar
Marco Molinari committed
    $op = arg(1);
  }
  $arg = arg(2);
      $output = _privatemsg_list($arg);
Tom Dobes's avatar
Tom Dobes committed
      $title = t('Private messages');
      $output = _privatemsg_view($arg);
      $title = t("Read message");
      $breadcrumb = array(l(t('Home'), ''), l(t('private messages'), 'privatemsg'));
    case t('Write a new message'):
      $output = _privatemsg_form($arg);
      $title = t("Write a new message");
      $breadcrumb = array(l(t('Home'), ''), l(t('private messages'), 'privatemsg'));
Tom Dobes's avatar
Tom Dobes committed
      $msg->recipient = db_result(db_query("SELECT name FROM {users} WHERE uid = '%d'", $arg));
      $output = _privatemsg_form($msg);
      $title = t("Write a new message");
      $breadcrumb = array(l(t('Home'), ''), l(t('private messages'), 'privatemsg'));
    case 'send':
    case t('Send private message'):
      if (!$edit["recipient"]) {
        $edit["recipient"] = $recipient;
      }
      $breadcrumb = array(l(t('Home'), ''), l(t('private messages'), 'privatemsg'));
      $output = _privatemsg_edit($edit);
      break;
    case t('Move to folder'):
      if ($edit["folder"] == 0 || db_result(db_query("SELECT fid FROM {privatemsg_folder} WHERE fid = '%d' AND uid = '%d'", $edit["folder"], $user->uid))) {
        // this folder belongs to him
Marco Molinari's avatar
Marco Molinari committed
        if ($msg) {
          foreach ($msg as $mid) {
            _privatemsg_move($mid, $edit["folder"]);
          $output = _privatemsg_list($edit["folder"]);
          break;
Marco Molinari's avatar
Marco Molinari committed
        }
      $output = _privatemsg_list();
    case t('Delete messages'):
      if ($msg) {
        foreach ($msg as $id) {
          _privatemsg_delete($id);
Marco Molinari's avatar
Marco Molinari committed
        }
      $output = _privatemsg_list();
      _privatemsg_delete($arg);
      $output = _privatemsg_list();
    case t('New folder'):
    case t('Add folder'):
      if ($edit["name"]) {
        // check for uniqueness
        if (!db_result(db_query("SELECT name FROM {privatemsg_folder} WHERE name = '%s' AND uid = '%d'", $edit["name"], $user->uid))) {
          db_query("INSERT INTO {privatemsg_folder} (uid, name) VALUES ('%d', '%s')", $user->uid, $edit["name"]);
        }
        $output = _privatemsg_list();
      }
      else {
        $title = t('Create new folder');
        $breadcrumb = array(l(t('Home'), ''), l('Private messages', 'privatemsg'));
        $output = _privatemsg_new_folder($edit);
      }
      break;

    case t('Delete folder'):
      // check ownership
      if (db_result(db_query("SELECT fid FROM {privatemsg_folder} WHERE fid = '%d' AND uid = '%d'", $edit["current_folder"], $user->uid))) {
        db_query("DELETE FROM {privatemsg_folder} WHERE fid = '%d'", $edit["current_folder"]);
        db_query("UPDATE {privatemsg} SET recipient_del = 1 WHERE folder = '%d'", $edit["current_folder"]);
      }

      $output = _privatemsg_list();
      $fid = $edit["current_folder"];

      if ($fid == 1) {
        db_query("UPDATE {privatemsg} SET author_del = 1 WHERE author = '%d'", $user->uid);
      }
      else if ($fid == 0 || db_result(db_query("SELECT fid FROM {privatemsg_folder} WHERE fid = '%d' AND uid = '%d'", $fid, $user->uid))) {
        // check ownership
        db_query("UPDATE {privatemsg} SET recipient_del = 1 WHERE folder = '%d' AND recipient = '%d'", $edit["current_folder"], $user->uid);
      }

      $output = _privatemsg_list();
      $output = _privatemsg_list();
Tom Dobes's avatar
Tom Dobes committed
      $title = t('Private messages');
Marco Molinari's avatar
Marco Molinari committed
  }
  drupal_set_title($title);
  drupal_set_breadcrumb($breadcrumb);
Tom Dobes's avatar
Tom Dobes committed
  return $output;
function _privatemsg_list($current_folder = 0) {
Marco Molinari's avatar
Marco Molinari committed
  if ($current_folder != 1) {
    $result = pager_query("SELECT id, subject, p.timestamp, u.uid, u.name, newmsg FROM {privatemsg} p, {users} u WHERE p.author = u.uid AND p.recipient = %d AND folder = '%s' AND p.recipient_del = 0 ORDER BY p.timestamp DESC", variable_get("privatemsg_per_page", 10), 0, NULL, $user->uid, $current_folder);
Marco Molinari's avatar
Marco Molinari committed
    if ($current_folder > 0) {
      $folder_name = db_result(db_query("SELECT name FROM {privatemsg_folder} WHERE fid = %d AND uid = %d", $current_folder, $user->uid));
Marco Molinari's avatar
Marco Molinari committed
    }
    else {
      $folder_name = t("Inbox");
Marco Molinari's avatar
Marco Molinari committed
  }
  else {
    // sent messages
    $result = pager_query("SELECT id, subject, p.timestamp, u.uid, u.name, newmsg FROM {privatemsg} p, {users} u WHERE p.recipient = u.uid AND p.author = %d AND p.author_del = 0 ORDER BY p.timestamp DESC", variable_get("privatemsg_per_page", 10), 0, NULL, $user->uid);
Marco Molinari's avatar
Marco Molinari committed
    $folder_name = t("Sent messages");
Marco Molinari's avatar
Marco Molinari committed
  $messages = array();
  while ($message = db_fetch_object($result)) {
    $messages[] = $message;
  }
Marco Molinari's avatar
Marco Molinari committed
  $folders[] = array(0, t("Inbox"));
  $result = db_query("SELECT fid, name FROM {privatemsg_folder} WHERE uid = %d", $user->uid);
Marco Molinari's avatar
Marco Molinari committed
  while ($folder = db_fetch_object($result)) {
    $folders[] = array($folder->fid, $folder->name);
Marco Molinari's avatar
Marco Molinari committed
  $folders[] = array(1, t("Sent messages"));
  return theme("privatemsg_list", $current_folder, $messages, $folders);
Marco Molinari's avatar
Marco Molinari committed
}
Marco Molinari's avatar
Marco Molinari committed
function _privatemsg_format_folder($current, $fid, $name) {
  if ($current == $fid) {
Marco Molinari's avatar
Marco Molinari committed
  }
  else {
    return l($name, "privatemsg/list/$fid");
  }
function _privatemsg_form($message = 0) {
  global $user;
Marco Molinari's avatar
Marco Molinari committed

  if ($message) {
    if (!is_object($message)) {
      $message = db_fetch_object(db_query("SELECT subject, message, u.name FROM {privatemsg} p, {users} u WHERE u.uid = p.author AND id = '%d' AND recipient = '%d'", $message, $user->uid));
      if (!stristr($message->subject, t("Re:"))) {
        $message->subject = t("Re:").' '.$message->subject;
Marco Molinari's avatar
Marco Molinari committed
      }
      $message->message = "\n".str_replace("\n", "\n> ", "\n".$message->message);
Marco Molinari's avatar
Marco Molinari committed
    }
Kjartan Mannes's avatar
Kjartan Mannes committed
  }
  drupal_set_html_head('<style type="text/css" media="all">
#edit-recipient {
  float: left;
}
#edit-quick {
  position: relative;
  top: -1em;
  left: 1em;
}
</style>');

  $form = form_textfield(t("To"), "recipient", $message->recipient, 50, 64);
  $form .= '<select id="edit-quick" name="quick" onChange="document.getElementById(\'edit-recipient\').value=quick.value"><option value="" selected="selected">--'.t("contacts").'--</option>';
  $result = db_query("SELECT DISTINCT(name) AS name FROM {privatemsg} p, {users} u WHERE p.author = u.uid AND recipient = '%d' AND p.timestamp > (UNIX_TIMESTAMP(NOW()) - (3600 * 24 * 30)) ORDER BY name", $user->uid);
  while ($name = db_fetch_object($result)) {
    $name = check_plain($name->name);
    $form .= "<option value='$name'>$name</option>";
Marco Molinari's avatar
Marco Molinari committed
  }
Marco Molinari's avatar
Marco Molinari committed
  $form .= form_textfield(t("Subject"), "subject", $message->subject, 50, 64);
  $form .= form_textarea(t("Message"), "message", $message->message, 80, 5);
  $form .= filter_form('format', $message->format);
  $form .= form_submit(t("Send private message"));
  return form($form);
Marco Molinari's avatar
Marco Molinari committed
function _privatemsg_edit($edit) {
  global $user;
  if ($edit['recipient'] == '') {
    form_set_error('recipient', t('The <em>Recipient</em> field is required.'));
    return _privatemsg_form(array2object($edit));
    $recipient = user_load(array('name' => $edit['recipient']));
  }
  
  if (!$recipient->uid) {
    form_set_error('recipient', t('The <em>Recipient</em> does not exist.'));
    return _privatemsg_form(array2object($edit));
  }
  else if (!(isset($account->privatemsg_allow) ? $account->privatemsg_allow : 1)) {
    form_set_error('recipient', t('%name does not accept private messages.', array('%name' => $account->name)));
    return _privatemsg_form(array2object($edit));
  }
  else if ($edit['subject'] == '') {
    form_set_error('subject', t('The <em>Subject</em> field is required.'));
    return _privatemsg_form(array2object($edit));
  }
  if ($edit['message'] == '') {
    form_set_error('message', t('The <em>Message</em> field is required.'));
    return _privatemsg_form(array2object($edit));
  }
  else if (array_key_exists('format', $edit) && !filter_access($edit['format'])) {
    form_set_error('format', t('The supplied input format is invalid.'));
    return _privatemsg_form(array2object($edit));
  }
  else {
    $result = db_query("INSERT INTO {privatemsg} (author, recipient, subject, message, timestamp, newmsg, hostname, format) VALUES ('%d', '%d', '%s', '%s', '%d', '%d', '%s', '%d')", $user->uid, $recipient->uid, $edit['subject'], $edit['message'], time(), 1, getenv("REMOTE_ADDR"), $edit['format']);
    drupal_set_message(t('Message sent.'));
    return _privatemsg_list();
Marco Molinari's avatar
Marco Molinari committed
function _privatemsg_view($message_id) {
  global $user;
  $result = db_query("SELECT p.id, u.uid, u.name, p.author, p.timestamp, p.subject, p.message, p.newmsg, p.recipient, p.format FROM {privatemsg} p, {users} u WHERE (recipient = '%d' OR author = '%d') AND author = u.uid AND id = '%d'", $user->uid, $user->uid, $message_id);
  if (($message->newmsg) && ($user->uid == $message->recipient)) {
    $result = db_query("UPDATE {privatemsg} SET newmsg = 0 WHERE id = %d", $message_id);
Marco Molinari's avatar
Marco Molinari committed
  }
  return theme("privatemsg_view", $message);
Marco Molinari's avatar
Marco Molinari committed
function _privatemsg_delete($id) {
Marco Molinari's avatar
Marco Molinari committed

  $result = db_query("SELECT author, recipient FROM {privatemsg} WHERE (recipient = %d OR author = %d) AND id = %d", $user->uid, $user->uid, $id);
Marco Molinari's avatar
Marco Molinari committed
  if ($message = db_fetch_object($result)) {
    if ($message->author == $user->uid) {
      db_query("UPDATE {privatemsg} SET author_del = 1 WHERE id = '%d'", $id);
Marco Molinari's avatar
Marco Molinari committed
    }
    if ($message->recipient == $user->uid) {
      db_query("UPDATE {privatemsg} SET recipient_del = 1 WHERE id = '%d'", $id);
Marco Molinari's avatar
Marco Molinari committed
    return true;
Marco Molinari's avatar
Marco Molinari committed
    return false;
Tom Dobes's avatar
Tom Dobes committed
function _privatemsg_get_new_messages($uid = 0) {
  global $user;
  if ($uid == 0) {
    $uid = $user->uid;
  }
  return db_result(db_query("SELECT COUNT(*) FROM {privatemsg} WHERE recipient = '%d' AND newmsg = 1 AND recipient_del = 0", $uid));
Marco Molinari's avatar
Marco Molinari committed
function _privatemsg_new_folder($edit) {
  $form = form_textfield(t("Name"), "name", "", 50, 64);
Marco Molinari's avatar
Marco Molinari committed
  $form .= form_submit(t("Add folder"));
  return form($form);
Marco Molinari's avatar
Marco Molinari committed
function _privatemsg_move($mid, $fid) {
  db_query("UPDATE {privatemsg} SET folder = '%d' WHERE id = '%d' AND recipient = '%d'", $fid, $mid, $user->uid);
/**
  @addtogroup theme_system

  Privatemsg module specific theme functions
  @{
**/

/**
 Returns content to view a private message

 @param message
**/
function theme_privatemsg_view($message) {
  global $user;

  if ($message) {
    $body = "
      <p><strong>".t("From").":</strong> ".format_name($message)."<br />
      <strong>".t("To").":</strong> ".format_name(user_load(array('uid' => $message->recipient)))."<br />
      <strong>".t("Subject").":</strong> ".check_plain($message->subject)."<br />
      <strong>".t("Date").":</strong> ".format_date($message->timestamp)."</p>
      ".check_output($message->message, $message->format);
    if ($message->recipient == $user->uid) {
      $links[] = l(t('Reply to this message'), "privatemsg/reply/$message->id");
    }
    if (($message->recipient == $user->uid) || (variable_get("privatemsg_sent_status", 1))) {
      $links[] = l(t('Delete this message'), "privatemsg/delete/$message->id", array('onClick' => "return confirm('".t('Are you sure to delete this message?')."')"));
    $links[] = l(t('List messages'), 'privatemsg');
    $body .= '<div class="links">'. theme('links', $links) .'</div>';
    drupal_set_message(t('Error: you can\'t read this message'), 'error');
    $body = '';
  }

  return $body;
}

/**
 Returns content to view a list of private messages

 @param current_folder
 @param messages
 @param folders
**/
function theme_privatemsg_list($current_folder, $messages, $folders) {
  $extra_folders = array();
  foreach ($folders as $folder) {
    $folder_list[] = _privatemsg_format_folder($current_folder, $folder[0], $folder[1]);
    if ($folder[0] != 1 && $folder[0] != $current_folder) {
      $extra_folders[$folder[0]] = $folder[1];
    }
  }

  foreach ($messages as $message) {
    $row = array();
    $row[] = array('data' => '<input type="checkbox" name="msg[]" value="'. $message->id .'">');
    }
    else {
      if (variable_get("privatemsg_sent_status", 1)) {
    $row[] = array('data' => format_date($message->timestamp, 'small'));
    $row[] = array('data' => format_name($message));
    $row[] = array('data' => l($message->subject, 'privatemsg/view/'. $message->id) . ($new ? (' '. theme('mark')) : ''));
  if (count($messages) < 1) {
    $out .= t('<p>No messages</p>');
  else {
    $header = array(
      array('data' => ''),
      array('data' => t('Date')),
      array('data' => ($current_folder == 1 ? t('To') : t('From'))),
      array('data' => t('Subject')),
    );

    if ($pager = theme("pager", array(), variable_get("privatemsg_per_page", 10))) {
      $rows[] = array(array('data' => $pager, 'colspan' => 5));
    $out .= theme('table', $header, $rows);
  }
  $out .= '<hr />'. form_submit(t("Write a new message"));
  if (count($messages) > 0) {
    $out .= form_submit(t("Delete messages"), "op", array("onClick" => "return confirm('".t("Are you sure you want to delete these messages?")."')"));
  }
  if ((count($extra_folders) > 0) && ($current_folder != 1) && (count($messages) > 0)) {
    $out .= '<br /><select name="edit[folder]">';
    foreach ($extra_folders as $fid => $folder_name) {
      $out .= "<option value='$fid'>$folder_name</option>";
    }
    $out .= '</select>';
    $out .= form_submit(t("Move to folder"));
  }
  if ($current_folder > 1) {
    // you can't delete Inbox
    $out .= form_submit(t("Delete folder"), "op", array("onClick" => "return confirm('".t("Are you sure you want to delete this folder and all its messages?")."')"));
  if (count($messages) > 0) {
    $out .= form_submit(t("Empty folder"), "op", array("onClick" => "return confirm('".t("Are you sure you want to delete every message in this folder?")."')"));
  }
  $out .= form_hidden("current_folder", $current_folder);
  $out .= form_submit(t("New folder"));
  return form($out);
}

/**  @} End of addtogroup theme_system **/

Marco Molinari's avatar
Marco Molinari committed
?>