2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: edit_page_css.ml,v 1.2 2004/09/07 13:40:10 rich Exp $
17 open Cocanwiki_emailnotify
19 let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ =
20 let page = q#param "page" in
21 let css = q#param "css" in
23 let css = if string_is_whitespace css then `Null else `String css in
25 (* Get the IP address of the user, if available. *)
27 try `String (Connection.remote_ip (Request.connection r))
28 with Not_found -> `Null in
30 (* Changing the CSS creates a new version of the page. This enables
31 * us to revert changes to the CSS easily.
33 let sth = dbh#prepare_cached "select id, title, description, creation_date,
36 where hostid = ? and url = ?" in
37 sth#execute [`Int hostid; `String page];
39 let oldpageid, title, description, creation_date, redirect =
40 match sth#fetch1 () with
41 [ `Int id; title; description; creation_date; redirect ] ->
42 id, title, description, creation_date, redirect
43 | _ -> assert false in
45 let sth = dbh#prepare_cached "set constraints pages_redirect_cn deferred" in
48 let sth = dbh#prepare_cached "update pages set url_deleted = url,
50 where hostid = ? and id = ?" in
51 sth#execute [`Int hostid; `Int oldpageid];
53 let sth = dbh#prepare_cached "insert into pages (hostid, url, title,
54 description, creation_date, logged_ip,
56 values (?, ?, ?, ?, ?, ?, ?, ?)" in
57 sth#execute [`Int hostid; `String page; title; description;
58 creation_date; logged_ip; redirect; css ];
60 let pageid = sth#serial "pages_id_seq" in
62 let sth = dbh#prepare_cached "insert into contents (pageid, ordering,
63 sectionname, content, divname)
64 select ? as pageid, ordering, sectionname,
68 sth#execute [`Int pageid; `Int oldpageid];
72 (* Email notification. *)
73 let subject = "CSS for page " ^ page ^ " has been modified" in
76 get_diff dbh hostid page ~version:pageid ~old_version:oldpageid () in
77 "Page: http://" ^ hostname ^ "/" ^ page ^ "\n\n" ^
80 email_notify ~subject ~body dbh hostid;
82 let buttons = [ ok_button ("/" ^ page);
83 { StdPages.label = "Edit stylesheet again";
84 StdPages.link = "/_bin/edit_page_css_form.cmo";
85 StdPages.method_ = None;
86 StdPages.params = [ "page", page ] } ] in
87 ok ~title:"Stylesheet changed" ~buttons
88 q ("The stylesheet was changed successfully. " ^
89 "Note: You must RELOAD the page to see changes to stylesheets.")