--- coherent_access.module	2009-01-15 14:32:22.000000000 +0100
+++ coherent_access.module.linksunten	2009-01-15 14:08:02.000000000 +0100
@@ -65,8 +65,10 @@
   }
 }
 
+// This function is currently not used:
+
 function coherent_access_show_collaborative_content($uid = NULL) {
-  if ($uid === NULL) {
+  if ($uid === NULL) { 
     global $user;
     $uid = $user->uid;
   }
@@ -76,7 +78,7 @@
 }
 
 function coherent_access_show_my_nodes($num = 0, $uid = NULL) {
-  if ($uid === NULL) {
+  if ($uid == NULL) {
     global $user;
     $uid = $user->uid;
   }
@@ -91,7 +93,7 @@
   if (!empty($nodes)) {
     $items = array();
     foreach ($nodes as $mode => $node) {
-      if (!empty($node)) {
+      if (!empty($mode)) { // changed by MN
         $items[$mode]['data'] = $text[$mode];
         $items[$mode]['children'] = array();
         foreach ($node as $nid => $info) {
@@ -129,6 +131,12 @@
     '#default_value' => variable_get('coherent_access_default_node_private', 0)
   );
   
+  $form['coherent_access_always_private'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('If checked, there is not button to publish a shared node.'),
+    '#default_value' => variable_get('coherent_access_always_private', FALSE)
+  );
+  
   $form['coherent_access_trust_editors'] = array(
     '#type' => 'checkbox',
     '#title' => t('Trust editors'),
@@ -145,13 +153,13 @@
   $form['coherent_access_subject'] = array(
     '#type' => 'textarea',
     '#title' => t('Email notification subject'),
-    '#default_value' => variable_get('coherent_access_subject', 'You have been added as a %role  for %nodetitle by %sender'),
+    '#default_value' => variable_get('coherent_access_subject', 'You have been added as a %role for %nodetitle by %sender'),
   );
   
   $form['coherent_access_body'] = array(
     '#type' => 'textarea',
     '#title' => t('Email notification body'),
-    '#default_value' => variable_get('coherent_access_body', 'You have been added as a %role for %nodetitle by %sender. You can access this by going to %nodeurl'),
+    '#default_value' => variable_get('coherent_access_body', 'Dear %recipient, You have been added as a %role for %nodetitle by %sender. You can access this by going to %nodeurl'),
   );
 
   return system_settings_form($form);
@@ -170,7 +178,7 @@
 */
 function coherent_access_menu() {
   $items = array();
-  global $user; 
+//  global $user;   // this is not used here... omit?  MN
   
   $items['admin/settings/coherent-access'] = array(
     'title' => 'Coherent Access',
@@ -180,6 +188,11 @@
     'access arguments' => array('administer site configuration'),
   );
 
+// MN:  thinking through this...
+// with %user, the argument passed to the callback function 
+// will be user_load(xxx) for a url of user/xxx/shared-posts
+// so it is not a user id that is being passed, but the user object
+
   $items['user/%user/shared-posts'] = array( //TEST: ensure links are created properly
     'type' => MENU_LOCAL_TASK,
     'title' => 'Shared Posts',
@@ -239,15 +252,14 @@
     else {
       $private = variable_get('coherent_access_default_node_private', 0);
     }
-  
+
     $form['shared_editing']['private'] = array(
-      '#type' => 'checkbox',
+      '#type' => variable_get('coherent_access_always_private', FALSE) ? 'hidden' : 'checkbox',
       '#title' => t('Private'),
       '#description' => t('If checked only those users listed as editors, or viewers below, as well as the author will be allowed to view and/or edit.'),
       '#default_value' => $private,
     );
 
-  
     $form['shared_editing']['edit'] = array(
       '#type' => 'fieldset',
       '#collapsible' => TRUE,
@@ -495,15 +507,14 @@
           foreach ($inserts as $uid => $mode) {
             if (empty($existing) || !array_key_exists($uid, $existing)) {
               $params['recipient'] = user_load(array('uid' => $uid));
-              if ($mode == COHERENT_ACCESS_EDIT | COHERENT_ACCESS_VIEW) {
+              if ($mode == 3) {
                 $params['role'] = 'editor';
               }
               else {
                 $params['role'] = 'viewer';
               }
               $mailkey = 'coherent_access'. $node->nid .'_'. $uid;
-              coherent_access_mail($key, $message, $params);
-              drupal_mail($mailkey, $params['recipient']->mail, $message['subject'], $message['body']);
+              drupal_mail('coherent_access', $mailkey, $params['recipient']->mail, user_preferred_language($params['recipient']), $params, $params['sender']->name);
             }
           }
         }
@@ -643,9 +654,12 @@
   return $gids;
 }
 
-function coherent_access_collaborative_content($uid) {
-  $account = user_load(array('uid' => $uid));
-  drupal_set_title($uid < 0 ? t('Shared Posts') : check_plain($account->name));
+function coherent_access_collaborative_content($u) { // changed to $u less confusing
+// $u is the result of user_load(%user), i.e. a user object here
+//  $account = user_load(array('uid' => $uid));  MN: Not needed!
+
+  $uid = $u->uid;
+  drupal_set_title($uid < 0 ? t('Shared Posts') : 'Shared Posts for ' . check_plain($u->name));
   $content = coherent_access_show_my_nodes(0, $uid);
   if ($content) {
     return $content;
@@ -678,7 +692,7 @@
   $node = $params['node'];
   
   $subject = variable_get('coherent_access_subject', 'You have been added as a %role for %nodetitle by %sender. You can access this by going to %nodeurl');
-  $body = variable_get('coherent_access_body', 'You have been added as a %role for %nodetitle by %sender. You can access this by going to %nodeurl');
+  $body = variable_get('coherent_access_body', 'Dear %recipient, You have been added as a %role for %nodetitle by %sender. You can access this by going to %nodeurl');
   
   $urlpath = 'node/'. $node->nid;
   
@@ -732,10 +746,11 @@
  *  with those being keyed by nid => array('title' => $title, 'type' => $type)
  */
 function coherent_access_get_user_nodes($uid) {
+
   $return = array('mine' => array(), 'editor' => array(), 'viewer' => array());
   
   // load mynodes
-  $result = db_query('SELECT n.nid, n.title, n.type FROM {node} n WHERE uid = %d ORDER BY n.changed DESC', $uid);
+  $result = db_query('SELECT n.nid, n.title, n.type FROM {node} n WHERE n.uid = %d ORDER BY n.changed DESC', $uid);
   while ($row = db_fetch_object($result)) {
     if (_coherent_access_is_coherently_accessible($row)) {
       $return['mine'][$row->nid] = array('title' => $row->title, 'type' => $row->type);
@@ -770,15 +785,14 @@
 // this function determines if the currently logged in user 
 // or the user with uid=$vuid if $vuid non-zero can access 
 // the shared shared post listing for user $uid
-function coherent_access_access_user_shared_posts($uid, $vuid = 0) {
+
+// MN: note callback only has one argument user_load(%user)
+// removed second argument and simplified code
+function coherent_access_access_user_shared_posts($u) {
   global $user;
-  if ($vuid == 0) {
-    $vuid = $user->uid;
-  }
-  
-  if (is_object($uid)) {
-    $uid = $uid->uid;
-  }
+
+  $vuid = $user->uid;
+  $uid = $u->uid;
   
   // as long as the user is the requesting user or admin, grant access
   if ($vuid == $uid || $vuid == 1) {
