Modified all scripts with appropriate restrictions based on
[cocanwiki.git] / scripts / delete_image_form.ml
1 (* COCANWIKI scripts.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: delete_image_form.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
5  *)
6
7 open Apache
8 open Registry
9 open Cgi
10 open Printf
11
12 open Cocanwiki
13 open Cocanwiki_template
14
15 let template = get_template "delete_image_form.html"
16
17 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
18   let id = int_of_string (q#param "id") in
19
20   let sth = dbh#prepare_cached "select name, width, height, alt
21                                   from images
22                                  where hostid = ? and id = ?" in
23   sth#execute [`Int hostid; `Int id];
24
25   let name, width, height, alt =
26     match sth#fetch1 () with
27         [ `String name; `Int width; `Int height; `String alt] ->
28           name, width, height, alt
29       | _ -> assert false in
30
31   template#set "id" (string_of_int id);
32   template#set "name" name;
33   template#set "width" (string_of_int width);
34   template#set "height" (string_of_int height);
35   template#set "alt" alt;
36
37   q#template template
38
39 let () =
40   register_script ~restrict:[CanEdit] run