summaryrefslogblamecommitdiff
path: root/tpl/notes/inc_relativestree.php
blob: fd47ab4294ecc52e202f4f1da213266ecf00da27 (plain) (tree)
1
2

     






















                                                                     
                                                                                                














                                                                                                              
                                                                                                                                    


                                      
                                                                                                          





                               
<?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>';