Index: pm_lite.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pm_lite/pm_lite.install,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 pm_lite.install
--- pm_lite.install	3 Jun 2008 05:05:49 -0000	1.1.2.2
+++ pm_lite.install	27 Mar 2010 08:48:21 -0000
@@ -73,6 +73,12 @@ function pm_lite_schema() {
         'not null' => TRUE,
         'default' => 0,
       ),
+      'broadcast' => array(
+        'description' => t("Indicator of a PM's type; 0 = private, 1 = broadcast"),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => '0',
+      ),
     ),
     'indexes' => array(
       'nid' => array('nid'),
@@ -82,3 +88,12 @@ function pm_lite_schema() {
 
   return $schema;
 }
+
+/**
+ * Implementation of hook_update_N().
+ */
+function pm_lite_update_6100() {
+  $ret = array();
+  $ret[] = update_sql('ALTER TABLE {pm_lite} ADD broadcast INT(10) DEFAULT 0');
+  return $ret;
+}
Index: pm_lite.js
===================================================================
RCS file: pm_lite.js
diff -N pm_lite.js
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ pm_lite.js	27 Mar 2010 08:48:21 -0000
@@ -0,0 +1,14 @@
+// $Id$
+
+$(function() {
+  id = '#pm_lite-broadcast';
+  setRecipientsVisible = function() {
+    if ($(id + ':checked').val() != null)
+      $('#pm_lite-recipients').css('display', 'none');
+    else
+      $('#pm_lite-recipients').css('display', 'block');
+  }
+
+  setRecipientsVisible();
+  $(id).click(setRecipientsVisible);
+});
\ No newline at end of file
Index: pm_lite.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pm_lite/pm_lite.module,v
retrieving revision 1.1.2.18
diff -u -p -r1.1.2.18 pm_lite.module
--- pm_lite.module	20 Feb 2009 05:43:36 -0000	1.1.2.18
+++ pm_lite.module	27 Mar 2010 08:48:22 -0000
@@ -1,4 +1,4 @@
-<?php
+<?php    
 // $Id: pm_lite.module,v 1.1.2.18 2009/02/20 05:43:36 rszrama Exp $
 
 /**
@@ -82,7 +82,7 @@ function pm_lite_menu() {
  * Implementation of hook_perm().
  */
 function pm_lite_perm() {
-  return array('administer pm_lite', 'access pm_lite');
+  return array('administer pm_lite', 'access pm_lite', 'send broadcast pm_lite messages');
 }
 
 /**
@@ -97,6 +97,21 @@ function pm_lite_theme() {
 }
 
 /**
+ * Implementation of hook_user_actions().
+ */
+function pm_lite_user_actions($uid) {
+  global $user;
+  $account = user_load($uid);
+  if ($user->uid == $account->uid) return array();
+  if (user_access('access pm_lite') && $account->pm_lite_allow !== 0)
+    return array(array(
+      '#title' => t('Send a private message.'),
+      '#link' => 'node/add/pm/to/'. $account->uid,
+    ));
+  return array();
+}
+
+/**
  * Implementation of hook_user().
  */
 function pm_lite_user($op, &$edit, &$account, $category = NULL) {
@@ -115,6 +130,7 @@ function pm_lite_user($op, &$edit, &$acc
       break;
 
     case 'view':
+      if (module_exists('user_actions')) break;
       // Show a send PM link if applicable.
       if (user_access('access pm_lite') && $account->pm_lite_allow !== 0) {
         $account->content['pm_lite'] = array(
@@ -316,7 +332,9 @@ function pm_lite_form(&$node) {
       $parent = node_load(arg(4));
 
       // Make sure this was a valid PM and the user has access to it.
-      if ($parent->nid && pm_lite_access('view', $parent, $user)) {
+      // Also, we need to do additional check for broadcast messages
+      if ($parent->nid && pm_lite_access('view', $parent, $user) &&
+          (!$parent->broadcast || user_access('send broadcast pm_lite messages'))) {
         // If so, first set the default recipients for the reply if necessary.
         $recipients = array($parent->uid);
 
@@ -396,6 +414,17 @@ function pm_lite_form(&$node) {
     $default = $node->recipients;
   }
 
+  drupal_add_js(drupal_get_path('module', 'pm_lite').'/pm_lite.js', 'module');
+  if (user_access('send broadcast pm_lite messages'))
+    $form['broadcast'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Broadcast'),
+      '#description' => t('Check this box if you want to send this message to all site\'s users'),
+      '#default_value' => $node->broadcast,
+      '#required' => FALSE,
+      '#weight' => -10,
+      '#id' => 'pm_lite-broadcast',
+    );
   // Add a recipient field.
   $form['recipients'] = array(
     '#type' => 'textfield',
@@ -403,8 +432,9 @@ function pm_lite_form(&$node) {
     '#description' => t('Type the username of the recipient. Separate names with commas to send to multiple recipients.'),
     '#autocomplete_path' => 'pm_lite/autocomplete',
     '#default_value' => $default,
-    '#required' => TRUE,
-    '#weight' => -10,
+    '#weight' => -7,
+    '#prefix' => '<div id="pm_lite-recipients">',
+    '#suffix' => '</div>',
   );
 
   // Always add the title field.
@@ -437,6 +467,13 @@ function pm_lite_form(&$node) {
  * Makes sure the recipients entered are all valid.
  */
 function pm_lite_validate($node, &$form) {
+  if ($form['broadcast']['#value'] && user_access('send broadcast pm_lite messages')) {
+    return;
+  }
+  if (trim($form['recipients']['#value']) == "") {
+    form_set_error('recipients', t('Recipient field is required'));
+  }
+
   // Put the recipients into an array.
   $recipients = explode(',', $form['recipients']['#value']);
 
@@ -462,18 +499,26 @@ function pm_lite_validate($node, &$form)
  * Creates a new row in the pm_lite table for every recipient.
  */
 function pm_lite_insert($node) {
-  // Put the recipients into an array.
-  $recipients = explode(',', $node->recipients);
-  $used_uids = array();
-
-  foreach ($recipients as $recipient) {
-    // Fetch the uid of the recipient.
-    $uid = db_result(db_query("SELECT uid FROM {users} WHERE name = '%s'", trim($recipient)));
-
-    // If it's still valid, add an entry for it.
-    if ($uid && !in_array($uid, $used_uids)) {
-      db_query("INSERT INTO {pm_lite} (nid, recipient, status, parent) VALUES (%d, '%s', 0, %d)", $node->nid, $uid, $node->parent);
-      $used_uids[] = $uid;
+  if ($node->broadcast) {
+    db_query(
+    'INSERT INTO {pm_lite} (nid, recipient, status, parent, broadcast)
+       SELECT %d, uid, 0, %d, 1
+         FROM {users}
+       WHERE status', $node->nid, $node->parent);
+  } else {
+    // Put the recipients into an array.
+    $recipients = explode(',', $node->recipients);
+    $used_uids = array();
+  
+    foreach ($recipients as $recipient) {
+      // Fetch the uid of the recipient.
+      $uid = db_result(db_query("SELECT uid FROM {users} WHERE name = '%s'", trim($recipient)));
+  
+      // If it's still valid, add an entry for it.
+      if ($uid && !in_array($uid, $used_uids)) {
+        db_query("INSERT INTO {pm_lite} (nid, recipient, status, parent) VALUES (%d, '%s', 0, %d)", $node->nid, $uid, $node->parent);
+        $used_uids[] = $uid;
+      }
     }
   }
 }
@@ -519,14 +564,31 @@ function pm_lite_update($node) {
  * Adds the recipients array to the node object.
  */
 function pm_lite_load($node) {
+  $username_table = 'users';
+  $username_field = 'name';
+  if (module_exists('realname')) {
+    $username_table = 'realname';
+    $username_field = 'realname';
+  }
+
   $data->pm_lite['recipients'] = array();
 
   // Loop through every entry in the PM Lite table and handle the data.
-  $result = db_query("SELECT p.*, u.name FROM {pm_lite} AS p LEFT JOIN {users} AS u ON p.recipient = u.uid WHERE nid = %d", $node->nid);
+  $result = db_query(
+  "SELECT p.*, u.name, r.$username_field AS display_name
+     FROM {pm_lite} AS p
+   LEFT JOIN users AS u
+     ON p.recipient = u.uid
+   LEFT JOIN {$username_table} AS r
+     ON p.recipient = r.uid
+   WHERE nid = %d", $node->nid);
   while ($row = db_fetch_array($result)) {
     // Add the recipient data to the recipients array.
-    $data->pm_lite['recipients'][$row['recipient']] = array('name' => $row['name']);
+    if (is_null($row['name'])) continue;
+    $data->pm_lite['recipients'][$row['recipient']] =
+      array('name' => $row['name'], 'display_name' => $row['display_name']);
   }
+  $node->broadcast = db_result(db_query('SELECT broadcast FROM {pm_lite} WHERE (nid=%d)', $node->nid));
 
   return $data;
 }
@@ -587,6 +649,8 @@ function pm_lite_view_form($form_state, 
 
   // If the user was a recipient of the PM.
   if (pm_lite_recipient($user->uid, $node)) {
+    // If this PM is broadcast, disable reply buttons
+    if ($node->broadcast) return;
     $form['pm_nid'] = array(
       '#type' => 'value',
       '#value' => $node->nid,
@@ -596,7 +660,7 @@ function pm_lite_view_form($form_state, 
       '#type' => 'submit',
       '#value' => t('Reply'),
       '#submit' => array('pm_lite_view_form_submit_reply'),
-      '#prefix' => '<span class="pm-view-form-label">'. t('With this message:') .'</span>',
+      '#prefix' => '<span class="pm-view-form-label">'. t('Actions:') .'</span>',
     );
 
     if (count($node->pm_lite['recipients']) > 1) {
@@ -752,10 +816,24 @@ function pm_lite_table($account, $view =
     array('data' => t('Date'), 'field' => 'n.created', 'sort' => 'desc'),
   );
 
+
+  $username_table = 'users'; $username_field = 'name';
+  if (module_exists('realname')) {
+    $username_table = 'realname';
+    $username_field = 'realname';
+  }  
+
   // Query the database for the account's PMs based on the specified view.
   switch ($view) {
     case 'inbox':
-      $result = pager_query("SELECT pm.nid, pm.status, u.uid, u.name, n.title, n.created FROM {pm_lite} pm LEFT JOIN {node} n ON pm.nid = n.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE pm.recipient = %d". tablesort_sql($header), $limit, 0, NULL, $account->uid);
+      $result = pager_query(
+      "SELECT pm.nid, pm.status, u.uid, u.$username_field AS name, n.title, n.created
+         FROM {pm_lite} pm
+       LEFT JOIN {node} n
+         ON pm.nid = n.nid
+       LEFT JOIN {$username_table} u
+         ON n.uid = u.uid
+       WHERE pm.recipient = %d". tablesort_sql($header), $limit, 0, NULL, $account->uid);
       break;
 
     case 'sent':
@@ -780,7 +858,12 @@ function pm_lite_table($account, $view =
 
       case 'sent':
         // Loop through every entry in the PM Lite table and handle the data.
-        $rec_result = db_query("SELECT pm.recipient, pm.status, u.name FROM {pm_lite} pm LEFT JOIN {users} u ON pm.recipient = u.uid WHERE pm.nid = %d", $pm['nid']);
+        $rec_result = db_query(
+        "SELECT pm.recipient, pm.status, u.$username_field AS name
+           FROM {pm_lite} pm
+         LEFT JOIN {$username_table} u
+           ON pm.recipient = u.uid
+         WHERE pm.nid = %d", $pm['nid']);
         while ($row = db_fetch_array($rec_result)) {
           $rec_status = '';
           if ($row['status'] == 0) {
@@ -843,16 +926,27 @@ function pm_lite_recipient($uid, $node) 
  */
 function pm_lite_header($node) {
   // Build the from variable.
-  $author = db_result(db_query("SELECT name FROM {users} WHERE uid = %d", $node->uid));
+  $username_table = 'users';
+  $username_field = 'name';
+  if (module_exists('realname')) {
+    $username_table = 'realname';
+    $username_field = 'realname';
+  }
+
+  $author = db_result(db_query("SELECT $username_field AS name FROM {$username_table} WHERE uid = %d", $node->uid));
   $from = l(check_plain($author), 'user/'. $node->uid);
 
-  // Build the to variable.
-  $recipients = array();
+  if ($node->broadcast) {
+    $to = t('All users');
+  } else{
+    // Build the to variable.
+    $recipients = array();
 
-  foreach ($node->pm_lite['recipients'] as $key => $value) {
-    $recipients[] = l(check_plain($value['name']), 'user/'. $key);
+    foreach ($node->pm_lite['recipients'] as $key => $value) {
+      $recipients[] = l(check_plain($value['display_name']), 'user/'. $key);
+    }
+    $to = implode(', ', $recipients);
   }
-  $to = implode(', ', $recipients);
 
   // Return the themed output.
   return theme('pm_lite_header', $from, $to, check_plain($node->title), format_date($node->created));
