--- bookexpand.module	2007-03-20 13:52:19.000000000 +0100
+++ bookexpand.patched.module	2007-04-30 17:47:49.000000000 +0200
@@ -120,7 +120,7 @@ function bookexpand_form_alter ($form_id
 					'#options' => bookexpand_toc_private($node->nid),
 					'#weight' => -4,
 					'#description' => user_access('create new books') ? t('The parent section in which to place this page.  Note that each page whose parent is &lt;top-level&gt; is an independent, top-level book.') : t('The parent that this page belongs in.'),
-				);			
+				);
 			}
 		}
 	}
@@ -187,8 +187,7 @@ function bookexpand_toc_role ($exclude =
 function bookexpand_toc_group ($exclude = 0) {
 
 	$request = $_SERVER['REQUEST_URI'];
-	preg_match('/edit\[og_groups\]\[\]\=(.*)/', $request, $match);
-	
+	preg_match('/node\/add\/book\?gids\[\]\=(.*)/', $request, $match);
 	global $user;
 	$uid = $user->uid;
 	$group = $user->og_groups;
@@ -231,8 +230,8 @@ function bookexpand_toc_user ($nid) {
 	global $user;
 	$uid = $user->uid;
 	
-	if (($uid != 1)&&(module_exists('private'))) {
-		$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid INNER JOIN {private} p ON n.nid = p.nid WHERE n.status = 1 AND n.uid = '.$uid.' AND p.private < 1 ORDER BY b.weight, n.title';
+	if ($uid != 1) {
+		$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.uid = '.$uid.' ORDER BY b.weight, n.title';
 	} else {
 		$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 ORDER BY b.weight, n.title';
 	}
@@ -249,8 +248,8 @@ function bookexpand_toc_private($nid) {
 	global $user;
 	$uid = $user->uid;
 	
-	if ($uid != 1) {
-		$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid INNER JOIN {private} p ON n.nid = p.nid WHERE n.status = 1 AND p.private <> 1 ORDER BY b.weight, n.title';
+	if (($uid != 1)&&(module_exists('private'))) {
+		$query = "SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid INNER JOIN {private} p ON n.nid = p.nid WHERE n.status = 1 AND p.private <> 1 OR p.nid = ANY (SELECT no.nid FROM {node} no WHERE no.uid = $uid) ORDER BY b.weight, n.title";
 	} else {
 		// User 1 can see all choices.
 		$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 ORDER BY b.weight, n.title';
