Feedback form. You need to set the hosts.feedback_email field
authorrich <rich>
Mon, 20 Sep 2004 17:18:25 +0000 (17:18 +0000)
committerrich <rich>
Mon, 20 Sep 2004 17:18:25 +0000 (17:18 +0000)
in the database to activate it for a particular site.

MANIFEST
scripts/.depend
scripts/Makefile
scripts/page.ml
scripts/send_feedback.ml [new file with mode: 0644]
scripts/send_feedback_form.ml [new file with mode: 0644]
templates/page.html
templates/send_feedback.txt [new file with mode: 0644]
templates/send_feedback_form.html [new file with mode: 0644]

index 0ec51e2..f0371c8 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -96,6 +96,8 @@ scripts/restore.ml
 scripts/restore_form.ml
 scripts/rss.ml
 scripts/search.ml
+scripts/send_feedback.ml
+scripts/send_feedback_form.ml
 scripts/signup.ml
 scripts/sitemap.ml
 scripts/undelete_file.ml
@@ -139,6 +141,8 @@ templates/page_404.html
 templates/recent.html
 templates/restore_form.html
 templates/rss.xml
+templates/send_feedback.txt
+templates/send_feedback_form.html
 templates/sitemap.html
 templates/undelete_file_form.html
 templates/undelete_image_form.html
index cf4a8c2..b29a791 100644 (file)
@@ -2,8 +2,8 @@
 00-TEMPLATE.cmx: cocanwiki.cmx cocanwiki_template.cmx 
 cgi_expires.cmo: cocanwiki_date.cmo 
 cgi_expires.cmx: cocanwiki_date.cmx 
-cocanwiki.cmo: cocanwiki_ok.cmo 
-cocanwiki.cmx: cocanwiki_ok.cmx 
+cocanwiki.cmo: cocanwiki_ok.cmo cocanwiki_strings.cmo 
+cocanwiki.cmx: cocanwiki_ok.cmx cocanwiki_strings.cmx 
 cocanwiki_diff.cmo: cocanwiki_files.cmo 
 cocanwiki_diff.cmx: cocanwiki_files.cmx 
 cocanwiki_images.cmo: cocanwiki_files.cmo cocanwiki_strings.cmo \
@@ -81,9 +81,9 @@ login_form.cmx: cocanwiki.cmx cocanwiki_strings.cmx cocanwiki_template.cmx
 logout.cmo: cocanwiki.cmo cocanwiki_ok.cmo 
 logout.cmx: cocanwiki.cmx cocanwiki_ok.cmx 
 page.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_ok.cmo \
-    cocanwiki_strings.cmo cocanwiki_template.cmi wikilib.cmi 
+    cocanwiki_template.cmi wikilib.cmi 
 page.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_ok.cmx \
-    cocanwiki_strings.cmx cocanwiki_template.cmx wikilib.cmx 
+    cocanwiki_template.cmx wikilib.cmx 
 pagestyle.cmo: cgi_expires.cmo cocanwiki.cmo 
 pagestyle.cmx: cgi_expires.cmx cocanwiki.cmx 
 preview.cmo: cocanwiki.cmo wikilib.cmi 
@@ -102,6 +102,10 @@ rss.cmo: cocanwiki.cmo cocanwiki_template.cmi wikilib.cmi
 rss.cmx: cocanwiki.cmx cocanwiki_template.cmx wikilib.cmx 
 search.cmo: cocanwiki.cmo 
 search.cmx: cocanwiki.cmx 
+send_feedback.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_template.cmi 
+send_feedback.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_template.cmx 
+send_feedback_form.cmo: cocanwiki.cmo cocanwiki_template.cmi 
+send_feedback_form.cmx: cocanwiki.cmx cocanwiki_template.cmx 
 signup.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_strings.cmo 
 signup.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_strings.cmx 
 sitemap.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_strings.cmo \
index 6cf7991..a5ca44a 100644 (file)
@@ -1,5 +1,5 @@
 # Makefile for COCANWIKI.
