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