Global settings display.
[cocanwiki.git] / scripts / host_menu.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: host_menu.ml,v 1.1 2004/09/22 11:41:03 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 "host_menu.html" in
32
33   (* Get lots of host-specific stuff from the database. *)
34   let sth =
35     dbh#prepare_cached
36       "select h.canonical_hostname, h.css is not null, h.edit_anon,
37               h.create_account_anon, h.theme_css is not null,
38               t.name, t.description, h.feedback_email
39          from hosts h left outer join themes t on h.theme_css = t.theme_css
40         where h.id = ?" in
41   sth#execute [`Int hostid];
42
43   let canonical_hostname, has_global_css, edit_anon, create_account_anon,
44       has_theme_css, theme_name, theme_description, has_feedback_email,
45       feedback_email =
46     match sth#fetch1 () with
47         [ `String canonical_hostname; `Bool has_global_css;
48           `Bool edit_anon; `Bool create_account_anon; `Bool has_theme_css;
49           (`String _ | `Null) as theme_name;
50           (`String _ | `Null) as theme_description;
51           (`String _ | `Null) as feedback_email ] ->
52           let theme_name =
53             match theme_name with `String s -> s | `Null -> "" in
54           let theme_description =
55             match theme_description with `String s -> s | `Null -> "" in
56           let feedback_email, has_feedback_email =
57             match feedback_email with
58                 `String s -> s, true
59               | `Null -> "", false in
60           canonical_hostname, has_global_css, edit_anon, create_account_anon,
61           has_theme_css, theme_name, theme_description, has_feedback_email,
62           feedback_email
63       | _ -> assert false in
64
65   template#set "canonical_hostname" canonical_hostname;
66   template#conditional "has_global_css" has_global_css;
67   template#conditional "edit_anon" edit_anon;
68   template#conditional "create_account_anon" create_account_anon;
69   template#conditional "has_theme_css" has_theme_css;
70   template#set "theme_name" theme_name;
71   template#set "theme_description" theme_description;
72   template#conditional "has_feedback_email" has_feedback_email;
73   template#set "feedback_email" feedback_email;
74
75   q#template template
76
77 let () =
78   register_script ~restrict:[CanManageSite] run