(* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. * $Id: host.ml,v 1.6 2004/09/09 12:21:22 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. *) open Apache open Registry open Cgi open Printf open Cocanwiki open Cocanwiki_template open Cocanwiki_date 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