-(* COCANWIKI scripts.
+(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: host.ml,v 1.2 2004/09/07 13:40:10 rich Exp $
+ * $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 Cgi
open Printf
-open Merjisforwiki
-
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
+let template = _get_template "admin/host.html"
- template#set "id" (string_of_int hostid);
+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 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 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 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
+ 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" (string_of_int page_count);
- template#set "total_count" (string_of_int total_count);
+ 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 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
+ 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;
- (* 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 () =