From 29c3cc58c530ac59a4c262c4399311595cca9d8f Mon Sep 17 00:00:00 2001 From: adamch Date: Sun, 17 Apr 2005 00:58:25 +0000 Subject: [PATCH] Hosted site link database --- TODO | 1 - group.sml | 2 +- link.mlt | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ link.sig | 11 +++++++ link.sml | 55 ++++++++++++++++++++++++++++++++ tables.sql | 23 +++++++------- user.mlt | 28 +++++++++++++--- 7 files changed, 195 insertions(+), 18 deletions(-) create mode 100644 link.mlt create mode 100644 link.sig create mode 100644 link.sml diff --git a/TODO b/TODO index 19777c3..d6a985c 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,4 @@ Member data - - Hosted web site registry - Summarize these with publicly accessible static pages Generic support requests diff --git a/group.sml b/group.sml index 5daf76c..3481eb2 100644 --- a/group.sml +++ b/group.sml @@ -67,7 +67,7 @@ fun userInGroupName (usr, grp) = in (case C.oneOrNoRows c ($`SELECT COUNT( * ) FROM Membership, WebGroup - WHERE (id = 0 OR (name = ^(C.stringToSql grp) AND grp = id)) + WHERE (grp = 0 OR (name = ^(C.stringToSql grp) AND grp = id)) AND usr = ^(C.intToSql usr)`) of SOME[x] => not (C.isNull x) andalso C.intFromSql x <> 0 | _ => false) diff --git a/link.mlt b/link.mlt new file mode 100644 index 0000000..ddfea35 --- /dev/null +++ b/link.mlt @@ -0,0 +1,93 @@ +<% @header[("title", ["Hosted sites"])]; + +val admin = Group.inGroupName "links"; +val you = Init.getUserId (); + +ref showNormal = true; + +if $"cmd" = "add" then + val id = Link.addLink (you, $"title", $"url", $"descr") %> +

Link added

