--- down/modules/workflow/workflow.module	2005-02-03 01:00:34.000000000 -0800
+++ modules/workflow/workflow.module	2005-05-09 19:38:12.000000000 -0700
@@ -131,6 +131,10 @@
             $sid = $_POST['edit']['_workflow'];
           }
           $output = form_select(t('Workflow'), '_workflow', $sid, $options);
+	  // add a new text area for comment logging of state changes
+	  // see comment_workflow function below 
+          $output .= form_textarea( //PDS - collect reason
+	     t('Workflow change reason'),'_workflow_reason',null,null,3,'If you change the state, explain why');
         }
         // note that no form element will be added if
         // there are no allowable transitions from our current state
@@ -228,6 +232,29 @@
   } 
 }
 
+/** added a little feature where it adds a comment whenever the state changes
+  * by patricksurry
+  * http://drupal.org/node/16643
+*/
+function comment_workflow($op, $old_state, $new_state, $node) {
+  switch ($op) {
+    case 'transition pre':
+      break;
+    case 'transition post':
+      // maybe we need to temporarily switch to an admin user here?
+      // or make sure users who change workflow have comment permission,
+      // and types with workflows allow comments
+      $wid = workflow_get_workflow_for_type($node->type);
+      $states = workflow_get_states($wid);
+      $comment->nid = $node->nid;
+      $comment->subject = 'Workflow: ' . $states[$old_state] . ' &rarr; ' . $states[$new_state];
+      $comment->comment = $_POST['edit']['_workflow_reason'];
+      if (!$comment->comment) $comment->comment = 'No reason given';
+      comment_post(object2array($comment));
+      break;
+  }
+}
+
 /**
  * Controller.
  *
