diff --git a/modules/book.module b/modules/book.module index 11a81836a8c..0073ca449ae 100644 --- a/modules/book.module +++ b/modules/book.module @@ -82,6 +82,10 @@ function book_link($type) { $links[] = "". t("collaborative book") .""; } + if ($type == "admin" && user_access("administer nodes")) { + $links[] = "". t("collaborative book") .""; + } + return $links ? $links : array(); } @@ -239,25 +243,26 @@ function book_tree($parent = "", $depth = 0) { ** Select all child nodes and render them into a table of contents: */ - $result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND b.parent = '$parent' ORDER BY b.weight, n.title"); + $result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND b.parent = '$parent' ORDER BY b.weight, n.title"); - while ($page = db_fetch_object($result)) { - // load the node: - $node = node_load(array("nid" => $page->nid)); + while ($page = db_fetch_object($result)) { + // load the node: + $node = node_load(array("nid" => $page->nid)); - // take the most recent approved revision: - if ($node->moderate) { - $node = node_revision_load($node, end(node_revision_list($node))); - } + // take the most recent approved revision: + if ($node->moderate) { + $node = node_revision_load($node, end(node_revision_list($node))); + } - // output the content: - $output .= "
  • nid\">". check_output($node->title) ."
  • "; + // output the content: + $output .= "
  • nid\">". check_output($node->title) ."
  • "; - // build the sub-tree of each child: - $output .= book_tree($node->nid, $depth + 1); - } + // build the sub-tree of each child: + $output .= book_tree($node->nid, $depth + 1); + } + + $output = ""; - $output = ""; } return $output; @@ -355,4 +360,93 @@ function book_export_html_recursive($parent = "", $depth = 1) { return $output; } +function book_admin_page($nid, $depth = 0) { + $weight = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30); + + $result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND b.parent = '$nid' ORDER BY b.weight, n.title"); + + while ($node = db_fetch_object($result)) { + $node = node_load(array("nid" => $node->nid)); + + $output .= ""; + $output .= "
    $node->title
    "; + $output .= " ". ($rev = end(node_revision_list($node)) ? $rev : 0) .""; + $output .= " nid\">". t("edit page") .""; + $output .= " nid\">". t("delete page") .""; + $output .= ""; + $output .= book_admin_page($node->nid, $depth + 1); + } + + return $output; +} + +function book_admin_view($nid, $depth = 0) { + + $node = node_load(array("nid" => $nid)); + + $output .= "

    ". check_output($node->title) ."

    "; + $output .= ""; + $output .= " "; + $output .= book_admin_page($nid); + $output .= "
    titlerevoperations
    "; + + return $output; +} + +function book_admin_orphan() { + + $result = db_query("SELECT n.nid, n.title, b.parent FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book'"); + + while ($page = db_fetch_object($result)) { + $pages[$page->nid] = $page; + } + + $output .= ""; + $output .= " "; + foreach ($pages as $nid => $node) { + if ($node->parent && empty($pages[$node->parent])) { + $output .= ""; + } + } + $output .= "
    titleoperations
    nid\">". check_output($node->title) ."nid\">". t("edit page") ."nid\">". t("delete page") ."
    "; + + return $output; +} + +function book_admin_links() { + $result = db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = 0 ORDER BY b.weight, n.title"); + + while ($book = db_fetch_object($result)) { + $links[] = "
    nid\">". t("book") .": ". check_output($book->title) .""; + } + + return $links; +} + +function book_admin() { + global $id, $op; + + if (user_access("administer nodes")) { + + /* + ** Compile a list of the administrative links: + */ + + $links = book_admin_links(); + $links[] = "". t("orphan pages") .""; + + print "". implode(" · ", $links) ."
    "; + + switch ($op) { + case "orphan": + print book_admin_orphan(); + break; + case "view": + print book_admin_view($id); + break; + default: + } + } +} + ?> diff --git a/modules/book/book.module b/modules/book/book.module index 11a81836a8c..0073ca449ae 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -82,6 +82,10 @@ function book_link($type) { $links[] = "". t("collaborative book") .""; } + if ($type == "admin" && user_access("administer nodes")) { + $links[] = "". t("collaborative book") .""; + } + return $links ? $links : array(); } @@ -239,25 +243,26 @@ function book_tree($parent = "", $depth = 0) { ** Select all child nodes and render them into a table of contents: */ - $result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND b.parent = '$parent' ORDER BY b.weight, n.title"); + $result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND b.parent = '$parent' ORDER BY b.weight, n.title"); - while ($page = db_fetch_object($result)) { - // load the node: - $node = node_load(array("nid" => $page->nid)); + while ($page = db_fetch_object($result)) { + // load the node: + $node = node_load(array("nid" => $page->nid)); - // take the most recent approved revision: - if ($node->moderate) { - $node = node_revision_load($node, end(node_revision_list($node))); - } + // take the most recent approved revision: + if ($node->moderate) { + $node = node_revision_load($node, end(node_revision_list($node))); + } - // output the content: - $output .= "
  • nid\">". check_output($node->title) ."
  • "; + // output the content: + $output .= "
  • nid\">". check_output($node->title) ."
  • "; - // build the sub-tree of each child: - $output .= book_tree($node->nid, $depth + 1); - } + // build the sub-tree of each child: + $output .= book_tree($node->nid, $depth + 1); + } + + $output = ""; - $output = ""; } return $output; @@ -355,4 +360,93 @@ function book_export_html_recursive($parent = "", $depth = 1) { return $output; } +function book_admin_page($nid, $depth = 0) { + $weight = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30); + + $result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND b.parent = '$nid' ORDER BY b.weight, n.title"); + + while ($node = db_fetch_object($result)) { + $node = node_load(array("nid" => $node->nid)); + + $output .= ""; + $output .= "
    $node->title
    "; + $output .= " ". ($rev = end(node_revision_list($node)) ? $rev : 0) .""; + $output .= " nid\">". t("edit page") .""; + $output .= " nid\">". t("delete page") .""; + $output .= ""; + $output .= book_admin_page($node->nid, $depth + 1); + } + + return $output; +} + +function book_admin_view($nid, $depth = 0) { + + $node = node_load(array("nid" => $nid)); + + $output .= "

    ". check_output($node->title) ."

    "; + $output .= ""; + $output .= " "; + $output .= book_admin_page($nid); + $output .= "
    titlerevoperations
    "; + + return $output; +} + +function book_admin_orphan() { + + $result = db_query("SELECT n.nid, n.title, b.parent FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book'"); + + while ($page = db_fetch_object($result)) { + $pages[$page->nid] = $page; + } + + $output .= ""; + $output .= " "; + foreach ($pages as $nid => $node) { + if ($node->parent && empty($pages[$node->parent])) { + $output .= ""; + } + } + $output .= "
    titleoperations
    nid\">". check_output($node->title) ."nid\">". t("edit page") ."nid\">". t("delete page") ."
    "; + + return $output; +} + +function book_admin_links() { + $result = db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = 0 ORDER BY b.weight, n.title"); + + while ($book = db_fetch_object($result)) { + $links[] = "
    nid\">". t("book") .": ". check_output($book->title) .""; + } + + return $links; +} + +function book_admin() { + global $id, $op; + + if (user_access("administer nodes")) { + + /* + ** Compile a list of the administrative links: + */ + + $links = book_admin_links(); + $links[] = "". t("orphan pages") .""; + + print "". implode(" · ", $links) ."
    "; + + switch ($op) { + case "orphan": + print book_admin_orphan(); + break; + case "view": + print book_admin_view($id); + break; + default: + } + } +} + ?>