2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: images.ml,v 1.2 2004/09/07 13:40:10 rich Exp $
15 open Cocanwiki_template
17 let template = get_template "images.html"
19 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
20 let deleted = q#param_true "deleted" in
21 template#conditional "deleted" deleted;
24 "select id, name, name_deleted, width, height, alt, octet_length (image),
27 where hostid = ? and " ^
28 (if not deleted then "name is not null"
29 else "name_deleted is not null") ^
31 let sth = dbh#prepare_cached sql in
32 sth#execute [`Int hostid];
37 let id, name, width, height, alt, size, tn_width, tn_height,
38 is_deleted, has_thumbnail =
40 | [`Int id; `String name; `Null; `Int width; `Int height;
41 `String alt; `Int size; `Int tn_width; `Int tn_height] ->
42 id, name, width, height, alt, size, tn_width, tn_height,
44 | [`Int id; `Null; `String name; `Int width; `Int height;
45 `String alt; `Int size; `Int tn_width; `Int tn_height] ->
46 id, name, width, height, alt, size, tn_width, tn_height,
48 | [`Int id; `String name; `Null; `Int width; `Int height;
49 `String alt; `Int size; `Null; `Null] ->
50 id, name, width, height, alt, size, 0, 0,
52 | [`Int id; `Null; `String name; `Int width; `Int height;
53 `String alt; `Int size; `Null; `Null] ->
54 id, name, width, height, alt, size, 0, 0,
56 | _ -> assert false in
57 [ "id", Template.VarString (string_of_int id);
58 "name", Template.VarString name;
59 "width", Template.VarString (string_of_int width);
60 "height", Template.VarString (string_of_int height);
61 "alt", Template.VarString alt;
62 "ksize", Template.VarString (string_of_int (size / 1024));
63 "tn_width", Template.VarString (string_of_int tn_width);
64 "tn_height", Template.VarString (string_of_int tn_height);
65 "is_deleted", Template.VarConditional is_deleted;
66 "has_thumbnail", Template.VarConditional has_thumbnail ]) in
68 template#table "images" table;