You are here

function privatemsg_user in Privatemsg 6

Same name and namespace in other branches
  1. 5.3 privatemsg.module \privatemsg_user()
  2. 5 privatemsg.module \privatemsg_user()
  3. 6.2 privatemsg.module \privatemsg_user()

File

./privatemsg.module, line 1407
Allows users to send private messages to other users.

Code

function privatemsg_user($op, &$edit, &$account, $category = NULL) {
  global $user;
  switch ($op) {
    case 'view':
      if ($url = privatemsg_get_link(array(
        $account,
      ))) {
        $account->content['privatemsg_send_new_message'] = array(
          '#type' => 'markup',
          '#value' => l(t('Send this user a message'), $url, array(
            'query' => drupal_get_destination(),
          )),
          '#weight' => 10,
        );
      }
      break;
    case 'login':
      if (variable_get('privatemsg_display_loginmessage', TRUE) && privatemsg_user_access()) {
        $count = privatemsg_unread_count();
        if ($count) {
          drupal_set_message(format_plural($count, 'You have <a href="@messages">1 unread message</a>.', 'You have <a href="@messages">@count unread messages</a>', array(
            '@messages' => url('messages'),
          )));
        }
      }
      break;
    case 'delete':

      // Load all mids of the messages the user wrote.
      $result = db_query("SELECT mid FROM {pm_message} WHERE author = %d", $account->uid);
      $mids = array();
      while ($row = db_fetch_array($result)) {
        $mids[] = $row['mid'];
      }

      // Delete messages the user wrote.
      db_query('DELETE FROM {pm_message} WHERE author = %d', $account->uid);
      if (!empty($mids)) {

        // Delete recipient entries in {pm_index} of the messages the user wrote.
        db_query('DELETE FROM {pm_index} WHERE mid IN (' . db_placeholders($mids) . ')', $mids);
      }

      // Delete recipient entries of that user.
      db_query('DELETE FROM {pm_index} WHERE uid = %d', $account->uid);
      break;
  }
}