--- coherent_access/coherent_access.module	2009-02-02 15:47:19.000000000 -0600
+++ ./coherent_access.module	2009-02-12 15:28:33.000000000 -0600
@@ -202,33 +202,41 @@ function coherent_access_shared_editing(
   $node = $form['#node'];
 
   $editors = array();
+  if ($node->nid) {
+    // get editors excluding delete privilege (as that is author only)
+    $result = db_query("SELECT u.uid, u.name FROM {users} u 
+                        LEFT JOIN {coherent_access_user} cu on cu.uid = u.uid
+                        LEFT JOIN {coherent_access_gid} cg ON cu.gid = cg.gid
+                        WHERE  cg.nid = %d 
+                          AND cg.mode & %d AND (cg.mode & %d = %d)",
+                        $node->nid, COHERENT_ACCESS_EDIT, COHERENT_ACCESS_DELETE, 0);
+    while ($editor = db_fetch_object($result)) {
+      $editors[$editor->uid] = $editor->name;
+    }
+  }
 
-  if ($user->uid == $node->uid || variable_get('coherent_access_trust_editors', TRUE) || user_access('administer nodes')) {
-    if ($node->nid) {
-      // get editors excluding delete privilege (as that is author only)
-      $result = db_query("SELECT u.uid, u.name FROM {users} u 
-                          LEFT JOIN {coherent_access_user} cu on cu.uid = u.uid
-                          LEFT JOIN {coherent_access_gid} cg ON cu.gid = cg.gid
-                          WHERE  cg.nid = %d 
-                            AND cg.mode & %d AND (cg.mode & %d = %d)",
-                          $node->nid, COHERENT_ACCESS_EDIT, COHERENT_ACCESS_DELETE, 0);
-      while ($editor = db_fetch_object($result)) {
-        $editors[$editor->uid] = $editor->name;
-      }
-    }
-  
-    $viewers = array();
-    if ($node->nid) {
-      $result = db_query("SELECT u.uid, u.name FROM {users} u 
-                          LEFT JOIN {coherent_access_user} cu on cu.uid = u.uid
-                          LEFT JOIN {coherent_access_gid} cg ON cu.gid = cg.gid
-                          WHERE  cg.nid = %d 
-                            AND cg.mode = %d", 
-                          $node->nid, COHERENT_ACCESS_VIEW);
-      while ($viewer = db_fetch_object($result)) {
-        $viewers[$viewer->uid] = $viewer->name;
-      }
+  $viewers = array();
+  if ($node->nid) {
+    $result = db_query("SELECT u.uid, u.name FROM {users} u 
+                        LEFT JOIN {coherent_access_user} cu on cu.uid = u.uid
+                        LEFT JOIN {coherent_access_gid} cg ON cu.gid = cg.gid
+                        WHERE  cg.nid = %d 
+                          AND cg.mode = %d", 
+                        $node->nid, COHERENT_ACCESS_VIEW);
+    while ($viewer = db_fetch_object($result)) {
+      $viewers[$viewer->uid] = $viewer->name;
     }
+  }
+
+  // see if this node is set as private
+  if (isset($node->coherent_access['private'])) {
+    $private = $node->coherent_access['private'];
+  }
+  else {
+    $private = variable_get('coherent_access_default_node_private', 0);
+  }
+
+  if ($user->uid == $node->uid || variable_get('coherent_access_trust_editors', TRUE) || user_access('administer nodes')) {
   
     $form['shared_editing'] = array(
       '#type' => 'fieldset',
@@ -239,14 +247,6 @@ function coherent_access_shared_editing(
       '#description' => t('Choose users who can edit and view this content. The content author is always an editor and the only one who can delete.'),
     );
 
-    // see if this node is set as private
-    if (isset($node->coherent_access['private'])) {
-      $private = $node->coherent_access['private'];
-    }
-    else {
-      $private = variable_get('coherent_access_default_node_private', 0);
-    }
-  
     $form['shared_editing']['private'] = array(
       '#type' => 'checkbox',
       '#title' => t('Private'),
@@ -254,7 +254,7 @@ function coherent_access_shared_editing(
       '#default_value' => $private,
     );
 
-  
+
     $form['shared_editing']['edit'] = array(
       '#type' => 'fieldset',
       '#collapsible' => TRUE,
@@ -289,7 +289,7 @@ function coherent_access_shared_editing(
       '#default_value' => serialize($editors),
     );
   
-    $form['shared_editing']['view'] = array(
+   $form['shared_editing']['view'] = array(
       '#type' => 'fieldset',
       '#collapsible' => TRUE,
       '#collapsed' => FALSE,
@@ -322,6 +322,23 @@ function coherent_access_shared_editing(
   
     $form['#after_build'][] = 'coherent_access_form_after_build';
   }
+  else {  // preserve existing shared_editing fields
+    $form['shared_editing'] = array(
+      '#tree' => TRUE,
+    );
+    $form['shared_editing']['private'] = array(
+      '#type' => 'value',
+      '#value' => $private,
+    );
+    $form['shared_editing']['view']['viewer_list'] = array(
+      '#type' => 'value',
+      '#value' => serialize($viewers),
+    );
+    $form['shared_editing']['edit']['editor_list'] = array(
+      '#type' => 'value',
+      '#value' => serialize($editors),
+    );
+  }
 }
 
 /**
@@ -813,7 +830,7 @@ function coherent_access_access_user_sha
   global $user;
   
   if ($auid == $user->uid || user_access('administer nodes')) {
-    return _coherent_access_user_has_shared_content($auser->uid);  // return true only if the user has shared content
+    return _coherent_access_user_has_shared_content($auid);  // return true only if the user has shared content
   }
   else {
     return FALSE;
