scripts/delete_user_form.ml
scripts/diff.ml
scripts/edit.ml
+scripts/edit_contact.ml
+scripts/edit_contact_form.ml
scripts/edit_page_css.ml
scripts/edit_page_css_form.ml
scripts/edit_sitemenu.ml
templates/diff.html
templates/edit.html
templates/edit_conflict.html
+templates/edit_contact_form.html
templates/edit_page_css_form.html
templates/edit_sitemenu.html
templates/edit_user_form.html
cocanwiki_ok.cmo cocanwiki_strings.cmo cocanwiki_template.cmi
edit.cmx: cocanwiki.cmx cocanwiki_diff.cmx cocanwiki_emailnotify.cmx \
cocanwiki_ok.cmx cocanwiki_strings.cmx cocanwiki_template.cmx
+edit_contact.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_template.cmi
+edit_contact.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_template.cmx
+edit_contact_form.cmo: cocanwiki.cmo cocanwiki_template.cmi
+edit_contact_form.cmx: cocanwiki.cmx cocanwiki_template.cmx
edit_page_css.cmo: cocanwiki.cmo cocanwiki_diff.cmo cocanwiki_emailnotify.cmo \
cocanwiki_ok.cmo cocanwiki_strings.cmo
edit_page_css.cmx: cocanwiki.cmx cocanwiki_diff.cmx cocanwiki_emailnotify.cmx \
# Makefile for COCANWIKI.
-# $Id: Makefile,v 1.17 2004/09/21 17:07:58 rich Exp $
+# $Id: Makefile,v 1.18 2004/09/21 18:24:15 rich Exp $
include ../Makefile.config
delete_user_form.cmo \
diff.cmo \
edit.cmo \
+ edit_contact.cmo \
+ edit_contact_form.cmo \
edit_page_css.cmo \
edit_page_css_form.cmo \
edit_sitemenu.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: edit_contact.ml,v 1.1 2004/09/21 18:24:15 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 id = int_of_string (q#param "id") in
+
+ 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
+ );
+
+ (* 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);
+
+ (* 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];
+
+ let sth = dbh#prepare_cached "insert into contact_emails (contactid, email)
+ values (?, ?)" in
+ List.iter (fun email ->
+ sth#execute [`Int id; `String email]) emails;
+
+ (* Finish off. *)
+ dbh#commit ();
+
+ 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
+ ok ~title:"Contact form edited" ~buttons
+ q "The contact form was edited."
+
+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: edit_contact_form.ml,v 1.1 2004/09/21 18:24:15 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 "edit_contact_form.html" in
+
+ let id = int_of_string (q#param "id") in
+ template#set "id" (string_of_int id);
+
+ (* Get details from the database. *)
+ let sth = dbh#prepare_cached "select name, subject from contacts
+ where hostid = ? and id = ?" in
+ sth#execute [`Int hostid; `Int id];
+
+ let name, subject =
+ match sth#fetch1 () with
+ [ `String name; `String subject ] -> name, subject
+ | _ -> assert false in
+
+ template#set "name" name;
+ template#set "subject" subject;
+
+ let sth = dbh#prepare_cached "select email from contact_emails
+ where contactid = ? order by 1" in
+ sth#execute [`Int id];
+
+ let table = sth#map (function [`String email] ->
+ [ "email", Template.VarString email ]
+ | _ -> assert false) in
+ template#table "emails" 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>Edit contact: ::name_html::</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>Edit contact: ::name_html::</h1>
+
+<form method="post" action="/_bin/edit_contact.cmo">
+<input type="hidden" name="id" value="::id::"/>
+<table class="left_table">
+<tr>
+<th> Form name: </th>
+<td> <input name="name" value="::name_html_tag::" size="32" /> </td>
+</tr>
+
+<tr>
+<th> Subject line for emails: </th>
+<td> <input name="subject" value="::subject_html_tag::" size="50" /> </td>
+</tr>
+
+<tr>
+<th> Email addresses: </th>
+<td>
+<textarea name="emails" cols="50" rows="10">::table(emails)::
+::email_html_textarea::::end::</textarea> </td>
+</tr>
+
+<tr>
+<td></td>
+<td> <input type="submit" value=" Edit 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