From: rich Date: Tue, 21 Sep 2004 15:55:48 +0000 (+0000) Subject: Create and delete contact forms. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=8c4a3ed306ab6afd228050c31c65344fe0fc1f46;p=cocanwiki.git Create and delete contact forms. --- diff --git a/MANIFEST b/MANIFEST index 40ae0ba..c9f2e7a 100644 --- a/MANIFEST +++ b/MANIFEST @@ -65,9 +65,13 @@ scripts/contact.ml scripts/contact_show.ml scripts/contacts.ml scripts/create.ml +scripts/create_contact.ml +scripts/create_contact_form.ml scripts/create_form.ml scripts/create_user.ml scripts/create_user_form.ml +scripts/delete_contact.ml +scripts/delete_contact_form.ml scripts/delete_file.ml scripts/delete_file_form.ml scripts/delete_image.ml @@ -127,8 +131,10 @@ templates/admin/host.html templates/contact.txt templates/contact_show.html templates/contacts.html +templates/create_contact_form.html templates/create_form.html templates/create_user_form.html +templates/delete_contact_form.html templates/delete_file_form.html templates/delete_image_form.html templates/delete_user_form.html diff --git a/scripts/.depend b/scripts/.depend index a93277e..85606ed 100644 --- a/scripts/.depend +++ b/scripts/.depend @@ -26,6 +26,10 @@ create.cmo: cocanwiki.cmo cocanwiki_emailnotify.cmo cocanwiki_ok.cmo \ wikilib.cmi create.cmx: cocanwiki.cmx cocanwiki_emailnotify.cmx cocanwiki_ok.cmx \ wikilib.cmx +create_contact.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_strings.cmo +create_contact.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_strings.cmx +create_contact_form.cmo: cocanwiki.cmo cocanwiki_template.cmi +create_contact_form.cmx: cocanwiki.cmx cocanwiki_template.cmx create_form.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_template.cmi \ wikilib.cmi create_form.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_template.cmx \ @@ -34,6 +38,10 @@ create_user.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_strings.cmo create_user.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_strings.cmx create_user_form.cmo: cocanwiki.cmo cocanwiki_template.cmi create_user_form.cmx: cocanwiki.cmx cocanwiki_template.cmx +delete_contact.cmo: cocanwiki.cmo cocanwiki_ok.cmo +delete_contact.cmx: cocanwiki.cmx cocanwiki_ok.cmx +delete_contact_form.cmo: cocanwiki.cmo cocanwiki_template.cmi +delete_contact_form.cmx: cocanwiki.cmx cocanwiki_template.cmx delete_file.cmo: cocanwiki.cmo cocanwiki_emailnotify.cmo cocanwiki_ok.cmo delete_file.cmx: cocanwiki.cmx cocanwiki_emailnotify.cmx cocanwiki_ok.cmx delete_file_form.cmo: cocanwiki.cmo cocanwiki_template.cmi diff --git a/scripts/Makefile b/scripts/Makefile index de06781..041205e 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -1,5 +1,5 @@ # Makefile for COCANWIKI. -# $Id: Makefile,v 1.15 2004/09/21 13:01:15 rich Exp $ +# $Id: Makefile,v 1.16 2004/09/21 15:55:48 rich Exp $ include ../Makefile.config @@ -27,8 +27,12 @@ OBJS := 00-TEMPLATE.cmo \ contacts.cmo \ create.cmo \ create_form.cmo \ + create_contact.cmo \ + create_contact_form.cmo \ create_user.cmo \ create_user_form.cmo \ + delete_contact.cmo \ + delete_contact_form.cmo \ delete_file.cmo \ delete_file_form.cmo \ delete_image.cmo \ diff --git a/scripts/create_contact.ml b/scripts/create_contact.ml new file mode 100644 index 0000000..85cb4c1 --- /dev/null +++ b/scripts/create_contact.ml @@ -0,0 +1,85 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: create_contact.ml,v 1.1 2004/09/21 15:55:48 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 Registry +open Cgi +open Printf + +open Cocanwiki +open Cocanwiki_ok +open Cocanwiki_strings + +let split_re = Pcre.regexp "[\\r\\n,;]+" + +let run r (q : cgi) (dbh : Dbi.connection) 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 + + let emails = Pcre.split ~rex:split_re emails in + let emails = List.map trim emails in + let emails = List.filter ((<>) "") emails in + + if name = "" then ( + error ~back_button:true ~title:"Name field missing" + q "You must name your contact form."; + raise CgiExit + ); + + if subject = "" then ( + error ~back_button:true ~title:"Subject line missing" + q "You must give a subject line, which appears on contact emails."; + raise CgiExit + ); + + 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."); + raise CgiExit + ); + + (* Update the database. *) + let sth = dbh#prepare_cached "insert into contacts (hostid, name, subject) + values (?, ?, ?)" in + sth#execute [`Int hostid; `String name; `String subject]; + + let contactid = sth#serial "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; + + (* Finish off. *) + dbh#commit (); + + let msg = sprintf "Contact form created. The contact id is %d. On the next page you will be given some same 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 = [ { StdPages.label = " View contact form "; + StdPages.link = "/_bin/contact_show.cmo"; + StdPages.method_ = None; + StdPages.params = [ "id", string_of_int contactid ] } ] in + ok ~title:"Contact form created" ~buttons q msg + +let () = + register_script ~restrict:[CanManageContacts] run diff --git a/scripts/create_contact_form.ml b/scripts/create_contact_form.ml new file mode 100644 index 0000000..8462c70 --- /dev/null +++ b/scripts/create_contact_form.ml @@ -0,0 +1,36 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: create_contact_form.ml,v 1.1 2004/09/21 15:55:48 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 Registry +open Cgi +open Printf + +open Cocanwiki +open Cocanwiki_template + +let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = + let template = get_template dbh hostid "create_contact_form.html" in + + q#template template + +let () = + register_script ~restrict:[CanManageContacts] run diff --git a/scripts/delete_contact.ml b/scripts/delete_contact.ml new file mode 100644 index 0000000..8f89c14 --- /dev/null +++ b/scripts/delete_contact.ml @@ -0,0 +1,70 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: delete_contact.ml,v 1.1 2004/09/21 15:55:49 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 Registry +open Cgi +open Printf + +open Cocanwiki +open Cocanwiki_ok + +let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = + (* Cancel? *) + if q#param_true "cancel" then ( + q#redirect ("http://" ^ hostname ^ "/_bin/contacts.cmo"); + raise CgiExit + ); + + (* We can delete multiple contact forms from this script, which is + * quite unusual. + *) + let ids = List.map int_of_string (q#param_all "delete") in + if ids = [] then ( + q#redirect ("http://" ^ hostname ^ "/_bin/contacts.cmo"); + raise CgiExit + ); + + (* Need to check the contact emails all belong to this host. *) + let qs = Dbi.placeholders (List.length ids) in + let sth = dbh#prepare_cached ("select count(*) from contacts + where hostid = ? and id in " ^ qs) in + sth#execute (`Int hostid :: (List.map (fun id -> `Int id) ids)); + + assert (sth#fetch1int () = List.length ids); + + (* Delete them. *) + let sth = dbh#prepare_cached ("delete from contact_emails + where contactid in " ^ qs) in + sth#execute (List.map (fun id -> `Int id) ids); + + let sth = dbh#prepare_cached ("delete from contacts + where hostid = ? and id in " ^ qs) in + sth#execute (`Int hostid :: (List.map (fun id -> `Int id) ids)); + + (* Finish off. *) + dbh#commit (); + + ok ~title:"Contact form(s) deleted" ~buttons:[ok_button "/_bin/contacts.cmo"] + q "Those contact form(s) were deleted." + +let () = + register_script ~restrict:[CanManageContacts] run diff --git a/scripts/delete_contact_form.ml b/scripts/delete_contact_form.ml new file mode 100644 index 0000000..4692bb9 --- /dev/null +++ b/scripts/delete_contact_form.ml @@ -0,0 +1,64 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: delete_contact_form.ml,v 1.1 2004/09/21 15:55:49 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 Registry +open Cgi +open Printf + +open Cocanwiki +open Cocanwiki_template + +let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = + let template = get_template dbh hostid "delete_contact_form.html" in + + (* We can delete multiple contact forms from this script, which is + * quite unusual. + *) + let ids = List.map int_of_string (q#param_all "delete") in + if ids = [] then ( + q#redirect ("http://" ^ hostname ^ "/_bin/contacts.cmo"); + raise CgiExit + ); + + let qs = Dbi.placeholders (List.length ids) in + let sth = dbh#prepare_cached ("select id, name, subject from contacts + where hostid = ? and id in " ^ qs ^ " + order by name, id") in + sth#execute (`Int hostid :: (List.map (fun id -> `Int id) ids)); + + let table = + sth#map (function [`Int id; `String name; `String subject] -> + [ "id", Template.VarString (string_of_int id); + "name", Template.VarString name; + "subject", Template.VarString subject ] + | _ -> assert false) in + + template#table "deletes" table; + + let table = + List.map (fun id -> [ "id", Template.VarString (string_of_int id) ]) ids in + template#table "ids" table; + + q#template template + +let () = + register_script ~restrict:[CanManageContacts] run diff --git a/templates/create_contact_form.html b/templates/create_contact_form.html new file mode 100644 index 0000000..2758a35 --- /dev/null +++ b/templates/create_contact_form.html @@ -0,0 +1,62 @@ + + + +Create a contact form + + + + + +

Create a contact form

+ +
+ + + + + + + + + + + + + + + + + + + + +
Form name:
Subject line for emails:
Email addresses:
+
+ + + + + + + + + + \ No newline at end of file diff --git a/templates/delete_contact_form.html b/templates/delete_contact_form.html new file mode 100644 index 0000000..b8d295b --- /dev/null +++ b/templates/delete_contact_form.html @@ -0,0 +1,52 @@ + + + +Delete contact forms + + + + + +

Delete contact forms

+ +

+Are you sure you want to delete all the contact forms listed below? +

+ + + +::table(deletes)::::end:: +
Name Subject line
::name_html:: ::subject_html::
+ +
+::table(ids)::::end:: + + +
+ + + + + + + + + \ No newline at end of file