Index: book_access.module
===================================================================
--- book_access.module	(revision 7)
+++ book_access.module	(working copy)
@@ -313,7 +313,7 @@
   global $user;
   $permitted_bids = NULL;
 
-  if ($user->uid == 0 || user_access('administer nodes')) {
+  if ($user->uid == 1 || user_access('administer nodes')) {
     return;
   }
 
@@ -334,11 +334,8 @@
   if (isset($options)) {
     foreach ($options as $bid => $value) {
       // <create new book> option uses current nid as the key, skip it
-      if ($bid == $nid) {
-        continue;
-      }
       if ($bid > 0 && !isset($permitted_bids[$bid])) {
-        unset($options[$nid]);
+        unset($options[$bid]);
       }
     }
   }
@@ -362,3 +359,47 @@
     return array('(unknown gid!)');
   }
 }
+
+
+/**
+ * Implementation of hook_nodeapi().
+ */
+function book_access_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
+  global $user;
+  switch ($op) {
+      case 'alter':
+
+        if ($user->uid == 1 || user_access('administer nodes') ){
+	  break; //show Add Child Page link
+	}
+
+        $sql = "
+          SELECT nid
+          FROM {node_access}
+          WHERE realm = 'book_access'
+          AND gid IN (%s)
+          AND grant_update > 0
+        ";
+
+	$permitted_bids = array();
+        $results = db_query($sql, implode(',', array_keys($user->roles)));
+
+        while ($result = db_fetch_array($results)) {
+          $permitted_bids[] = $result['nid'];
+        }
+	$book_permitted = in_array( $node->book['bid'], $permitted_bids);
+
+	
+        $child_type = variable_get('book_child_type', 'book');
+	if($book_permitted && (user_access('add content to books') || user_access('administer book outlines')) && node_access('create', $child_type) && $node->status == 1 && $node->book['depth'] < MENU_MAX_DEPTH) {
+	  break; //show Add Child Page link
+	}
+        unset($node->links['book_add_child']); //remove Add Child Page link
+        break;
+  }
+
+  return $node;
+}
+
+
+?>
