Added the per-user 'manage contacts' permission.
[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.5 2004/09/17 15:24:54 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 : Dbi.connection) hostid _ _ =
32   let template = get_template dbh hostid "edit_user_form.html" in
33
34   let userid = int_of_string (q#param "userid") in
35
36   let sth =
37     dbh#prepare_cached
38       "select u.name, u.email, u.registration_date,
39               u.can_edit, u.can_manage_users, u.can_manage_contacts,
40               (select count(*) from pages where logged_user = u.id),
41               (select count(*) from pages
42                 where logged_user = u.id and url_deleted is null)
43          from users u where u.hostid = ? and u.id = ?" in
44   sth#execute [`Int hostid; `Int userid];
45
46   let name, email, registration_date, can_edit, can_manage_users,
47       can_manage_contacts, nr_edits, nr_edits_live =
48     match sth#fetch1 () with
49         [`String name; (`Null | `String _) as email;
50          `Date registration_date;
51          `Bool can_edit; `Bool can_manage_users; `Bool can_manage_contacts;
52          `Int nr_edits; `Int nr_edits_live] ->
53           name, email, registration_date, can_edit, can_manage_users,
54           can_manage_contacts, nr_edits, nr_edits_live
55       | _ -> assert false in
56
57   template#set "userid" (string_of_int userid);
58   template#set "name" name;
59   template#set "email" (match email with `Null -> "" | `String s -> s);
60   template#set "registration_date" (printable_date' registration_date);
61   template#conditional "can_edit" can_edit;
62   template#conditional "can_manage_users" can_manage_users;
63   template#conditional "can_manage_contacts" can_manage_contacts;
64   template#set "nr_edits" (string_of_int nr_edits);
65   template#set "nr_edits_live" (string_of_int nr_edits_live);
66
67   q#template template
68
69 let () =
70   register_script ~restrict:[CanManageUsers] run