-# $Id: Makefile,v 1.13 2004/09/20 15:34:36 rich Exp $
+# $Id: Makefile,v 1.14 2004/09/20 17:18:26 rich Exp $
 
 include ../Makefile.config
 
@@ -57,6 +57,8 @@ OBJS := 00-TEMPLATE.cmo \
        restore_form.cmo \
        rss.cmo \
        search.cmo \
+       send_feedback.cmo \
+       send_feedback_form.cmo \
        signup.cmo \
        sitemap.cmo \
        undelete_file.cmo \
index 9378107..3ff3e01 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: page.ml,v 1.15 2004/09/20 15:34:36 rich Exp $
+ * $Id: page.ml,v 1.16 2004/09/20 17:18:26 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
@@ -45,13 +45,15 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {edit_anon=edit_anon} user =
   let page = q#param "page" in
   let page = if page = "" then "index" else page in
 
-  (* Host-specific CSS? *)
-  let sth = dbh#prepare_cached "select css is not null from hosts
-                                 where id = ?" in
+  (* Host-specific fields. *)
+  let sth = dbh#prepare_cached "select css is not null,
+                                       feedback_email is not null
+                                  from hosts where id = ?" in
   sth#execute [`Int hostid];
-  let has_host_css =
+  let has_host_css, has_feedback_email =
     match sth#fetch1 () with
-      | [ `Bool has_host_css ] -> has_host_css
+      | [ `Bool has_host_css; `Bool has_feedback_email ] ->
+         has_host_css, has_feedback_email
       | _ -> assert false in
 
   (* Can the user edit?  Manage users?  etc. *)
@@ -80,6 +82,8 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {edit_anon=edit_anon} user =
     t#conditional "has_host_css" has_host_css;
     t#conditional "has_page_css" has_page_css;
 
+    t#conditional "has_feedback_email" has_feedback_email;
+
     t#conditional "can_edit" can_edit;
     t#conditional "can_manage_users" can_manage_users;
     t#conditional "can_manage_contacts" can_manage_contacts;
diff --git a/scripts/send_feedback.ml b/scripts/send_feedback.ml
new file mode 100644 (file)
index 0000000..3dc1a1e
--- /dev/null
@@ -0,0 +1,92 @@
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: send_feedback.ml,v 1.1 2004/09/20 17:18:26 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 ExtString
+
+open Cocanwiki
+open Cocanwiki_template
+open Cocanwiki_ok
+
+let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user =
+  let template = get_template dbh hostid "send_feedback.txt" in
+
+  if q#param_true "cancel" then (
+    (* Request cancelled. *)
+    q#redirect ("http://" ^ hostname);
+    raise CgiExit
+  );
+
+  (* Get the feedback email for this host. *)
+  let sth =
+    dbh#prepare_cached "select feedback_email from hosts where id = ?" in
+  sth#execute [`Int hostid];
+
+  let to_addr = sth#fetch1string () in
+
+  (* Get the fields. *)
+  let page = q#param "page" in
+  let name = q#param "name" in
+  let email = q#param "email" in
+  let feedback = q#param "feedback" in
+
+  template#set "page" page;
+  template#set "name" name;
+  template#set "email" email;
+  template#set "feedback" feedback;
+
+  (* Get the IP address for logging purposes. *)
+  let ip =
+    try Connection.remote_ip (Request.connection r) with Not_found -> "" in
+
+  (* Get the User-Agent string.  Consider in future rejecting spammers
+   * who don't set User-Agent.
+   *)
+  let ua =
+    try Table.get (Request.headers_in r) "User-Agent" with Not_found -> "" in
+
+  (* Get the user details, if any. *)
+  let username =
+    match user with
+       Anonymous -> "anonymous"
+      | User (userid, username, _) ->
+         sprintf "%s (%d)" username userid in
+
+  template#set "ip" ip;
+  template#set "ua" ua;
+  template#set "username" username;
+  template#set "hostname" hostname;
+
+  (* Send the feedback email. *)
+  let subject = "Wiki feedback: Feedback about " ^ page ^ " page" in
+  let body = template#to_string in
+  Sendmail.send_mail ~subject ~to_addr:[to_addr] ~body ();
+
+  (* Confirm. *)
+  ok ~title:"Thank you for your feedback" ~buttons:[ok_button "/"]
+    q "An email has been sent to the site administrators."
+
+let () =
+  register_script run
diff --git a/scripts/send_feedback_form.ml b/scripts/send_feedback_form.ml
new file mode 100644 (file)
index 0000000..7fef87e
--- /dev/null
@@ -0,0 +1,40 @@
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: send_feedback_form.ml,v 1.1 2004/09/20 17:18:26 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 "send_feedback_form.html" in
+
+  let page = q#param "page" in
+
+  template#set "page" page;
+
+  q#template template
+
+let () =
+  register_script ~restrict:[CanManageUsers] run
index 1a5fb71..6d7e0ec 100644 (file)
@@ -84,6 +84,9 @@
 <ul id="footer" class="menu">
 <li class="first"> Last change: ::last_modified_date_html:: </li>
 <li> <a href="/copyright">Copyright &copy; ::year::</a> </li>
