"book_find", "page" => "book_page", "user" => "book_user", "admin" => "book_admin"); class Book { function Book($nid, $userid, $title, $body, $parent, $weight, $timestamp) { $this->nid = $nid; $this->userid = $userid; $this->title = $title; $this->body = $body; $this->parent = $parent; $this->weight = $weight; $this->timestamp = $timestamp; } } function book_navigation($node) { if ($node->nid) { $next = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE b.parent = '$node->parent' AND b.weight > $node->weight ORDER BY b.weight ASC")); $prev = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE b.parent = '$node->parent' AND b.weight < $node->weight ORDER BY b.weight DESC")); } $output .= "
"; $output .= "\n"; $output .= " \n"; $output .= " \n"; $output .= "
". ($prev ? "nid\">". t("previous") ."" : t("previous")) ."index". ($next ? "nid\">". t("next") ."" : t("next")) ."
". ($prev ? "". check_output($prev->title) ."" : "") ."". ($node->parent ? "parent\">". t("up") ."" : t("up")) ."". ($next ? "". check_output($next->title) ."" : "") ."
\n"; return $output; } function theme_book($node) { global $theme; if ($node->title) { $output .= "\n"; $output .= " \n"; $output .= "
". check_output($node->title) ."". ($node->body ? "
Last updated by ". format_username($node->userid) ." on ". format_date($node->timestamp) ." " : "") ."
". node_info($node) ."
\n"; } if ($node->body) { $output .= "

". check_output($node->body, 1) ."

"; } $theme->box(t("Handbook"), $output ."". book_overview($node->nid) ."". book_navigation($node)); } function book_view($node, $page = 1) { if ($page) { global $theme; $theme->header(); theme_book($node); $theme->footer(); } else { theme_book($node); } } function book_find($keys) { global $status, $user; $find = array(); $result = db_query("SELECT n.*, u.userid FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid LEFT JOIN users u ON n.author = u.id WHERE n.type = 'book' AND n.status = '$status[posted]' AND (n.title LIKE '%". check_input($keys) ."%' OR b.body LIKE '%". check_input($keys) ."%') ORDER BY n.timestamp DESC LIMIT 20"); while ($node = db_fetch_object($result)) { array_push($find, array("title" => check_output($node->title), "link" => (user_access($user, "book") ? "admin.php?mod=book&op=edit&id=$node->nid" : "node.php?id=$node->nid"), "user" => $node->userid, "date" => $node->timestamp)); } return $find; } function book_search() { global $keys, $mod; print search_form($keys); print search_data($keys, $mod); } function book_toc($parent = 0, $offset = 0, $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); } return $toc; } function book_form($edit = array()) { global $allowed_html, $PHP_SELF, $REQUEST_URI, $status, $theme, $user; $output .= "
\n"; $output .= "". t("Author") .":
\n"; $output .= "\n"; $output .= format_username(($edit[userid] ? $edit[userid] : $user->userid)) ."

\n"; if ($edit[pid]) { $node = node_get_object("nid", $edit[pid]); $output .= "". t("Parent") .":
\n"; $output .= "id\">". check_output($node->title) ."

\n"; $output .= "". t("The parent subject or category the new page belongs in.") ."

\n"; } else { $output .= "". t("Parent") .":
\n"; foreach (book_toc() as $key=>$value) $options2 .= ""; if (user_access($user, "book")) $options2 .= ""; $output .= "
\n"; $output .= "". t("The parent subject or category the new page belongs in.") ."

\n"; } $output .= "". t("Subject") .":
\n"; $output .= "

\n"; $output .= "". t("Content") .":
\n"; $output .= "
\n"; $output .= "". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".

\n"; if ($edit[pid]) { $output .= "". t("Log message") .":
\n"; $output .= "
\n"; $output .= "". t("A brief explanation of your update.") ."

\n"; } if (user_access($user, "book")) { $status = array_intersect($status, array(0, 2, 3)); $output .= "". t("Weight") .":
\n"; for ($count = 0; $count < 25; $count++) $options3 .= ""; $output .= "
\n"; $output .= "". t("The heavier nodes will sink and the lighter nodes will be positioned nearer the top.") ."

\n"; $output .= "". t("Status") .":
\n"; foreach ($status as $value=>$key) $options4 .= ""; $output .= "

\n"; } if (!$edit) { $output .= "\n"; } else if (!$edit[title]) { $output .= "". t("Warning: you did not supply a title.") ."

\n"; $output .= "\n"; } else { $output .= "\n"; $output .= "\n"; } $output .= "\n"; $output .= "\n"; $output .= "

\n"; return $output; } function book_save($edit) { node_save(array_diff(array_merge($edit, array(nid => $edit[nid], type => "book")), array(userid => $edit[userid]))); } 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 = "") { 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]' AND b.parent = '$parent' ORDER BY b.weight"); $output .= "
"; while ($node = db_fetch_object($result)) { $number++; if ($offset) $output .= "
$offset$number. nid\">". check_output($node->title) ."\n"; else $output .= "

$number. nid\">". check_output($node->title) ."\n"; if ($PHP_SELF == "/admin.php") $output .= " (weight: $node->weight, status: $node->status) (nid\">edit, nid\">delete)"; $output .= book_overview($node->nid, "$offset$number."); } $output .= "

"; return $output; } function book_history() { 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"); $output .= "\n"; $output .= " \n"; while ($node = db_fetch_object($result)) { $output .= " "; } $output .= "
nodestatusdateoperations
nid\">". check_output($node->title) ."$node->status". format_date($node->timestamp, "small") ."nid\">viewnid\">editnid\">delete
\n"; return $output; } function book_admin() { global $op, $id, $edit, $user; print "add new page | history | search book | overview
\n"; switch ($op) { case "add": print book_form(); break; case "delete": print book_delete($id); print book_overview(); break; case "history": print book_history(); break; case "edit": print book_form(node_get_array(nid, $id)); break; case "search": book_search(); break; case t("Preview"): book_view(new Book(($edit[nid] ? $edit[nid] : -1), ($edit[userid] ? $edit[userid] : $user->userid), $edit[title], $edit[body], $edit[parent], $edit[weight], ($edit[timestamp] ? $edit[timestamp] : time())), 0); print book_form($edit); break; case t("Submit"): book_save($edit); print book_overview(); break; default: print book_overview(); } } function book_page($id = 0) { global $theme; book_view(node_get_object("nid", $nid)); } function book_user() { global $edit, $id, $op, $theme, $user; switch($op) { case "update": $node = node_get_object("nid", $id); $theme->box("Update a book page", book_form(array(nid => -1, pid => $id, title => $node->title, body => $node->body, parent => $node->parent))); break; case t("Preview"): book_view(new Book(($edit[nid] ? $edit[nid] : -1), $user->userid, $edit[title], $edit[body], $edit[parent], $edit[weight], ($edit[timestamp] ? $edit[timestamp] : time())), 0); $theme->box("Submit a book page", book_form($edit)); break; case t("Submit"): book_save($edit); $theme->box(t("Submit a book page"), t("Thank you for your submission.")); break; default: $theme->box("Submit a book page", book_form()); } } ?>