summaryrefslogtreecommitdiff
path: root/tpl/notes/inc_relativestree.php
blob: 01cb956f68182e1013d4e2175a5251f56f5187c7 (plain) (blame)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php


$notes_tree = array();
$notes_parents = array();
$n = sql("SELECT id, parent, title FROM notes ".
	"WHERE owner = ?" .
	($note['owner'] == $user['id'] ? " " : " AND public != 0 ") .
	"ORDER BY title ASC", $note['owner']);
while ($nn = $n->fetch()) {
	$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 '</div><div class="contents-left">';
echo '<h1>' . $note['ownername'] . '</h1><br />';
echo '<div class="small_right"><a href="?p=user-notes-' . $note['owner'] . '">voir tout</a></div>';

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 '<p>' . $branch['title'] . '</p>';
		else
			echo '<p><a href="?p=view-notes-' . $branch['id'] . '">' . $branch['title'] . '</a></p>';
		if (isset($notest[$branch['id']])) {
			echo '<div class="tree_branch">';
			n_tree_branch($branch['id']);
			echo '</div>';
		} else if ($can_new && $branch['id'] == $note['id']) {
			echo '<div class="tree_branch">';
			if ($can_new) echo '<p><a class="tool_link" href="?p=new-notes-' . $branch['id'] . '">+ nouvelle note</a></p>';
			echo '</div>';
		}
	}
	if ($can_new) echo '<p><a class="tool_link" href="?p=new-notes-' . $id . '">+ nouvelle note</a></p>';
}

echo '<div class="tree_root">';
n_tree_branch(0);
echo '</div>';