+csv dep for PG'OCaml.
[cocanwiki.git] / scripts / edit_host_settings_form.ml
1 (* COCANWIKI - a wiki written in Objective CAML.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: edit_host_settings_form.ml,v 1.10 2006/12/06 09:46:57 rich Exp $
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; see the file COPYING.  If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *)
21
22 open Apache
23 open Registry
24 open Cgi
25 open Printf
26
27 open Cocanwiki
28 open Cocanwiki_template
29
30 let run r (q : cgi) dbh hostid _ _ =
31   let template = get_template r dbh hostid "edit_host_settings_form.html" in
32
33   (* List of themes. *)
34   let rows =
35     PGSQL(dbh) "select theme_css, name, description
36                   from themes order by 2, 1" in
37
38   let themes =
39     List.map (fun (theme_css, name, description) ->
40                 theme_css, (name, description)) rows in
41
42   (* Get lots of host-specific stuff from the database. *)
43   let rows =
44     PGSQL(dbh)
45       "select canonical_hostname, edit_anon, create_account_anon, theme_css,
46               feedback_email, mailing_list, search_box, navigation, view_anon,
47               brand, brand_tagline, brand_description, ie_imagetoolbar_no,
48               global_noodp
49          from hosts where id = $hostid" in
50
51   let canonical_hostname, edit_anon, create_account_anon, theme_css,
52       feedback_email, mailing_list, search_box, navigation, view_anon,
53       brand, brand_tagline, brand_description, ie_imagetoolbar_no,
54       global_noodp =
55     match rows with
56     | [canonical_hostname, edit_anon, create_account_anon, theme_css,
57        feedback_email, mailing_list, search_box, navigation, view_anon,
58        brand, brand_tagline, brand_description, ie_imagetoolbar_no,
59        global_noodp ] ->
60         let theme_css =
61           match theme_css with Some s -> s | None -> "" in
62         let feedback_email =
63           match feedback_email with Some s -> s | None -> "" in
64         let brand =
65           match brand with Some s -> s | None -> "" in
66         let brand_tagline =
67           match brand_tagline with Some s -> s | None -> "" in
68         let brand_description =
69           match brand_description with Some s -> s | None -> "" in
70         canonical_hostname, edit_anon, create_account_anon, theme_css,
71         feedback_email, mailing_list, search_box, navigation, view_anon,
72         brand, brand_tagline, brand_description, ie_imagetoolbar_no,
73         global_noodp
74     | _ -> assert false in
75
76   template#set "canonical_hostname" canonical_hostname;
77   template#conditional "edit_anon" edit_anon;
78   template#conditional "create_account_anon" create_account_anon;
79   template#set "feedback_email" feedback_email;
80   template#conditional "mailing_list" mailing_list;
81   template#conditional "search_box" search_box;
82   template#conditional "ie_imagetoolbar_no" ie_imagetoolbar_no;
83   template#conditional "global_noodp" global_noodp;
84   template#conditional "navigation" navigation;
85   template#conditional "view_anon" view_anon;
86   template#set "brand" brand;
87   template#set "brand_tagline" brand_tagline;
88   template#set "brand_description" brand_description;
89
90   (* Themes table. *)
91   let table =
92     List.map (fun (css, (name, description)) ->
93                 let selected = css = theme_css in
94                 [ "theme_css", Template.VarString css;
95                   "name", Template.VarString name;
96                   "description", Template.VarString description;
97                   "selected", Template.VarConditional selected ]) themes in
98   template#table "themes" table;
99
100   q#template template
101
102 let () =
103   register_script ~restrict:[CanManageSite] run