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