(* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. * $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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. *) open Apache open Registry open Cgi open Printf open Cocanwiki open Cocanwiki_template open Cocanwiki_date let run r (q : cgi) (dbh : Dbi.connection) hostid host user = let template = get_template dbh hostid "user_prefs_form.html" in let userid, name, prefs = match user with | Anonymous -> assert false | User (userid, name, _, prefs) -> userid, name, prefs in 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 registration_date from users where hostid = ? and id = ?" in sth#execute [`Int hostid; `Int userid]; let registration_date = match sth#fetch1 () with [ `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" prefs.email_notify; q#template template let () = register_script ~anonymous:false run