2001-03-24 16:36:13 +00:00
<?php
2001-10-20 18:57:09 +00:00
// $Id$
2001-03-24 16:36:13 +00:00
2001-11-01 17:04:20 +00:00
function book_node($field) {
global $user;
$info = array("name" => "book page");
return $info[$field];
}
function book_access($op, $node) {
if ($op == "view") {
2001-11-03 18:38:30 +00:00
return ($node->nid && $node->status && !$node->moderate);
2001-11-01 17:04:20 +00:00
}
if ($op == "create") {
return 1;
}
if ($op == "update") {
return 1;
}
}
2001-11-01 11:00:51 +00:00
function book_link($type) {
if ($type == "page" && user_access("access content")) {
$links[] = "<a href=\"module.php?mod=book\">". t("collaborative book") ."</a>";
2001-03-25 10:57:01 +00:00
}
2001-11-01 11:00:51 +00:00
return $links ? $links : array();
2001-03-25 10:57:01 +00:00
}
2001-11-01 11:00:51 +00:00
function book_load($node) {
$book = db_fetch_object(db_query("SELECT parent, weight FROM book WHERE nid = '$node->nid'"));
return $book;
2001-06-29 22:08:57 +00:00
}
2001-11-01 11:00:51 +00:00
function book_insert($node) {
if ($node->pid && $node->status == 1) {
db_query("UPDATE node SET status = 0 WHERE nid = '$node->pid'");
2001-06-29 22:08:57 +00:00
}
2001-11-01 11:00:51 +00:00
db_query("INSERT INTO book (nid, pid, parent, weight, log) VALUES ('$node->nid', '$node->pid', '$node->parent', '$node->weight', '$node->log')");
}
2001-06-29 22:08:57 +00:00
2001-11-01 11:00:51 +00:00
function book_update($node) {
if ($node->pid && $node->status == 1) {
db_query("UPDATE node SET status = 0 WHERE nid = '$node->pid'");
2001-06-29 22:08:57 +00:00
}
2001-11-01 11:00:51 +00:00
db_query("UPDATE book SET parent = '$node->parent', weight = '$node->weight', log = '$node->log' WHERE nid = '$node->nid'");
}
2001-06-29 22:08:57 +00:00
2001-11-01 11:00:51 +00:00
function book_delete($node) {
if ($node->pid && $node->status == 1) {
db_query("UPDATE node SET status = 1 WHERE nid = '$node->pid'");
}
db_query("DELETE FROM book WHERE nid = '$node->nid'");
2001-06-20 20:00:40 +00:00
}
2001-11-01 11:00:51 +00:00
function book_save($node) {
2001-11-01 17:04:20 +00:00
if ($node->nid && user_access("administer nodes")) {
return array("pid", "log", "parent", "weight");
2001-11-01 11:00:51 +00:00
}
else {
2001-11-01 17:04:20 +00:00
return array("moderate" => 1, "promote" => 0, "status" => 0, "log", "parent", "weight");
2001-11-01 11:00:51 +00:00
}
2001-04-07 15:02:28 +00:00
}
2001-04-04 12:54:10 +00:00
function book_location($node, $nodes = array()) {
2001-10-16 20:13:22 +00:00
$parent = db_fetch_object(db_query("SELECT n.nid, n.title, b.parent FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.nid = '$node->parent'"));
2001-04-04 12:54:10 +00:00
if ($parent->title) {
$nodes = book_location($parent, $nodes);
array_push($nodes, $parent);
}
return $nodes;
}
2001-04-16 18:21:22 +00:00
function book_view($node, $main = 0) {
2001-11-01 11:00:51 +00:00
global $theme;
2001-03-24 16:36:13 +00:00
2001-05-24 10:05:18 +00:00
if ($main) {
$theme->node($node, $main);
2001-04-04 12:54:10 +00:00
}
2001-05-24 10:05:18 +00:00
else {
if ($node->nid && $node->parent) {
$list = book_parent_query($node->parent);
2001-11-01 11:00:51 +00:00
$next = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND $list AND (b.weight > '$node->weight' OR (b.weight = '$node->weight' AND n.title > '". check_query($node->title) ."')) ORDER BY b.weight ASC,n.title ASC"));
$prev = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND $list AND (b.weight < '$node->weight' OR (b.weight = '$node->weight' AND n.title < '". check_query($node->title) ."')) ORDER BY b.weight DESC,n.title DESC"));
2001-05-24 10:05:18 +00:00
}
2001-04-04 12:54:10 +00:00
2001-05-24 10:05:18 +00:00
$output .= "<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" WIDTH=\"100%\">\n";
2001-04-04 12:54:10 +00:00
2001-05-24 10:05:18 +00:00
if ($node->title) {
foreach (book_location($node) as $level) {
$location .= "$indent <A HREF=\"node.php?id=$level->nid\">$level->title</A><BR>";
$indent .= "-";
}
2001-04-04 12:54:10 +00:00
2001-11-01 17:04:20 +00:00
$output .= " <TR><TD COLSPAN=\"2\">$location</TD><TD ALIGN=\"right\"><A HREF=\"module.php?mod=node&op=edit&id=$node->nid\">update</A></TD></TR>\n";
2001-05-24 10:05:18 +00:00
$output .= " <TR><TD COLSPAN=\"3\"><HR></TD></TR>";
2001-11-01 11:00:51 +00:00
$output .= " <TR><TD COLSPAN=\"3\"><B><BIG>". check_output($node->title) ."</BIG></B>". ($node->body ? "<BR><SMALL><I>Last updated by ". format_name($node) ." on ". format_date($node->created) ."</I></SMALL> " : "") ."</TD></TR>\n";
2001-05-24 10:05:18 +00:00
}
2001-04-04 12:54:10 +00:00
2001-05-24 10:05:18 +00:00
if ($node->body) {
$output .= " <TR><TD COLSPAN=\"3\"><BR>". check_output($node->body, 1) ."</TD></TR>";
}
2001-03-24 16:36:13 +00:00
2001-05-24 10:05:18 +00:00
if ($node->nid) {
$output .= " <TR><TD COLSPAN=\"3\"><BR>". book_tree($node->nid) ."</TD></TR>";
}
2001-05-06 19:51:14 +00:00
2001-05-24 10:05:18 +00:00
$output .= " <TR><TD COLSPAN=\"3\"><HR></TD></TR>";
$output .= " <TR><TD ALIGN=\"left\" WIDTH=\"33%\">". ($prev ? "<A HREF=\"node.php?id=$prev->nid\">". t("previous") ."</A>" : t("previous")) ."</TD><TD ALIGN=\"center\" WIDTH=\"34%\"><A HREF=\"module.php?mod=book\">index</A></TD><TD ALIGN=\"right\" WIDTH=\"33%\">". ($next ? "<A HREF=\"node.php?id=$next->nid\">". t("next") ."</A>" : t("next")) ."</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"left\" WIDTH=\"33%\">". ($prev ? "<SMALL>". check_output($prev->title) ."</SMALL>" : " ") ."</TD><TD ALIGN=\"center\" WIDTH=\"34%\">". ($node->parent ? "<A HREF=\"node.php?id=$node->parent\">". t("up") ."</A>" : t("up")) ."</TD><TD ALIGN=\"right\" WIDTH=\"33%\">". ($next ? "<SMALL>". check_output($next->title) ."</SMALL>" : " ") ."</TD></TR>\n";
$output .= "</TABLE>\n";
2001-04-04 12:54:10 +00:00
2001-05-24 10:05:18 +00:00
$theme->box(t("Handbook"), $output);
}
2001-03-24 16:36:13 +00:00
}
2001-05-06 19:51:14 +00:00
function book_parent_query($parent) {
2001-09-26 18:28:10 +00:00
if ($parent > 0) {
2001-05-06 19:51:14 +00:00
$list = array();
foreach (book_parent($parent) as $pid) array_push($list, "b.parent = $pid");
}
else {
$list = array("b.parent = ''");
}
return "(". implode(" OR ", $list) .")";
}
function book_toc($parent = "", $indent = "", $toc = array()) {
2001-05-07 18:44:40 +00:00
2001-05-06 19:51:14 +00:00
// select all child nodes:
2001-11-01 11:00:51 +00:00
$result = db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = 1 AND ". book_parent_query($parent) ." ORDER BY b.weight");
2001-05-06 19:51:14 +00:00
2001-05-07 18:44:40 +00:00
// add root node:
2001-06-29 22:08:57 +00:00
if (user_access("administer nodes")) {
2001-06-25 19:36:04 +00:00
$toc[0] = "<root>";
2001-05-07 18:44:40 +00:00
}
2001-05-06 19:51:14 +00:00
// build table of contents:
2001-03-25 16:42:52 +00:00
while ($node = db_fetch_object($result)) {
2001-04-04 12:54:10 +00:00
$toc[$node->nid] = "$indent $node->title";
$toc = book_toc($node->nid, "$indent-", $toc);
2001-03-25 16:42:52 +00:00
}
2001-05-06 19:51:14 +00:00
2001-03-25 16:42:52 +00:00
return $toc;
}
2001-11-03 18:38:30 +00:00
function book_form($node, $help, $error) {
2001-09-28 16:20:55 +00:00
global $user;
2001-03-24 16:36:13 +00:00
2001-11-01 11:00:51 +00:00
$output .= form_select(t("Parent"), "parent", $node->parent, book_toc(), t("The parent subject or category the page belongs in."));
$output .= form_textarea(t("Content"), "body", $node->body, 60, 20, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
$output .= form_textarea(t("Log message"), "log", $node->log, 60, 5, t("An explanation of the additions or updates being made to help the group understand your motivations."));
2001-03-25 10:57:01 +00:00
2001-06-29 22:08:57 +00:00
if (user_access("administer nodes")) {
2001-11-01 11:00:51 +00:00
$output .= form_select(t("Weight"), "weight", $node->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), t("The heavier nodes will sink and the lighter nodes will be positioned nearer the top."));
2001-03-24 16:36:13 +00:00
}
2001-11-01 11:00:51 +00:00
if ($node->pid > 0) {
$output .= form_hidden("pid", $node->pid);
2001-06-17 18:31:25 +00:00
}
2001-11-01 11:00:51 +00:00
return $output;
2001-06-17 18:31:25 +00:00
}
2001-05-06 19:51:14 +00:00
function book_parent($nid) {
2001-11-01 11:00:51 +00:00
if ($node = node_load(array("nid" => $nid))) {
2001-05-06 19:51:14 +00:00
$list[$nid] = $nid;
}
if ($node->pid) {
$list = array_merge($list, book_parent($node->pid));
}
return $list ? $list : array();
}
2001-04-08 10:31:59 +00:00
function book_tree($parent = "", $depth = 0) {
2001-11-01 11:00:51 +00:00
global $PHP_SELF;
2001-03-24 16:36:13 +00:00
2001-05-06 19:51:14 +00:00
if ($depth < 3 || strstr($PHP_SELF,"admin.php")) {
// select all child nodes:
2001-11-01 11:00:51 +00:00
$result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = 1 AND ". book_parent_query($parent) ." ORDER BY b.weight, n.title");
2001-05-06 19:51:14 +00:00
// render output:
while ($node = db_fetch_object($result)) {
2001-09-27 18:30:36 +00:00
$output .= "<LI><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A>". (strstr($PHP_SELF, "admin.php") ? " <SMALL>(weight: $node->weight/$node->parent, status: $node->status) (<A HREF=\"admin.php?mod=node&type=book&op=edit&id=$node->nid\">edit</A>)</SMALL>" : "") ."</LI>\n";
2001-05-06 19:51:14 +00:00
$output .= book_tree($node->nid, $depth + 1);
}
$output = "<UL>$output</UL>";
}
return $output;
}
2001-07-15 17:32:33 +00:00
function book_render() {
2001-11-01 11:00:51 +00:00
global $theme;
2001-04-08 10:31:59 +00:00
2001-11-01 11:00:51 +00:00
$result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = 0 AND n.status = 1 ORDER BY b.weight");
2001-07-15 17:32:33 +00:00
while ($node = db_fetch_object($result)) {
$output .= "<DT><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></DT><DD>". check_output($node->body, 1) ."<BR><BR></DD>";
}
$theme->header();
$theme->box(t("Handbook"), "<DL>$output</DL>");
$theme->footer();
}
function book_page() {
global $op, $id, $theme;
2001-06-29 22:08:57 +00:00
if (user_access("access content")) {
2001-04-08 10:31:59 +00:00
2001-07-15 17:32:33 +00:00
switch ($op) {
case "feed":
2001-08-11 14:54:39 +00:00
print book_export_html($id, $depth = 1);
2001-07-15 17:32:33 +00:00
break;
default:
book_render();
2001-06-20 20:00:40 +00:00
}
}
else {
$theme->header();
$theme->box(t("Access denied"), message_access());
$theme->footer();
}
2001-03-24 16:36:13 +00:00
}
2001-08-11 14:54:39 +00:00
function book_export_html($id = "", $depth = 1) {
2001-11-01 11:00:51 +00:00
$result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = 1 AND n.nid = '". check_input($id) ."'");
2001-08-11 14:54:39 +00:00
while ($node = db_fetch_object($result)) {
$output .= "<H$depth>". check_output($node->title) ."</H$depth>";
if ($node->body) $output .= "<blockquote>". check_output($node->body, 1) ."</blockquote>";
}
$output .= book_export_html_recursive($id, $depth);
return $output;
}
function book_export_html_recursive($parent = "", $depth = 1) {
2001-11-01 11:00:51 +00:00
$result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = 1 AND b.parent = '$parent' ORDER BY b.weight");
2001-04-11 19:44:24 +00:00
while ($node = db_fetch_object($result)) {
$output .= "<H$depth>". check_output($node->title) ."</H$depth>";
2001-08-11 14:54:39 +00:00
if ($node->body) $output .= "<blockquote>". check_output($node->body, 1) ."</blockquote>";
if ($node->pid) $output .= book_export_html_recursive($node->pid, $depth + 1);
$output .= book_export_html_recursive($node->nid, $depth + 1);
2001-04-11 19:44:24 +00:00
}
2001-06-24 19:12:30 +00:00
2001-04-11 19:44:24 +00:00
return $output;
}
2001-11-01 11:00:51 +00:00
2001-03-24 16:36:13 +00:00
?>