Index: nodequeue.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodequeue/nodequeue.module,v
retrieving revision 1.97
diff -u -p -r1.97 nodequeue.module
--- nodequeue.module	24 Oct 2009 20:35:08 -0000	1.97
+++ nodequeue.module	25 Oct 2009 14:58:24 -0000
@@ -1031,9 +1031,10 @@ function _nodequeue_dragdrop_get_nodes($
   $result = db_query('SELECT DISTINCT(n.nid), n.title, n.uid, u.name, n.created, nq.position FROM {node} n LEFT JOIN {users} u on n.uid = u.uid LEFT JOIN {nodequeue_nodes} nq ON nq.nid = n.nid WHERE nq.sqid = %d ORDER BY nq.position '. $order, $subqueue->sqid);
 
   $nodes = array();
+  
   while ($node = db_fetch_object($result)) {
     $node->visible = isset($visible[$node->nid]) ? TRUE : FALSE;
-    $nodes[] = $node;
+    $nodes[$node->position] = $node; 
   }
 
   return $nodes;
@@ -1051,22 +1052,22 @@ function nodequeue_arrange_subqueue_form
 
   // prepare the main part of the form which will be themed as a table
   $count = count($nodes);
-  foreach ($nodes as $node) {
+  foreach ($nodes as $position => $node) {
     $form[$node->nid]['#node'] = (array) $node;
     if ($node->visible) {
-      $form[$node->nid]['#node'] = (array) $node;
-      $form[$node->nid]['title'] = array('#value' => l($node->title, 'node/'. $node->nid));
-      $form[$node->nid]['author'] = array('#value' => theme('username', $node));
-      $form[$node->nid]['date'] = array('#value' => format_date($node->created, 'small'));
+      $form['nodes'][$position]['#node'] = (array) $node;
+      $form['nodes'][$position]['title'] = array('#value' => l($node->title, 'node/'. $node->nid));
+      $form['nodes'][$position]['author'] = array('#value' => theme('username', $node));
+      $form['nodes'][$position]['date'] = array('#value' => format_date($node->created, 'small'));
     }
     else {
-      $form[$node->nid]['title'] = array('#value' => t('Restricted node, NID: @nid', array('@nid' => $node->nid)));
-      $form[$node->nid]['author'] = array('#value' => '');
-      $form[$node->nid]['date'] = array('#value' => '');
+      $form['nodes'][$position]['title'] = array('#value' => t('Restricted node, NID: @nid', array('@nid' => $node->nid)));
+      $form['nodes'][$position]['author'] = array('#value' => '');
+      $form['nodes'][$position]['date'] = array('#value' => '');
     }
 
-    $form[$node->nid]['edit'] = array('#value' => l(t('edit'), 'node/'. $node->nid .'/edit', array('attributes' => array('title' => t('Edit this node')))));
-    $form[$node->nid]['position'] = array(
+    $form['nodes'][$position]['edit'] = array('#value' => l(t('edit'), 'node/'. $node->nid .'/edit', array('attributes' => array('title' => t('Edit this node')))));
+    $form['nodes'][$position]['position'] = array(
       '#type' => 'position',
       '#delta' => $count,
       '#default_value' => $node->position,
@@ -1083,7 +1084,7 @@ function nodequeue_arrange_subqueue_form
         'id' => 'nodequeue-remove-'. $node->nid,
       ),
     );
-    $form[$node->nid]['remove'] = array('#value' => l(t('remove'), '', $attr));
+    $form['nodes'][$node->position]['remove'] = array('#value' => l(t('remove'), '', $attr));
   }
 
   // add a textfield for adding nodes to the queue
@@ -1172,9 +1173,9 @@ function nodequeue_arrange_subqueue_form
  */
 function nodequeue_arrange_subqueue_form_submit($form, &$form_state, $reverse = FALSE, $shuffle = FALSE) {
   $nodes = array();
-  foreach ($form_state['values'] as $nid => $element) {
-    if (is_numeric($nid)) {
-      $nodes[$form_state['values'][$nid]['position']] = $nid;
+  foreach ($form_state['values']['nodes'] as $pos => $element) {
+    if (is_numeric($pos)) {
+      $nodes[$form_state['values']['nodes'][$pos]['position']] = $nid;
     }
   }
 
@@ -1230,6 +1231,7 @@ function nodequeue_save_subqueue_order($
   $clean = array();
   $count = 1;
   ksort($nodes);
+  
   foreach ($nodes as $pos => $nid) {
     if (!is_numeric($nid) || $nid < 1) {
       return array(NODEQUEUE_INVALID_NID, 'Invalid nid value. New subqueue order not saved.');
@@ -2728,26 +2730,24 @@ function theme_nodequeue_arrange_subqueu
   // render form as table rows
   $rows = array();
   $counter = 1;
-  foreach (element_children($form) as $key) {
-    if (isset($form[$key]['title'])) {
-      $row = array();
-
-      $row[] = drupal_render($form[$key]['title']);
-      $row[] = drupal_render($form[$key]['author']);
-      $row[] = drupal_render($form[$key]['date']);
-      $row[] = drupal_render($form[$key]['position']);
-      $row[] = drupal_render($form[$key]['edit']);
-      $row[] = drupal_render($form[$key]['remove']);
-      $row[] = array(
-        'data' => $counter,
-        'class' => 'position'
-      );
-
-      $rows[] = array(
-        'data'  => $row,
-        'class' => 'draggable',
-      );
-    }
+  foreach (element_children($form['nodes']) as $pos => $key) {
+  drupal_set_message("render for pos $pos");
+    $row = array();
+    $row[] = drupal_render($form['nodes'][$pos + 1]['title']);
+    $row[] = drupal_render($form['nodes'][$pos + 1]['author']);
+    $row[] = drupal_render($form['nodes'][$pos + 1]['date']);
+    $row[] = drupal_render($form['nodes'][$pos + 1]['position']);
+    $row[] = drupal_render($form['nodes'][$pos + 1]['edit']);
+    $row[] = drupal_render($form['nodes'][$pos + 1]['remove']);
+    $row[] = array(
+      'data' => $counter,
+      'class' => 'position'
+    );
+
+    $rows[] = array(
+      'data'  => $row,
+      'class' => 'draggable',
+    );
 
     $counter++;
   }
@@ -2756,7 +2756,7 @@ function theme_nodequeue_arrange_subqueu
   }
 
   // render the main nodequeue table
-  $header = array(t('Title'), t('Author'), t('Post Date'), t('Position'), array('data' => t('Operations'), 'colspan' => 2), t('Position'));
+  $header = array(t('Title'), t('Author'), t('Post Date'), t('Position'), array('data' => t('Operations'), 'colspan' => 2), array('data' => t('Position'), 'sort' => 'desc'));
   $output .= theme('table', $header, $rows, array('id' => 'nodequeue-dragdrop', 'class' => 'nodequeue-dragdrop'));
 
   // render the autocomplete field for adding a node to the table
