All new templates. Site menu displays basically everywhere.
[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.4 2004/09/09 09:35:35 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
15 let template = _get_template "admin/edit_hostnames_form.html"
16
17 let run r (q : cgi) (dbh : Dbi.connection) _ _ _ =
18   let hostid = int_of_string (q#param "hostid") in
19
20   template#set "id" (string_of_int hostid);
21
22   let sth = dbh#prepare_cached
23               "select canonical_hostname from hosts where id = ?" in
24   sth#execute [`Int hostid];
25
26   let canonical_hostname = sth#fetch1string () in
27   template#set "canonical_hostname" canonical_hostname;
28
29   let sth = dbh#prepare_cached "select name from hostnames
30                                  where hostid = ?
31                                    and name <> ?" in
32   sth#execute [`Int hostid; `String canonical_hostname];
33
34   let hostnames = sth#map (function [`String hostname] -> hostname
35                              | _ -> assert false) in
36   template#set "hostnames" (String.concat "\n" hostnames);
37
38   q#template template
39
40 let () =
41   register_script run