Serial columns now 64 bits.
[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.6 2004/11/03 13:36:45 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 : Dbi.connection) hostid _ _ =
31   let template = get_template dbh hostid "edit_host_settings_form.html" in
32
33   (* List of themes. *)
34   let sth = dbh#prepare_cached "select theme_css, name, description
35                                   from themes order by 2, 1" in
36   sth#execute [];
37
38   let themes =
39     sth#map (function [`String theme_css; `String name; `String description] ->
40                theme_css, (name, description)
41                | _ -> assert false) in
42
43   (* Get lots of host-specific stuff from the database. *)
44   let sth =
45     dbh#prepare_cached
46       "select canonical_hostname, edit_anon, create_account_anon, theme_css,
47               feedback_email, mailing_list, search_box, navigation, view_anon,
48               coalesce (brand, ''), coalesce (brand_tagline, ''),
49               coalesce (brand_description, '')
50          from hosts where id = ?" in
51   sth#execute [`Int hostid];
52
53   let canonical_hostname, edit_anon, create_account_anon, theme_css,
54       feedback_email, mailing_list, search_box, navigation, view_anon,
55       brand, brand_tagline, brand_description =
56     match sth#fetch1 () with
57         [ `String canonical_hostname;
58           `Bool edit_anon; `Bool create_account_anon;
59           (`String _ | `Null) as theme_css;
60           (`String _ | `Null) as feedback_email;
61           `Bool mailing_list; `Bool search_box; `Bool navigation;
62           `Bool view_anon;
63           `String brand; `String brand_tagline; `String brand_description ] ->
64           let theme_css =
65             match theme_css with `String s -> s | `Null -> "" in
66           let feedback_email =
67             match feedback_email with `String s -> s | `Null -> "" in
68           canonical_hostname, edit_anon, create_account_anon, theme_css,
69           feedback_email, mailing_list, search_box, navigation, view_anon,
70           brand, brand_tagline, brand_description
71       | _ -> assert false in
72
73   template#set "canonical_hostname" canonical_hostname;
74   template#conditional "edit_anon" edit_anon;
75   template#conditional "create_account_anon" create_account_anon;
76   template#set "feedback_email" feedback_email;
77   template#conditional "mailing_list" mailing_list;
78   template#conditional "search_box" search_box;
79   template#conditional "navigation" navigation;
80   template#conditional "view_anon" view_anon;
81   template#set "brand" brand;
82   template#set "brand_tagline" brand_tagline;
83   template#set "brand_description" brand_description;
84
85   (* Themes table. *)
86   let table =
87     List.map (fun (css, (name, description)) ->
88                 let selected = css = theme_css in
89                 [ "theme_css", Template.VarString css;
90                   "name", Template.VarString name;
91                   "description", Template.VarString description;
92                   "selected", Template.VarConditional selected ]) themes in
93   template#table "themes" table;
94
95   q#template template
96
97 let () =
98   register_script ~restrict:[CanManageSite] run