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.6 2004/09/22 10:19:26 rich Exp $
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.
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.
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.
28 open Cocanwiki_template
31 let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
32 let template = get_template dbh hostid "edit_user_form.html" in
34 let userid = int_of_string (q#param "userid") in
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,
41 (select count(*) from pages where logged_user = u.id),
42 (select count(*) from pages
43 where logged_user = u.id and url_deleted is null)
44 from users u where u.hostid = ? and u.id = ?" in
45 sth#execute [`Int hostid; `Int userid];
47 let name, email, registration_date, can_edit, can_manage_users,
48 can_manage_contacts, can_manage_site, can_edit_global_css,
49 nr_edits, nr_edits_live =
50 match sth#fetch1 () with
51 [`String name; (`Null | `String _) as email;
52 `Date registration_date;
53 `Bool can_edit; `Bool can_manage_users; `Bool can_manage_contacts;
54 `Bool can_manage_site; `Bool can_edit_global_css;
55 `Int nr_edits; `Int nr_edits_live] ->
56 name, email, registration_date, can_edit, can_manage_users,
57 can_manage_contacts, can_manage_site, can_edit_global_css,
58 nr_edits, nr_edits_live
59 | _ -> assert false in
61 template#set "userid" (string_of_int userid);
62 template#set "name" name;
63 template#set "email" (match email with `Null -> "" | `String s -> s);
64 template#set "registration_date" (printable_date' registration_date);
65 template#conditional "can_edit" can_edit;
66 template#conditional "can_manage_users" can_manage_users;
67 template#conditional "can_manage_contacts" can_manage_contacts;
68 template#conditional "can_manage_site" can_manage_site;
69 template#conditional "can_edit_global_css" can_edit_global_css;
70 template#set "nr_edits" (string_of_int nr_edits);
71 template#set "nr_edits_live" (string_of_int nr_edits_live);
76 register_script ~restrict:[CanManageUsers] run