(* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. * $Id: edit_host_css_form.ml,v 1.5 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. *) open Apache open Registry open Cgi open Printf open Cocanwiki open Cocanwiki_template 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 run r (q : cgi) dbh hostid _ _ = let template = get_template r dbh hostid "edit_host_css_form.html" in (* 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 let content = match css with | Global -> PGSQL(dbh) "select css from hosts where id = $hostid" | Ie6_fixes -> PGSQL(dbh) "select ie6_fixes_css from hosts where id = $hostid" | Ie7_fixes -> PGSQL(dbh) "select ie7_fixes_css from hosts where id = $hostid" in let content = match content with | [Some c] -> c | _ -> "" in template#set "css" (string_of_stylesheet css); template#set "content" content; q#template template let () = register_script ~restrict:[CanEditGlobalCSS] run