--- workflow.module.orig	2007-12-18 18:58:49.000000000 -0800
+++ workflow.module	2007-12-18 19:31:21.000000000 -0800
@@ -151,7 +151,6 @@ function workflow_tab_form(&$node, $wid,
   $choices = workflow_field_choices($node);
   $min = $states[$current] == t('(creation)') ? 1 : 2;
   if (count($choices) >= $min) { // bail out if user has no new target state(s)    
-    ksort($choices);
     $wid = workflow_get_workflow_for_type($node->type);
     $name = check_plain(workflow_get_name($wid));
     // see if scheduling information is present
@@ -319,7 +318,7 @@ function workflow_node_form(&$form, $tit
     );
   }
   else {
-    
+
     $form['workflow'][$name] = array(
       '#type' => 'radios',
       '#title' => $title,
@@ -383,12 +382,12 @@ function workflow_form_alter($form_id, &
     $wid = workflow_get_workflow_for_type($node->type);
     $states = workflow_get_states($wid) + array(t('(creation)'));
     $current = workflow_node_current_state($node);
+    
     $min = $states[$current] == t('(creation)') ? 1 : 2;
     if (count($choices) < $min) { // bail out if user has no new target state(s)
       return;
     }
 
-    ksort($choices);
     $name = check_plain(workflow_get_name($wid));
 
     // if the current node state is not one of the choices, autoselect first choice
@@ -569,10 +568,21 @@ function workflow_field_choices($node) {
     $roles = 'ALL';
   }
   $transitions = workflow_allowable_transitions($current_sid, 'to', $roles);
-
+  
   if ($current_sid != _workflow_creation_state($wid)) { // include current state if not (creation)
     $transitions = array($current_sid => $states[$current_sid]) + $transitions;
   }
+  
+  // sort by state weights
+  if ($transitions) {
+    $result = db_query("SELECT sid, weight FROM {workflow_states} WHERE wid=%d AND sid IN (" . implode(",", array_keys($transitions)) . ") ORDER BY weight, state", $wid);
+    $sorted_transitions = array();
+    while ($row = db_fetch_array($result)) {
+      $sorted_transitions[$row['sid']] = $states[$row['sid']];
+    }
+    return $sorted_transitions;
+  }
+  
   return $transitions;
 }
 
@@ -1663,7 +1673,7 @@ function workflow_allowable_transitions(
   $field_where = $dir != 'to' ? 'target_sid' : 'sid';
   $result = db_query("SELECT t.tid, t.%s as state_id, s.state as state_name FROM "
     . "{workflow_transitions} t INNER JOIN {workflow_states} s ON s.sid = "
-    . "t.%s WHERE t.%s = %d", $field, $field, $field_where, $sid);
+    . "t.%s WHERE t.%s = %d ORDER BY s.weight, s.state", $field, $field, $field_where, $sid);
 
   while ($t = db_fetch_object($result)) {
     if ($roles == 'ALL' || workflow_transition_allowed($t->tid, $roles)) {
