From d0060968b77c39bdf8abffb071c971c166b59edb Mon Sep 17 00:00:00 2001 From: Nicolas BERNSTEIN Date: Sat, 17 Sep 2011 16:48:29 +0200 Subject: First commit. --- lib/notes/delete.php | 13 +++++++++++++ lib/notes/edit.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/notes/index.php | 9 +++++++++ lib/notes/move.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ lib/notes/new.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ lib/notes/source.php | 22 ++++++++++++++++++++++ lib/notes/user.php | 33 +++++++++++++++++++++++++++++++++ lib/notes/view.php | 21 +++++++++++++++++++++ 8 files changed, 239 insertions(+) create mode 100644 lib/notes/delete.php create mode 100644 lib/notes/edit.php create mode 100644 lib/notes/index.php create mode 100644 lib/notes/move.php create mode 100644 lib/notes/new.php create mode 100644 lib/notes/source.php create mode 100644 lib/notes/user.php create mode 100644 lib/notes/view.php (limited to 'lib/notes') diff --git a/lib/notes/delete.php b/lib/notes/delete.php new file mode 100644 index 0000000..e8ef31e --- /dev/null +++ b/lib/notes/delete.php @@ -0,0 +1,13 @@ += 3, 'notes'); +$noteid = intval($args[2]); + +$note = mysql_fetch_assoc(sql("SELECT owner FROM notes WHERE id = $noteid")); +assert_error($note && $note['owner'] == $user['id'], + "This note does not exist, or you are not allowed to delete it."); + +token_validate("Do you really want to delete this note ? All children notes will become children of the root note.", "view-notes-$noteid"); +sql("DELETE FROM notes WHERE id = $noteid"); +sql("UPDATE notes SET parent = 0 WHERE parent = $noteid"); +header("Location: user-notes-" . $user['id']); diff --git a/lib/notes/edit.php b/lib/notes/edit.php new file mode 100644 index 0000000..17f1573 --- /dev/null +++ b/lib/notes/edit.php @@ -0,0 +1,50 @@ + "Title : ", "name" => "title", "value" => $note_title), + array("label" => "Public ? ", "name" => "public", "type" => "checkbox", "checked" => $note_public), + array("label" => "Text : ", "name" => "text", "type" => "textarea", "value" => $note_text), + array("label" => "Preview : ", "name" => "preview", "type" => "submit", "value" => "Preview"), + ); +$validate = "Edit note"; + +require("tpl/notes/edit.php"); diff --git a/lib/notes/index.php b/lib/notes/index.php new file mode 100644 index 0000000..3c81f46 --- /dev/null +++ b/lib/notes/index.php @@ -0,0 +1,9 @@ += 3, 'notes'); +$noteid = intval($args[2]); + +$note = mysql_fetch_assoc(sql( + "SELECT na.id AS id, na.title AS title, na.text AS text, na.public AS public, na.owner AS owner, ". + "nb.title AS parent_title, nb.id AS parent_id, account.login AS ownername FROM notes na ". + "LEFT JOIN notes nb ON na.parent = nb.id LEFT JOIN account ON account.id = na.owner ". + "WHERE na.id = $noteid" +)); +assert_error($note && $note['owner'] == $user['id'], + "This note does not exist, or you are not allowed to move it."); + +if (count($args) == 4) { + $newparent = intval($args[3]); + // SHOULD CHECK FOR TREE CONSISTENCY, SKIP FOR NOW. + if ($newparent != 0) { + $p = mysql_fetch_assoc(sql("SELECT id, owner FROM notes WHERE id = $newparent")); + } + if ($newparent != 0 && !$p) { + $error = "Selected parent does not exist."; + } else if ($newparent != 0 && $p['owner'] != $user['id']) { + $error = "Selected parent is not belong to you."; + } else { + sql("UPDATE notes SET parent = $newparent WHERE id = $noteid"); + header("Location: view-notes-$noteid"); + die(); + } +} + +$notes_tree = array(); +$n = sql("SELECT id, parent, title FROM notes ". + "WHERE owner = " . $user['id'] . " AND id != $noteid AND parent != $noteid ORDER BY title ASC"); +while ($nn = mysql_fetch_assoc($n)) { + if (isset($notes_tree[$nn['parent']])) { + $notes_tree[$nn['parent']][] = $nn; + } else { + $notes_tree[$nn['parent']] = array($nn); + } +} + +$title = "Move note : " . $note["title"]; +require("tpl/notes/move.php"); diff --git a/lib/notes/new.php b/lib/notes/new.php new file mode 100644 index 0000000..1213b94 --- /dev/null +++ b/lib/notes/new.php @@ -0,0 +1,47 @@ + "Title : ", "name" => "title", "value" => $note_title), + array("label" => "Public ? ", "name" => "public", "type" => "checkbox", "checked" => $note_public), + array("label" => "Text : ", "name" => "text", "type" => "textarea", "value" => $note_text), + ); +$validate = "Create note"; + +require("tpl/notes/new.php"); diff --git a/lib/notes/source.php b/lib/notes/source.php new file mode 100644 index 0000000..4ff40d7 --- /dev/null +++ b/lib/notes/source.php @@ -0,0 +1,22 @@ + + + + + + + +
+ + += $apps['notes']['new'] && $user['id'] == $note['owner']); +$can_edit = ($user['priv'] >= $apps['notes']['edit'] && $user['id'] == $note['owner']); +$can_delete = ($user['priv'] >= $apps['notes']['delete'] && $user['id'] == $note['owner']); +$can_move = ($user['priv'] >= $apps['notes']['move'] && $user['id'] == $note['owner']); + +require("tpl/notes/view.php"); + -- cgit v1.2.3