diff options
Diffstat (limited to 'tpl/notes')
-rw-r--r-- | tpl/notes/edit.php | 17 | ||||
-rw-r--r-- | tpl/notes/inc_relativestree.php | 139 | ||||
-rw-r--r-- | tpl/notes/index.php | 11 | ||||
-rw-r--r-- | tpl/notes/move.php | 16 | ||||
-rw-r--r-- | tpl/notes/new.php | 18 | ||||
-rw-r--r-- | tpl/notes/user.php | 27 | ||||
-rw-r--r-- | tpl/notes/view.php | 18 |
7 files changed, 246 insertions, 0 deletions
diff --git a/tpl/notes/edit.php b/tpl/notes/edit.php new file mode 100644 index 0000000..7e4d88f --- /dev/null +++ b/tpl/notes/edit.php @@ -0,0 +1,17 @@ +<?php + +require("tpl/general/top.php"); + +echo '<div class="small_right"><a href="view-notes-' . $note['id'] . '">return to note</a></div>'; + +require("tpl/general/inc_form.php"); + +if (isset($preview)) { + echo '<hr /><h1>Preview</h1>'; + echo' <div class="error">Warning : this is only a preview. Click the "Edit note" button above to save changes.</div>'; + echo $preview; +} + +$can_new = false; +require("tpl/notes/inc_relativestree.php"); +require("tpl/general/bottom.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 @@ +<?php + +/* OLD WAY + +// ******* FETCH DATA + +if ($note['parent_id'] != 0) { + $brothers = array(); + $n = sql("SELECT id, title, owner FROM notes WHERE parent = " . $note['parent_id'] . " ". + ($note['owner'] == $user['id'] ? "" : " AND public != 0 "). + "ORDER BY title ASC"); + while ($nn = mysql_fetch_assoc($n)) $brothers[] = $nn; +} +$children = array(); +$n = sql("SELECT id, title, owner FROM notes WHERE parent = " . $note['id'] . " " . + ($note['owner'] == $user['id'] ? "" : " AND public != 0 ") . + "ORDER BY title ASC"); +while ($nn = mysql_fetch_assoc($n)) $children[] = $nn; + +$user_root_notes = array(); +$n = sql("SELECT id, title, owner FROM notes WHERE parent = 0 AND owner = " . $note['owner'] . " " . + ($note['owner'] == $user['id'] ? "" : " AND public != 0 ") . + "ORDER BY title ASC"); +while ($nn = mysql_fetch_assoc($n)) $user_root_notes[] = $nn; + +// ****** DISPLAY TREE + +echo '</div><div class="contents-left">'; +echo '<h1>' . $note['ownername'] . '</h1><br />'; +echo '<div class="small_right"><a href="user-notes-' . $note['owner'] . '">complete tree</a></div>'; + +function list_brothers_and_children() { + global $brothers, $children, $note, $user, $can_new; + echo '<div class="tree_branch">'; + foreach($brothers as $b) { + if ($b['id'] == $note['id']) { + echo '<p>' . $b['title'] . '</p><div class="tree_branch">'; + foreach($children as $nn) { + echo '<p><a href="view-notes-' . $nn['id'] . '">' . $nn['title'] . '</a></p>'; + } + if ($can_new) { + echo '<p><a class="tool_link" href="new-notes-' . $b['id'] . '">+ new note</a></p>'; + } + echo '</div>'; + } else { + echo '<p><a href="view-notes-' . $b['id'] .'">' . $b['title'] . '</a></p>'; + } + } + if ($can_new) { + echo '<p><a class="tool_link" href="new-notes-' . $note['parent_id'] . '">+ new note</a></p>'; + } + echo '</div>'; +} + +echo '<div class="tree_branch">'; +$did_show_up = false; +foreach($user_root_notes as $n) { + if ($n['id'] == $note['id']) { + $did_show_up = true; + echo '<p>' . $n['title'] . '</p><div class="tree_branch">'; + foreach($children as $nn) { + echo '<p><a href="view-notes-' . $nn['id'] . '">' . $nn['title'] . '</a></p>'; + } + if ($can_new) { + echo '<p><a class="tool_link" href="new-notes-' . $note['id'] . '">+ new note</a></p>'; + } + echo '</div>'; + } else { + echo '<p><a href="view-notes-' . $n['id'] . '">' . $n['title'] . '</a></p>'; + if ($n['id'] == $note['parent_id']) { + $did_show_up = true; + list_brothers_and_children(); + } + } +} +if ($can_new) { + echo '<p><a class="tool_link" href="new-notes-0">+ new note</a></p>'; +} +echo '</div>'; + +if (!$did_show_up) { + echo '<br /><br />'; + echo '<a href="view-notes-' . $note['parent_id'] . '">' . $note['parent_title'] . '</a>'; + 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 '</div><div class="contents-left">'; +echo '<h1>' . $note['ownername'] . '</h1><br />'; +echo '<div class="small_right"><a href="user-notes-' . $note['owner'] . '">complete tree</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'] . '">+ new note</a></p>'; + echo '</div>'; + } + } + if ($can_new) echo '<p><a class="tool_link" href="new-notes-' . $id . '">+ new note</a></p>'; +} + +echo '<div class="tree_root">'; +n_tree_branch(0); +echo '</div>'; + diff --git a/tpl/notes/index.php b/tpl/notes/index.php new file mode 100644 index 0000000..1be4cd5 --- /dev/null +++ b/tpl/notes/index.php @@ -0,0 +1,11 @@ +<?php +$title = "User's notebooks"; +require("tpl/general/top.php"); + +echo "<ul>"; +foreach($users as $u) { + echo '<li><a href="user-notes-' . $u['id'] . '">' . $u['name'] . '</a> (' . $u['nbNotes'] . ' notes)</li>'; +} +echo "</ul>"; + +require("tpl/general/bottom.php"); diff --git a/tpl/notes/move.php b/tpl/notes/move.php new file mode 100644 index 0000000..d94e745 --- /dev/null +++ b/tpl/notes/move.php @@ -0,0 +1,16 @@ +<?php + +require("tpl/general/top.php"); + +function f($n) { + global $note; + return $n['title'] . ' - <a class="tool_link" href="move-notes-' . $note['id'] . '-' . $n['id'] . '">move here</a>'; +} + +require("tpl/general/inc_tree.php"); +tree($notes_tree, @f); +echo '<a class="tool_link" href="move-notes-'.$note['id'].'-0">move to root</a>'; + +$can_new = false; +require("tpl/notes/inc_relativestree.php"); +require("tpl/general/bottom.php"); diff --git a/tpl/notes/new.php b/tpl/notes/new.php new file mode 100644 index 0000000..ca17f21 --- /dev/null +++ b/tpl/notes/new.php @@ -0,0 +1,18 @@ +<?php + +require("tpl/general/top.php"); + +if (isset($parent)) { + echo '<div class="small_right"><a href="view-notes-' . $parent['id'] . '">back to ' . + $parent['title'] . '</a></div>'; +} + +require("tpl/general/inc_form.php"); + +if (isset($parent)) { + $note = $parent; + $can_new = false; + require("tpl/notes/inc_relativestree.php"); +} + +require("tpl/general/bottom.php"); diff --git a/tpl/notes/user.php b/tpl/notes/user.php new file mode 100644 index 0000000..4da34e9 --- /dev/null +++ b/tpl/notes/user.php @@ -0,0 +1,27 @@ +<?php +$title = $note_owner['name'] . "'s notebook"; +require("tpl/general/top.php"); + +function f($n) { + return '<a href="view-notes-' . $n['id'] . '">' . $n['title'] . '</a>'; +} + +require("tpl/general/inc_tree.php"); +tree($notes_tree, @f); +if ($note_owner['id'] == $user['id']) { + echo '<a class="tool_link" href="new-notes-0">create new note</a>'; +} + +echo '</div><div class="contents-left">'; +echo '<h1>Other users</h1>'; +echo "<ul>"; +foreach($users as $u) { + if ($u['id'] == $userid) { + echo '<li>' . $u['name'] . ' (' . $u['nbNotes'] . ' notes)</li>'; + } else { + echo '<li><a href="user-notes-' . $u['id'] . '">' . $u['name'] . '</a> (' . $u['nbNotes'] . ' notes)</li>'; + } +} +echo "</ul>"; + +require("tpl/general/bottom.php"); diff --git a/tpl/notes/view.php b/tpl/notes/view.php new file mode 100644 index 0000000..c33e836 --- /dev/null +++ b/tpl/notes/view.php @@ -0,0 +1,18 @@ +<?php +$title = $note["title"]; +require("tpl/general/top.php"); + +$t = array(); +if ($note['parent_id'] != 0) { + $t[] = 'parent : <a href="view-notes-'. $note['parent_id'] . '">' . $note['parent_title'] . '</a>'; +} +if ($can_edit) $t[] = '<a href="edit-notes-' . $note['id'] . '">edit</a>'; +$t[] = '<a href="source-notes-' . $note['id'] . '">view source</a>'; +if ($can_move) $t[] = '<a href="move-notes-' . $note['id'] . '">move</a>'; +if ($can_delete) $t[] = '<a href="delete-notes-' . $note['id'] . '">delete</a>'; +echo '<div class="small_right">' . implode(' | ', $t) . '</div>'; +echo $note['html']; + +require("tpl/notes/inc_relativestree.php"); + +require("tpl/general/bottom.php"); |