Index: pm_workflow_ng/README.txt
===================================================================
RCS file: pm_workflow_ng/README.txt
diff -N pm_workflow_ng/README.txt
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ pm_workflow_ng/README.txt	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,41 @@
+********************************************************************
+                     D R U P A L    M O D U L E
+********************************************************************
+Name: pm_workflow_ng
+Author: Dominik Kiss <dominik.kiss[at]gmx.at> nodestroy at drupal.org
+Drupal Version: 5
+********************************************************************
+DESCRIPTION:
+
+This module extends privatemsg module with workflow-ng functionality.
+
+It implements hook_privatemsg() and calls workflow-ng events on 
+the various privatemsg actions (listed below).
+
+- prune (Message is permanently removed)
+- delete (Message is marked as deleted)
+- view (Message is about to be displayed for viewing)
+- sent (Message was sent)
+
+There is also a workflow-ng action provided, that means you can send
+a privatemsg via workflow-ng (e.g: at buddylist2 userA requests to
+add userB to his buddylist. after this, a workflow-ng event is 
+thrown, and a privatemsg will be sent to userB).
+
+Default Configuration:
+Send a eMail and log to watchdog, when a privatemsg is sent.
+
+NOTE: With the action "Send a private message" the action "Load user
+by name" is very usefull, so you can configure a specific user 
+(e.g: admin) as sender.
+
+********************************************************************
+INSTALLATION:
+
+1. Download the module from drupal.org and place it into your drupal
+   directory (/sites/all/modules)
+   
+2. Enable the module at:
+   administer -> site building -> modules
+   
+
Index: pm_workflow_ng/pm_workflow_ng.module
===================================================================
RCS file: pm_workflow_ng/pm_workflow_ng.module
diff -N pm_workflow_ng/pm_workflow_ng.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ pm_workflow_ng/pm_workflow_ng.module	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,156 @@
+<?php
+
+/**
+ * This include file implements workflow ng functionality on behalf of the
+ * privatemsg.module 
+ */
+ 
+// action to send privatemsgs
+include_once 'pm_workflow_ng_action.inc'; 
+ 
+
+// token support
+include_once 'pm_workflow_ng_token.inc';
+ 
+ 
+/**
+ * Implementation of hook_event_info()
+ */
+function pm_workflow_ng_event_info() {
+  return array(
+    'privatemsg_prune' => array(
+      '#label' => t('Message is permanently removed'),
+      '#module' => t('Privatemsg'),
+      '#arguments' => array(
+        'userA' => array('#entity' => 'user', '#label' => t('UserA, sender of message')),
+        'userB' => array('#entity' => 'user', '#label' => t('UserB, recipient of message')),
+        'privatemsginfo' => array('#entity' => 'privatemsginfo', '#label' => t('Message')),
+       ),
+    ),  
+    'privatemsg_delete' => array(
+      '#label' => t('Message is marked as deleted'),
+      '#module' => t('Privatemsg'),
+      '#arguments' => array(
+        'userA' => array('#entity' => 'user', '#label' => t('UserA, sender of message')),
+        'userB' => array('#entity' => 'user', '#label' => t('UserB, recipient of message')),
+        'privatemsginfo' => array('#entity' => 'privatemsginfo', '#label' => t('Message')),
+       ),
+    ),    
+    'privatemsg_view' => array(
+      '#label' => t('Message is about to be displayed for viewing'),
+      '#module' => t('Privatemsg'),
+      '#arguments' => array(
+        'userA' => array('#entity' => 'user', '#label' => t('UserA, sender of message')),
+        'userB' => array('#entity' => 'user', '#label' => t('UserB, recipient of message')),
+        'privatemsginfo' => array('#entity' => 'privatemsginfo', '#label' => t('Message')),
+       ),
+    ),    
+    'privatemsg_sent' => array(
+      '#label' => t('Message was sent'),
+      '#module' => t('Privatemsg'),
+      '#arguments' => array(
+        'userA' => array('#entity' => 'user', '#label' => t('UserA, sender of message')),
+        'userB' => array('#entity' => 'user', '#label' => t('UserB, recipient of message')),
+        'privatemsginfo' => array('#entity' => 'privatemsginfo', '#label' => t('Message')),
+       ),
+    ),
+  );
+}
+
+/**
+ * Implementation of hook_privatemsg()
+ */
+function pm_workflow_ng_privatemsg($message, $op) {  
+  if (module_exists('workflow_ng')) {    
+    $userA = user_load(array('uid' => $message->uid));
+    $userB = user_load(array('uid' => $message->recipient));
+    $privatemsginfo = array();
+    $privatemsginfo['message'] = $message->message;
+    $privatemsginfo['subject'] = $message->subject;
+    workflow_ng_invoke_event('privatemsg_'.$op, $userA, $userB, $privatemsginfo);   
+  }
+}
+
+/**
+ * Implementation of hook_configuration()
+ */
+function pm_workflow_ng_configuration() {
+  $configurations = array (
+  'user_gets_pm_send_mail' => 
+  array (
+    '#type' => 'configuration',
+    '#altered' => false,
+    '#event' => 'privatemsg_sent',
+    '#label' => '[MAIL] UserB gets privatemsg from UserA',
+    '#active' => 1,
+    '#module' => 'workflow-ng',
+    0 => 
+    array (
+      '#type' => 'action',
+      '#name' => 'workflow_ng_action_mail_to_user',
+      '#argument map' => 
+      array (
+        'userB' => 'user',
+      ),
+      '#settings' => 
+      array (
+        'from' => '[userA:site-mail]',
+        'from_args' => 
+        array (
+          0 => 'userA',
+        ),
+        'subject' => '[userA:site-name]: new message from [userA:user]',
+        'subject_args' => 
+        array (
+          0 => 'userA',
+        ),
+        'message' => 'Hi [userB:user],
+
+you got a new private message from [userA:user].
+
+**************************
+subject: [privatemsginfo:subject]
+message:
+[privatemsginfo:message]
+**************************
+
+your
+[userA:site-name] team',
+        'message_args' => 
+        array (
+          0 => 'userA',
+          1 => 'userB',
+          2 => 'privatemsginfo',
+        ),
+      ),
+      '#label' => 'Send a mail to a user',
+    ),
+    1 => 
+    array (
+      '#type' => 'action',
+      '#name' => 'workflow_ng_action_watchdog',
+      '#settings' => 
+      array (
+        'severity' => '0',
+        'type' => 'workflow-ng',
+        'message' => '[userB:user] ([userB:uid]) got a privatemsg from [userA:user] ([userA:uid])',
+        'link' => '',
+        'message_args' => 
+        array (
+          0 => 'userA',
+          1 => 'userB',
+        ),
+        'link_args' => 
+        array (
+        ),
+      ),
+    ),
+    '#name' => 'user_gets_pm_send_mail',
+  ),
+);
+  
+  return $configurations;	
+}
+
+
+
Index: pm_workflow_ng/pm_workflow_ng_token.inc
===================================================================
RCS file: pm_workflow_ng/pm_workflow_ng_token.inc
diff -N pm_workflow_ng/pm_workflow_ng_token.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ pm_workflow_ng/pm_workflow_ng_token.inc	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,28 @@
+<?php
+
+/**
+ * This include file implements token functionality on behalf of the
+ * privatemsg.module 
+ */
+ 
+/**
+ * Implementation of hook_token_values()
+ */
+function pm_workflow_ng_token_values($type, $object = NULL) {
+  if ($type == 'privatemsginfo') {
+    $tokens['message'] = check_plain($object['message']);
+    $tokens['subject'] = check_plain($object['subject']);
+    return $tokens;
+  }
+}
+
+/**
+ * Implementation of hook_token_values()
+ */ 
+function pm_workflow_ng_token_list($type = 'all') {
+  if ($type == 'privatemsginfo' || $type == 'all') {
+    $tokens['privatemsginfo']['message'] = t("Message which is send by userA to userB");
+    $tokens['privatemsginfo']['subject'] = t("Subject of message");
+    return $tokens;
+  }
+}
Index: pm_workflow_ng/pm_workflow_ng.info
===================================================================
RCS file: pm_workflow_ng/pm_workflow_ng.info
diff -N pm_workflow_ng/pm_workflow_ng.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ pm_workflow_ng/pm_workflow_ng.info	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,4 @@
+name = Private message workflow-ng 
+description = implements workflow-ng functionality 
+dependencies = token workflow_ng privatemsg
+package = Mail
Index: pm_workflow_ng/pm_workflow_ng_action.inc
===================================================================
RCS file: pm_workflow_ng/pm_workflow_ng_action.inc
diff -N pm_workflow_ng/pm_workflow_ng_action.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ pm_workflow_ng/pm_workflow_ng_action.inc	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,61 @@
+<?php
+
+// workflow-ng action for privatemsg
+
+/*
+* Implementation of hook_action_info()
+*/
+function pm_workflow_ng_action_info() {
+  return array(
+    'pm_workflow_ng_action_send_privatemsg' => array(
+      '#label' => t('Send a private message'),
+      '#arguments' => array(
+        'user_rep'  => array('#entity' => 'user', '#label' => t('Recipient')),
+        'user_sen'  => array('#entity' => 'user', '#label' => t('Sender')),
+      ),
+      '#module' => t('Privatemsg'),
+    ),
+  );
+}
+
+function pm_workflow_ng_action_send_privatemsg($user_rep, $user_sen, $settings){
+	// send pm
+	_privatemsg_send($user_sen, $user_rep, $settings['subject'], $settings['message'], FILTER_FORMAT_DEFAULT);
+}
+
+function pm_workflow_ng_action_send_privatemsg_form($settings = array(), $argument_info) {
+  $form = array();
+   
+  $form['subject'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Subject'),
+    '#size'  => '40',
+    '#default_value' => $settings['subject'],
+    '#description' => t('Subject of privatemsg.'),
+  );
+  
+  $form['message'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Message'),
+    '#default_value' => $settings['message'],
+    '#description' => t('The private message that should be send.'),
+  );
+  
+  workflow_ng_token_replacement_help($form, $argument_info);
+  
+  $form['error'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Display as error message'),
+    '#default_value' => $settings['error'],
+  );
+  
+  return $form;
+}
+
+function pm_workflow_ng_action_send_privatemsg_submit($form_id, $form_values) {
+  //returns the needed settings
+  $settings = workflow_ng_token_get_settings(array('subject', 'message'), $form_values);
+  return $settings + array('error' => $form_values['error']);
+}
+
+
