--- workspace.module	2005-06-01 16:31:25.000000000 -0400
+++ ../../modules/workspace/workspace.module	2005-06-03 04:24:16.000000000 -0400
@@ -155,7 +155,7 @@
   }
 
   $sql = 'SELECT '. implode(', ', $node_select) .' FROM '. implode(', ', $node_from) .' '. implode(' ', $node_join) .' WHERE '. implode(' ', $node_where);
-  $count_sql = 'SELECT COUNT(n.nid) FROM '. implode(', ', $node_from) .' '. implode(' ', $node_join) .' WHERE '. implode(' ', $node_where);
+  // $count_sql = 'SELECT COUNT(n.nid) FROM '. implode(', ', $node_from) .' '. implode(' ', $node_join) .' WHERE '. implode(' ', $node_where);
 
   if ($comments_enabled) {
     $select = '';
@@ -165,16 +165,21 @@
     }
     $comment_sql = 'SELECT c.nid AS cnid, c.uid, "" AS type, c.cid, c.subject, c.status, c.timestamp, c.pid, 0 '. $select .' FROM {node} n, {comments} AS c LEFT JOIN {node_comment_statistics} s ON n.nid = s.nid WHERE c.uid = '. db_escape_string($user->uid);
     $sql .= ' UNION '. $comment_sql;
-    $count_sql = 'SELECT COUNT(n.nid) + COUNT(c.cid) FROM '. implode(', ', $node_from) .' '. implode(' ', $node_join) .' LEFT JOIN {comments} AS c ON c.uid = '. db_escape_string($user->uid). ' WHERE '. implode(' ', $node_where);
-  }
- 
+    // $count_sql = 'SELECT COUNT(n.nid) + COUNT(c.cid) FROM '. implode(', ', $node_from) .' '. implode(' ', $node_join) .' LEFT JOIN {comments} AS c ON c.uid = '. db_escape_string($user->uid). ' WHERE '. implode(' ', $node_where);
+  } 
+
+  // This replaces the function of the SQL that has been commented out above.
+  // The $count_sql for when comment.module is enabled is broken and does not report accurate values.
+  $mods_enabled = array('comments' => $comments_enabled, 'nodeperm_role' => $nodeperm_role_enabled);  
+  $count_sql = "SELECT " . workspace_count_fakeout($mods_enabled, $node_from, $node_join, $node_where);
+
    // build the combined node/comment listing
   $header = array(
     array('data' => t('Type'), 'field' => 'type'),
     array('data' => t('Title'), 'field' => 'title'),
     array('data' => t('Owner'), 'field' => 'uid'),
     array('data' => t('Published'), 'field' => 'status'),
-    array('data' => t('Modified'), 'field' => 'changed', 'sort' => 'asc'),
+    array('data' => t('Modified'), 'field' => 'changed', 'sort' => 'desc'),
     $comments_enabled ? array('data' => t('Replies'), 'field' => 'comment_count') : array('data' => ''),
     array('data' => t('Operations'), 'colspan' => 2)
   );
@@ -341,6 +346,32 @@
   return count($errors) == 0;
 }
 
+/*
+ * This is a *workaround* for the $count_sql problem that misinforms pager_query().  
+ * This should probably be accomplished in SQL like the original attempted to do.
+ * Below are the original queries. The top one is the broken one that tries to count 
+ * nodes and comments posted by or editable by a user.  The bottom query seems to work
+ * fine, though I haven't tested it with the nodeperm module enabled.  Good luck.
+ *
+ * $count_sql = 'SELECT COUNT(n.nid) + COUNT(c.cid) FROM '. implode(', ', $node_from) .' '. implode(' ', $node_join) .' LEFT JOIN {comments} AS c ON c.uid = '. db_escape_string($user->uid). ' WHERE '. implode(' ', $node_where);
+ * $count_sql = 'SELECT COUNT(n.nid) FROM '. implode(', ', $node_from) .' '. implode(' ', $node_join) .' WHERE '. implode(' ', $node_where);
+ */
+function workspace_count_fakeout($mods_enabled, $node_from, $node_join, $node_where) {
+  global $user;
+  $fakeout = 0;
+  $count_sql = '(SELECT COUNT(n.uid) as count FROM '. implode(', ', $node_from) .' '. implode(' ', $node_join) .' WHERE '. implode(' ', $node_where). ')';
+
+  if ($mods_enabled['comments']) {
+    $count_sql .= ' UNION (SELECT COUNT(c.uid) as count FROM {comments} AS c WHERE c.uid = '. db_escape_string($user->uid). ')';
+  } 
+ 
+  $result = db_query($count_sql);
+  while($row = db_fetch_array($result)) {
+    $fakeout += $row['count'];
+  }
+  return $fakeout;
+}
+
 /********************************************************************
 * Module Functions :: Setters
 ********************************************************************/
