Moved to merjis/tools/wiki.
[cocanwiki.git] / scripts / admin / edit_hostnames_form.ml
1 (* COCANWIKI scripts.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: edit_hostnames_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_hostnames_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 "select name from hostnames
29                                  where hostid = ?
30                                    and name <> ?" in
31   sth#execute [`Int hostid; `String canonical_hostname];
32
33   let hostnames = sth#map (function [`String hostname] -> hostname
34                              | _ -> assert false) in
35   template#set "hostnames" (String.concat "\n" hostnames);
36
37   q#template template
38
39 let () =
40   register_script run