(* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. * $Id: host.ml,v 1.10 2006/03/28 16:24:08 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 _ _ _ = let hostid = Int32.of_string (q#param "hostid") in template#set "id" (Int32.to_string hostid); (* Pull out some overall details for this host. *) let rows = PGSQL(dbh) "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 = $hostid" in let canonical_hostname, has_css, page_count, total_count, last_modified_date, creation_date = match rows with | [ canonical_hostname, Some has_css, page_count, total_count, last_modified_date, creation_date ] -> let page_count = match page_count with | None -> 0L | Some n -> n in let total_count = match total_count with | None -> 0L | Some n -> n in let last_modified_date = match last_modified_date with | None -> "" | Some t -> printable_date t in let creation_date = match creation_date with | None -> "" | Some 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" (Int64.to_string page_count); template#set "total_count" (Int64.to_string total_count); template#set "last_modified_date" last_modified_date; template#set "creation_date" creation_date; (* Pull out any aliases. *) let rows = PGSQL(dbh) "select name from hostnames where hostid = $hostid and name <> $canonical_hostname" in let table = List.map ( fun hostname -> [ "hostname", Template.VarString hostname ] ) rows in template#table "hostnames" table; q#template template let () = register_script run