summaryrefslogtreecommitdiff
path: root/tpl/notes/inc_relativestree.php
blob: fd47ab4294ecc52e202f4f1da213266ecf00da27 (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'] .
	($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 '</div><div class="contents-left">';
echo '<h1>' . $note['ownername'] . '</h1><br />';
echo '<div class="small_right"><a href="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="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="new-notes-' . $branch['id'] . '">+ nouvelle note</a></p>';
			echo '</div>';
		}
	}
	if ($can_new) echo '<p><a class="tool_link" href="new-notes-' . $id . '">+ nouvelle note</a></p>';
}

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