diff options
-rw-r--r-- | modules/book.module | 49 | ||||
-rw-r--r-- | modules/book/book.module | 49 |
2 files changed, 40 insertions, 58 deletions
diff --git a/modules/book.module b/modules/book.module index 1b975695b..6a094870a 100644 --- a/modules/book.module +++ b/modules/book.module @@ -44,7 +44,7 @@ function theme_book($node) { $output .= "<P>". check_output($node->body, 1) ."</P>"; } - $theme->box(t("Handbook"), $output ."". book_overview($node->nid) ."". book_navigation($node)); + $theme->box(t("Handbook"), $output ."". book_tree($node->nid) ."". book_navigation($node)); } function book_view($node, $page = 1) { @@ -75,12 +75,13 @@ function book_search() { print search_data($keys, $mod); } -function book_toc($parent = 0, $offset = 0, $toc = array()) { +function book_toc($parent = 0, $offset = "", $toc = array()) { global $status; $result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.type = 'book' AND n.status = '$status[posted]' AND b.parent = '$parent' ORDER BY b.weight"); while ($node = db_fetch_object($result)) { - $toc[$node->nid] = ($offset ? $offset : "") ."". ++$number .". $node->title"; - $toc = book_toc($node->nid, ($offset ? $offset : "") ."$number.", $toc); + $toc[$node->nid] = "$offset $node->title"; + if ($node->pid) $toc = book_toc($node->pid, "$offset-", $toc); + $toc = book_toc($node->nid, "$offset-", $toc); } return $toc; } @@ -163,33 +164,23 @@ function book_delete($id) { return ($node = node_del("nid", $id) ? "book page has been deleted" : "failed to delete book page: change status to 'dumped' first"); } -function book_overview($parent = "", $offset = "") { +function book_tree($parent = "") { global $PHP_SELF, $status; - $result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.type = 'book' AND (n.status = '$status[posted]' OR n.status = '$status[expired]') AND b.parent = '$parent' ORDER BY b.weight"); - - $output .= "<DL>"; + $result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.type = 'book' AND n.status = '$status[posted]' AND b.parent = '$parent' ORDER BY b.weight"); - $nodes = array(); + $output .= "<UL>"; while ($node = db_fetch_object($result)) { - if ($node->status == $status[posted]) { - $number++; - if ($offset) $output .= "<DT>$offset$number. <A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A>\n"; - else $output .= "<DT><P>$number. <B><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></B>\n"; - if ($PHP_SELF == "/admin.php") $output .= " <SMALL>(weight: $node->weight, status: $node->status) (<A HREF=\"admin.php?mod=book&op=edit&id=$node->nid\">edit</A>, <A HREF=\"admin.php?mod=book&op=delete&id=$node->nid\">delete</A>)</SMALL>"; - } - array_push($nodes, $node); + $output .= "<LI><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A>"; + if ($PHP_SELF == "/admin.php") $output .= " <SMALL>(weight: $node->weight/$node->parent, status: $node->status) (<A HREF=\"admin.php?mod=book&op=edit&id=$node->nid\">edit</A>, <A HREF=\"admin.php?mod=book&op=delete&id=$node->nid\">delete</A>)</SMALL>\n"; + if ($node->pid) $output .= book_tree($node->pid); + $output .= book_tree($node->nid); } - - foreach ($nodes as $node) { - $output .= book_overview($node->nid, "$offset$number."); - } - - $output .= "</DL>"; + $output .= "</UL>"; return $output; } -function book_history() { +function book_list() { global $status; $result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.type = 'book' AND n.status != '$status[expired]' ORDER BY n.timestamp DESC"); @@ -206,7 +197,7 @@ function book_history() { function book_admin() { global $op, $id, $edit, $user; - print "<SMALL><A HREF=\"admin.php?mod=book&op=add\">add new page</A> | <A HREF=\"admin.php?mod=book&op=history\">history</A> | <A HREF=\"admin.php?mod=book&op=search\">search book</A> | <A HREF=\"admin.php?mod=book\">overview</A></SMALL><HR>\n"; + print "<SMALL><A HREF=\"admin.php?mod=book&op=add\">add new page</A> | <A HREF=\"admin.php?mod=book&op=search\">search book</A> | <A HREF=\"admin.php?mod=book&op=list\">list overview</A> | <A HREF=\"admin.php?mod=book\">tree overview</A></SMALL><HR>\n"; switch ($op) { case "add": @@ -214,10 +205,10 @@ function book_admin() { break; case "delete": print book_delete($id); - print book_overview(); + print book_tree(); break; - case "history": - print book_history(); + case "list": + print book_list(); break; case "edit": print book_form(node_get_array(nid, $id)); @@ -231,10 +222,10 @@ function book_admin() { break; case t("Submit"): book_save($edit); - print book_overview(); + print book_tree(); break; default: - print book_overview(); + print book_tree(); } } diff --git a/modules/book/book.module b/modules/book/book.module index 1b975695b..6a094870a 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -44,7 +44,7 @@ function theme_book($node) { $output .= "<P>". check_output($node->body, 1) ."</P>"; } - $theme->box(t("Handbook"), $output ."". book_overview($node->nid) ."". book_navigation($node)); + $theme->box(t("Handbook"), $output ."". book_tree($node->nid) ."". book_navigation($node)); } function book_view($node, $page = 1) { @@ -75,12 +75,13 @@ function book_search() { print search_data($keys, $mod); } -function book_toc($parent = 0, $offset = 0, $toc = array()) { +function book_toc($parent = 0, $offset = "", $toc = array()) { global $status; $result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.type = 'book' AND n.status = '$status[posted]' AND b.parent = '$parent' ORDER BY b.weight"); while ($node = db_fetch_object($result)) { - $toc[$node->nid] = ($offset ? $offset : "") ."". ++$number .". $node->title"; - $toc = book_toc($node->nid, ($offset ? $offset : "") ."$number.", $toc); + $toc[$node->nid] = "$offset $node->title"; + if ($node->pid) $toc = book_toc($node->pid, "$offset-", $toc); + $toc = book_toc($node->nid, "$offset-", $toc); } return $toc; } @@ -163,33 +164,23 @@ function book_delete($id) { return ($node = node_del("nid", $id) ? "book page has been deleted" : "failed to delete book page: change status to 'dumped' first"); } -function book_overview($parent = "", $offset = "") { +function book_tree($parent = "") { global $PHP_SELF, $status; - $result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.type = 'book' AND (n.status = '$status[posted]' OR n.status = '$status[expired]') AND b.parent = '$parent' ORDER BY b.weight"); - - $output .= "<DL>"; + $result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.type = 'book' AND n.status = '$status[posted]' AND b.parent = '$parent' ORDER BY b.weight"); - $nodes = array(); + $output .= "<UL>"; while ($node = db_fetch_object($result)) { - if ($node->status == $status[posted]) { - $number++; - if ($offset) $output .= "<DT>$offset$number. <A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A>\n"; - else $output .= "<DT><P>$number. <B><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></B>\n"; - if ($PHP_SELF == "/admin.php") $output .= " <SMALL>(weight: $node->weight, status: $node->status) (<A HREF=\"admin.php?mod=book&op=edit&id=$node->nid\">edit</A>, <A HREF=\"admin.php?mod=book&op=delete&id=$node->nid\">delete</A>)</SMALL>"; - } - array_push($nodes, $node); + $output .= "<LI><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A>"; + if ($PHP_SELF == "/admin.php") $output .= " <SMALL>(weight: $node->weight/$node->parent, status: $node->status) (<A HREF=\"admin.php?mod=book&op=edit&id=$node->nid\">edit</A>, <A HREF=\"admin.php?mod=book&op=delete&id=$node->nid\">delete</A>)</SMALL>\n"; + if ($node->pid) $output .= book_tree($node->pid); + $output .= book_tree($node->nid); } - - foreach ($nodes as $node) { - $output .= book_overview($node->nid, "$offset$number."); - } - - $output .= "</DL>"; + $output .= "</UL>"; return $output; } -function book_history() { +function book_list() { global $status; $result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.type = 'book' AND n.status != '$status[expired]' ORDER BY n.timestamp DESC"); @@ -206,7 +197,7 @@ function book_history() { function book_admin() { global $op, $id, $edit, $user; - print "<SMALL><A HREF=\"admin.php?mod=book&op=add\">add new page</A> | <A HREF=\"admin.php?mod=book&op=history\">history</A> | <A HREF=\"admin.php?mod=book&op=search\">search book</A> | <A HREF=\"admin.php?mod=book\">overview</A></SMALL><HR>\n"; + print "<SMALL><A HREF=\"admin.php?mod=book&op=add\">add new page</A> | <A HREF=\"admin.php?mod=book&op=search\">search book</A> | <A HREF=\"admin.php?mod=book&op=list\">list overview</A> | <A HREF=\"admin.php?mod=book\">tree overview</A></SMALL><HR>\n"; switch ($op) { case "add": @@ -214,10 +205,10 @@ function book_admin() { break; case "delete": print book_delete($id); - print book_overview(); + print book_tree(); break; - case "history": - print book_history(); + case "list": + print book_list(); break; case "edit": print book_form(node_get_array(nid, $id)); @@ -231,10 +222,10 @@ function book_admin() { break; case t("Submit"): book_save($edit); - print book_overview(); + print book_tree(); break; default: - print book_overview(); + print book_tree(); } } |