+csv dep for PG'OCaml.
[cocanwiki.git] / scripts / edit_host_css.ml
index 790486b..bfbe99f 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: edit_host_css.ml,v 1.5 2005/11/24 14:54:11 rich Exp $
+ * $Id: edit_host_css.ml,v 1.7 2006/12/06 09:46:57 rich Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -28,29 +28,53 @@ open Cocanwiki
 open Cocanwiki_ok
 open Cocanwiki_strings
 
-let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
-  let css = q#param "css" in
+type stylesheet = Global | Ie6_fixes | Ie7_fixes
+let string_of_stylesheet = function
+  | Global -> "global"
+  | Ie6_fixes -> "ie6_fixes"
+  | Ie7_fixes -> "ie7_fixes"
+let stylesheet_of_string = function
+  | "global" -> Global
+  | "ie6_fixes" -> Ie6_fixes
+  | "ie7_fixes" -> Ie7_fixes
+  | str -> failwith ("stylesheet_of_string: unknown stylesheet: " ^ str)
 
-  let css = if string_is_whitespace css then `Null else `String css in
+let run r (q : cgi) dbh hostid _ _ =
+  (* Which stylesheet to edit? *)
+  let css = if q#param_exists "css" then q#param "css" else "global" in
+  let css = stylesheet_of_string css in
+
+  (* Get the updated content. *)
+  let content = q#param "content" in
+  let content = if string_is_whitespace content then None else Some content in
 
   (* XXX We should version the global stylesheet.  However this requires
    * some fairly non-trivial coding.
    *)
-  let sth = dbh#prepare_cached "update hosts set css = ? where id = ?" in
-  sth#execute [css; `Int hostid];
+  (match css with
+   | Global ->
+       PGSQL(dbh)
+        "update hosts set css = $?content where id = $hostid"
+   | Ie6_fixes ->
+       PGSQL(dbh)
+        "update hosts set ie6_fixes_css = $?content where id = $hostid"
+   | Ie7_fixes ->
+       PGSQL(dbh)
+        "update hosts set ie7_fixes_css = $?content where id = $hostid"
+  );
 
-  dbh#commit ();
+  PGOCaml.commit dbh;
 
   let buttons = [
     ok_button "/_bin/host_menu.cmo";
     { Template.StdPages.label = "Edit stylesheet again";
       Template.StdPages.link = "/_bin/edit_host_css_form.cmo";
       Template.StdPages.method_ = None;
-      Template.StdPages.params = [] }
+      Template.StdPages.params = [ "css", string_of_stylesheet css ] }
   ] in
 
-  ok ~title:"Global stylesheet changed" ~buttons
-    dbh hostid q
+  ok ~title:"Stylesheet changed" ~buttons
+    dbh hostid q
     ("The stylesheet was changed successfully.  " ^
      "Note: You must RELOAD the page to see changes to stylesheets.")