(* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. * $Id: host.ml,v 1.2 2004/09/07 13:40:10 rich Exp $ *) open Apache open Registry open Cgi open Printf open Merjisforwiki open Cocanwiki open Cocanwiki_template let template = get_template "admin/host.html" let run r (q : cgi) (dbh : Dbi.connection) _ _ = let hostid = int_of_string (q#param "hostid") in template#set "id" (string_of_int hostid); (* Pull out some overall details for this host. *) let sth = dbh#prepare_cached "select h.canonical_hostname, h.css is not null, (select count(*) from pages where hostid = h.id and url is not null), (select count(*) from pages where hostid = h.id), (select max(last_modified_date) from pages where hostid = h.id and url is not null), (select min(last_modified_date) from pages where hostid = h.id and url is not null) from hosts h where h.id = ?" in sth#execute [`Int hostid]; let canonical_hostname, has_css, page_count, total_count, last_modified_date, creation_date = match sth#fetch1 () with [ `String canonical_hostname; `Bool has_css; (`Null | `Int _) as page_count; (`Null | `Int _) as total_count; (`Null | `Timestamp _) as last_modified_date; (`Null | `Timestamp _) as creation_date ] -> let page_count = match page_count with `Null -> 0 | `Int n -> n in let total_count = match total_count with `Null -> 0 | `Int n -> n in let last_modified_date = match last_modified_date with `Null -> "" | `Timestamp t -> printable_date t in let creation_date = match creation_date with `Null -> "" | `Timestamp t -> printable_date t in canonical_hostname, has_css, page_count, total_count, last_modified_date, creation_date | _ -> assert false in template#set "canonical_hostname" canonical_hostname; template#conditional "has_css" has_css; template#set "page_count" (string_of_int page_count); template#set "total_count" (string_of_int total_count); template#set "last_modified_date" last_modified_date; template#set "creation_date" creation_date; (* Pull out any aliases. *) let sth = dbh#prepare_cached "select name from hostnames where hostid = ? and name <> ?" in sth#execute [`Int hostid; `String canonical_hostname]; let table = sth#map (function [`String hostname] -> [ "hostname", Template.VarString hostname ] | _ -> assert false) in template#table "hostnames" table; (* Pull out any email notifications. *) let sth = dbh#prepare_cached "select email, name from email_notify where hostid = ?" in sth#execute [`Int hostid]; let table = sth#map (function [`String email; `Null] -> [ "email", Template.VarString email; "name", Template.VarString "" ] | [ `String email; `String name] -> [ "email", Template.VarString email; "name", Template.VarString name ] | _ -> assert false) in template#table "emails" table; q#template template let () = register_script run