+ +<% elseif $"mod" <> "" then + val id = Web.stoi ($"mod"); + val link = Link.lookupLink id; + if (iff admin then false else you <> #usr link) then + %>

You can't modify somebody else's link.

<% + else + showNormal := false %> + +

Modify link

+ +
+ + + + + + +
Title:
URL:
Description:
+
+<% end + +elseif $"save" <> "" then + val id = Web.stoi ($"save"); + val link = Link.lookupLink id; + if (iff admin then false else you <> #usr link) then + %>

You can't modify somebody else's link.

<% + else + Link.modLink {link with title = $"title", url = $"url", descr = $"descr"} + %>

Link modified

<% + end + +elseif $"del" <> "" then + val id = Web.stoi ($"del"); + val link = Link.lookupLink id; + if (iff admin then false else you <> #usr link) then + %>

You can't delete somebody else's link.

<% + else + showNormal := false %> +

Are you sure you want to delete link to "<% Web.html (#title link) %>"?

+ Yes, delete "<% Web.html (#title link) %>"!<% + end + +elseif $"del2" <> "" then + val id = Web.stoi ($"del2"); + val link = Link.lookupLink id; + if (iff admin then false else you <> #usr link) then + %>

You can't delete somebody else's link.

<% + else + Link.deleteLink id; + %>

Link "<% Web.html (#title link) %>" deleted

<% + end +end; + +if showNormal then %> + + +<% foreach (name, link) in Link.listLinks () do %> + + + +<% if (iff admin then true else you = #usr link) then %> + +<% end %> + +<% end %> +
<% Web.html (#title link) %><% Web.html (#descr link) %>(<% name %>)[Modify] [Delete]
+ +

Add a link to a site you host with Hcoop

+ +
+ + + + + + +
Title:
URL:
Description:
+
+ +<% end %> + +<% @footer[] %> \ No newline at end of file diff --git a/link.sig b/link.sig new file mode 100644 index 0000000..f0d78dc --- /dev/null +++ b/link.sig @@ -0,0 +1,11 @@ +signature LINK = +sig + type link = {id : int, usr : int, title : string, url : string, descr : string} + + val lookupLink : int -> link + val listLinks : unit -> (string * link) list + val listUserLinks : int -> link list + val addLink : int * string * string * string -> int + val modLink : link -> unit + val deleteLink : int -> unit +end \ No newline at end of file diff --git a/link.sml b/link.sml new file mode 100644 index 0000000..dffd86d --- /dev/null +++ b/link.sml @@ -0,0 +1,55 @@ +structure Link :> LINK = +struct + +open Util Sql Init + +type link = {id : int, usr : int, title : string, url : string, descr : string} + +fun mkLinkRow [id, usr, title, url, descr] = + {id = C.intFromSql id, usr = C.intFromSql usr, title = C.stringFromSql title, + url = C.stringFromSql url, descr = C.stringFromSql descr} + | mkLinkRow row = rowError ("link", row) + +fun lookupLink id = + mkLinkRow (C.oneRow (getDb ()) ($`SELECT id, usr, title, url, descr + FROM Link + WHERE id = ^(C.intToSql id)`)) + +fun mkLinkRow' (name :: rest) = (C.stringFromSql name, mkLinkRow rest) + | mkLinkRow' row = Init.rowError ("user'", row) + +fun listLinks () = + C.map (getDb ()) mkLinkRow' ($`SELECT name, Link.id, usr, title, url, descr + FROM Link JOIN WebUser ON usr = WebUser.id + ORDER BY title`) + +fun listUserLinks usr = + C.map (getDb ()) mkLinkRow ($`SELECT id, usr, title, url, descr + FROM Link + WHERE usr = ^(C.intToSql usr) + ORDER BY title`) + +fun addLink (usr, title, url, descr) = + let + val db = getDb () + val id = nextSeq (db, "LinkSeq") + in + C.dml db ($`INSERT INTO Link (id, usr, title, url, descr) + VALUES (^(C.intToSql id), ^(C.intToSql usr), ^(C.stringToSql title), ^(C.stringToSql url), ^(C.stringToSql descr))`); + id + end + +fun modLink (link : link) = + let + val db = getDb () + in + ignore (C.dml db ($`UPDATE Link SET + usr = ^(C.intToSql (#usr link)), title = ^(C.stringToSql (#title link)), + url = ^(C.stringToSql (#url link)), descr = ^(C.stringToSql (#descr link)) + WHERE id = ^(C.intToSql (#id link))`)) + end + +fun deleteLink id = + ignore (C.dml (getDb ()) ($`DELETE FROM Link WHERE id = ^(C.intToSql id)`)) + +end diff --git a/tables.sql b/tables.sql index 1ffc2a4..b4996bb 100644 --- a/tables.sql +++ b/tables.sql @@ -33,18 +33,6 @@ INSERT INTO WebGroup (id, name) VALUES (0, 'root'); -INSERT INTO WebGroup - (id, name) VALUES - (1, 'money'); - -INSERT INTO WebGroup - (id, name) VALUES - (2, 'paying'); - -INSERT INTO WebGroup - (id, name) VALUES - (3, 'poll'); - CREATE TABLE Membership( grp INTEGER NOT NULL, usr INTEGER NOT NULL, @@ -135,3 +123,14 @@ CREATE TABLE Lives( PRIMARY KEY (usr, loc), FOREIGN KEY (usr) REFERENCES WebUser(id) ON DELETE CASCADE, FOREIGN KEY (loc) REFERENCES Location(id) ON DELETE CASCADE); + +CREATE TABLE Link( + id INTEGER PRIMARY KEY, + usr INTEGER NOT NULL, + title TEXT NOT NULL, + url TEXT NOT NULL, + descr TEXT NOT NULL, + FOREIGN KEY (usr) REFERENCES WebUser(id) ON DELETE CASCADE); + +CREATE SEQUENCE LinkSeq START 1; + diff --git a/user.mlt b/user.mlt index 7316db6..013cb73 100644 --- a/user.mlt +++ b/user.mlt @@ -19,16 +19,36 @@ val user = Init.lookupUser id; %><% Web.html (#name loc) %><% end %> +<% val links = Link.listUserLinks id; + +switch links of + (_::_) => %> - Contact information + Hosted sites + +<% foreach link in links do %> + <% Web.html (#title link) %><% + if #descr link <> "" then %>: <% Web.html (#descr link) end + %> +<% end +end; + +val level = iff Group.inGroupName "contact" then Contact.ADMINS else Contact.MEMBERS; -<% val level = iff Group.inGroupName "contact" then Contact.ADMINS else Contact.MEMBERS; +val contacts = Contact.listUserContacts (id, level); + +switch contacts of + (_::_) => %> + + + Contact information -foreach (kind, cont) in Contact.listUserContacts (id, level) do %> +<% foreach (kind, cont) in contacts do %> <% Web.html (#name kind) %>: <% Contact.format (kind, cont) %> -<% end %> +<% end +end %> -- 2.20.1