8c32335f4848e12674cf2c6007976f9add1d04e8
[cocanwiki.git] / scripts / admin / edit_emails_form.ml
1 (* COCANWIKI scripts.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: edit_emails_form.ml,v 1.1 2004/09/07 10:14:10 rich Exp $
5  *)
6
7 open Apache
8 open Registry
9 open Cgi
10 open Printf
11
12 open Cocanwiki
13
14 let template = get_template "admin/edit_emails_form.html"
15
16 let run r (q : cgi) (dbh : Dbi.connection) _ _ =
17   let hostid = int_of_string (q#param "hostid") in
18
19   template#set "id" (string_of_int hostid);
20
21   let sth = dbh#prepare_cached
22               "select canonical_hostname from hosts where id = ?" in
23   sth#execute [`Int hostid];
24
25   let canonical_hostname = sth#fetch1string () in
26   template#set "canonical_hostname" canonical_hostname;
27
28   let sth = dbh#prepare_cached
29               "select email, name from email_notify where hostid = ?" in
30   sth#execute [`Int hostid];
31
32   let emails = sth#map (function
33                             [`String email; `Null] ->
34                               email
35                           | [`String email; `String name] ->
36                               sprintf "%s <%s>" name email
37                           | _ -> assert false) in
38
39   template#set "emails" (String.concat "\n" emails);
40
41   q#template template
42
43 let () =
44   register_script run