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.5 2005/03/31 14:24:04 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 : Dbi.connection) 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);
42 (* Get the feedback email for this host. *)
44 dbh#prepare_cached "select feedback_email from hosts where id = ?" in
45 sth#execute [`Int hostid];
47 let to_addr = sth#fetch1string () in
50 let page = q#param "page" in
51 let name = q#param "name" in
52 let email = q#param "email" in
53 let feedback = q#param "feedback" in
55 template#set "page" page;
56 template#set "name" name;
57 template#set "email" email;
58 template#set "feedback" feedback;
60 (* Get the IP address for logging purposes. *)
62 try Connection.remote_ip (Request.connection r) with Not_found -> "" in
64 (* Get the User-Agent string. Consider in future rejecting spammers
65 * who don't set User-Agent.
68 try Table.get (Request.headers_in r) "User-Agent" with Not_found -> "" in
70 (* Get the user details, if any. *)
73 Anonymous -> "anonymous"
74 | User (userid, username, _, _) ->
75 sprintf "%s (%d)" username userid in
79 template#set "username" username;
80 template#set "hostname" hostname;
82 (* Send the feedback email. *)
83 let subject = "Wiki feedback: Feedback about " ^ page ^ " page" in
84 let body = template#to_string in
85 Sendmail.send_mail ~subject ~to_addr:[to_addr] body;
88 ok ~title:"Thank you for your feedback" ~buttons:[ok_button "/"]
89 q "An email has been sent to the site administrators."
92 register_script ~restrict:[CanView] run