+::if(has_feedback_email)::
+<li> <a href="/_bin/send_feedback_form.cmo?page=::page_url::">Send feedback</a> </li>
+::end::
 <li> Powered by <a href="http://sandbox.merjis.com/">::cocanwiki_package_html:: ::cocanwiki_version_html::</a> </li>
 </ul>
 </div>
diff --git a/templates/send_feedback.txt b/templates/send_feedback.txt
new file mode 100644 (file)
index 0000000..ab59d85
--- /dev/null
@@ -0,0 +1,20 @@
+This is an automatically generated message from the feedback form at
+::hostname::.  Someone has filled out this form and sent it to you
+below.
+
+----------------------------------------------------------------------
+Feedback about page http://::hostname::/::page:::
+
+Name:   ::name::
+Email:  ::email::
+
+Feedback:
+
+::feedback::
+----------------------------------------------------------------------
+
+LOGGING INFORMATION:
+
+IP address: ::ip::
+Username:   ::username::
+User-Agent: ::ua::
diff --git a/templates/send_feedback_form.html b/templates/send_feedback_form.html
new file mode 100644 (file)
index 0000000..8e8989a
--- /dev/null
@@ -0,0 +1,72 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>Send feedback about this page</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>Send feedback about this page</h1>
+
+<form method="post" action="/_bin/send_feedback.cmo">
+<input type="hidden" name="page" value="::page_html_tag::"/>
+<table class="left_table">
+<tr>
+<th> Name: </th>
+<td> <input name="name" value="" size="50" /> </td>
+</tr>
+<tr>
+<th> Email: </th>
+<td> <input name="email" value="" size="50" /> </td>
+</tr>
+<tr>
+<th> Feedback: </th>
+<td> <textarea name="feedback" rows="8" cols="60"></textarea> </td>
+</tr>
+<tr>
+<td> </td>
+<td> <em>All fields are optional, but please give us your
+email address if you'd like us to get back to you.</em> </td>
+</tr>
+<tr>
+<td></td>
+<td> <input type="submit" name="submit" value="   Send feedback   " />
+<input type="submit" name="cancel" value="   Cancel   " /> </td>
+</tr>
+</table>
+</form>
+
+<h2>Contents of the page</h2>
+
+<iframe longdesc="Frame showing the original contents of the page about which you are sending feedback." width="100%" height="500" src="/::page_html_tag::"></iframe>
+<noframes>
+<a href="/::page_html_tag::" target="_blank">Go here to see the page on which you are sending feedback.</a>
+</noframes>
+
+<ul id="topmenu" class="menu">
+<li class="first"> <a href="/">Home&nbsp;page</a> </li>
+<li> <a href="/_sitemap">Sitemap</a> </li>
+<li> <a href="/_recent">Recent&nbsp;changes</a> </li>
+</ul>
+
+<div id="menu_div">
+<ul id="bottommenu" class="menu">
+<li class="first"> <a href="/">Home&nbsp;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 &copy; ::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