From d0060968b77c39bdf8abffb071c971c166b59edb Mon Sep 17 00:00:00 2001 From: Nicolas BERNSTEIN Date: Sat, 17 Sep 2011 16:48:29 +0200 Subject: First commit. --- tpl/notes/inc_relativestree.php | 139 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 tpl/notes/inc_relativestree.php (limited to 'tpl/notes/inc_relativestree.php') diff --git a/tpl/notes/inc_relativestree.php b/tpl/notes/inc_relativestree.php new file mode 100644 index 0000000..be0e224 --- /dev/null +++ b/tpl/notes/inc_relativestree.php @@ -0,0 +1,139 @@ +
'; +echo '

' . $note['ownername'] . '


'; +echo ''; + +function list_brothers_and_children() { + global $brothers, $children, $note, $user, $can_new; + echo '
'; + foreach($brothers as $b) { + if ($b['id'] == $note['id']) { + echo '

' . $b['title'] . '

'; + foreach($children as $nn) { + echo '

' . $nn['title'] . '

'; + } + if ($can_new) { + echo '

+ new note

'; + } + echo '
'; + } else { + echo '

' . $b['title'] . '

'; + } + } + if ($can_new) { + echo '

+ new note

'; + } + echo '
'; +} + +echo '
'; +$did_show_up = false; +foreach($user_root_notes as $n) { + if ($n['id'] == $note['id']) { + $did_show_up = true; + echo '

' . $n['title'] . '

'; + foreach($children as $nn) { + echo '

' . $nn['title'] . '

'; + } + if ($can_new) { + echo '

+ new note

'; + } + echo '
'; + } else { + echo '

' . $n['title'] . '

'; + if ($n['id'] == $note['parent_id']) { + $did_show_up = true; + list_brothers_and_children(); + } + } +} +if ($can_new) { + echo '

+ new note

'; +} +echo '
'; + +if (!$did_show_up) { + echo '

'; + echo '' . $note['parent_title'] . ''; + list_brothers_and_children(); +} + +*/ + +// *** NEW WAY + +$notes_tree = array(); +$notes_parents = array(); +$n = sql("SELECT id, parent, title FROM notes ". + "WHERE owner = " . $note['owner'] . + ($note['owner'] == $user['id'] ? " " : " AND public != 0 ") . + "ORDER BY title ASC"); +while ($nn = mysql_fetch_assoc($n)) { + $notes_parents[$nn['id']] = $nn['parent']; + if (isset($notes_tree[$nn['parent']])) { + $notes_tree[$nn['parent']][] = $nn; + } else { + $notes_tree[$nn['parent']] = array($nn); + } +} + +$notest = array(0 => @$notes_tree[0]); +for($id = $note['id']; $id != 0; $id = $notes_parents[$id]) { + $notest[$id] = @$notes_tree[$id]; +} + +echo '
'; +echo '

' . $note['ownername'] . '


'; +echo ''; + +function n_tree_branch($id) { + global $notest, $note, $can_new; + if (!isset($notest[$id])) return; + foreach($notest[$id] as $branch) { + if ($branch['id'] == $note['id']) + echo '

' . $branch['title'] . '

'; + else + echo '

' . $branch['title'] . '

'; + if (isset($notest[$branch['id']])) { + echo '
'; + n_tree_branch($branch['id']); + echo '
'; + } else if ($can_new && $branch['id'] == $note['id']) { + echo '
'; + if ($can_new) echo '

+ new note

'; + echo '
'; + } + } + if ($can_new) echo '

+ new note

'; +} + +echo '
'; +n_tree_branch(0); +echo '
'; + -- cgit v1.2.3