Change subject line so it shows the name of the site.
[cocanwiki.git] / scripts / create_contact.ml
index 17e70f8..0ec61db 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: create_contact.ml,v 1.5 2005/11/24 14:54:11 rich Exp $
+ * $Id: create_contact.ml,v 1.6 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
@@ -30,7 +30,7 @@ open Cocanwiki_strings
 
 let split_re = Pcre.regexp "[\\r\\n,;]+"
 
-let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
+let run r (q : cgi) dbh hostid _ _ =
   let name = trim (q#param "name") in
   let subject = trim (q#param "subject") in
   let emails = try q#param "emails" with Not_found -> "" in
@@ -61,27 +61,27 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
   );
 
   (* Update the database. *)
-  let sth = dbh#prepare_cached "insert into contacts (hostid, name, subject)
-                                values (?, ?, ?)" in
-  sth#execute [`Int hostid; `String name; `String subject];
+  PGSQL(dbh) "insert into contacts (hostid, name, subject)
+              values ($hostid, $name, $subject)";
 
-  let contactid = Int64.to_int (sth#serial "contacts_id_seq") in
+  let contactid = PGOCaml.serial4 dbh "contacts_id_seq" in
 
-  let sth = dbh#prepare_cached "insert into contact_emails (contactid, email)
-                                values (?, ?)" in
-  List.iter (fun email ->
-              sth#execute [`Int contactid; `String email]) emails;
+  List.iter (
+    fun email ->
+      PGSQL(dbh) "insert into contact_emails (contactid, email)
+                  values ($contactid, $email)"
+  ) emails;
 
   (* Finish off. *)
-  dbh#commit ();
+  PGOCaml.commit dbh;
 
-  let msg = sprintf "Contact form created.  The contact id is %d.  On the next page you will be given some same <html> code which you should copy and paste onto a web page to create a simple form, which can then be modified for your requirements." contactid in
+  let msg = sprintf "Contact form created.  The contact id is %ld.  On the next page you will be given some same <html> code which you should copy and paste onto a web page to create a simple form, which can then be modified for your requirements." contactid in
 
   let buttons = [ { Template.StdPages.label = "   View contact form   ";
                    Template.StdPages.link = "/_bin/contact_show.cmo";
                    Template.StdPages.method_ = None;
                    Template.StdPages.params =
-                     [ "id", string_of_int contactid ] } ] in
+                     [ "id", Int32.to_string contactid ] } ] in
   ok ~title:"Contact form created" ~buttons dbh hostid q msg
 
 let () =