Serial columns now 64 bits.
[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.7 2004/10/11 14:13:04 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               u.can_manage_site, u.can_edit_global_css, u.can_import_mail,
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];
46
47   let name, email, registration_date, can_edit, can_manage_users,
48       can_manage_contacts, can_manage_site, can_edit_global_css,
49       can_import_mail, 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          `Bool can_import_mail;
56          `Int nr_edits; `Int nr_edits_live] ->
57           name, email, registration_date, can_edit, can_manage_users,
58           can_manage_contacts, can_manage_site, can_edit_global_css,
59           can_import_mail, nr_edits, nr_edits_live
60       | _ -> assert false in
61
62   template#set "userid" (string_of_int userid);
63   template#set "name" name;
64   template#set "email" (match email with `Null -> "" | `String s -> s);
65   template#set "registration_date" (printable_date' registration_date);
66   template#conditional "can_edit" can_edit;
67   template#conditional "can_manage_users" can_manage_users;
68   template#conditional "can_manage_contacts" can_manage_contacts;
69   template#conditional "can_manage_site" can_manage_site;
70   template#conditional "can_edit_global_css" can_edit_global_css;
71   template#conditional "can_import_mail" can_import_mail;
72   template#set "nr_edits" (string_of_int nr_edits);
73   template#set "nr_edits_live" (string_of_int nr_edits_live);
74
75   q#template template
76
77 let () =
78   register_script ~restrict:[CanManageUsers] run