diff --git a/modules/book.module b/modules/book.module index e0639cbe846..0f954c64b75 100644 --- a/modules/book.module +++ b/modules/book.module @@ -602,27 +602,15 @@ function book_export_html_recurse($parent = "", $depth = 1) { function book_admin_view_line($node, $depth = 0) { - /* - ** Extract the revision number: - */ - - if ($list = node_revision_list($node)) { - $revision = end($list); - } - else { - $revision = 0; - } - /* ** Diplay the book page: */ $output .= ""; - $output .= "
". l(check_output($node->title), array("id" => $node->nid)) ."
"; - $output .= " $revision"; + $output .= "
". form_textfield(NULL, "$node->nid][title", $node->title, 64, 255) ."
"; + $output .= " ". form_weight(NULL, "$node->nid][weight", $node->weight) .""; + $output .= " ". l(t("view node"), array("id" => $node->nid)) .""; $output .= " ". la(t("edit node"), array("mod" => "node", "op" => "edit", "id" => $node->nid)) .""; - //TODO: get this link to work. Must pass $nid along so it is received by book_node_link() - //$output .= " ". la(t("edit book outline"), array("mod" => "book", "nid" => $node->nid, "op" => "Edit+book+outline")) .""; $output .= " ". la(t("delete node"), array("mod" => "node", "op" => "delete", "id" => $node->nid)) .""; $output .= ""; @@ -630,8 +618,6 @@ function book_admin_view_line($node, $depth = 0) { } function book_admin_view_book($nid, $depth = 1) { - $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 b.parent = '%d' ORDER BY b.weight, n.title", $nid); while ($node = db_fetch_object($result)) { @@ -649,13 +635,44 @@ function book_admin_view($nid, $depth = 0) { $output .= "

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

"; $output .= ""; - //TODO: change colspan below to 3 after adding new link in book_admin_view_line() - $output .= " "; + $output .= " "; $output .= book_admin_view_line($node); $output .= book_admin_view_book($nid); - $output .= "
titlerevoperations
titleweightoperations
"; + $output .= "
"; - return $output; + $output .= form_submit(t("Save book pages")); + + return form($output); +} + +function book_admin_save($nid, $edit = array()) { + + $book = node_load(array("nid" => $nid)); + + foreach ($edit as $nid => $value) { + /* + ** Check to see whether the title needs updating: + */ + + $title = db_result(db_query("SELECT title FROM node WHERE nid = '%d'", $nid)); + if ($title != $value["title"]) { + db_query("UPDATE node SET title = '%s' WHERE nid = '%d'", $value["title"], $nid); + } + + /* + ** Check to see whether the weight needs updating: + */ + + $weight = db_result(db_query("SELECT weight FROM book WHERE nid = '%d'", $nid)); + if ($weight != $value["weight"]) { + db_query("UPDATE book SET weight = '%d' WHERE nid = '%d'", $value["weight"], $nid); + } + } + + $message = t("updated book '%title'", array("%title" => $book->title)); + watchdog("special", $message); + + return $message; } function book_admin_orphan() { @@ -692,7 +709,7 @@ function book_admin_links() { } function book_admin() { - global $id, $op; + global $id, $op, $edit; if (user_access("administer nodes")) { @@ -714,6 +731,9 @@ function book_admin() { case "orphan": print book_admin_orphan(); break; + case t("Save book pages"); + print status(book_admin_save($id, $edit)); + // fall through: case "view": print book_admin_view($id); break; diff --git a/modules/book/book.module b/modules/book/book.module index e0639cbe846..0f954c64b75 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -602,27 +602,15 @@ function book_export_html_recurse($parent = "", $depth = 1) { function book_admin_view_line($node, $depth = 0) { - /* - ** Extract the revision number: - */ - - if ($list = node_revision_list($node)) { - $revision = end($list); - } - else { - $revision = 0; - } - /* ** Diplay the book page: */ $output .= ""; - $output .= "
". l(check_output($node->title), array("id" => $node->nid)) ."
"; - $output .= " $revision"; + $output .= "
". form_textfield(NULL, "$node->nid][title", $node->title, 64, 255) ."
"; + $output .= " ". form_weight(NULL, "$node->nid][weight", $node->weight) .""; + $output .= " ". l(t("view node"), array("id" => $node->nid)) .""; $output .= " ". la(t("edit node"), array("mod" => "node", "op" => "edit", "id" => $node->nid)) .""; - //TODO: get this link to work. Must pass $nid along so it is received by book_node_link() - //$output .= " ". la(t("edit book outline"), array("mod" => "book", "nid" => $node->nid, "op" => "Edit+book+outline")) .""; $output .= " ". la(t("delete node"), array("mod" => "node", "op" => "delete", "id" => $node->nid)) .""; $output .= ""; @@ -630,8 +618,6 @@ function book_admin_view_line($node, $depth = 0) { } function book_admin_view_book($nid, $depth = 1) { - $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 b.parent = '%d' ORDER BY b.weight, n.title", $nid); while ($node = db_fetch_object($result)) { @@ -649,13 +635,44 @@ function book_admin_view($nid, $depth = 0) { $output .= "

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

"; $output .= ""; - //TODO: change colspan below to 3 after adding new link in book_admin_view_line() - $output .= " "; + $output .= " "; $output .= book_admin_view_line($node); $output .= book_admin_view_book($nid); - $output .= "
titlerevoperations
titleweightoperations
"; + $output .= "
"; - return $output; + $output .= form_submit(t("Save book pages")); + + return form($output); +} + +function book_admin_save($nid, $edit = array()) { + + $book = node_load(array("nid" => $nid)); + + foreach ($edit as $nid => $value) { + /* + ** Check to see whether the title needs updating: + */ + + $title = db_result(db_query("SELECT title FROM node WHERE nid = '%d'", $nid)); + if ($title != $value["title"]) { + db_query("UPDATE node SET title = '%s' WHERE nid = '%d'", $value["title"], $nid); + } + + /* + ** Check to see whether the weight needs updating: + */ + + $weight = db_result(db_query("SELECT weight FROM book WHERE nid = '%d'", $nid)); + if ($weight != $value["weight"]) { + db_query("UPDATE book SET weight = '%d' WHERE nid = '%d'", $value["weight"], $nid); + } + } + + $message = t("updated book '%title'", array("%title" => $book->title)); + watchdog("special", $message); + + return $message; } function book_admin_orphan() { @@ -692,7 +709,7 @@ function book_admin_links() { } function book_admin() { - global $id, $op; + global $id, $op, $edit; if (user_access("administer nodes")) { @@ -714,6 +731,9 @@ function book_admin() { case "orphan": print book_admin_orphan(); break; + case t("Save book pages"); + print status(book_admin_save($id, $edit)); + // fall through: case "view": print book_admin_view($id); break;