2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: images.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
13 open Cocanwiki_template
15 let template = get_template "images.html"
17 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
18 let deleted = q#param_true "deleted" in
19 template#conditional "deleted" deleted;
22 "select id, name, name_deleted, width, height, alt, octet_length (image),
25 where hostid = ? and " ^
26 (if not deleted then "name is not null"
27 else "name_deleted is not null") ^
29 let sth = dbh#prepare_cached sql in
30 sth#execute [`Int hostid];
35 let id, name, width, height, alt, size, tn_width, tn_height,
36 is_deleted, has_thumbnail =
38 | [`Int id; `String name; `Null; `Int width; `Int height;
39 `String alt; `Int size; `Int tn_width; `Int tn_height] ->
40 id, name, width, height, alt, size, tn_width, tn_height,
42 | [`Int id; `Null; `String name; `Int width; `Int height;
43 `String alt; `Int size; `Int tn_width; `Int tn_height] ->
44 id, name, width, height, alt, size, tn_width, tn_height,
46 | [`Int id; `String name; `Null; `Int width; `Int height;
47 `String alt; `Int size; `Null; `Null] ->
48 id, name, width, height, alt, size, 0, 0,
50 | [`Int id; `Null; `String name; `Int width; `Int height;
51 `String alt; `Int size; `Null; `Null] ->
52 id, name, width, height, alt, size, 0, 0,
54 | _ -> assert false in
55 [ "id", Template.VarString (string_of_int id);
56 "name", Template.VarString name;
57 "width", Template.VarString (string_of_int width);
58 "height", Template.VarString (string_of_int height);
59 "alt", Template.VarString alt;
60 "ksize", Template.VarString (string_of_int (size / 1024));
61 "tn_width", Template.VarString (string_of_int tn_width);
62 "tn_height", Template.VarString (string_of_int tn_height);
63 "is_deleted", Template.VarConditional is_deleted;
64 "has_thumbnail", Template.VarConditional has_thumbnail ]) in
66 template#table "images" table;
71 register_script ~restrict:[CanEdit] run