Added the framework to allow us to populate standards parts of the
[cocanwiki.git] / scripts / users.ml
1 (* COCANWIKI scripts.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: users.ml,v 1.2 2004/09/08 15:46:53 rich Exp $
5  *)
6
7 open Apache
8 open Registry
9 open Cgi
10 open Printf
11
12 open Cocanwiki
13 open Cocanwiki_template
14 open Cocanwiki_date
15
16 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
17   let template = get_template dbh hostid "users.html" in
18
19   let sth =
20     dbh#prepare_cached
21       "select id, name, email, registration_date, can_edit, can_manage_users
22          from users where hostid = ? order by name" in
23   sth#execute [`Int hostid];
24
25   let table =
26     sth#map
27       (function
28            [`Int userid; `String name; (`Null | `String _) as email;
29             `Date registration_date;
30             `Bool can_edit; `Bool can_manage_users] ->
31              let email = match email with `Null -> "" | `String s -> s in
32              [ "userid", Template.VarString (string_of_int userid);
33                "name", Template.VarString name;
34                "email", Template.VarString email;
35                "registration_date",
36                  Template.VarString (printable_date' registration_date);
37                "can_edit", Template.VarConditional can_edit;
38                "can_manage_users", Template.VarConditional can_manage_users ]
39          | _ -> assert false) in
40
41   template#table "users" table;
42
43   q#template template
44
45 let () =
46   register_script ~restrict:[CanManageUsers] run