Added styling to some pages which previously were "outside" the site
[cocanwiki.git] / scripts / user_prefs_form.ml
index c346f17..4d66eb7 100644 (file)
@@ -1,7 +1,7 @@
 (* 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.5 2006/03/28 16:24:08 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
@@ -28,39 +28,34 @@ open Cocanwiki
 open Cocanwiki_template
 open Cocanwiki_date
 
-let run r (q : cgi) (dbh : Dbi.connection) hostid _ user =
+let run r (q : cgi) dbh 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 sth =
-    dbh#prepare_cached
-      "select name, email, registration_date, can_edit, email_notify
-         from users where hostid = ? and id = ?" in
-  sth#execute [`Int hostid; `Int userid];
+  let can_edit = can_edit host user in
 
-  let name, email, has_email, registration_date, can_edit, email_notify =
-    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
-      | _ -> assert false in
+  (* Pull out the registration date - not stored in the user object. *)
+  let registration_date = List.hd (
+    PGSQL(dbh)
+      "select registration_date from users
+        where hostid = $hostid and id = $userid"
+  ) 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