2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: host.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
13 open Cocanwiki_template
16 let template = get_template "admin/host.html"
18 let run r (q : cgi) (dbh : Dbi.connection) _ _ =
19 let hostid = int_of_string (q#param "hostid") in
21 template#set "id" (string_of_int hostid);
23 (* Pull out some overall details for this host. *)
24 let sth = dbh#prepare_cached
25 "select h.canonical_hostname, h.css is not null,
26 (select count(*) from pages
27 where hostid = h.id and url is not null),
28 (select count(*) from pages
30 (select max(last_modified_date) from pages
31 where hostid = h.id and url is not null),
32 (select min(last_modified_date) from pages
33 where hostid = h.id and url is not null)
36 sth#execute [`Int hostid];
38 let canonical_hostname, has_css, page_count, total_count,
39 last_modified_date, creation_date =
40 match sth#fetch1 () with
41 [ `String canonical_hostname;
43 (`Null | `Int _) as page_count; (`Null | `Int _) as total_count;
44 (`Null | `Timestamp _) as last_modified_date;
45 (`Null | `Timestamp _) as creation_date ] ->
46 let page_count = match page_count with
49 let total_count = match total_count with
52 let last_modified_date = match last_modified_date with
54 | `Timestamp t -> printable_date t in
55 let creation_date = match creation_date with
57 | `Timestamp t -> printable_date t in
58 canonical_hostname, has_css, page_count, total_count,
59 last_modified_date, creation_date
60 | _ -> assert false in
62 template#set "canonical_hostname" canonical_hostname;
63 template#conditional "has_css" has_css;
64 template#set "page_count" (string_of_int page_count);
65 template#set "total_count" (string_of_int total_count);
66 template#set "last_modified_date" last_modified_date;
67 template#set "creation_date" creation_date;
69 (* Pull out any aliases. *)
70 let sth = dbh#prepare_cached "select name from hostnames
73 sth#execute [`Int hostid; `String canonical_hostname];
75 let table = sth#map (function [`String hostname] ->
76 [ "hostname", Template.VarString hostname ]
77 | _ -> assert false) in
78 template#table "hostnames" table;
80 (* Pull out any email notifications. *)
81 let sth = dbh#prepare_cached "select email, name from email_notify
83 sth#execute [`Int hostid];
85 let table = sth#map (function
86 [`String email; `Null] ->
87 [ "email", Template.VarString email;
88 "name", Template.VarString "" ]
89 | [ `String email; `String name] ->
90 [ "email", Template.VarString email;
91 "name", Template.VarString name ]
92 | _ -> assert false) in
93 template#table "emails" table;