X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=scripts%2Fedit_contact.ml;h=fa496619ddffc8b2af8025b3c290401e9433afe2;hb=262f6a0c34949247ba6b78399b787e693da38d86;hp=18b4a5cd9e841e1390eef5c67d20b4b76e73d1ba;hpb=6b0b6830a2e784eee99dcd1b1a3cb8b44e27c765;p=cocanwiki.git diff --git a/scripts/edit_contact.ml b/scripts/edit_contact.ml index 18b4a5c..fa49661 100644 --- a/scripts/edit_contact.ml +++ b/scripts/edit_contact.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: edit_contact.ml,v 1.2 2004/09/23 11:56:47 rich Exp $ + * $Id: edit_contact.ml,v 1.5 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,8 +30,8 @@ open Cocanwiki_strings let split_re = Pcre.regexp "[\\r\\n,;]+" -let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = - let id = int_of_string (q#param "id") in +let run r (q : cgi) dbh hostid _ _ = + let id = Int32.of_string (q#param "id") in let name = trim (q#param "name") in let subject = trim (q#param "subject") in @@ -44,55 +44,52 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = if name = "" then ( error ~back_button:true ~title:"Name field missing" - q "You must name your contact form."; + dbh hostid q "You must name your contact form."; return () ); if subject = "" then ( error ~back_button:true ~title:"Subject line missing" - q "You must give a subject line, which appears on contact emails."; + dbh hostid q + "You must give a subject line, which appears on contact emails."; return () ); if emails = [] then ( error ~back_button:true ~title:"No email addresses" - q ("There are no email addresses listed for this contact form. You " ^ - "must list at least one valid email address."); + dbh hostid q + ("There are no email addresses listed for this contact form. You " ^ + "must list at least one valid email address."); return () ); (* Need to verify that the contact belongs to the host. *) - let sth = dbh#prepare_cached "select 1 from contacts - where hostid = ? and id = ?" in - sth#execute [`Int hostid; `Int id]; - - assert (sth#fetch1int () = 1); + let rows = PGSQL(dbh) "select 1 from contacts + where hostid = $hostid and id = $id" in + assert (rows = [ Some 1l ]); (* Update the database. *) - let sth = dbh#prepare_cached "update contacts set name = ?, subject = ? - where hostid = ? and id = ?" in - sth#execute [`String name; `String subject; `Int hostid; `Int id]; - - let sth = - dbh#prepare_cached "delete from contact_emails where contactid = ?" in - sth#execute [`Int id]; + PGSQL(dbh) "update contacts set name = $name, subject = $subject + where hostid = $hostid and id = $id"; + PGSQL(dbh) "delete from contact_emails where contactid = $id"; - let sth = dbh#prepare_cached "insert into contact_emails (contactid, email) - values (?, ?)" in - List.iter (fun email -> - sth#execute [`Int id; `String email]) emails; + List.iter ( + fun email -> + PGSQL(dbh) "insert into contact_emails (contactid, email) + values ($id, $email)" + ) emails; (* Finish off. *) - dbh#commit (); + PGOCaml.commit dbh; let buttons = [ ok_button "/_bin/contacts.cmo"; - { StdPages.label = " View contact form "; - StdPages.link = "/_bin/contact_show.cmo"; - StdPages.method_ = None; - StdPages.params = [ "id", string_of_int id ] } ] in + { Template.StdPages.label = " View contact form "; + Template.StdPages.link = "/_bin/contact_show.cmo"; + Template.StdPages.method_ = None; + Template.StdPages.params = [ "id", Int32.to_string id ] } ] in ok ~title:"Contact form edited" ~buttons - q "The contact form was edited." + dbh hostid q "The contact form was edited." let () = register_script ~restrict:[CanManageContacts] run