--- G:/Downloads/CTO D6 Upgrade/CTO D6 Modules/workflow-6.x-1.1/workflow/workflow.module	Thu Jan 01 15:09:16 2009
+++ E:/PAMPA/PAMPA/apache/htdocs/cto/modules/workflow/workflow.module	Tue Feb 10 19:49:28 2009
@@ -1467,19 +1467,42 @@
         $account = user_load(array('uid' => $row->uid));
         $comment = $row->comment;
       }
+      
+      // If $node->workflow exists but $node->workflow_stamp does not,
+      // the node is being submitted but the form data has not been saved to the database yet,
+      // so we set the token values from the workflow form fields.
+      if (isset($node->workflow) && !isset($node->workflow_stamp)) {
+        $sid = $node->workflow;
+        $old_sid = $row->sid;
+        $date = time();
+        $user_name = $node->uid ? $node->name : variable_get('anonymous', 'Anonymous');
+        $uid = $node->uid;
+        $mail = $node->uid ? $node->user_mail : '';
+        $comment = $node->workflow_comment;
+      }
+      else {
+        //Default to the most recent transition data in the workflow history table
+        $sid = $row->sid;
+        $old_sid = $row->old_sid;
+        $date = $row->stamp;
+        $user_name = $account->uid ? $account->name : variable_get('anonymous', 'Anonymous');
+        $uid = $account->uid;
+        $mail = $account->uid ? $account->mail : '';
+        $comment = $row->comment;
+      }
 
-      $values['workflow-current-state-name']                =  $states[$row->sid];
-      $values['workflow-old-state-name']                    =  $states[$row->old_sid];
+      $values['workflow-current-state-name']                =  $states[$sid];
+      $values['workflow-old-state-name']                    =  $states[$old_sid];
 
-      $values['workflow-current-state-date-iso']            =  date('Ymdhis',$row->stamp);
-      $values['workflow-current-state-date-tstamp']         =  $row->stamp;
-      $values['workflow-current-state-date-formatted']      =  date('M d, Y h:i:s', $row->stamp);
+      $values['workflow-current-state-date-iso']            =  date('Ymdhis', $date);
+      $values['workflow-current-state-date-tstamp']         =  $date;
+      $values['workflow-current-state-date-formatted']      =  date('M d, Y h:i:s', $date);
 
-      $values['workflow-current-state-updating-user-name']  = $account->uid ? $account->name : variable_get('anonymous', 'Anonymous');
-      $values['workflow-current-state-updating-user-uid']   = $account->uid;
-      $values['workflow-current-state-updating-user-mail']  = $account->uid ? $account->mail : '';
+      $values['workflow-current-state-updating-user-name']  = $user_name;
+      $values['workflow-current-state-updating-user-uid']   = $uid;
+      $values['workflow-current-state-updating-user-mail']  = $mail;
 
-      $values['workflow-current-state-log-entry']           = $row->comment;
+      $values['workflow-current-state-log-entry']           = $comment;
       break;
   }
 
