1 (* COCANWIKI - a wiki written in Objective CAML.
2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: send_feedback.ml,v 1.10 2006/07/31 09:49:43 rich Exp $
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
30 open Cocanwiki_template
33 let run r (q : cgi) dbh hostid {hostname = hostname} user =
34 let template = get_template dbh hostid "send_feedback.txt" in
36 if q#param_true "cancel" then
37 (* Request cancelled. *)
38 q#redirect ("http://" ^ hostname);
40 (* Get the feedback email for this host. *)
41 let to_addr = List.hd (
43 "select feedback_email from hosts where id = $hostid"
45 let to_addr = Option.get to_addr in
48 let page = q#param "page" in
49 let name = q#param "name" in
50 let email = q#param "email" in
51 let feedback = q#param "feedback" in
53 template#set "page" page;
54 template#set "name" name;
55 template#set "email" email;
56 template#set "feedback" feedback;
58 (* Get the IP address for logging purposes. *)
60 try Connection.remote_ip (Request.connection r) with Not_found -> "" in
62 (* Get the User-Agent string. Consider in future rejecting spammers
63 * who don't set User-Agent.
66 try Table.get (Request.headers_in r) "User-Agent" with Not_found -> "" in
68 (* Get the user details, if any. *)
71 Anonymous -> "anonymous"
72 | User (userid, username, _, _) ->
73 sprintf "%s (%ld)" username userid in
77 template#set "username" username;
78 template#set "hostname" hostname;
80 (* Send the feedback email. *)
81 let subject = "Wiki feedback: Feedback about " ^ page ^ " page" in
82 let body = template#to_string in
84 let to_addrs = [ "", to_addr ] in
86 "text/plain", ["charset", Mimestring.mk_param "UTF-8"] in
88 let msg = Netsendmail.compose ~subject ~to_addrs ~content_type body in
89 Netsendmail.sendmail msg;
92 ok ~title:"Thank you for your feedback" ~buttons:[ok_button "/"]
93 dbh hostid q "An email has been sent to the site administrators."
96 register_script ~restrict:[CanView] run