4a25b6607695d41dade7b9a0d8dbe2c165451246
[cocanwiki.git] / scripts / admin / edit_host_css.ml
1 (* COCANWIKI scripts.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: edit_host_css.ml,v 1.2 2004/09/07 13:40:10 rich Exp $
5  *)
6
7 open Apache
8 open Registry
9 open Cgi
10 open Printf
11
12 open Merjisforwiki
13
14 open Cocanwiki
15 open Cocanwiki_ok
16
17 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
18   let hostid = int_of_string (q#param "hostid") in
19
20   let css = q#param "css" in
21
22   let css = if string_is_whitespace css then `Null else `String css in
23
24   (* XXX We should version the global stylesheet.  However this requires
25    * some fairly non-trivial coding.
26    *)
27   let sth = dbh#prepare_cached "update hosts set css = ? where id = ?" in
28   sth#execute [css; `Int hostid];
29
30   dbh#commit ();
31
32   let buttons = [
33     { StdPages.label = "OK";
34       StdPages.link = "/_bin/admin/host.cmo";
35       StdPages.method_ = None;
36       StdPages.params = [ "hostid", string_of_int hostid ] };
37     { StdPages.label = "Edit stylesheet again";
38       StdPages.link = "/_bin/admin/edit_host_css_form.cmo";
39       StdPages.method_ = None;
40       StdPages.params = [ "hostid", string_of_int hostid ] }
41   ] in
42
43   ok ~title:"Stylesheet changed" ~buttons
44     q ("The stylesheet was changed successfully.  " ^
45        "Note: You must RELOAD the page to see changes to stylesheets.")
46
47 let () =
48   register_script run