@@ -167,7 +167,7 @@ function book_form(&$node, &$help, &$error) {
$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."));
if(user_access("administer nodes")){
$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 pages will sink and the lighter pages will be positioned nearer the top."));
$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."));
@@ -221,7 +221,7 @@ function book_node_link($node = 0) {
$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("Weight"),"weight",$page->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 pages will sink and the lighter pages will be positioned nearer the top."));
$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){
$output.=form_submit(t("Update book outline"));
...
...
@@ -280,7 +280,6 @@ function book_revision_load($page, $conditions = array()) {
/*
** Return the path (call stack) to a certain book page.
*/
functionbook_location($node,$nodes=array()){
$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 = '%d'",$node->parent));
if($parent->title){
...
...
@@ -290,6 +289,48 @@ function book_location($node, $nodes = array()) {
return$nodes;
}
functionbook_location_down($node,$nodes=array()){
$last_direct_child=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 b.parent = %d ORDER BY b.weight DESC, n.title DESC",$node->nid));
$direct_above=db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') AND (b.weight < %d OR (b.weight = %d AND n.title < '%s')) ORDER BY b.weight DESC, n.title DESC",$node->parent,$node->weight,$node->weight,$node->title));
if($direct_above){
// get last leaf of $above
$path=book_location_down($direct_above);
return$path?array_pop($path):$direct_above;
}
else{
// direct parent
$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.nid = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '')",$node->parent));
return$prev;
}
}
functionbook_next($node){
// get first direct child
$child=db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight ASC, n.title ASC",$node->nid));
if($child){
return$child;
}
// no direct child: get next for this level or any parent
array_push($path=book_location($node),$node);// path to root node including this one
// loop through nodes to root, starting with this node
while($leaf=array_pop($path)){
$next=db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') AND (b.weight > %d OR (b.weight = %d AND n.title > '%s')) ORDER BY b.weight ASC, n.title ASC",$leaf->parent,$leaf->weight,$leaf->weight,$leaf->title));
if($next){
return$next;
}
}
}
functionbook_body($node){
global$op;
...
...
@@ -349,9 +390,9 @@ function book_view($node, $main = 0) {
** Construct the "next" and "previous" links:
*/
if($node->nid&&$node->parent){
$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 b.parent = '%d' AND (b.weight > '%d' OR (b.weight = '%d' AND n.title > '%s')) AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight ASC, n.title ASC",$node->parent,$node->weight,$node->weight,$node->title));
$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 b.parent = '%d' AND (b.weight < '%d' OR (b.weight = '%d' AND n.title < '%s')) AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight DESC, n.title DESC",$node->parent,$node->weight,$node->weight,$node->title));
@@ -167,7 +167,7 @@ function book_form(&$node, &$help, &$error) {
$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."));
if(user_access("administer nodes")){
$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 pages will sink and the lighter pages will be positioned nearer the top."));
$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."));
@@ -221,7 +221,7 @@ function book_node_link($node = 0) {
$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("Weight"),"weight",$page->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 pages will sink and the lighter pages will be positioned nearer the top."));
$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){
$output.=form_submit(t("Update book outline"));
...
...
@@ -280,7 +280,6 @@ function book_revision_load($page, $conditions = array()) {
/*
** Return the path (call stack) to a certain book page.
*/
functionbook_location($node,$nodes=array()){
$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 = '%d'",$node->parent));
if($parent->title){
...
...
@@ -290,6 +289,48 @@ function book_location($node, $nodes = array()) {
return$nodes;
}
functionbook_location_down($node,$nodes=array()){
$last_direct_child=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 b.parent = %d ORDER BY b.weight DESC, n.title DESC",$node->nid));
$direct_above=db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') AND (b.weight < %d OR (b.weight = %d AND n.title < '%s')) ORDER BY b.weight DESC, n.title DESC",$node->parent,$node->weight,$node->weight,$node->title));
if($direct_above){
// get last leaf of $above
$path=book_location_down($direct_above);
return$path?array_pop($path):$direct_above;
}
else{
// direct parent
$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.nid = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '')",$node->parent));
return$prev;
}
}
functionbook_next($node){
// get first direct child
$child=db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight ASC, n.title ASC",$node->nid));
if($child){
return$child;
}
// no direct child: get next for this level or any parent
array_push($path=book_location($node),$node);// path to root node including this one
// loop through nodes to root, starting with this node
while($leaf=array_pop($path)){
$next=db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') AND (b.weight > %d OR (b.weight = %d AND n.title > '%s')) ORDER BY b.weight ASC, n.title ASC",$leaf->parent,$leaf->weight,$leaf->weight,$leaf->title));
if($next){
return$next;
}
}
}
functionbook_body($node){
global$op;
...
...
@@ -349,9 +390,9 @@ function book_view($node, $main = 0) {
** Construct the "next" and "previous" links:
*/
if($node->nid&&$node->parent){
$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 b.parent = '%d' AND (b.weight > '%d' OR (b.weight = '%d' AND n.title > '%s')) AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight ASC, n.title ASC",$node->parent,$node->weight,$node->weight,$node->title));
$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 b.parent = '%d' AND (b.weight < '%d' OR (b.weight = '%d' AND n.title < '%s')) AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight DESC, n.title DESC",$node->parent,$node->weight,$node->weight,$node->title));