diff options
author | Nicolas BERNSTEIN <alexis211@gmail.com> | 2011-09-17 16:48:29 +0200 |
---|---|---|
committer | Nicolas BERNSTEIN <alexis211@gmail.com> | 2011-09-17 16:48:29 +0200 |
commit | d0060968b77c39bdf8abffb071c971c166b59edb (patch) | |
tree | 0be52e00a25bd298235a0cf916fb07496d3ab95f /lib/notes/user.php | |
download | Bits-d0060968b77c39bdf8abffb071c971c166b59edb.tar.gz Bits-d0060968b77c39bdf8abffb071c971c166b59edb.zip |
First commit.
Diffstat (limited to 'lib/notes/user.php')
-rw-r--r-- | lib/notes/user.php | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/notes/user.php b/lib/notes/user.php new file mode 100644 index 0000000..e420946 --- /dev/null +++ b/lib/notes/user.php @@ -0,0 +1,33 @@ +<?php + +assert_redir(count($args) == 3, 'notes'); +$userid = intval($args[2]); + +if ($userid == $user['id']) { + $note_owner = $user; +} else { + $note_owner = mysql_fetch_assoc(sql("SELECT login AS name, id FROM account WHERE id = $userid")); + assert_error($note_owner, "That user id does not exist.", "no such user"); +} + +$users = array(); +$n = sql("SELECT account.id AS id, login AS name, COUNT(notes.id) AS nbNotes FROM account ". + "LEFT JOIN notes ON notes.owner = account.id ". + "WHERE notes.public != 0 AND notes.id != 0 ". + "GROUP BY account.id ORDER BY nbNotes DESC"); +while ($nn = mysql_fetch_assoc($n)) $users[] = $nn; + +$notes_tree = array(); +$n = sql("SELECT id, parent, title FROM notes ". + "WHERE owner = $userid ". + ($userid == $user['id'] ? "" : "AND public != 0 "). + "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); + } +} + +require("tpl/notes/user.php"); |