(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: user_prefs_form.ml,v 1.1 2004/10/23 15:00:16 rich Exp $
+ * $Id: user_prefs_form.ml,v 1.3 2004/11/01 12:57:53 rich Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
open Cocanwiki_template
open Cocanwiki_date
-let run r (q : cgi) (dbh : Dbi.connection) hostid _ user =
+let run r (q : cgi) (dbh : Dbi.connection) hostid host user =
let template = get_template dbh hostid "user_prefs_form.html" in
- let userid =
+ let userid, name, prefs =
match user with
| Anonymous -> assert false
- | User (userid, _, _) -> userid in
+ | User (userid, name, _, prefs) -> userid, name, prefs in
- (* Pull out the preferences. *)
+ let can_edit = can_edit host user in
+
+ (* Pull out the registration date - not stored in the user object. *)
let sth =
dbh#prepare_cached
- "select name, email, registration_date, can_edit, email_notify
- from users where hostid = ? and id = ?" in
+ "select registration_date from users where hostid = ? and id = ?" in
sth#execute [`Int hostid; `Int userid];
- let name, email, has_email, registration_date, can_edit, email_notify =
+ let registration_date =
match sth#fetch1 () with
- [ `String name; (`Null | `String _) as email;
- `Date registration_date; `Bool can_edit; `Bool email_notify ] ->
- let email, has_email =
- match email with
- `Null -> "", false
- | `String email -> email, true in
- name, email, has_email, registration_date,
- can_edit, email_notify
+ [ `Date registration_date ] -> registration_date
| _ -> assert false in
+ let email, has_email =
+ match prefs.email with
+ None -> "", false
+ | Some email -> email, true in
+
template#set "name" name;
template#set "email" email;
template#conditional "has_email" has_email;
template#set "registration_date" (printable_date' registration_date);
template#conditional "can_edit" can_edit;
- template#conditional "email_notify" email_notify;
+ template#conditional "email_notify" prefs.email_notify;
q#template template