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
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
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 \
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
# 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
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 \
--- /dev/null
+(* 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.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 <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 = [ { 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
--- /dev/null
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * 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
--- /dev/null
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * 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
--- /dev/null
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * 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
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>Create a contact form</title>
+<meta name="robots" content="noindex,nofollow"/>
+<meta name="author" content="http://www.merjis.com/" />
+<link rel="stylesheet" href="::theme_css_html_tag::" type="text/css" title="Standard"/>
+</head><body>
+
+<h1>Create a contact form</h1>
+
+<form method="post" action="/_bin/create_contact.cmo">
+<table class="left_table">
+<tr>
+<th> Form name: </th>
+<td> <input name="name" value="" size="32" /> </td>
+</tr>
+
+<tr>
+<th> Subject line for emails: </th>
+<td> <input name="subject" value="" size="50" /> </td>
+</tr>
+
+<tr>
+<th> Email addresses: </th>
+<td> <textarea name="emails" cols="50" rows="10"></textarea> </td>
+</tr>
+
+<tr>
+<td></td>
+<td> <input type="submit" value=" Create contact form "/> </td>
+</tr>
+</table>
+</form>
+
+
+<ul id="topmenu" class="menu">
+<li class="first"> <a href="/">Home page</a> </li>
+<li> <a href="/_sitemap">Sitemap</a> </li>
+<li> <a href="/_recent">Recent changes</a> </li>
+</ul>
+
+<div id="menu_div">
+<ul id="bottommenu" class="menu">
+<li class="first"> <a href="/">Home page</a> </li>
+::table(sitemenu)::<li> <a href="/::url_html_tag::">::label_html::</a> </li>
+::end::
+<li> <a href="/_sitemap">Sitemap</a> </li>
+</ul>
+</div>
+
+<div id="footer_div">
+<hr/>
+
+<ul id="footer" class="menu">
+<li class="first"> <a href="/copyright">Copyright © ::year::</a> </li>
+<li> Powered by <a href="http://sandbox.merjis.com/">::cocanwiki_package_html:: ::cocanwiki_version_html::</a> </li>
+</ul>
+</div>
+
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>Delete contact forms</title>
+<meta name="robots" content="noindex,nofollow"/>
+<meta name="author" content="http://www.merjis.com/" />
+<link rel="stylesheet" href="::theme_css_html_tag::" type="text/css" title="Standard"/>
+</head><body>
+
+<h1>Delete contact forms</h1>
+
+<p>
+Are you sure you want to delete all the contact forms listed below?
+</p>
+
+<table class="top_table">
+<tr><th> Name </th> <th> Subject line </th></tr>
+::table(deletes)::<tr><td> ::name_html:: </td> <td> ::subject_html:: </td></tr>::end::
+</table>
+
+<form method="post" action="/_bin/delete_contact.cmo">
+::table(ids)::<input type="hidden" name="delete" value="::id::"/>::end::
+<input type="submit" name="doit" value=" Delete all "/>
+<input type="submit" name="cancel" value=" Cancel "/>
+</form>
+
+<ul id="topmenu" class="menu">
+<li class="first"> <a href="/">Home page</a> </li>
+<li> <a href="/_sitemap">Sitemap</a> </li>
+<li> <a href="/_recent">Recent changes</a> </li>
+</ul>
+
+<div id="menu_div">
+<ul id="bottommenu" class="menu">
+<li class="first"> <a href="/">Home page</a> </li>
+::table(sitemenu)::<li> <a href="/::url_html_tag::">::label_html::</a> </li>
+::end::
+<li> <a href="/_sitemap">Sitemap</a> </li>
+</ul>
+</div>
+
+<div id="footer_div">
+<hr/>
+
+<ul id="footer" class="menu">
+<li class="first"> <a href="/copyright">Copyright © ::year::</a> </li>
+<li> Powered by <a href="http://sandbox.merjis.com/">::cocanwiki_package_html:: ::cocanwiki_version_html::</a> </li>
+</ul>
+</div>
+
+</body>
+</html>
\ No newline at end of file