Added styling to some pages which previously were "outside" the site
[cocanwiki.git] / scripts / contacts.ml
index 22adc38..5a0762c 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: contacts.ml,v 1.1 2004/09/17 16:03:34 rich Exp $
+ * $Id: contacts.ml,v 1.3 2006/03/27 18:09:46 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
@@ -27,28 +27,26 @@ open Printf
 open Cocanwiki
 open Cocanwiki_template
 
-let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
+let run r (q : cgi) dbh hostid _ _ =
   let template = get_template dbh hostid "contacts.html" in
 
   (* Pull out all the contacts from the database. *)
-  let sth = dbh#prepare_cached
-             "select c.id, c.name, c.subject,
-                      (select count(*) from contact_emails
-                        where contactid = c.id)
-                 from contacts c
-                where c.hostid = ?
-                order by c.name, c.id" in
-  sth#execute [`Int hostid];
+  let rows = PGSQL(dbh)
+    "select c.id, c.name, c.subject,
+            (select count(*)::int4 from contact_emails
+              where contactid = c.id)
+       from contacts c
+      where c.hostid = $hostid
+      order by c.name, c.id" in
 
   let table =
-    sth#map
-      (function
-          [`Int id; `String name; `String subject; `Int count] ->
-            [ "id", Template.VarString (string_of_int id);
-              "name", Template.VarString name;
-              "subject", Template.VarString subject;
-              "count", Template.VarString (string_of_int count) ]
-        | _ -> assert false) in
+    List.map
+      (fun (id, name, subject, count) ->
+        [ "id", Template.VarString (Int32.to_string id);
+          "name", Template.VarString name;
+          "subject", Template.VarString subject;
+          "count", Template.VarString (Int32.to_string (Option.get count)) ]
+      ) rows in
 
   template#table "contacts" table;