ca84d9ecf81dd6debbe2b5d30e2f1be4655c3a7b
[cocanwiki.git] / scripts / users.ml
1 (* COCANWIKI - a wiki written in Objective CAML.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: users.ml,v 1.9 2006/03/27 18:09:47 rich Exp $
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; see the file COPYING.  If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *)
21
22 open Apache
23 open Registry
24 open Cgi
25 open Printf
26
27 open Cocanwiki
28 open Cocanwiki_template
29 open Cocanwiki_date
30
31 let run r (q : cgi) dbh hostid _ _ =
32   let template = get_template dbh hostid "users.html" in
33
34   let sth =
35     dbh#prepare_cached
36       "select id, name, email, registration_date, invite is not null,
37               can_edit, can_manage_users,
38               can_manage_contacts, can_manage_site, can_edit_global_css,
39               can_import_mail
40          from users where hostid = ? order by name" in
41   sth#execute [Some hostid];
42
43   let table =
44     sth#map
45       (function
46            [Some userid; Some name; (None | Some _) as email;
47             `Date registration_date; `Bool invite_pending;
48             `Bool can_edit; `Bool can_manage_users;
49             `Bool can_manage_contacts; `Bool can_manage_site;
50             `Bool can_edit_global_css; `Bool can_import_mail] ->
51              let email = match email with None -> "" | Some s -> s in
52              [ "userid", Template.VarString (Int32.to_string userid);
53                "name", Template.VarString name;
54                "email", Template.VarString email;
55                "registration_date",
56                  Template.VarString (printable_date' registration_date);
57                "invite_pending",
58                  Template.VarConditional invite_pending;
59                "can_edit", Template.VarConditional can_edit;
60                "can_manage_users", Template.VarConditional can_manage_users;
61                "can_manage_contacts",
62                  Template.VarConditional can_manage_contacts;
63                "can_manage_site", Template.VarConditional can_manage_site;
64                "can_edit_global_css",
65                  Template.VarConditional can_edit_global_css;
66                "can_import_mail",
67                  Template.VarConditional can_import_mail;]
68          | _ -> assert false) in
69
70   template#table "users" table;
71
72   q#template template
73
74 let () =
75   register_script ~restrict:[CanManageUsers] run