Fixed some problems found in testing. Now appears to be working fully.
[cocanwiki.git] / scripts / edit_user_form.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: edit_user_form.ml,v 1.10 2006/03/27 19:10:29 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 "edit_user_form.html" in
33
34   let userid = Int32.of_string (q#param "userid") in
35
36   let rows =
37     PGSQL(dbh)
38       "select u.name, u.email, u.registration_date,
39               u.can_edit, u.can_manage_users, u.can_manage_contacts,
40               u.can_manage_site, u.can_edit_global_css, u.can_import_mail,
41               (select count(*) from pages where logged_user = u.id)::int4,
42               (select count(*) from pages
43                 where logged_user = u.id and url_deleted is null)::int4
44          from users u where u.hostid = $hostid and u.id = $userid" in
45
46   let name, email, registration_date, can_edit, can_manage_users,
47       can_manage_contacts, can_manage_site, can_edit_global_css,
48       can_import_mail, nr_edits, nr_edits_live =
49     match rows with
50     | [name, email, registration_date,
51        can_edit, can_manage_users, can_manage_contacts,
52        can_manage_site, can_edit_global_css,
53        can_import_mail,
54        nr_edits, nr_edits_live] ->
55         name, email, registration_date, can_edit, can_manage_users,
56         can_manage_contacts, can_manage_site, can_edit_global_css,
57         can_import_mail, nr_edits, nr_edits_live
58     | _ -> assert false in
59
60   template#set "userid" (Int32.to_string userid);
61   template#set "name" name;
62   template#set "email" (match email with None -> "" | Some s -> s);
63   template#set "registration_date" (printable_date' registration_date);
64   template#conditional "can_edit" can_edit;
65   template#conditional "can_manage_users" can_manage_users;
66   template#conditional "can_manage_contacts" can_manage_contacts;
67   template#conditional "can_manage_site" can_manage_site;
68   template#conditional "can_edit_global_css" can_edit_global_css;
69   template#conditional "can_import_mail" can_import_mail;
70   template#set "nr_edits" (Int32.to_string (Option.get nr_edits));
71   template#set "nr_edits_live" (Int32.to_string (Option.get nr_edits_live));
72
73   q#template template
74
75 let () =
76   register_script ~restrict:[CanManageUsers] run