2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: host.ml,v 1.2 2004/09/07 13:40:10 rich Exp $
15 open Cocanwiki_template
17 let template = get_template "admin/host.html"
19 let run r (q : cgi) (dbh : Dbi.connection) _ _ =
20 let hostid = int_of_string (q#param "hostid") in
22 template#set "id" (string_of_int hostid);
24 (* Pull out some overall details for this host. *)
25 let sth = dbh#prepare_cached
26 "select h.canonical_hostname, h.css is not null,
27 (select count(*) from pages
28 where hostid = h.id and url is not null),
29 (select count(*) from pages
31 (select max(last_modified_date) from pages
32 where hostid = h.id and url is not null),
33 (select min(last_modified_date) from pages
34 where hostid = h.id and url is not null)
37 sth#execute [`Int hostid];
39 let canonical_hostname, has_css, page_count, total_count,
40 last_modified_date, creation_date =
41 match sth#fetch1 () with
42 [ `String canonical_hostname;
44 (`Null | `Int _) as page_count; (`Null | `Int _) as total_count;
45 (`Null | `Timestamp _) as last_modified_date;
46 (`Null | `Timestamp _) as creation_date ] ->
47 let page_count = match page_count with
50 let total_count = match total_count with
53 let last_modified_date = match last_modified_date with
55 | `Timestamp t -> printable_date t in
56 let creation_date = match creation_date with
58 | `Timestamp t -> printable_date t in
59 canonical_hostname, has_css, page_count, total_count,
60 last_modified_date, creation_date
61 | _ -> assert false in
63 template#set "canonical_hostname" canonical_hostname;
64 template#conditional "has_css" has_css;
65 template#set "page_count" (string_of_int page_count);
66 template#set "total_count" (string_of_int total_count);
67 template#set "last_modified_date" last_modified_date;
68 template#set "creation_date" creation_date;
70 (* Pull out any aliases. *)
71 let sth = dbh#prepare_cached "select name from hostnames
74 sth#execute [`Int hostid; `String canonical_hostname];
76 let table = sth#map (function [`String hostname] ->
77 [ "hostname", Template.VarString hostname ]
78 | _ -> assert false) in
79 template#table "hostnames" table;
81 (* Pull out any email notifications. *)
82 let sth = dbh#prepare_cached "select email, name from email_notify
84 sth#execute [`Int hostid];
86 let table = sth#map (function
87 [`String email; `Null] ->
88 [ "email", Template.VarString email;
89 "name", Template.VarString "" ]
90 | [ `String email; `String name] ->
91 [ "email", Template.VarString email;
92 "name", Template.VarString name ]
93 | _ -> assert false) in
94 template#table "emails" table;