Index: book.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/book/book.module,v
retrieving revision 1.406.2.1
diff -u -p -r1.406.2.1 book.module
--- book.module	14 Feb 2007 04:30:33 -0000	1.406.2.1
+++ book.module	31 Aug 2008 19:04:58 -0000
@@ -23,7 +23,7 @@ function book_node_info() {
  * Implementation of hook_perm().
  */
 function book_perm() {
-    return array('outline posts in books', 'create book pages', 'create new books', 'edit book pages', 'edit own book pages', 'see printer-friendly version');
+  return array('outline posts in books', 'create book pages', 'create new books', 'edit book pages', 'edit own book pages', 'see printer-friendly version', 'search book pages');
 }
 
 /**
@@ -151,32 +151,50 @@ function book_menu($may_cache) {
  * single-node view of a book node.
  */
 function book_block($op = 'list', $delta = 0) {
-  $block = array();
-  if ($op == 'list') {
-    $block[0]['info'] = t('Book navigation');
-    return $block;
-  }
-  else if ($op == 'view') {
-    // Only display this block when the user is browsing a book:
-    if (arg(0) == 'node' && is_numeric(arg(1))) {
-      $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.nid = %d'), arg(1));
-      if (db_num_rows($result) > 0) {
-        $node = db_fetch_object($result);
+  $blocks = array();
 
-        $path = book_location($node);
-        $path[] = $node;
+  if ($op == 'list') {
+    $blocks[0]['info'] = t('Book navigation');
+    if (module_exists('search')) {
+      $blocks[1]['info'] = t('Search the Handbooks');
+    }
 
-        $expand = array();
-        foreach ($path as $key => $node) {
-          $expand[] = $node->nid;
+    return $blocks;    
+  }
+  elseif ($op == 'view') {
+    switch ($delta) {
+      case '1':
+        if (user_access('search content') && user_access('search book pages') && module_exists('search')) {
+          return array(
+            'subject' => t('Search the Handbooks'), 
+            'content' => drupal_get_form('book_search_box', 'book'),
+          );
         }
+        break;
+      
+      default:
+        // Only display this block when the user is browsing a book:
+        if (arg(0) == 'node' && is_numeric(arg(1))) {
+          $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.nid = %d'), arg(1));
+          if (db_num_rows($result) > 0) {
+            $node = db_fetch_object($result);
+
+            $path = book_location($node);
+            $path[] = $node;
+
+            $expand = array();
+            foreach ($path as $key => $node) {
+              $expand[] = $node->nid;
+            }
 
-        $block['subject'] = check_plain($path[0]->title);
-        $block['content'] = book_tree($expand[0], 5, $expand);
+            $block['subject'] = check_plain($path[0]->title);
+            $block['content'] = book_tree($expand[0], 5, $expand);
+          }
+        }
+        break;
       }
-    }
 
-    return $block;
+    return $blocks;
   }
 }
 
@@ -253,6 +271,30 @@ function book_form(&$node) {
 }
 
 /**
+ * Implementation of hook_form().
+ *
+ * @param string $node_type
+ *   The nodes to search with this form. Should only be Book nodes.
+ */
+function book_search_box($node_type) {
+  $form = search_box('book_search_box_'. $node_type);
+  $form['node_type'] = array(
+    '#type' => 'value',
+    '#value' => $node_type,
+  );
+  $form['#base'] = 'book_search_box_form';
+
+  return $form;
+}
+
+function book_search_box_form_submit($form_id, $form_values) {
+  $search_string = trim($form_values[$form_id . '_' . $form_values['node_type'] . '_keys']);
+  $search_type   = 'type:' . $form_values['node_type'];
+  
+  return 'search/node/' . $search_string . ' ' . $search_type;
+}
+
+/**
  * Implementation of function book_outline()
  * Handles all book outline operations.
  */
