--- /var/www/drupal/modules/signup_status/modules/signup_status_invite/signup_status_invite.module	2009-01-31 02:44:47.000000000 +0800
+++ /var/www/drupal/sites/all/modules/signup_status_invite/signup_status_invite.module	2009-09-17 13:20:05.000000000 +0800
@@ -111,13 +111,32 @@
     '#type' => 'fieldset',
   );
   $form['invite']['#title'] = t('Invite a user to the node');
-  $form['invite']['mail'] = array(
+/*
+$form['invite']['mail'] = array(
     '#type' => 'textfield',
     '#title' => t('To'),
     '#description' => t('Type the comma separated list of e-mails of the people you would like to invite to the node.'),
     '#required' => TRUE,
     '#autocomplete_path' => 'node/'. $node->nid .'/signup-invite/autocomplete',
   );
+*/  
+  $form['invite']['users'] = array(
+    '#type' => 'textfield',
+    '#title' => t('To'),
+    '#description' => t('Type the comma separated list of users you would like to invite to the node.'),
+    '#required' => TRUE,
+    '#autocomplete_path' => 'user/autocomplete',
+  );
+  if ($list = messaging_method_list($user)) {
+    $form['invite']['method'] = array(
+      '#type'          => 'select',
+      '#title'         => t('Send method'),
+      '#default_value' => messaging_method_default($user),
+      '#options' => $list,
+      '#description'   => t('Sending method.'),
+      '#disabled' => count($list) == 1,
+    );
+  }
   $form['invite']['message'] = array(
     '#type' => 'textarea',
     '#title' => t('Your message'),
@@ -132,43 +151,30 @@
     '#type' => 'submit',
     '#value' => t('Invite'),
   );
-
   return $form;
 }
 
 /**
  * Invite form validation.
- */
+ a*/
 function signup_status_invite_form_validate($form, &$form_state) {
   global $user;
   $values = $form_state['values'];
-
-  $mails = array_filter(array_map(create_function('$a', 'return trim($a);'), explode(',', $values['mail'])));
-  if (in_array($user->mail, $mails)) {
-    form_set_error('mail', t('You may not invite yourself - @self.', array('@self' => $user->mail)));
+  $users = explode(',' , $values['users']);
+  if (in_array ($user->name, $users)) {
+    form_set_error('users', t('You may not invite yourself - @self.', array('@self' => $user->name)));
   }
-
-  $bad_mails = array();
-  foreach ($mails as $mail) {
-    if (($account = user_load(array('mail' => $mail))) && $account->status == 0) {
-      form_set_error('mail', t('A user %name with the e-mail address %mail is blocked.', array('%name' => $account->name, '%mail' => $mail)));
-    }
-    else if ($account && db_result(db_query_range("SELECT sid FROM {signup_log} WHERE uid = %d AND nid = %d", $account->uid, $values['nid'], 0, 1))) {
-      form_set_error('mail', t('A user %name with the e-mail address %mail is already signuped to the node.', array('%name' => $account->name, '%mail' => $mail)));
-    }
-    else if (!$account) {
-      form_set_error('mail', t('There is no user with the e-mail address %mail.', array('%mail' => $mail)));
-    }
-    else if (valid_email_address($mail)) {
-      $form_state['valid_mails'][] = $mail;
+  foreach ($users as $name) {
+    if ($account = user_load(array('name' => $name)))
+    {
+      if (db_result(db_query_range("SELECT sid FROM {signup_log} WHERE uid = %d AND nid = %d", $account->uid, $values['nid'], 0, 1))) {
+      form_set_error('users', t('%name is already signuped to the node.', array('%name' => $account->name)));
+      }
     }
     else {
-      $bad_mails[] = $mail;
+      form_set_error('users', t('There is no such user - %name.', array('%name' =>$name)));
     }
   }
-  if (count($bad_mails)) {
-    form_set_error('mail', t('Invalid email address: @value.', array('@value' => implode(', ', $bad_mails))));
-  }
 }
 
 /**
@@ -177,6 +183,7 @@
 function signup_status_invite_form_submit($form, &$form_state) {
   global $user;
   $values = $form_state['values'];
+  $method = $values['method'];
   $node = node_load($values['nid']);
 
   $variables = array(
@@ -186,20 +193,22 @@
     '!name' => $user->name,
   );
 
-  foreach ($form_state['valid_mails'] as $mail) {
-    $account = user_load(array('mail' => $mail));
-    db_query("INSERT INTO {signup_log} (uid, nid, anon_mail, signup_time, form_data, status) VALUES (%d, %d, '%s', %d, '%s', %d)", $account->uid, $values['nid'], '', time(), serialize(array()), SIGNUP_STATUS_INVITE_STATUS);
-    $sid = db_last_insert_id('signup_log', 'sid');
-    _signup_status_change('invite', (object)array('sid' => $sid, 'uid' => $account->uid, 'nid' => $values['nid'], 'anon_mail' => '', 'status' => SIGNUP_STATUS_INVITE_STATUS));
-    $signup_url = url('signup/edit/'. $sid, array('absolute' => TRUE));
-    $message = drupal_mail('signup_status_invite', 'invite', $mail, $GLOBALS['language'], array('account' => $account, 'variables' => array_merge($variables, array('!signup_url' => $signup_url))), $user->mail);
-    if ($message['result']) {
-      watchdog('signup_status_invite', 'Invite e-mail was mailed from %name to %mail.', array('%name' => $user->name, '%mail' => $mail));
-      drupal_set_message(t('The invite has been mailed to e-mail address %mail.', array('%mail' => $mail)));
-    }
-    else {
-      watchdog('signup_status_invite', 'Error mailing invite e-mail from %user to %mail.', array('%name' => $user->name, '%mail' => $mail), WATCHDOG_ERROR);
-      drupal_set_message(t('Unable to send mail. Please contact the site admin.'), 'error');
+  $users = explode(',' , $values['users']);
+  foreach ($users as $name) {
+    if ($account = user_load(array('name' => $name))) {
+      db_query("INSERT INTO {signup_log} (uid, nid, anon_mail, signup_time, form_data, status) VALUES (%d, %d, '%s', %d, '%s', %d)", $account->uid, $values['nid'], '', time(), serialize(array()), SIGNUP_STATUS_INVITE_STATUS);
+      $sid = db_last_insert_id('signup_log', 'sid');
+      _signup_status_change('invite', (object)array('sid' => $sid, 'uid' => $account->uid, 'nid' => $values['nid'], 'anon_mail' => '', 'status' => SIGNUP_STATUS_INVITE_STATUS));
+      $signup_url = url('signup/edit/'. $sid, array('absolute' => TRUE));
+      $message = array(
+        'subject' => 'invite',
+        'body' => array_merge($variables, array('!signup_url' => $signup_url)),
+//        'params' => Optional message params, indexed by sending method group I.e. params for mail methods will be in $message['params']['mail']
+//        'render' => Optional flag to mark the message subject and body as rendered
+        'sender' => $user->uid, 
+//        'sender_account' => Optional user account to use as message sender
+      );
+      messaging_message_send_user($account, $message, $method, $queue = 0);
     }
   }
 }
