All new templates. Site menu displays basically everywhere.
[cocanwiki.git] / scripts / edit_user_form.ml
1 (* COCANWIKI scripts.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: edit_user_form.ml,v 1.3 2004/09/09 09:35:33 rich Exp $
5  *)
6
7 open Apache
8 open Registry
9 open Cgi
10 open Printf
11
12 open Cocanwiki
13 open Cocanwiki_template
14 open Cocanwiki_date
15
16 let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
17   let template = get_template dbh hostid "edit_user_form.html" in
18
19   let userid = int_of_string (q#param "userid") in
20
21   let sth =
22     dbh#prepare_cached
23       "select u.name, u.email, u.registration_date,
24               u.can_edit, u.can_manage_users,
25               (select count(*) from pages where logged_user = u.id),
26               (select count(*) from pages
27                 where logged_user = u.id and url_deleted is null)
28          from users u where u.hostid = ? and u.id = ?" in
29   sth#execute [`Int hostid; `Int userid];
30
31   let name, email, registration_date, can_edit, can_manage_users, nr_edits,
32       nr_edits_live =
33     match sth#fetch1 () with
34         [`String name; (`Null | `String _) as email;
35          `Date registration_date;
36          `Bool can_edit; `Bool can_manage_users;
37          `Int nr_edits; `Int nr_edits_live] ->
38           name, email, registration_date, can_edit, can_manage_users,
39           nr_edits, nr_edits_live
40       | _ -> assert false in
41
42   template#set "userid" (string_of_int userid);
43   template#set "name" name;
44   template#set "email" (match email with `Null -> "" | `String s -> s);
45   template#set "registration_date" (printable_date' registration_date);
46   template#conditional "can_edit" can_edit;
47   template#conditional "can_manage_users" can_manage_users;
48   template#set "nr_edits" (string_of_int nr_edits);
49   template#set "nr_edits_live" (string_of_int nr_edits_live);
50
51   q#template template
52
53 let () =
54   register_script ~restrict:[CanManageUsers] run