From 6e8dc4366763f1d7a6ed8ada88926f51c16a596a Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sat, 16 Apr 2005 21:39:38 +0000 Subject: [PATCH] Finished user-level contact stuff --- TODO | 1 - contact.mlt | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- contact.sig | 1 + contact.sml | 14 +++++++++++++- dir.mlt | 22 ++++++++++++++++++++++ user.mlt | 25 +++++++++++++++++++++++++ 6 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 dir.mlt create mode 100644 user.mlt diff --git a/TODO b/TODO index 859db30..f7412b7 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,4 @@ Member data - - Contact information - Geographic location - Hosted web site registry - Summarize these with publicly accessible static pages diff --git a/contact.mlt b/contact.mlt index 75b6978..eed7986 100644 --- a/contact.mlt +++ b/contact.mlt @@ -5,6 +5,51 @@ ref showNormal = true; if $"cmd" = "add" then val id = Contact.addContact (Init.getUserId(), Web.stoi ($"knd"), $"v", Contact.privFromInt (Web.stoi ($"priv"))) %>

Contact added

+ +<% elseif $"mod" <> "" then + showNormal := false; + val id = Web.stoi ($"mod"); + val cont = Contact.lookupContact id %> + +

Modify contact entry

+ +
+ + + + + + +
Kind:
Value:
Readable by:
+
+ +<% elseif $"save" <> "" then + val id = Web.stoi ($"save"); + val cont = Contact.lookupContact id; + Contact.modContact {cont with knd = Web.stoi ($"knd"), v = $"v", priv = Contact.privFromInt (Web.stoi ($"priv"))} %> +

Contact entry saved

+ +<% elseif $"del" <> "" then + showNormal := false; + val id = Web.stoi ($"del"); + val cont = Contact.lookupContact id %> +

Are you sure you want to delete contact entry "<% Web.html (#v cont) %>"?

+ Yes, delete "<% Web.html (#v cont) %>"! + +<% elseif $"del2" <> "" then + val id = Web.stoi ($"del2"); + val cont = Contact.lookupContact id; + Contact.deleteContact id %> +

Contact entry "<% Web.html (#v cont) %>" deleted

+ <% end; if showNormal then %> @@ -34,7 +79,13 @@ if showNormal then %> <% foreach (kind, cont) in Contact.listUserContacts (Init.getUserId(), Contact.ADMINS) do %> - + + + <% end %>
<% Web.html (#name kind) %>:<% Contact.format (kind, cont) %>
<% Contact.format (kind, cont) %><% switch #priv cont of + Contact.PUBLIC => %>Public<% + | Contact.MEMBERS => %>Members only<% + | Contact.ADMINS => %>Admins only<% + end %>[Modify] [Delete]
diff --git a/contact.sig b/contact.sig index 1fb0454..1c11d72 100644 --- a/contact.sig +++ b/contact.sig @@ -22,6 +22,7 @@ sig val modContact : contact -> unit val deleteContact : int -> unit val listUserContacts : int * priv -> (kind * contact) list + val listContactsByKind : int * priv -> (string * contact) list val format : kind * contact -> string end \ No newline at end of file diff --git a/contact.sml b/contact.sml index 345ab51..3c3698d 100644 --- a/contact.sml +++ b/contact.sml @@ -103,7 +103,7 @@ fun lookupContact id = let val c = getDb () in - (case C.oneOrNoRows c ($`SELECT id, usr, knd, v, priv Contact WHERE id = ^(C.intToSql id)`) of + (case C.oneOrNoRows c ($`SELECT id, usr, knd, v, priv FROM Contact WHERE id = ^(C.intToSql id)`) of NONE => raise Fail "Contact not found" | SOME r => mkContactRow r) end @@ -134,6 +134,18 @@ fun listUserContacts (usr, priv) = AND priv <= ^(privToSql priv) ORDER BY name, v`) +fun mkKindContactRow r = + case r of + name :: rest => (C.stringFromSql name, mkContactRow rest) + | _ => Init.rowError ("name/contact", r) + +fun listContactsByKind (knd, priv) = + C.map (getDb ()) mkKindContactRow ($`SELECT name, Contact.id, usr, knd, v, priv + FROM Contact JOIN WebUser ON WebUser.id = usr + WHERE knd = ^(C.intToSql knd) + AND priv <= ^(privToSql priv) + ORDER BY name`) + fun format (kind : kind, cont : contact) = case #makeUrl kind of SOME (pre, post) => String.concat ["", Web.html (#v cont), ""] diff --git a/dir.mlt b/dir.mlt new file mode 100644 index 0000000..c973671 --- /dev/null +++ b/dir.mlt @@ -0,0 +1,22 @@ +<% if $"id" = "" then + @header [("title", ["Contact information directory"])] + + foreach kind in Contact.listKinds () do %> + <% Web.html (#name kind) %>
+ <% end +else + val id = Web.stoi ($"id"); + val kind = Contact.lookupKind id; + @header [("title", [Web.html (#name kind) ^ " directory"])]; + + val level = iff Group.inGroupName "contact" then Contact.ADMINS else Contact.MEMBERS; + + %><% + foreach (name, cont) in Contact.listContactsByKind (id, level) do %> + + + <% end + %>
<% name %><% Contact.format (kind, cont) %>
<% +end; + +@footer[] %> \ No newline at end of file diff --git a/user.mlt b/user.mlt new file mode 100644 index 0000000..498fc49 --- /dev/null +++ b/user.mlt @@ -0,0 +1,25 @@ +<% val id = Web.stoi ($"id"); +val user = Init.lookupUser id; + +@header[("title", [#name user])] %> + + + + + + + + + + + +<% val level = iff Group.inGroupName "contact" then Contact.ADMINS else Contact.MEMBERS; + +foreach (kind, cont) in Contact.listUserContacts (id, level) do %> + + +<% end %> + +
Member: <% #name user %>
Real name: <% Web.html (#rname user) %>
Hcoop e-mail: <% #name user %>@hcoop.net
Joined: <% #joined user %>
Contact information
<% Web.html (#name kind) %>:<% Contact.format (kind, cont) %>
+ +<% @footer[] %> -- 2.20.1