1 (* COCANWIKI - a wiki written in Objective CAML.
2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: host.ml,v 1.7 2004/10/21 19:54:29 rich Exp $
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
28 open Cocanwiki_template
31 let template = _get_template "admin/host.html"
33 let run r (q : cgi) (dbh : Dbi.connection) _ _ _ =
34 let hostid = int_of_string (q#param "hostid") in
36 template#set "id" (string_of_int hostid);
38 (* Pull out some overall details for this host. *)
39 let sth = dbh#prepare_cached
40 "select h.canonical_hostname, h.css is not null,
41 (select count(*) from pages
42 where hostid = h.id and url is not null),
43 (select count(*) from pages
45 (select max(last_modified_date) from pages
46 where hostid = h.id and url is not null),
47 (select min(last_modified_date) from pages
48 where hostid = h.id and url is not null)
51 sth#execute [`Int hostid];
53 let canonical_hostname, has_css, page_count, total_count,
54 last_modified_date, creation_date =
55 match sth#fetch1 () with
56 [ `String canonical_hostname;
58 (`Null | `Int _) as page_count; (`Null | `Int _) as total_count;
59 (`Null | `Timestamp _) as last_modified_date;
60 (`Null | `Timestamp _) as creation_date ] ->
61 let page_count = match page_count with
64 let total_count = match total_count with
67 let last_modified_date = match last_modified_date with
69 | `Timestamp t -> printable_date t in
70 let creation_date = match creation_date with
72 | `Timestamp t -> printable_date t in
73 canonical_hostname, has_css, page_count, total_count,
74 last_modified_date, creation_date
75 | _ -> assert false in
77 template#set "canonical_hostname" canonical_hostname;
78 template#conditional "has_css" has_css;
79 template#set "page_count" (string_of_int page_count);
80 template#set "total_count" (string_of_int total_count);
81 template#set "last_modified_date" last_modified_date;
82 template#set "creation_date" creation_date;
84 (* Pull out any aliases. *)
85 let sth = dbh#prepare_cached "select name from hostnames
88 sth#execute [`Int hostid; `String canonical_hostname];
90 let table = sth#map (function [`String hostname] ->
91 [ "hostname", Template.VarString hostname ]
92 | _ -> assert false) in
93 template#table "hostnames" table;