summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorSteven Wittens <steven@10.no-reply.drupal.org>2004-08-10 14:16:01 +0000
committerSteven Wittens <steven@10.no-reply.drupal.org>2004-08-10 14:16:01 +0000
commitaf0be96a62d03df5d8085f660b171652d38aaa0b (patch)
treedf402fbcbc3b12feded136492b2012981a2fec53 /modules
parentf99830a4985f4a69ef6ffe96a9f2aca734b450af (diff)
downloadbrdo-af0be96a62d03df5d8085f660b171652d38aaa0b.tar.gz
brdo-af0be96a62d03df5d8085f660b171652d38aaa0b.tar.bz2
- #4266: When editing a book page, hide the page and its children from the "Parent" selector to prevent circular relationships in the book hierarchy.
Diffstat (limited to 'modules')
-rw-r--r--modules/book.module19
-rw-r--r--modules/book/book.module19
2 files changed, 22 insertions, 16 deletions
diff --git a/modules/book.module b/modules/book.module
index a4f72ebc6..1fded670e 100644
--- a/modules/book.module
+++ b/modules/book.module
@@ -210,7 +210,7 @@ function book_form(&$node) {
global $user;
$op = $_POST['op'];
- $output = form_select(t('Parent'), 'parent', $node->parent, book_toc(), t('The parent subject or category the page belongs in.'));
+ $output = form_select(t('Parent'), 'parent', $node->parent, book_toc($node->nid), t('The parent subject or category the page belongs in.'));
if (function_exists('taxonomy_node_form')) {
$output .= implode('', taxonomy_node_form('book', $node));
@@ -269,7 +269,7 @@ function book_node_link($node = 0) {
if ($edit['nid']) {
$page = db_fetch_object(db_query('SELECT * FROM {book} WHERE nid = %d', $node->nid));
- $output .= form_select(t('Parent'), 'parent', $page->parent, book_toc(), t('The parent subject or category the page belongs in.'));
+ $output .= form_select(t('Parent'), 'parent', $page->parent, book_toc($node->nid), t('The parent subject or category the page belongs in.'));
$output .= form_weight(t('Weight'), 'weight', $node->weight, 15, t('The heavier pages will sink and the lighter pages will be positioned nearer the top.'));
if ($page->nid) {
@@ -520,21 +520,24 @@ function book_navigation($node) {
return $node;
}
-function book_toc_recurse($nid, $indent, $toc, $children) {
-
+function book_toc_recurse($nid, $indent, $toc, $children, $exclude) {
if ($children[$nid]) {
foreach ($children[$nid] as $foo => $node) {
- $toc[$node->nid] = $indent .' '. $node->title;
- $toc = book_toc_recurse($node->nid, $indent .'--', $toc, $children);
+ if (!$exclude || $exclude != $node->nid) {
+ $toc[$node->nid] = $indent .' '. $node->title;
+ $toc = book_toc_recurse($node->nid, $indent .'--', $toc, $children, $exclude);
+ }
}
}
return $toc;
}
-function book_toc($parent = 0, $indent = '', $toc = array()) {
+function book_toc($exclude = 0, $parent = 0, $indent = '', $toc = array()) {
$result = db_query('SELECT DISTINCT(n.nid), n.title, b.parent FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND '. node_access_where_sql() .' ORDER BY b.weight, n.title');
+ print "Exclude: ". $exclude;
+
while ($node = db_fetch_object($result)) {
if (!$children[$node->parent]) {
$children[$node->parent] = array();
@@ -548,7 +551,7 @@ function book_toc($parent = 0, $indent = '', $toc = array()) {
$toc[0] = '<'. t('top-level') .'>';
}
- $toc = book_toc_recurse($parent, $indent, $toc, $children);
+ $toc = book_toc_recurse($parent, $indent, $toc, $children, $exclude);
return $toc;
}
diff --git a/modules/book/book.module b/modules/book/book.module
index a4f72ebc6..1fded670e 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -210,7 +210,7 @@ function book_form(&$node) {
global $user;
$op = $_POST['op'];
- $output = form_select(t('Parent'), 'parent', $node->parent, book_toc(), t('The parent subject or category the page belongs in.'));
+ $output = form_select(t('Parent'), 'parent', $node->parent, book_toc($node->nid), t('The parent subject or category the page belongs in.'));
if (function_exists('taxonomy_node_form')) {
$output .= implode('', taxonomy_node_form('book', $node));
@@ -269,7 +269,7 @@ function book_node_link($node = 0) {
if ($edit['nid']) {
$page = db_fetch_object(db_query('SELECT * FROM {book} WHERE nid = %d', $node->nid));
- $output .= form_select(t('Parent'), 'parent', $page->parent, book_toc(), t('The parent subject or category the page belongs in.'));
+ $output .= form_select(t('Parent'), 'parent', $page->parent, book_toc($node->nid), t('The parent subject or category the page belongs in.'));
$output .= form_weight(t('Weight'), 'weight', $node->weight, 15, t('The heavier pages will sink and the lighter pages will be positioned nearer the top.'));
if ($page->nid) {
@@ -520,21 +520,24 @@ function book_navigation($node) {
return $node;
}
-function book_toc_recurse($nid, $indent, $toc, $children) {
-
+function book_toc_recurse($nid, $indent, $toc, $children, $exclude) {
if ($children[$nid]) {
foreach ($children[$nid] as $foo => $node) {
- $toc[$node->nid] = $indent .' '. $node->title;
- $toc = book_toc_recurse($node->nid, $indent .'--', $toc, $children);
+ if (!$exclude || $exclude != $node->nid) {
+ $toc[$node->nid] = $indent .' '. $node->title;
+ $toc = book_toc_recurse($node->nid, $indent .'--', $toc, $children, $exclude);
+ }
}
}
return $toc;
}
-function book_toc($parent = 0, $indent = '', $toc = array()) {
+function book_toc($exclude = 0, $parent = 0, $indent = '', $toc = array()) {
$result = db_query('SELECT DISTINCT(n.nid), n.title, b.parent FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND '. node_access_where_sql() .' ORDER BY b.weight, n.title');
+ print "Exclude: ". $exclude;
+
while ($node = db_fetch_object($result)) {
if (!$children[$node->parent]) {
$children[$node->parent] = array();
@@ -548,7 +551,7 @@ function book_toc($parent = 0, $indent = '', $toc = array()) {
$toc[0] = '<'. t('top-level') .'>';
}
- $toc = book_toc_recurse($parent, $indent, $toc, $children);
+ $toc = book_toc_recurse($parent, $indent, $toc, $children, $exclude);
return $toc;
}